From 7d03a5b0ff594218c06aa560990fcf76d9fbe213 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sat, 26 Jun 2021 10:09:51 -0400 Subject: [PATCH] Kobo Glo UI/brightness/DPI support --- alert.cpp | 7 +++++++ alert.h | 1 + brightnessdialog.cpp | 26 +++++++++++++++++++++++--- functions.h | 3 +++ main.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ mainwindow.cpp | 24 +++++++++++++++++++----- reader.cpp | 41 +++++++++++++++++++++++++++++++++++------ settings.cpp | 27 +++++++++++++++++++++++++-- 8 files changed, 153 insertions(+), 16 deletions(-) diff --git a/alert.cpp b/alert.cpp index 3eeebda..1b1f825 100644 --- a/alert.cpp +++ b/alert.cpp @@ -89,6 +89,7 @@ void alert::on_continueBtn_clicked() // We continue anyway and re-set the ALERT flag string_writeconfig("/external_root/boot/flags/ALERT", "false"); string_writeconfig("/external_root/boot/flags/ALERT_SIGN", "false"); + updateReset(); QProcess process; process.startDetached("inkbox", QStringList()); qApp->quit(); @@ -111,6 +112,7 @@ void alert::on_continue2Btn_clicked() { // We continue anyway and re-set the ALERT flag string_writeconfig("/external_root/boot/flags/ALERT", "false"); + updateReset(); if(signatureError == true) { string_writeconfig("/external_root/boot/flags/ALERT_SIGN", "false"); @@ -125,3 +127,8 @@ void alert::on_continue2Btn_clicked() qApp->quit(); } } + +void alert::updateReset() { + string_writeconfig("/mnt/onboard/onboard/.inkbox/can_really_update", "false"); + string_writeconfig("/mnt/onboard/onboard/.inkbox/can_update", "false"); +} diff --git a/alert.h b/alert.h index 3f75c88..fcc560a 100644 --- a/alert.h +++ b/alert.h @@ -19,6 +19,7 @@ public: bool signatureError = false; bool downgradeError = false; bool criticalBattery = false; + void updateReset(); private slots: void on_continueBtn_clicked(); diff --git a/brightnessdialog.cpp b/brightnessdialog.cpp index 52f40d2..d9883ba 100644 --- a/brightnessdialog.cpp +++ b/brightnessdialog.cpp @@ -19,7 +19,18 @@ brightnessDialog::brightnessDialog(QWidget *parent) : this->setStyleSheet(stylesheetFile.readAll()); stylesheetFile.close(); - int value = get_brightness(); + // I know, Mini and Touch don't have frontlights but that's a template to include others later... + int value; + if(global::isN705 == true or global::isN905C == true) { + value = get_brightness(); + } + else if(global::isN613 == true) { + setDefaultWorkDir(); + value = brightness_checkconfig(".config/03-brightness/config"); + } + else { + ; + } // Setting the slider to the appropriate position ui->horizontalSlider->setValue(value); @@ -52,7 +63,16 @@ brightnessDialog::brightnessDialog(QWidget *parent) : ui->brightnessLabel->setFont(QFont(crimson_bold)); // Saving current brightness value in case we want to go backwards - oldValue = get_brightness(); + if(global::isN705 == true or global::isN705 == true) { + oldValue = get_brightness(); + } + else if(global::isN613 == true) { + setDefaultWorkDir(); + oldValue = brightness_checkconfig(".config/03-brightness/config"); + } + else { + ; + } } brightnessDialog::~brightnessDialog() @@ -112,7 +132,7 @@ void brightnessDialog::pre_set_brightness(int brightnessValue) { deviceChecked = true; } - if(device == "n705\n" or device == "n905\n") { + if(global::isN705 == true or global::isN905C == true) { set_brightness(brightnessValue); } else { diff --git a/functions.h b/functions.h index a6e2a66..6581421 100644 --- a/functions.h +++ b/functions.h @@ -59,6 +59,9 @@ namespace global { inline QString textBrowserContents; } inline QString systemInfoText; + inline bool isN705; + inline bool isN905C; + inline bool isN613; } // 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 fc82862..9fb4336 100644 --- a/main.cpp +++ b/main.cpp @@ -72,6 +72,26 @@ int main(int argc, char *argv[]) } string_writeconfig("/inkbox/skip_opendialog", "true"); + device = checkDevice(); + if(device == "n705\n") { + global::isN705 = true; + global::isN905C = false; + global::isN613 = false; + } + else if(device == "n905\n") { + global::isN705 = false; + global::isN905C = true; + global::isN613 = false; + } + else if(device == "n613\n") { + global::isN705 = false; + global::isN905C = false; + global::isN613 = true; + } + else { + ; + } + QApplication a(argc, argv); reader w; @@ -91,6 +111,26 @@ int main(int argc, char *argv[]) w.setStyleSheet(stylesheetFile.readAll()); stylesheetFile.close(); + device = checkDevice(); + if(device == "n705\n") { + global::isN705 = true; + global::isN905C = false; + global::isN613 = false; + } + else if(device == "n905\n") { + global::isN705 = false; + global::isN905C = true; + global::isN613 = false; + } + else if(device == "n613\n") { + global::isN705 = false; + global::isN905C = false; + global::isN613 = true; + } + else { + ; + } + const QScreen* screen = qApp->primaryScreen(); w.setGeometry(QRect(QPoint(0,0), screen->geometry ().size())); w.show(); diff --git a/mainwindow.cpp b/mainwindow.cpp index d7a6ba5..b6d4c65 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -74,7 +74,7 @@ MainWindow::MainWindow(QWidget *parent) homeIconWidth = sW / 18; homeIconHeight = sW / 18; } - else { + else if(checkconfig_str_val == "n905\n") { stdIconWidth = sW / 14; stdIconHeight = sH / 14; brightnessIconWidth = sW / 26; @@ -82,6 +82,14 @@ MainWindow::MainWindow(QWidget *parent) homeIconWidth = sW / 20; homeIconHeight = sW / 20; } + else if(checkconfig_str_val == "n613\n") { + stdIconWidth = sW / 12.5; + stdIconHeight = sH / 12.5; + brightnessIconWidth = sW / 24.5; + brightnessIconHeight = sH / 24.5; + homeIconWidth = sW / 18.5; + homeIconHeight = sW / 18.5; + } // Setting icons up ui->pushButton->setIcon(QIcon(":/resources/book.png")); @@ -123,6 +131,9 @@ MainWindow::MainWindow(QWidget *parent) if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 1px; padding-right: 1px;"); } + else if(checkconfig_str_val == "n613\n") { + ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px;"); + } else { ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px;"); } @@ -692,14 +703,17 @@ void MainWindow::resetIcons() { void MainWindow::setBatteryIcon() { // Battery string_checkconfig_ro("/opt/inkbox_device"); - if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { - // Hide brightness controls; they won't be very useful there anyway... - ui->brightnessBtn->hide(); - ui->line_7->hide(); + if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n" or checkconfig_str_val == "n613\n") { + // Hide brightness controls; they won't be very useful there anyway (for anything but the Glo) ... + if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { + ui->brightnessBtn->hide(); + ui->line_7->hide(); + } // Setting icons up stdIconWidth = sW / 16; stdIconHeight = sH / 16; + QPixmap chargingPixmap(":/resources/battery_charging.png"); QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio); QPixmap fullPixmap(":/resources/battery_full.png"); diff --git a/reader.cpp b/reader.cpp index 7420b57..4f00301 100644 --- a/reader.cpp +++ b/reader.cpp @@ -155,7 +155,17 @@ reader::reader(QWidget *parent) : ui->bookInfoLabel->setFont(crimson); // Getting brightness level - int brightness_value = get_brightness(); + int brightness_value; + if(global::isN705 == true or global::isN905C == true) { + brightness_value = get_brightness(); + } + else if(global::isN613 == true) { + setDefaultWorkDir(); + brightness_value = brightness_checkconfig(".config/03-brightness/config"); + } + else { + ; + } ui->brightnessStatus->setValue(brightness_value); // Defining pixmaps @@ -810,24 +820,43 @@ void reader::on_hideOptionsBtn_clicked() void reader::on_brightnessDecBtn_clicked() { - int bval = get_brightness(); + int bval; + if(global::isN705 == true or global::isN905C == true) { + bval = get_brightness(); + } + else if(global::isN613 == true) { + setDefaultWorkDir(); + bval = brightness_checkconfig(".config/03-brightness/config"); + } + else { + ; + } int set_bval = bval - 1; pre_set_brightness(set_bval); brightness_writeconfig(set_bval); bval = get_brightness(); - ui->brightnessStatus->setValue(bval); + ui->brightnessStatus->setValue(set_bval); } void reader::on_brightnessIncBtn_clicked() { - int bval = get_brightness(); + int bval; + if(global::isN705 == true or global::isN905C == true) { + bval = get_brightness(); + } + else if(global::isN613 == true) { + setDefaultWorkDir(); + bval = brightness_checkconfig(".config/03-brightness/config"); + } + else { + ; + } int set_bval = bval + 1; pre_set_brightness(set_bval); brightness_writeconfig(set_bval); - bval = get_brightness(); - ui->brightnessStatus->setValue(bval); + ui->brightnessStatus->setValue(set_bval); } void reader::on_aboutBtn_clicked() diff --git a/settings.cpp b/settings.cpp index f3824c5..676a56d 100644 --- a/settings.cpp +++ b/settings.cpp @@ -131,7 +131,7 @@ settings::settings(QWidget *parent) : } else { int dpi_number = checkconfig_str_val.toInt(); - // Checking if it's a Mini or a Touch + // Checking if it's a Mini, Touch or a Glo string_checkconfig_ro("/opt/inkbox_device"); if(checkconfig_str_val == "n705\n") { if(dpi_number == 187) { @@ -144,7 +144,7 @@ settings::settings(QWidget *parent) : ui->uiScalingSlider->setValue(2); } } - if(checkconfig_str_val == "n905\n") { + else if(checkconfig_str_val == "n905\n") { if(dpi_number == 160) { ui->uiScalingSlider->setValue(0); } @@ -155,6 +155,17 @@ settings::settings(QWidget *parent) : ui->uiScalingSlider->setValue(2); } } + else if(checkconfig_str_val == "n613\n") { + if(dpi_number == 195) { + ui->uiScalingSlider->setValue(0); + } + if(dpi_number == 210) { + ui->uiScalingSlider->setValue(1); + } + if(dpi_number == 225) { + ui->uiScalingSlider->setValue(2); + } + } else { if(dpi_number == 187) { ui->uiScalingSlider->setValue(0); @@ -536,6 +547,9 @@ void settings::on_uiScalingSlider_valueChanged(int value) if(checkconfig_str_val == "n905\n") { string_writeconfig(".config/09-dpi/config", "160"); } + if(checkconfig_str_val == "n613\n") { + string_writeconfig(".config/09-dpi/config", "195"); + } } if(value == 1) { string_checkconfig_ro("/opt/inkbox_device"); @@ -545,6 +559,9 @@ void settings::on_uiScalingSlider_valueChanged(int value) if(checkconfig_str_val == "n905\n") { string_writeconfig(".config/09-dpi/config", "187"); } + if(checkconfig_str_val == "n613\n") { + string_writeconfig(".config/09-dpi/config", "210"); + } } if(value == 2) { string_checkconfig_ro("/opt/inkbox_device"); @@ -554,6 +571,9 @@ void settings::on_uiScalingSlider_valueChanged(int value) if(checkconfig_str_val == "n905\n") { string_writeconfig(".config/09-dpi/config", "200"); } + if(checkconfig_str_val == "n613\n") { + string_writeconfig(".config/09-dpi/config", "225"); + } } // Making sense for the user @@ -652,6 +672,9 @@ void settings::on_enableUiScalingCheckBox_toggled(bool checked) else if(checkconfig_str_val == "n905\n") { string_writeconfig(".config/09-dpi/config", "160"); } + else if(checkconfig_str_val == "n613\n") { + string_writeconfig(".config/09-dpi/config", "195"); + } else { string_writeconfig(".config/09-dpi/config", "187"); }