From 81f179af49133f6d72cc74f100300a0d22e23ea3 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Tue, 29 Jun 2021 12:26:30 -0400 Subject: [PATCH] Misc fixes --- functions.h | 1 + main.cpp | 21 +++++++++------ mainwindow.cpp | 2 +- reader.cpp | 69 +++++++++++++++++++++++++++++++++++++++++--------- reader.h | 2 ++ 5 files changed, 74 insertions(+), 21 deletions(-) diff --git a/functions.h b/functions.h index ddf28ec..1b1b01a 100644 --- a/functions.h +++ b/functions.h @@ -26,6 +26,7 @@ namespace global { inline int bookNumber; inline bool skipOpenDialog; inline bool startBatteryWatchdog; + inline bool startUsbmsPrompt; inline bool bookIsEpub; } namespace kobox { diff --git a/main.cpp b/main.cpp index 747acb3..c81b96a 100644 --- a/main.cpp +++ b/main.cpp @@ -33,6 +33,10 @@ int main(int argc, char *argv[]) // Tell scripts that we're currently running string_writeconfig("/tmp/inkbox_running", "true"); + // Variables + global::reader::startBatteryWatchdog = false; + global::reader::startUsbmsPrompt = false; + // Checking if battery level is critical; if true (and if it is not charging), then display a "Please charge your eReader" splash and power off. if(isBatteryCritical() == true) { string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status"); @@ -62,18 +66,12 @@ int main(int argc, char *argv[]) return a.exec(); } // 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) { + 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::reader::startBatteryWatchdog = true; + global::reader::startUsbmsPrompt = true; global::reader::skipOpenDialog = true; - if(checkconfig("/inkbox/bookIsEpub") == true) { - global::reader::bookIsEpub = true; - } - else { - global::reader::bookIsEpub = false; - } - string_writeconfig("/inkbox/skip_opendialog", "true"); string_checkconfig_ro("/opt/inkbox_device"); if(checkconfig_str_val == "n705\n") { @@ -105,6 +103,13 @@ int main(int argc, char *argv[]) } else { + if(checkconfig("/inkbox/bookIsEpub") == true) { + global::reader::bookIsEpub = true; + } + else { + global::reader::bookIsEpub = false; + } + QApplication a(argc, argv); MainWindow w; diff --git a/mainwindow.cpp b/mainwindow.cpp index 22b0a47..0adfd3d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -312,7 +312,7 @@ MainWindow::MainWindow(QWidget *parent) // USB mass storage prompt QTimer *usbmsPrompt = new QTimer(this); - usbmsPrompt->setInterval(2000); + usbmsPrompt->setInterval(500); connect(usbmsPrompt, &QTimer::timeout, [&]() { if(checkconfig("/opt/inkbox_genuine") == true) { if(global::usbms::showUsbmsDialog != true) { diff --git a/reader.cpp b/reader.cpp index d62b9ac..4d05fc5 100644 --- a/reader.cpp +++ b/reader.cpp @@ -344,17 +344,10 @@ reader::reader(QWidget *parent) : writeconfig_pagenumber(); } else { - // TEMPORARY [ - if(global::reader::bookIsEpub == true) { - quit_restart(); - } - // TEMPORARY ] - else { - // Retrieve split_total from tmpfs - string_checkconfig("/tmp/inkboxPageNumber"); - split_total = checkconfig_str_val.toInt(); - setup_book(book_file, 0, true); - } + // Retrieve split_total from tmpfs + string_checkconfig("/tmp/inkboxPageNumber"); + split_total = checkconfig_str_val.toInt(); + setup_book(book_file, 0, true); } // Get text; no need to do it multiple times for ePUB books @@ -472,7 +465,14 @@ reader::reader(QWidget *parent) : ui->bookInfoLabel->setText(infoLabelContent); } else { - QString bookReadRelativePath = book_file.split("/").last(); + QString bookReadRelativePath; + if(wakeFromSleep == true) { + string_checkconfig_ro("/tmp/inkboxBookPath"); + bookReadRelativePath = checkconfig_str_val.split("/").last(); + } + else { + bookReadRelativePath = book_file.split("/").last(); + } ui->bookInfoLabel->setText(bookReadRelativePath); } @@ -519,6 +519,39 @@ reader::reader(QWidget *parent) : string_writeconfig(".config/08-recent_books/4", str_book_3); } + // USB mass storage prompt + if(global::reader::startUsbmsPrompt == true) { + QTimer *usbmsPrompt = new QTimer(this); + usbmsPrompt->setInterval(500); + connect(usbmsPrompt, &QTimer::timeout, [&]() { + if(checkconfig("/opt/inkbox_genuine") == true) { + if(global::usbms::showUsbmsDialog != true) { + string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status"); + if(usbmsStatus != checkconfig_str_val) { + global::usbms::showUsbmsDialog = true; + } + } + else { + string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status"); + usbmsStatus = checkconfig_str_val; + if(usbmsStatus != "Charging\n") { + // Loop again... + ; + } + else { + // An USB cable is connected! + openUsbmsDialog(); + } + } + } + else { + // Do nothing, we're running along with Nickel & friends... + ; + } + } ); + usbmsPrompt->start(); + } + // Battery watchdog if(global::reader::startBatteryWatchdog == true) { QTimer *t = new QTimer(this); @@ -691,9 +724,11 @@ bool reader::epub_file_match(QString file) { QString fileExt = file.right(4); if(fileExt == "epub" or fileExt == "EPUB") { + string_writeconfig("/inkbox/bookIsEpub", "true"); return true; } else { + string_writeconfig("/inkbox/bookIsEpub", "false"); return false; } } @@ -1412,3 +1447,13 @@ void reader::on_nightModeBtn_clicked() isNightModeActive = true; } } + +void reader::openUsbmsDialog() { + global::usbms::showUsbmsDialog = false; + global::usbms::usbmsDialog = true; + + generalDialogWindow = new generalDialog(this); + generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); + generalDialogWindow->show(); + QApplication::processEvents(); +} diff --git a/reader.h b/reader.h index d13d073..54e5f82 100644 --- a/reader.h +++ b/reader.h @@ -74,6 +74,7 @@ public: QPixmap scaledEmptyPixmap; QList content; QString epubPageContent; + QString usbmsStatus; int setup_book(QString book, int i, bool run_parser); void checkwords(); @@ -91,6 +92,7 @@ public: void setPageStyle(); void alignText(int alignment); void delay(int seconds); + void openUsbmsDialog(); private slots: void on_nextBtn_clicked();