From 7d25c6bbcdb38afdfbcd4f015593ec332184a04a Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sat, 16 Apr 2022 19:40:30 -0400 Subject: [PATCH] Improve testPing; support landscape PDFs --- encryptionmanager.cpp | 1 + functions.h | 98 +++++++++++++++++++++++++++++++++---------- generaldialog.cpp | 2 +- main.cpp | 8 ++++ mainwindow.cpp | 16 +++---- reader.cpp | 28 +++++++++++++ reader.h | 3 ++ 7 files changed, 126 insertions(+), 30 deletions(-) diff --git a/encryptionmanager.cpp b/encryptionmanager.cpp index a4c8a1a..34a5e46 100644 --- a/encryptionmanager.cpp +++ b/encryptionmanager.cpp @@ -278,6 +278,7 @@ void encryptionManager::unlockEncryptedStorage() { } } else { + log("Unlocking successful", className); quit_restart(); } } diff --git a/functions.h b/functions.h index 9af4b01..85ea8e5 100644 --- a/functions.h +++ b/functions.h @@ -35,6 +35,7 @@ namespace global { inline bool startUsbmsPrompt; inline bool bookIsEpub; inline bool globalReadingSettings; + inline int pdfOrientation; } namespace kobox { inline bool showKoboxSplash; @@ -582,20 +583,44 @@ namespace { } else if(fileType == 1) { if(global::deviceID == "n705\n" or global::deviceID == "n905\n") { - defaultPdfPageHeight = 750; - defaultPdfPageWidth = 550; + if(global::reader::pdfOrientation == 0) { + defaultPdfPageHeight = 750; + defaultPdfPageWidth = 550; + } + else { + defaultPdfPageHeight = 550; + defaultPdfPageWidth = 750; + } } else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n" or global::deviceID == "emu\n") { - defaultPdfPageHeight = 974; - defaultPdfPageWidth = 708; + if(global::reader::pdfOrientation == 0) { + defaultPdfPageHeight = 974; + defaultPdfPageWidth = 708; + } + else { + defaultPdfPageHeight = 708; + defaultPdfPageWidth = 974; + } } else if(global::deviceID == "n437\n") { - defaultPdfPageHeight = 1398; - defaultPdfPageWidth = 1022; + if(global::reader::pdfOrientation == 0) { + defaultPdfPageHeight = 1398; + defaultPdfPageWidth = 1022; + } + else { + defaultPdfPageHeight = 1022; + defaultPdfPageWidth = 1398; + } } else if(global::deviceID == "n873\n") { - defaultPdfPageHeight = 1630; - defaultPdfPageWidth = 1214; + if(global::reader::pdfOrientation == 0) { + defaultPdfPageHeight = 1630; + defaultPdfPageWidth = 1214; + } + else { + defaultPdfPageHeight = 1214; + defaultPdfPageWidth = 1630; + } } QString function = __func__; log(function + "Defined default PDF page height to " + QString::number(defaultPdfPageHeight), "functions"); @@ -619,7 +644,9 @@ namespace { * 1: Bring DOWN brightness * 2: Auto; smooth brightness transition between two brightness levels */ - QString function = __func__; log(function + ": Setting brightness to " + QString::number(value), "functions"); + if(global::deviceID != "n705\n" && global::deviceID != "n905\n") { + QString function = __func__; log(function + ": Setting brightness to " + QString::number(value), "functions"); + } if(mode == 0) { int brightness = 0; while(brightness != value) { @@ -655,7 +682,7 @@ namespace { } } bool connectToNetwork(QString essid, QString passphrase) { - log("Connecting to network " + essid, "functions"); + log("Connecting to network '" + essid + "'", "functions"); std::string essid_str = essid.toStdString(); std::string passphrase_str = passphrase.toStdString(); string_writeconfig("/run/wifi_network_essid", essid_str); @@ -730,19 +757,48 @@ namespace { close(ntxfd); return !!ptr; } - int testPing() { - QString pingProg = "ping"; - QStringList pingArgs; - pingArgs << "-c" << "1" << "1.1.1.1"; + int testPing(bool blocking) { QProcess *pingProcess = new QProcess(); - pingProcess->start(pingProg, pingArgs); - pingProcess->waitForFinished(); - int exitCode = pingProcess->exitCode(); - pingProcess->deleteLater(); - if(exitCode == 0) { - global::network::isConnected = true; + if(blocking == true) { + QString pingProg = "ping"; + QStringList pingArgs; + pingArgs << "-c" << "1" << "1.1.1.1"; + pingProcess->start(pingProg, pingArgs); + pingProcess->waitForFinished(); + int exitCode = pingProcess->exitCode(); + pingProcess->deleteLater(); + if(exitCode == 0) { + global::network::isConnected = true; + } + else { + global::network::isConnected = false; + } + return exitCode; + } + else { + QString pingProg = "sh"; + QStringList pingArgs; + pingArgs << "/mnt/onboard/.adds/inkbox/test_ping.sh"; + pingProcess->startDetached(pingProg, pingArgs); + } + pingProcess->deleteLater(); + } + bool getTestPingResults() { + // To be used when the testPing() function is used in non-blocking mode. + if(QFile::exists("/run/test_ping_status")) { + if(checkconfig("/run/test_ping_status") == true) { + global::network::isConnected = true; + return true; + } + else { + global::network::isConnected = false; + return false; + } + } + else { + global::network::isConnected = false; + return false; } - return exitCode; } } diff --git a/generaldialog.cpp b/generaldialog.cpp index 6b5bcad..3d86b44 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -387,7 +387,7 @@ void generalDialog::on_okBtn_clicked() } } else if(ui->searchComboBox->currentText() == "Online library") { - if(testPing() == 0 or global::deviceID == "emu\n") { + if(testPing(true) == 0 or global::deviceID == "emu\n") { string_writeconfig("/inkbox/searchComboBoxFunction", "Online library"); log("Searching online library for '" + global::keyboard::keyboardText + "'", className); diff --git a/main.cpp b/main.cpp index 46d8092..41756ce 100644 --- a/main.cpp +++ b/main.cpp @@ -39,6 +39,14 @@ int main(int argc, char *argv[]) log("Running on device " + global::deviceID, "main"); setDefaultWorkDir(); + if(checkconfig("/run/wifi_able") == true) { + log("Device has Wi-Fi capabilities", "main"); + global::device::isWifiAble = true; + } + else { + log("Device does not have Wi-Fi capabilities", "main"); + global::device::isWifiAble = false; + } if(checkconfig(".config/18-encrypted_storage/status") == true and checkconfig("/external_root/run/encfs_mounted") == false) { // Open Encryption Manager to unlock encrypted storage QApplication a(argc, argv); diff --git a/mainwindow.cpp b/mainwindow.cpp index 4236e94..f0061cc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -904,8 +904,8 @@ void MainWindow::refreshScreen() { } void MainWindow::setupSearchDialog() { - log("Launching Search dialog", className); if(global::forbidOpenSearchDialog == false) { + log("Launching Search dialog", className); global::keyboard::keyboardDialog = true; global::keyboard::searchDialog = true; global::keyboard::keyboardText = ""; @@ -933,7 +933,7 @@ void MainWindow::updateWifiIcon(int mode) { if(mode == 0) { lastWifiState = 0; QTimer *wifiIconTimer = new QTimer(this); - wifiIconTimer->setInterval(1000); + wifiIconTimer->setInterval(10000); connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(setWifiIcon())); wifiIconTimer->start(); } @@ -975,10 +975,11 @@ bool MainWindow::checkWifiState() { } void MainWindow::setWifiIcon() { - if(checkconfig("/run/wifi_able") == true) { - global::device::isWifiAble = true; + if(global::device::isWifiAble == true) { if(checkWifiState() == true) { - if(testPing() == 0) { + testPing(false); + getTestPingResults(); + if(global::network::isConnected == true) { if(lastWifiState != 3) { lastWifiState = 3; ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png")); @@ -1002,7 +1003,6 @@ void MainWindow::setWifiIcon() { } } else { - global::device::isWifiAble = false; ui->wifiBtn->hide(); ui->line_9->hide(); } @@ -1061,8 +1061,8 @@ void MainWindow::closeIndefiniteToast() { } void MainWindow::openUpdateDialogOTA(bool open) { - QString function = __func__; log(function + ": Showing update dialog (OTA)", className); if(open == true) { + QString function = __func__; log(function + ": Showing update dialog (OTA)", className); global::otaUpdate::isUpdateOta = true; openUpdateDialog(); } @@ -1130,7 +1130,7 @@ void MainWindow::openEncfsRepackDialog() { void MainWindow::on_libraryButton_clicked() { log("Launching Online Library", className); - if(testPing() == 0 or global::deviceID == "emu\n") { + if(testPing(true) == 0 or global::deviceID == "emu\n") { resetFullWindowException = false; resetWindow(false); if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) { diff --git a/reader.cpp b/reader.cpp index 64f29cf..74b55dc 100644 --- a/reader.cpp +++ b/reader.cpp @@ -36,6 +36,7 @@ reader::reader(QWidget *parent) : mupdf::convertRelativeValues = false; wordwidgetLock = false; goToSavedPageDone = false; + initialPdfRotationDone = false; ui->setupUi(this); ui->brightnessStatus->setFont(QFont("u001")); @@ -795,6 +796,7 @@ int reader::setup_book(QString book, int i, bool run_parser) { is_epub = true; } else if(pdf_file_match(book) == true) { + getPdfOrientation(book); QString pdfProg("/usr/local/bin/mutool"); QStringList pdfArgs; convertMuPdfVars(1, true); @@ -2103,6 +2105,12 @@ void reader::setupPng() { graphicsScene->setSceneRect(rect); ui->graphicsView->items().clear(); ui->graphicsView->setScene(graphicsScene); + if(global::reader::pdfOrientation == 1) { + if(!initialPdfRotationDone) { + ui->graphicsView->rotate(270); + initialPdfRotationDone = true; + } + } } else if(is_image == true) { QPixmap pixmap("/run/image.png"); @@ -2249,3 +2257,23 @@ void reader::closeIndefiniteToast() { // Warning: use with caution toastWindow->close(); } + +void reader::getPdfOrientation(QString file) { + log("Getting viewport orientation for PDF file '" + file + "'", className); + string_writeconfig("/inkbox/pdf_orientation_file_request", file.toStdString()); + string_writeconfig("/opt/ibxd", "get_pdf_orientation\n"); + while(true) { + if(QFile::exists("/inkbox/pdf_orientation_result")) { + QString result = readFile("/inkbox/pdf_orientation_result").trimmed(); + if(result == "Portrait") { + QString function = __func__; log(function + ": Orientation is portrait", className); + global::reader::pdfOrientation = 0; + } + else { + QString function = __func__; log(function + ": Orientation is landscape", className); + global::reader::pdfOrientation = 1; + } + break; + } + } +} diff --git a/reader.h b/reader.h index 71278e1..9007b34 100644 --- a/reader.h +++ b/reader.h @@ -97,6 +97,8 @@ public: QString usbmsStatus; int pageNumberInt; int totalPagesInt; + int pdfOrientation; + bool initialPdfRotationDone; int setup_book(QString book, int i, bool run_parser); void checkwords(); @@ -162,6 +164,7 @@ private slots: void showToast(QString messageToDisplay); void on_quitBtn_clicked(); void closeIndefiniteToast(); + void getPdfOrientation(QString file); signals: void openBookFile(QString book, bool relativePath);