From 6b8875272f997b9faa1dc9ceccfb70bd7b15b1b2 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sun, 5 Sep 2021 11:47:09 -0400 Subject: [PATCH] Open book file from local storage search in Reader --- functions.h | 1 + main.cpp | 5 +++-- mainwindow.cpp | 25 ++++++++++--------------- mainwindow.h | 1 + reader.cpp | 11 ++++++++--- reader.h | 5 ++++- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/functions.h b/functions.h index fde351c..d9cd9dd 100644 --- a/functions.h +++ b/functions.h @@ -94,6 +94,7 @@ namespace global { inline bool isN905C; inline bool isN613; inline bool isN873; + inline bool runningInstanceIsReaderOnly; } // https://stackoverflow.com/questions/6080853/c-multiple-definition-error-for-global-functions-in-the-header-file/20679534#20679534 diff --git a/main.cpp b/main.cpp index be25490..d9c6357 100644 --- a/main.cpp +++ b/main.cpp @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); alert w; - const QScreen* screen = qApp->primaryScreen(); + const QScreen * screen = qApp->primaryScreen(); w.setGeometry(QRect(QPoint(0,0), screen->geometry().size())); w.show(); return a.exec(); @@ -68,6 +68,7 @@ int main(int argc, char *argv[]) // If we're waking from sleep and we have the lockscreen enabled, we'll "resume" the book from scratch else if(checkconfig("/tmp/suspendBook") == true && checkconfig("/inkbox/bookIsEpub") == false) { // Start the low/critical battery alert timer from the Reader framework since MainWindow is not going to be shown + global::runningInstanceIsReaderOnly = true; global::reader::startBatteryWatchdog = true; global::reader::startUsbmsPrompt = true; global::reader::skipOpenDialog = true; @@ -154,7 +155,7 @@ int main(int argc, char *argv[]) ; } - const QScreen* screen = qApp->primaryScreen(); + const QScreen * screen = qApp->primaryScreen(); w.setGeometry(QRect(QPoint(0,0), screen->geometry ().size())); w.show(); return a.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 42bbece..e783750 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -643,9 +643,7 @@ void MainWindow::on_appsBtn_clicked() void MainWindow::on_pushButton_clicked() { - readerWindow = new reader(); - readerWindow->setAttribute(Qt::WA_DeleteOnClose); - readerWindow->showFullScreen(); + openReaderFramework(); } void MainWindow::on_searchBtn_clicked() @@ -666,9 +664,7 @@ void MainWindow::on_book1Btn_clicked() global::reader::skipOpenDialog = true; global::reader::bookNumber = 1; - readerWindow = new reader(); - readerWindow->setAttribute(Qt::WA_DeleteOnClose); - readerWindow->showFullScreen(); + openReaderFramework(); } void MainWindow::on_book2Btn_clicked() @@ -676,9 +672,7 @@ void MainWindow::on_book2Btn_clicked() global::reader::skipOpenDialog = true; global::reader::bookNumber = 2; - readerWindow = new reader(); - readerWindow->setAttribute(Qt::WA_DeleteOnClose); - readerWindow->showFullScreen(); + openReaderFramework(); } void MainWindow::on_book3Btn_clicked() @@ -686,9 +680,7 @@ void MainWindow::on_book3Btn_clicked() global::reader::skipOpenDialog = true; global::reader::bookNumber = 3; - readerWindow = new reader(); - readerWindow->setAttribute(Qt::WA_DeleteOnClose); - readerWindow->showFullScreen(); + openReaderFramework(); } void MainWindow::on_book4Btn_clicked() @@ -696,9 +688,7 @@ void MainWindow::on_book4Btn_clicked() global::reader::skipOpenDialog = true; global::reader::bookNumber = 4; - readerWindow = new reader(); - readerWindow->setAttribute(Qt::WA_DeleteOnClose); - readerWindow->showFullScreen(); + openReaderFramework(); } void MainWindow::on_brightnessBtn_clicked() @@ -1011,7 +1001,12 @@ void MainWindow::openBookFile(QString book, bool relativePath) { global::reader::skipOpenDialog = true; global::reader::bookFile = book; + openReaderFramework(); +} + +void MainWindow::openReaderFramework() { readerWindow = new reader(); readerWindow->setAttribute(Qt::WA_DeleteOnClose); + connect(readerWindow, SIGNAL(openBookFile(QString, bool)), SLOT(openBookFile(QString, bool))); readerWindow->showFullScreen(); } diff --git a/mainwindow.h b/mainwindow.h index c1dcc9a..b6c5414 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -86,6 +86,7 @@ private slots: void openUpdateDialogOTA(bool open); void launchOtaUpdater(); void openBookFile(QString book, bool relativePath); + void openReaderFramework(); private: Ui::MainWindow *ui; diff --git a/reader.cpp b/reader.cpp index 9fb9d4a..6a6a05b 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1856,7 +1856,7 @@ void reader::setupSearchDialog() { generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); connect(generalDialogWindow, SIGNAL(refreshScreen()), SLOT(searchRefreshScreen())); connect(generalDialogWindow, SIGNAL(destroyed(QObject*)), SLOT(setupSearchDialog())); - connect(generalDialogWindow, SIGNAL(openBookFile(QString, bool)), SLOT(openBookFile(QString, bool))); + connect(generalDialogWindow, SIGNAL(openBookFile(QString, bool)), SLOT(openBookFileNative(QString, bool))); connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString))); generalDialogWindow->show(); } @@ -2062,6 +2062,11 @@ void reader::on_increaseScaleBtn_clicked() } } -void reader::openBookFile(QString book, bool relativePath) { - qDebug() << "Open book:" << book; +void reader::openBookFileNative(QString book, bool relativePath) { + if(global::runningInstanceIsReaderOnly == false) { + emit openBookFile(book, relativePath); + } + else { + showToast("Not supported"); + } } diff --git a/reader.h b/reader.h index 2c58f46..dc96eef 100644 --- a/reader.h +++ b/reader.h @@ -119,7 +119,6 @@ public: void setBitterFont(); void setCrimsonProFont(); void setIbarraFont(); - void showToast(QString messageToDisplay); bool pdf_file_match(QString file); private slots: @@ -156,6 +155,10 @@ private slots: void on_pdfScaleSlider_valueChanged(int value); void on_decreaseScaleBtn_clicked(); void on_increaseScaleBtn_clicked(); + void openBookFileNative(QString book, bool relativePath); + void showToast(QString messageToDisplay); + +signals: void openBookFile(QString book, bool relativePath); private: