Improve testPing; support landscape PDFs

This commit is contained in:
Nicolas Mailloux 2022-04-16 19:40:30 -04:00
parent 105b13cb86
commit 7d25c6bbcd
7 changed files with 126 additions and 30 deletions

View file

@ -278,6 +278,7 @@ void encryptionManager::unlockEncryptedStorage() {
}
}
else {
log("Unlocking successful", className);
quit_restart();
}
}

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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) {

View file

@ -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;
}
}
}

View file

@ -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);