From e19f3867ca1d9496fb39acc24d700b8762e3257c Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sat, 1 May 2021 15:53:52 -0400 Subject: [PATCH] KoBox settings: enable/disable X11 --- functions.h | 4 ++ generaldialog.cpp | 22 +++++-- generaldialog.h | 1 + koboxsettings.cpp | 35 ++++++++++ koboxsettings.h | 7 ++ koboxsettings.ui | 164 +++++++++++++++++++++++++++++++++++----------- settings.cpp | 2 +- 7 files changed, 191 insertions(+), 44 deletions(-) diff --git a/functions.h b/functions.h index 061a71e..f05290c 100644 --- a/functions.h +++ b/functions.h @@ -24,6 +24,7 @@ namespace global { } namespace kobox { inline bool showKoboxSplash; + inline bool koboxSettingsRebootDialog; } namespace mainwindow { namespace tabSwitcher { @@ -37,6 +38,9 @@ namespace global { inline bool updateDialog; inline bool lowBatteryDialog; } + namespace settings { + inline bool settingsRebootDialog; + } } // https://stackoverflow.com/questions/6080853/c-multiple-definition-error-for-global-functions-in-the-header-file/20679534#20679534 diff --git a/generaldialog.cpp b/generaldialog.cpp index c49fdab..b8aa04f 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -62,13 +62,18 @@ generalDialog::generalDialog(QWidget *parent) : this->adjustSize(); string_writeconfig("/inkbox/updateDialog", "false"); } - else if(checkconfig("/inkbox/settingsRebootDialog") == true) { + else if(global::settings::settingsRebootDialog == true) { settingsRebootDialog = true; ui->stackedWidget->setCurrentIndex(1); - ui->bodyLabel->setText("The settings you chose might require a complete reboot of the device for them to work properly."); + if(global::kobox::koboxSettingsRebootDialog == true) { + koboxSettingsRebootDialog = true; + ui->bodyLabel->setText("The device will reboot now, since the settings you chose require it to work properly."); + } + else { + ui->bodyLabel->setText("The settings you chose might require a complete reboot of the device for them to work properly."); + } ui->headerLabel->setText("Information"); this->adjustSize(); - string_writeconfig("/inkbox/settingsRebootDialog", "false"); } else if(global::mainwindow::lowBatteryDialog == true) { lowBatteryDialog = true; @@ -158,9 +163,14 @@ void generalDialog::on_acceptBtn_clicked() } if(settingsRebootDialog == true) { - QProcess process; - process.startDetached("inkbox.sh", QStringList()); - qApp->quit(); + if(koboxSettingsRebootDialog == true) { + reboot(true); + } + else { + QProcess process; + process.startDetached("inkbox.sh", QStringList()); + qApp->quit(); + } } // We don't have any other option ;p diff --git a/generaldialog.h b/generaldialog.h index 1acc949..34d67ad 100644 --- a/generaldialog.h +++ b/generaldialog.h @@ -19,6 +19,7 @@ public: bool resetDialog = false; bool updateDialog = false; bool settingsRebootDialog = false; + bool koboxSettingsRebootDialog = false; bool lowBatteryDialog = false; private slots: diff --git a/koboxsettings.cpp b/koboxsettings.cpp index c303014..1062dde 100644 --- a/koboxsettings.cpp +++ b/koboxsettings.cpp @@ -1,5 +1,6 @@ #include "koboxsettings.h" #include "ui_koboxsettings.h" +#include "functions.h" #include @@ -17,6 +18,15 @@ koboxSettings::koboxSettings(QWidget *parent) : // UI tweaks ui->okBtn->setProperty("type", "borderless"); + + if(checkconfig("/external_root/boot/flags/X11_START") == true) { + ui->koboxStatusLabel->setText("KoBox is enabled"); + not_user_change = true; + ui->checkBox->click(); + } + else { + ui->koboxStatusLabel->setText("KoBox is disabled"); + } } koboxSettings::~koboxSettings() @@ -28,3 +38,28 @@ void koboxSettings::on_okBtn_clicked() { koboxSettings::close(); } + +void koboxSettings::on_checkBox_toggled(bool checked) +{ + if(checked == true) { + if(not_user_change != true) { + string_writeconfig("/external_root/boot/flags/X11_START", "true"); + openSettingsRebootDialog(); + } + else { + not_user_change = false; + } + } + else { + string_writeconfig("/external_root/boot/flags/X11_START", "false"); + openSettingsRebootDialog(); + } +} + +void koboxSettings::openSettingsRebootDialog() { + global::settings::settingsRebootDialog = true; + global::kobox::koboxSettingsRebootDialog = true; + generalDialogWindow = new generalDialog(this); + generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); + generalDialogWindow->show(); +} diff --git a/koboxsettings.h b/koboxsettings.h index 4f830d6..0124fe5 100644 --- a/koboxsettings.h +++ b/koboxsettings.h @@ -3,6 +3,8 @@ #include +#include "generaldialog.h" + namespace Ui { class koboxSettings; } @@ -15,11 +17,16 @@ public: explicit koboxSettings(QWidget *parent = nullptr); ~koboxSettings(); + bool not_user_change = false; + void openSettingsRebootDialog(); + private slots: void on_okBtn_clicked(); + void on_checkBox_toggled(bool checked); private: Ui::koboxSettings *ui; + generalDialog *generalDialogWindow; }; #endif // KOBOXSETTINGS_H diff --git a/koboxsettings.ui b/koboxsettings.ui index d2c4392..789b31a 100644 --- a/koboxsettings.ui +++ b/koboxsettings.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 446 + 514 @@ -16,17 +16,112 @@ - - - - QFrame::Plain - - - 5 - - - Qt::Horizontal - + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + KoBox is <status> + + + Qt::AlignCenter + + + + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + + + + Enable + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Chivo + true + + + + KoBox status + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + @@ -46,31 +141,26 @@ - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - + + + + - + + + + QFrame::Plain + + + 5 + + + Qt::Horizontal + + + + @@ -86,7 +176,7 @@ OK - + QFrame::Plain diff --git a/settings.cpp b/settings.cpp index 478a8a8..f8a0ec5 100644 --- a/settings.cpp +++ b/settings.cpp @@ -241,7 +241,7 @@ void settings::on_okBtn_clicked() { if(launch_sh == true) { if(ui_enable_changed == true) { ui_enable_changed = false; - string_writeconfig("/inkbox/settingsRebootDialog", "true"); + global::settings::settingsRebootDialog = true; generalDialogWindow = new generalDialog(); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->show();