2021-03-25 05:00:19 -07:00
# include "settings.h"
# include "ui_settings.h"
# include "mainwindow.h"
# include "ui_mainwindow.h"
2021-04-05 06:50:58 -07:00
# include "functions.h"
2021-03-25 05:00:19 -07:00
# include <QFile>
# include <QMessageBox>
# include <QSettings>
# include <QWidget>
# include <iostream>
# include <fstream>
# include <streambuf>
# include <string>
# include <QProcess>
# include <QTimer>
# include <QIcon>
2021-04-30 20:55:38 -07:00
# include <QScreen>
2021-04-30 15:19:48 -07:00
2021-03-25 05:00:19 -07:00
using namespace std ;
settings : : settings ( QWidget * parent ) :
QWidget ( parent ) ,
ui ( new Ui : : settings )
{
ui - > setupUi ( this ) ;
2022-03-02 21:40:11 -08:00
settings : : setFont ( QFont ( " u001 " ) ) ;
ui - > comboBox - > setFont ( QFont ( " u001 " ) ) ;
2022-03-13 11:06:29 -07:00
ui - > tzComboBox - > setFont ( QFont ( " u001 " ) ) ;
2022-03-02 21:40:11 -08:00
ui - > sleepTimeoutComboBox - > setFont ( QFont ( " u001 " ) ) ;
2022-04-03 20:26:15 -07:00
ui - > uiScaleNumberLabel - > setFont ( QFont ( " Inter " ) ) ;
2022-03-03 19:03:20 -08:00
ui - > aboutBtn - > setFont ( QFont ( " u001 " ) ) ;
2022-03-02 21:40:11 -08:00
ui - > okBtn - > setFont ( QFont ( " Inter " ) ) ;
2021-04-04 18:02:08 -07:00
ui - > setPasscodeBtn - > setProperty ( " type " , " borderless " ) ;
2021-03-25 05:00:19 -07:00
ui - > okBtn - > setProperty ( " type " , " borderless " ) ;
ui - > aboutBtn - > setProperty ( " type " , " borderless " ) ;
ui - > requestLeaseBtn - > setProperty ( " type " , " borderless " ) ;
ui - > usbmsBtn - > setProperty ( " type " , " borderless " ) ;
ui - > updateBtn - > setProperty ( " type " , " borderless " ) ;
2021-03-31 05:38:59 -07:00
ui - > resetBtn - > setProperty ( " type " , " borderless " ) ;
2021-06-08 05:03:46 -07:00
ui - > showSystemInfoBtn - > setProperty ( " type " , " borderless " ) ;
2022-02-22 21:22:57 -08:00
ui - > generateSystemReportBtn - > setProperty ( " type " , " borderless " ) ;
2021-08-25 10:16:41 -07:00
ui - > checkOtaUpdateBtn - > setProperty ( " type " , " borderless " ) ;
2021-03-25 05:00:19 -07:00
ui - > previousBtn - > setProperty ( " type " , " borderless " ) ;
ui - > nextBtn - > setProperty ( " type " , " borderless " ) ;
2021-11-14 18:22:58 -08:00
ui - > repackBtn - > setProperty ( " type " , " borderless " ) ;
2022-03-02 21:40:11 -08:00
ui - > label - > setStyleSheet ( " font-size: 10.5pt; font-weight: bold " ) ;
ui - > okBtn - > setStyleSheet ( " font-weight: bold " ) ;
2021-03-26 21:10:49 -07:00
ui - > aboutBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2021-03-25 05:00:19 -07:00
ui - > requestLeaseBtn - > setStyleSheet ( " font-size: 9pt " ) ;
ui - > usbmsBtn - > setStyleSheet ( " font-size: 9pt " ) ;
ui - > updateBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2021-03-31 05:38:59 -07:00
ui - > resetBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2021-06-08 05:03:46 -07:00
ui - > showSystemInfoBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2022-02-22 21:22:57 -08:00
ui - > generateSystemReportBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2021-08-25 10:16:41 -07:00
ui - > checkOtaUpdateBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2021-03-30 05:24:13 -07:00
ui - > comboBox - > setStyleSheet ( " font-size: 9pt " ) ;
2022-04-15 17:27:58 -07:00
ui - > tzComboBox - > setStyleSheet ( " font-size: 9pt " ) ;
2021-06-28 16:57:40 -07:00
ui - > sleepTimeoutComboBox - > setStyleSheet ( " font-size: 9pt " ) ;
2021-04-04 18:02:08 -07:00
ui - > setPasscodeBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2021-11-14 18:22:58 -08:00
ui - > repackBtn - > setStyleSheet ( " font-size: 9pt " ) ;
2022-04-03 20:26:15 -07:00
ui - > uiScaleNumberLabel - > setStyleSheet ( " font-size: 9pt; font-weight: bold " ) ;
2021-03-25 05:00:19 -07:00
ui - > previousBtn - > setText ( " " ) ;
ui - > previousBtn - > setIcon ( QIcon ( " :/resources/chevron-left.png " ) ) ;
ui - > nextBtn - > setText ( " " ) ;
ui - > nextBtn - > setIcon ( QIcon ( " :/resources/chevron-right.png " ) ) ;
ui - > requestLeaseBtn - > hide ( ) ;
ui - > usbmsBtn - > hide ( ) ;
ui - > label_3 - > hide ( ) ;
ui - > label_4 - > hide ( ) ;
ui - > label_5 - > hide ( ) ;
ui - > label_6 - > hide ( ) ;
ui - > line_3 - > hide ( ) ;
ui - > line_7 - > hide ( ) ;
ui - > updateBtn - > hide ( ) ;
ui - > updateLabel - > hide ( ) ;
2021-04-04 20:15:24 -07:00
ui - > enableLockscreenCheckBox - > hide ( ) ;
ui - > setPasscodeBtn - > hide ( ) ;
ui - > setPasscodeLabel - > hide ( ) ;
2021-04-05 12:35:25 -07:00
ui - > securityLabel - > hide ( ) ;
ui - > line_2 - > hide ( ) ;
ui - > uiScaleNumberLabel - > hide ( ) ;
ui - > uiScalingSlider - > hide ( ) ;
ui - > uiScalingLabel - > hide ( ) ;
2021-03-25 05:00:19 -07:00
2021-06-20 19:57:10 -07:00
// Variables
2021-08-29 12:05:07 -07:00
defineDefaultPageSize ( 0 ) ;
defineDefaultPageSize ( 1 ) ;
2021-06-20 19:57:10 -07:00
2021-03-25 05:00:19 -07:00
// Settings tweaking + enabling specific features whether it's running on the provided integrated OS or Kobo firmware
if ( checkconfig ( " .config/01-demo/config " ) = = true ) {
ui - > demoCheckBox - > click ( ) ;
}
if ( checkconfig ( " .config/02-clock/config " ) = = true ) {
ui - > clockCheckBox - > click ( ) ;
}
if ( checkconfig ( " .config/05-quote/config " ) = = true ) {
ui - > quoteCheckBox - > click ( ) ;
}
2021-07-10 22:08:38 -07:00
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n705 \n " or global : : deviceID = = " n905 \n " or global : : deviceID = = " n613 \n " or global : : deviceID = = " n236 \n " or global : : deviceID = = " n437 \n " or global : : deviceID = = " n306 \n " ) {
2021-07-10 22:08:38 -07:00
if ( checkconfig ( " .config/10-dark_mode/config " ) = = true ) {
ui - > darkModeCheckBox - > click ( ) ;
}
}
else {
ui - > darkModeCheckBox - > hide ( ) ;
ui - > darkModeCheckBox - > deleteLater ( ) ;
2021-03-25 05:00:19 -07:00
}
2021-03-26 21:10:49 -07:00
// Words number
2021-03-25 05:00:19 -07:00
string_checkconfig ( " .config/07-words_number/config " ) ;
if ( checkconfig_str_val = = " " ) {
;
}
else {
int words_number = checkconfig_str_val . toInt ( ) ;
ui - > wordsNumber - > setValue ( words_number ) ;
}
2021-03-26 21:10:49 -07:00
2021-06-20 19:57:10 -07:00
// ePUB page size
if ( checkconfig ( " .config/13-epub_page_size/set " ) = = true ) {
string_checkconfig_ro ( " .config/13-epub_page_size/width " ) ;
if ( checkconfig_str_val ! = " " ) {
int pageWidth = checkconfig_str_val . toInt ( ) ;
ui - > pageSizeWidthSpinBox - > setValue ( pageWidth ) ;
}
else {
// Failsafe: setting default
ui - > pageSizeWidthSpinBox - > setValue ( defaultEpubPageWidth ) ;
}
string_checkconfig_ro ( " .config/13-epub_page_size/height " ) ;
if ( checkconfig_str_val ! = " " ) {
int pageHeight = checkconfig_str_val . toInt ( ) ;
ui - > pageSizeHeightSpinBox - > setValue ( pageHeight ) ;
}
else {
// Failsafe: setting default
ui - > pageSizeHeightSpinBox - > setValue ( defaultEpubPageHeight ) ;
}
}
else {
ui - > pageSizeWidthSpinBox - > setValue ( defaultEpubPageWidth ) ;
ui - > pageSizeHeightSpinBox - > setValue ( defaultEpubPageHeight ) ;
}
2021-06-27 10:28:41 -07:00
// QTextEdit scroll bar in Reader framework
if ( checkconfig ( " .config/14-reader_scrollbar/config " ) = = true ) {
ui - > readerScrollBarCheckBox - > click ( ) ;
}
2021-03-26 21:10:49 -07:00
// Sticky menubar
if ( checkconfig ( " .config/11-menubar/sticky " ) = = true ) {
ui - > menuBarCheckBox - > click ( ) ;
}
2021-03-25 05:00:19 -07:00
// Scaling
string_checkconfig ( " .config/09-dpi/config " ) ;
if ( checkconfig_str_val = = " " ) {
;
}
else {
int dpi_number = checkconfig_str_val . toInt ( ) ;
2021-06-26 07:09:51 -07:00
// Checking if it's a Mini, Touch or a Glo
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n705 \n " ) {
2021-04-09 17:54:20 -07:00
if ( dpi_number = = 187 ) {
ui - > uiScalingSlider - > setValue ( 0 ) ;
}
if ( dpi_number = = 214 ) {
ui - > uiScalingSlider - > setValue ( 1 ) ;
}
if ( dpi_number = = 227 ) {
ui - > uiScalingSlider - > setValue ( 2 ) ;
}
2021-03-25 05:00:19 -07:00
}
2022-05-22 12:38:02 -07:00
else if ( global : : deviceID = = " n905 \n " or global : : deviceID = = " kt \n " ) {
2021-04-09 17:54:20 -07:00
if ( dpi_number = = 160 ) {
ui - > uiScalingSlider - > setValue ( 0 ) ;
}
if ( dpi_number = = 187 ) {
ui - > uiScalingSlider - > setValue ( 1 ) ;
}
if ( dpi_number = = 200 ) {
ui - > uiScalingSlider - > setValue ( 2 ) ;
}
2021-03-25 05:00:19 -07:00
}
2022-04-02 13:49:18 -07:00
else if ( global : : deviceID = = " n613 \n " or global : : deviceID = = " n236 \n " or global : : deviceID = = " n306 \n " ) {
2021-06-26 07:09:51 -07:00
if ( dpi_number = = 195 ) {
ui - > uiScalingSlider - > setValue ( 0 ) ;
}
if ( dpi_number = = 210 ) {
ui - > uiScalingSlider - > setValue ( 1 ) ;
}
if ( dpi_number = = 225 ) {
ui - > uiScalingSlider - > setValue ( 2 ) ;
}
}
2022-04-02 13:49:18 -07:00
else if ( global : : deviceID = = " n437 \n " ) {
2022-02-06 19:49:06 -08:00
if ( dpi_number = = 275 ) {
ui - > uiScalingSlider - > setValue ( 0 ) ;
}
if ( dpi_number = = 290 ) {
ui - > uiScalingSlider - > setValue ( 1 ) ;
}
if ( dpi_number = = 305 ) {
ui - > uiScalingSlider - > setValue ( 2 ) ;
}
}
2022-04-02 13:49:18 -07:00
else if ( global : : deviceID = = " n873 \n " ) {
2021-07-10 22:08:38 -07:00
if ( dpi_number = = 285 ) {
ui - > uiScalingSlider - > setValue ( 0 ) ;
}
if ( dpi_number = = 300 ) {
ui - > uiScalingSlider - > setValue ( 1 ) ;
}
if ( dpi_number = = 315 ) {
ui - > uiScalingSlider - > setValue ( 2 ) ;
}
}
2021-04-09 17:54:20 -07:00
else {
if ( dpi_number = = 187 ) {
ui - > uiScalingSlider - > setValue ( 0 ) ;
}
if ( dpi_number = = 214 ) {
ui - > uiScalingSlider - > setValue ( 1 ) ;
}
if ( dpi_number = = 227 ) {
ui - > uiScalingSlider - > setValue ( 2 ) ;
}
2021-03-25 05:00:19 -07:00
}
}
2021-03-30 05:24:13 -07:00
// Refresh
2021-06-28 16:57:40 -07:00
string_checkconfig_ro ( " .config/04-book/refresh " ) ;
2021-03-30 05:24:13 -07:00
if ( checkconfig_str_val = = " " ) {
// Set default option, 3
string_writeconfig ( " .config/04-book/refresh " , " 3 " ) ;
ui - > comboBox - > setCurrentText ( " 3 pages " ) ;
}
else {
int refreshInt = checkconfig_str_val . toInt ( ) ;
if ( refreshInt = = - 1 ) {
ui - > comboBox - > setCurrentText ( " Never refresh " ) ;
}
if ( refreshInt = = 0 ) {
ui - > comboBox - > setCurrentText ( " Every page " ) ;
}
if ( refreshInt = = 1 ) {
ui - > comboBox - > setCurrentText ( " 1 page " ) ;
}
if ( refreshInt = = 2 ) {
ui - > comboBox - > setCurrentText ( " 2 pages " ) ;
}
if ( refreshInt = = 3 ) {
ui - > comboBox - > setCurrentText ( " 3 pages " ) ;
}
if ( refreshInt = = 4 ) {
ui - > comboBox - > setCurrentText ( " 4 pages " ) ;
}
if ( refreshInt = = 5 ) {
ui - > comboBox - > setCurrentText ( " 5 pages " ) ;
}
if ( refreshInt = = 6 ) {
ui - > comboBox - > setCurrentText ( " 6 pages " ) ;
}
2021-06-28 16:57:40 -07:00
}
// Sleep mode timeout
string_checkconfig_ro ( " .config/15-sleep_timeout/config " ) ;
if ( checkconfig_str_val = = " " ) {
// Set default option, '15 minutes'
string_writeconfig ( " .config/15-sleep_timeout/config " , " 15 " ) ;
ui - > sleepTimeoutComboBox - > setCurrentText ( " 15 minutes " ) ;
}
else {
int sleepTimeoutInt = checkconfig_str_val . toInt ( ) ;
if ( sleepTimeoutInt = = - 1 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " Never " ) ;
}
if ( sleepTimeoutInt = = 2 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " 2 minutes " ) ;
}
if ( sleepTimeoutInt = = 5 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " 5 minutes " ) ;
}
if ( sleepTimeoutInt = = 10 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " 10 minutes " ) ;
}
if ( sleepTimeoutInt = = 15 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " 15 minutes " ) ;
}
if ( sleepTimeoutInt = = 30 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " 30 minutes " ) ;
}
if ( sleepTimeoutInt = = 60 ) {
ui - > sleepTimeoutComboBox - > setCurrentText ( " 60 minutes " ) ;
2021-03-30 05:24:13 -07:00
}
}
2021-04-04 20:15:24 -07:00
// Lock screen
2021-04-04 20:31:15 -07:00
if ( checkconfig ( " .config/12-lockscreen/config " ) = = true ) {
2021-04-04 20:15:24 -07:00
ui - > enableLockscreenCheckBox - > click ( ) ;
}
2021-08-05 21:50:28 -07:00
// Global reading settings
if ( checkconfig ( " .config/16-global_reading_settings/config " ) = = true ) {
ui - > globalReadingSettingsCheckBox - > click ( ) ;
}
2021-10-17 19:31:44 -07:00
// Encrypted storage
if ( checkconfig ( " .config/18-encrypted_storage/status " ) = = true ) {
ui - > enableEncryptedStorageCheckBox - > click ( ) ;
}
2021-10-18 05:46:27 -07:00
else {
// Next interaction will be by the user
enableEncryptedStorageUserChange = true ;
}
2021-11-14 19:23:09 -08:00
if ( getEncFSStatus ( ) = = false ) {
2021-11-14 18:22:58 -08:00
ui - > repackLabel - > hide ( ) ;
ui - > repackBtn - > hide ( ) ;
}
2021-10-17 19:31:44 -07:00
2021-04-05 12:35:25 -07:00
// DPI checkbox
2021-04-06 19:23:23 -07:00
string_checkconfig ( " .config/09-dpi/config " ) ;
2021-04-07 04:44:24 -07:00
// Check if the string is a number; else, we don't check the check box
2021-04-06 19:23:23 -07:00
if ( checkconfig_str_val = = " false " ) {
2021-04-06 18:39:08 -07:00
string_writeconfig ( " .config/09-dpi/config-enabled " , " false " ) ;
}
2021-04-06 19:23:23 -07:00
else {
string_writeconfig ( " .config/09-dpi/config-enabled " , " true " ) ;
}
if ( checkconfig ( " .config/09-dpi/config-enabled " ) = = true ) {
2021-04-05 12:35:25 -07:00
ui_not_user_change = true ;
ui - > enableUiScalingCheckBox - > click ( ) ;
}
2022-03-13 11:06:29 -07:00
// Timezone
2022-04-16 20:20:24 -07:00
ui - > tzComboBox - > addItems ( QStringList ( readFile ( " :/resources/tzlist " ) . split ( " \n " , Qt : : SkipEmptyParts ) ) ) ;
timezone_not_user_change = true ;
2022-03-13 11:06:29 -07:00
if ( readFile ( " .config/19-timezone/config-name " ) . isEmpty ( ) ) {
ui - > tzComboBox - > setCurrentText ( " UTC " ) ;
}
else {
ui - > tzComboBox - > setCurrentText ( readFile ( " .config/19-timezone/config-name " ) ) ;
}
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
// Enforcing security policy if the user has not rooted the device
if ( checkconfig ( " /external_root/opt/root/rooted " ) = = true ) {
ui - > requestLeaseBtn - > show ( ) ;
ui - > label_4 - > show ( ) ;
ui - > label_3 - > show ( ) ;
ui - > line_3 - > show ( ) ;
}
else {
ui - > requestLeaseBtn - > hide ( ) ;
ui - > label_4 - > hide ( ) ;
ui - > label_3 - > hide ( ) ;
ui - > line_3 - > hide ( ) ;
}
2021-04-05 12:35:25 -07:00
ui - > securityLabel - > show ( ) ;
ui - > line_2 - > show ( ) ;
2021-04-04 20:15:24 -07:00
ui - > enableLockscreenCheckBox - > show ( ) ;
ui - > setPasscodeBtn - > show ( ) ;
ui - > setPasscodeLabel - > show ( ) ;
2021-03-25 05:00:19 -07:00
ui - > usbmsBtn - > show ( ) ;
ui - > label_5 - > show ( ) ;
ui - > label_6 - > show ( ) ;
ui - > line_7 - > show ( ) ;
ui - > okBtn - > setText ( " OK " ) ;
}
2021-04-06 10:40:43 -07:00
else {
ui - > label_8 - > setText ( " Reset InkBox " ) ;
}
2021-03-25 05:00:19 -07:00
2021-08-25 10:16:41 -07:00
if ( global : : device : : isWifiAble = = false ) {
2021-08-25 10:32:33 -07:00
ui - > checkOtaUpdateLabel - > hide ( ) ;
ui - > checkOtaUpdateBtn - > hide ( ) ;
ui - > checkOtaUpdateLabel - > deleteLater ( ) ;
ui - > checkOtaUpdateBtn - > deleteLater ( ) ;
2021-08-25 10:16:41 -07:00
ui - > checkOtaUpdateGridLayout - > deleteLater ( ) ;
}
2021-03-25 05:00:19 -07:00
2022-04-03 20:26:15 -07:00
QFile stylesheetFile ( " /mnt/onboard/.adds/inkbox/eink.qss " ) ;
2021-03-25 05:00:19 -07:00
stylesheetFile . open ( QFile : : ReadOnly ) ;
this - > setStyleSheet ( stylesheetFile . readAll ( ) ) ;
stylesheetFile . close ( ) ;
}
settings : : ~ settings ( )
{
delete ui ;
}
void settings : : on_okBtn_clicked ( ) {
// Prevent potential unknown damage launching via shell script this could do
if ( launch_sh = = true ) {
2021-04-05 12:35:25 -07:00
if ( ui_enable_changed = = true ) {
ui_enable_changed = false ;
2021-05-01 12:53:52 -07:00
global : : settings : : settingsRebootDialog = true ;
2021-04-05 12:35:25 -07:00
generalDialogWindow = new generalDialog ( ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
else {
QProcess process ;
process . startDetached ( " inkbox.sh " , QStringList ( ) ) ;
qApp - > quit ( ) ;
}
2021-03-25 05:00:19 -07:00
}
else {
QProcess process ;
process . startDetached ( " inkbox " , QStringList ( ) ) ;
qApp - > quit ( ) ;
}
}
void settings : : on_aboutBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " Showing About message box " , className ) ;
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
2021-05-26 05:06:50 -07:00
QString aboutmsg = " InkBox is an open-source, Qt-based eBook reader. It aims to bring you the latest Qt features while being also fast and responsive. " ;
2022-03-02 21:40:11 -08:00
aboutmsg . prepend ( " <font face='u001'> " ) ;
2021-03-25 05:00:19 -07:00
string_checkconfig_ro ( " /external_root/opt/isa/version " ) ;
2022-03-02 21:40:11 -08:00
aboutmsg . append ( " <br><br>InkBox " ) ;
2021-03-25 05:00:19 -07:00
aboutmsg . append ( checkconfig_str_val ) ;
2022-03-02 21:40:11 -08:00
aboutmsg . append ( " </font> " ) ;
2021-03-25 05:00:19 -07:00
QMessageBox : : information ( this , tr ( " Information " ) , aboutmsg ) ;
}
else {
2021-06-05 15:54:38 -07:00
QMessageBox : : information ( this , tr ( " About " ) , tr ( " InkBox is an open-source Qt-based eBook reader. It aims to bring you the latest Qt features while being also fast and responsive. " ) ) ;
2021-03-25 05:00:19 -07:00
}
}
void settings : : on_demoCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " demo setting (change MainWindow label) " ;
2021-03-25 05:00:19 -07:00
// Write to config file
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
checked_box = true ;
writeconfig ( " .config/01-demo/config " , " InkboxChangeLabel= " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
checked_box = false ;
writeconfig ( " .config/01-demo/config " , " InkboxChangeLabel= " ) ;
}
}
void settings : : on_clockCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " clock with seconds setting " ;
2021-03-25 05:00:19 -07:00
// Write to config file
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
checked_box = true ;
writeconfig ( " .config/02-clock/config " , " ClockShowSeconds= " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
checked_box = false ;
writeconfig ( " .config/02-clock/config " , " ClockShowSeconds= " ) ;
}
}
void settings : : on_quoteCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " show quotes setting " ;
2021-03-25 05:00:19 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
checked_box = true ;
writeconfig ( " .config/05-quote/config " , " DisableQuote= " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
checked_box = false ;
writeconfig ( " .config/05-quote/config " , " DisableQuote= " ) ;
}
}
void settings : : on_requestLeaseBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " Requesting DHCP lease " , className ) ;
2021-03-25 05:00:19 -07:00
QString prog ( " chroot " ) ;
QStringList args ;
args < < " /external_root " < < " /usr/sbin/dhclient " ;
QProcess * proc = new QProcess ( ) ;
proc - > start ( prog , args ) ;
proc - > waitForFinished ( ) ;
2021-08-29 12:05:07 -07:00
proc - > deleteLater ( ) ;
2021-03-25 05:00:19 -07:00
}
void settings : : on_usbmsBtn_clicked ( )
{
2021-09-26 19:05:45 -07:00
usbms_launch ( ) ;
2021-03-25 05:00:19 -07:00
}
2021-04-02 18:06:15 -07:00
// Now I know that QStackedWidgets exist... ;p
2021-03-25 05:00:19 -07:00
void settings : : on_previousBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Previous' button clicked " , className ) ;
2021-03-25 05:00:19 -07:00
settings_page = settings_page - 1 ;
if ( settings_page = = 1 ) {
2021-03-27 22:14:37 -07:00
ui - > stackedWidget - > setCurrentIndex ( 0 ) ;
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
// Enforcing security policy if the user has not rooted the device
if ( checkconfig ( " /external_root/opt/root/rooted " ) = = true ) {
ui - > requestLeaseBtn - > show ( ) ;
ui - > label_4 - > show ( ) ;
ui - > label_3 - > show ( ) ;
ui - > line_3 - > show ( ) ;
}
else {
ui - > requestLeaseBtn - > hide ( ) ;
ui - > label_4 - > hide ( ) ;
ui - > label_3 - > hide ( ) ;
ui - > line_3 - > hide ( ) ;
}
}
}
else {
if ( settings_page = = 2 ) {
2021-03-27 22:14:37 -07:00
ui - > stackedWidget - > setCurrentIndex ( 1 ) ;
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
if ( checkconfig ( " /mnt/onboard/onboard/.inkbox/can_update " ) = = true ) {
ui - > updateBtn - > show ( ) ;
ui - > updateLabel - > show ( ) ;
}
2021-03-27 22:14:37 -07:00
else {
ui - > updateBtn - > show ( ) ;
ui - > updateLabel - > show ( ) ;
}
2021-03-25 05:00:19 -07:00
}
}
if ( settings_page < = 0 ) {
// Prevent unwanted accesses
settings_page = settings_page + 1 ;
}
}
}
void settings : : on_nextBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Next' button clicked " , className ) ;
2021-03-25 05:00:19 -07:00
settings_page = settings_page + 1 ;
if ( settings_page = = 2 ) {
2021-03-27 22:14:37 -07:00
ui - > stackedWidget - > setCurrentIndex ( 1 ) ;
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
// Enforcing security policy if the user has not rooted the device
if ( checkconfig ( " /external_root/opt/root/rooted " ) = = true ) {
ui - > requestLeaseBtn - > show ( ) ;
ui - > label_4 - > show ( ) ;
ui - > label_3 - > show ( ) ;
ui - > line_3 - > show ( ) ;
}
else {
ui - > requestLeaseBtn - > hide ( ) ;
ui - > label_4 - > hide ( ) ;
ui - > label_3 - > hide ( ) ;
ui - > line_3 - > hide ( ) ;
}
if ( checkconfig ( " /mnt/onboard/onboard/.inkbox/can_update " ) = = true ) {
ui - > updateBtn - > show ( ) ;
ui - > updateLabel - > show ( ) ;
}
}
}
if ( settings_page > = 3 ) {
settings_page = settings_page - 1 ;
}
}
void settings : : on_wordsNumber_valueChanged ( int arg1 )
{
QString number = QString : : number ( arg1 ) ;
string number_str = number . toStdString ( ) ;
string_writeconfig ( " .config/07-words_number/config " , number_str ) ;
2022-04-17 19:25:29 -07:00
log ( " Set text files words number to " + number , className ) ;
2021-03-25 05:00:19 -07:00
}
void settings : : on_updateBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Update' button clicked " , className ) ;
2021-03-25 05:00:19 -07:00
string_writeconfig ( " /mnt/onboard/onboard/.inkbox/can_really_update " , " true " ) ;
string_writeconfig ( " /external_root/opt/update/will_update " , " true " ) ;
string_writeconfig ( " /external_root/boot/flags/WILL_UPDATE " , " true " ) ;
2021-05-28 05:36:24 -07:00
QString prog ( " /sbin/reboot " ) ;
2021-03-25 05:00:19 -07:00
QStringList args ;
QProcess * proc = new QProcess ( ) ;
proc - > start ( prog , args ) ;
proc - > waitForFinished ( ) ;
2021-08-29 12:05:07 -07:00
proc - > deleteLater ( ) ;
2021-03-25 05:00:19 -07:00
}
void settings : : on_darkModeCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " dark mode setting " ;
2021-03-25 05:00:19 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
string_writeconfig ( " .config/10-dark_mode/config " , " true " ) ;
string_writeconfig ( " /tmp/invertScreen " , " y " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-03-25 05:00:19 -07:00
string_writeconfig ( " .config/10-dark_mode/config " , " false " ) ;
string_writeconfig ( " /tmp/invertScreen " , " n " ) ;
}
}
void settings : : on_uiScalingSlider_valueChanged ( int value )
{
2022-04-17 19:25:29 -07:00
log ( " Setting DPI level to " + QString : : number ( value ) , className ) ;
2021-03-25 05:00:19 -07:00
if ( value = = 0 ) {
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n705 \n " ) {
2021-04-09 17:54:20 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 187 " ) ;
}
2022-05-22 12:38:02 -07:00
if ( global : : deviceID = = " n905 \n " or global : : deviceID = = " kt \n " ) {
2021-04-09 17:54:20 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 160 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n613 \n " or global : : deviceID = = " n236 \n " or global : : deviceID = = " n306 \n " ) {
2021-06-26 07:09:51 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 195 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n437 \n " ) {
2022-02-06 19:49:06 -08:00
string_writeconfig ( " .config/09-dpi/config " , " 275 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n873 \n " ) {
2021-07-10 22:08:38 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 285 " ) ;
}
2021-03-25 05:00:19 -07:00
}
if ( value = = 1 ) {
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n705 \n " ) {
2021-04-09 17:54:20 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 214 " ) ;
}
2022-05-22 12:38:02 -07:00
if ( global : : deviceID = = " n905 \n " or global : : deviceID = = " kt \n " ) {
2021-04-09 17:54:20 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 187 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n613 \n " or global : : deviceID = = " n236 \n " or global : : deviceID = = " n306 \n " ) {
2021-06-26 07:09:51 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 210 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n437 \n " ) {
2022-02-06 19:49:06 -08:00
string_writeconfig ( " .config/09-dpi/config " , " 290 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n873 \n " ) {
2021-07-10 22:08:38 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 300 " ) ;
}
2021-03-25 05:00:19 -07:00
}
if ( value = = 2 ) {
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n705 \n " ) {
2021-04-09 17:54:20 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 227 " ) ;
}
2022-05-22 12:38:02 -07:00
if ( global : : deviceID = = " n905 \n " or global : : deviceID = = " kt \n " ) {
2021-04-09 17:54:20 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 200 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n613 \n " or global : : deviceID = = " n236 \n " or global : : deviceID = = " n306 \n " ) {
2021-06-26 07:09:51 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 225 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n437 \n " ) {
2022-02-06 19:49:06 -08:00
string_writeconfig ( " .config/09-dpi/config " , " 305 " ) ;
}
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n873 \n " ) {
2021-07-10 22:08:38 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 315 " ) ;
}
2021-03-25 05:00:19 -07:00
}
// Making sense for the user
value = value + 1 ;
QString value_qstr = QString : : number ( value ) ;
ui - > uiScaleNumberLabel - > setText ( value_qstr ) ;
if ( not_user_change = = true ) {
launch_sh = false ;
// If value is changed, it will launch inkbox.sh detached when "OK" is pressed.
not_user_change = false ;
}
else {
// This is supposed to happen when the user clicks the slider, and not the software. Refer to setValue() methods for uiScalingSlider in main().
launch_sh = true ;
}
}
2021-03-26 21:10:49 -07:00
void settings : : on_menuBarCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " sticky menu bar setting " ;
2021-03-26 21:10:49 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-03-26 21:10:49 -07:00
checked_box = true ;
writeconfig ( " .config/11-menubar/sticky " , " StickyMenuBar= " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-03-26 21:10:49 -07:00
checked_box = false ;
writeconfig ( " .config/11-menubar/sticky " , " StickyMenuBar= " ) ;
}
}
2021-03-30 05:24:13 -07:00
void settings : : on_comboBox_currentIndexChanged ( const QString & arg1 )
{
2022-04-17 19:25:29 -07:00
log ( " Setting page refresh setting to " + arg1 , className ) ;
2021-03-30 05:24:13 -07:00
if ( arg1 = = " Every page " ) {
string_writeconfig ( " .config/04-book/refresh " , " 0 " ) ;
}
if ( arg1 = = " 1 page " ) {
string_writeconfig ( " .config/04-book/refresh " , " 1 " ) ;
}
if ( arg1 = = " 2 pages " ) {
string_writeconfig ( " .config/04-book/refresh " , " 2 " ) ;
}
if ( arg1 = = " 3 pages " ) {
string_writeconfig ( " .config/04-book/refresh " , " 3 " ) ;
}
if ( arg1 = = " 4 pages " ) {
string_writeconfig ( " .config/04-book/refresh " , " 4 " ) ;
}
if ( arg1 = = " 5 pages " ) {
string_writeconfig ( " .config/04-book/refresh " , " 5 " ) ;
}
if ( arg1 = = " 6 pages " ) {
string_writeconfig ( " .config/04-book/refresh " , " 6 " ) ;
}
if ( arg1 = = " Never refresh " ) {
string_writeconfig ( " .config/04-book/refresh " , " -1 " ) ;
}
}
2021-03-31 05:38:59 -07:00
void settings : : on_resetBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Reset' button clicked " , className ) ;
2021-03-31 05:38:59 -07:00
// We write to a temporary file to show a "Reset" prompt
string_writeconfig ( " /inkbox/resetDialog " , " true " ) ;
2022-03-03 19:03:20 -08:00
// We setup the dialog
2022-04-17 19:25:29 -07:00
log ( " Showing reset dialog " , className ) ;
2021-03-31 05:38:59 -07:00
generalDialogWindow = new generalDialog ( ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
2021-04-04 17:25:07 -07:00
void settings : : on_setPasscodeBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Set passcode' button clicked " , className ) ;
log ( " Launching lockscreen binary " , className ) ;
2021-04-04 17:25:07 -07:00
string_writeconfig ( " /tmp/setPasscode " , " true " ) ;
QProcess process ;
process . startDetached ( " lockscreen " , QStringList ( ) ) ;
qApp - > quit ( ) ;
}
void settings : : on_enableLockscreenCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " lockscreen setting " ;
2021-04-04 17:25:07 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-04-04 18:02:08 -07:00
string_writeconfig ( " .config/12-lockscreen/config " , " true " ) ;
2021-04-04 17:25:07 -07:00
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-04-04 18:02:08 -07:00
string_writeconfig ( " .config/12-lockscreen/config " , " false " ) ;
2021-04-04 17:25:07 -07:00
}
}
2021-04-05 12:35:25 -07:00
void settings : : on_enableUiScalingCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " UI scaling setting " ;
2021-04-05 12:35:25 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-04-10 08:34:11 -07:00
// Writing default value depending on the device
2022-04-02 13:49:18 -07:00
if ( global : : deviceID = = " n705 \n " ) {
2021-04-10 08:34:11 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 187 " ) ;
}
2022-05-22 12:38:02 -07:00
else if ( global : : deviceID = = " n905 \n " or global : : deviceID = = " kt \n " ) {
2021-04-10 08:34:11 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 160 " ) ;
}
2022-04-02 13:49:18 -07:00
else if ( global : : deviceID = = " n613 \n " or global : : deviceID = = " n236 \n " or global : : deviceID = = " n306 \n " ) {
2021-06-26 07:09:51 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 195 " ) ;
}
2022-04-02 13:49:18 -07:00
else if ( global : : deviceID = = " n437 \n " ) {
2022-02-06 19:49:06 -08:00
string_writeconfig ( " .config/09-dpi/config " , " 275 " ) ;
}
2022-04-02 13:49:18 -07:00
else if ( global : : deviceID = = " n873 \n " ) {
2021-07-10 22:08:38 -07:00
string_writeconfig ( " .config/09-dpi/config " , " 285 " ) ;
}
2021-04-10 08:34:11 -07:00
else {
string_writeconfig ( " .config/09-dpi/config " , " 187 " ) ;
}
2021-04-05 12:35:25 -07:00
string_writeconfig ( " .config/09-dpi/config-enabled " , " true " ) ;
ui - > uiScaleNumberLabel - > show ( ) ;
ui - > uiScalingSlider - > show ( ) ;
ui - > uiScalingLabel - > show ( ) ;
launch_sh = true ;
if ( ui_not_user_change = = true ) {
ui_enable_changed = false ;
}
else {
ui_enable_changed = true ;
}
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-04-05 12:35:25 -07:00
string_writeconfig ( " .config/09-dpi/config " , " false " ) ;
string_writeconfig ( " .config/09-dpi/config-enabled " , " false " ) ;
ui - > uiScaleNumberLabel - > hide ( ) ;
ui - > uiScalingSlider - > hide ( ) ;
ui - > uiScalingLabel - > hide ( ) ;
launch_sh = true ;
ui_enable_changed = true ;
}
}
2021-06-08 05:03:46 -07:00
void settings : : on_showSystemInfoBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Show system info' button clicked " , className ) ;
2021-06-08 05:03:46 -07:00
getSystemInfo ( ) ;
2021-06-29 11:42:51 -07:00
global : : usbms : : usbmsDialog = false ;
2021-06-08 05:03:46 -07:00
global : : text : : textBrowserContents = global : : systemInfoText ;
2021-06-14 09:24:20 -07:00
global : : text : : textBrowserDialog = true ;
// Show a system info dialog
2022-04-17 19:25:29 -07:00
log ( " Showing system info dialog " , className ) ;
2021-06-14 09:24:20 -07:00
generalDialogWindow = new generalDialog ( ) ;
2022-07-12 09:34:36 -07:00
generalDialogWindow - > yIncrease = determineYIncrease ( ) ;
2022-06-17 20:59:21 -07:00
generalDialogWindow - > increaseSize ( ) ;
2021-06-14 09:24:20 -07:00
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2021-06-08 05:03:46 -07:00
}
2021-06-20 19:57:10 -07:00
void settings : : on_pageSizeWidthSpinBox_valueChanged ( int arg1 )
{
std : : string value = std : : to_string ( arg1 ) ;
string_writeconfig ( " .config/13-epub_page_size/width " , value ) ;
string_writeconfig ( " .config/13-epub_page_size/set " , " true " ) ;
2022-04-17 19:25:29 -07:00
log ( " Set ePUB page size width to " + QString : : number ( arg1 ) , className ) ;
2021-06-20 19:57:10 -07:00
}
void settings : : on_pageSizeHeightSpinBox_valueChanged ( int arg1 )
{
std : : string value = std : : to_string ( arg1 ) ;
string_writeconfig ( " .config/13-epub_page_size/height " , value ) ;
string_writeconfig ( " .config/13-epub_page_size/set " , " true " ) ;
2022-04-17 19:25:29 -07:00
log ( " Set ePUB page size height to " + QString : : number ( arg1 ) , className ) ;
2021-06-20 19:57:10 -07:00
}
2021-06-27 10:28:41 -07:00
void settings : : on_readerScrollBarCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " scrollbar display if necessary setting " ;
2021-06-27 10:28:41 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-06-27 10:28:41 -07:00
string_writeconfig ( " .config/14-reader_scrollbar/config " , " true " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-06-27 10:28:41 -07:00
string_writeconfig ( " .config/14-reader_scrollbar/config " , " false " ) ;
}
}
2021-06-28 16:57:40 -07:00
void settings : : on_sleepTimeoutComboBox_currentIndexChanged ( const QString & arg1 )
{
2022-04-17 19:25:29 -07:00
log ( " Setting sleep timeout setting to " + arg1 , className ) ;
2021-06-28 16:57:40 -07:00
setDefaultWorkDir ( ) ;
if ( arg1 = = " Never " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " -1 " ) ;
}
if ( arg1 = = " 2 minutes " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " 2 " ) ;
}
if ( arg1 = = " 5 minutes " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " 5 " ) ;
}
if ( arg1 = = " 10 minutes " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " 10 " ) ;
}
if ( arg1 = = " 15 minutes " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " 15 " ) ;
}
if ( arg1 = = " 30 minutes " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " 30 " ) ;
}
if ( arg1 = = " 60 minutes " ) {
string_writeconfig ( " .config/15-sleep_timeout/config " , " 60 " ) ;
}
}
2021-06-29 12:28:54 -07:00
void settings : : brightnessDown ( ) {
cinematicBrightness ( 0 , 1 ) ;
}
2021-08-05 21:50:28 -07:00
void settings : : on_globalReadingSettingsCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " global reading settings setting " ;
2021-08-05 21:50:28 -07:00
if ( checked = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-08-05 21:50:28 -07:00
checked_box = true ;
writeconfig ( " .config/16-global_reading_settings/config " , " GlobalReadingSettings= " ) ;
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-08-05 21:50:28 -07:00
checked_box = false ;
writeconfig ( " .config/16-global_reading_settings/config " , " GlobalReadingSettings= " ) ;
}
}
2021-08-25 10:16:41 -07:00
void settings : : on_checkOtaUpdateBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Check for OTA update' button clicked " , className ) ;
2022-05-16 20:57:35 -07:00
if ( testPing ( true ) = = 0 or global : : deviceID = = " emu \n " ) {
launchOtaUpdater ( ) ;
}
else {
emit showToast ( " Wi-Fi connection error " ) ;
}
2021-08-25 10:16:41 -07:00
}
void settings : : openUpdateDialog ( ) {
2022-04-17 19:25:29 -07:00
log ( " Showing update dialog " , className ) ;
2021-08-25 10:16:41 -07:00
global : : mainwindow : : updateDialog = true ;
// Write to a temporary file to show an "Update" prompt
string_writeconfig ( " /inkbox/updateDialog " , " true " ) ;
// Show the dialog
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2021-08-25 10:32:33 -07:00
connect ( generalDialogWindow , SIGNAL ( showToast ( QString ) ) , SLOT ( showToastNative ( QString ) ) ) ;
connect ( generalDialogWindow , SIGNAL ( closeIndefiniteToast ( ) ) , SLOT ( closeIndefiniteToastNative ( ) ) ) ;
2021-08-25 10:16:41 -07:00
QApplication : : processEvents ( ) ;
}
void settings : : launchOtaUpdater ( ) {
2021-09-04 11:16:09 -07:00
global : : toast : : modalToast = true ;
global : : toast : : indefiniteToast = true ;
emit showToast ( " Checking for updates " ) ;
2021-08-25 10:16:41 -07:00
otaManagerWindow = new otaManager ( this ) ;
connect ( otaManagerWindow , SIGNAL ( canOtaUpdate ( bool ) ) , SLOT ( openUpdateDialogOTA ( bool ) ) ) ;
otaManagerWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
void settings : : openUpdateDialogOTA ( bool open ) {
2021-09-04 19:18:17 -07:00
emit closeIndefiniteToast ( ) ;
2021-08-25 10:16:41 -07:00
if ( open = = true ) {
global : : otaUpdate : : isUpdateOta = true ;
openUpdateDialog ( ) ;
}
else {
2021-09-05 06:52:35 -07:00
emit showToast ( " No update available " ) ;
2021-08-25 10:16:41 -07:00
}
}
2021-08-25 10:32:33 -07:00
void settings : : showToastNative ( QString messageToDisplay ) {
emit showToast ( messageToDisplay ) ;
2021-08-25 10:16:41 -07:00
}
2021-08-25 10:32:33 -07:00
void settings : : closeIndefiniteToastNative ( ) {
emit closeIndefiniteToast ( ) ;
2021-08-25 10:16:41 -07:00
}
2021-09-26 19:05:45 -07:00
void settings : : usbms_launch ( )
{
2022-04-17 19:25:29 -07:00
log ( " Showing USBMS splash " , className ) ;
2021-09-26 19:05:45 -07:00
global : : usbms : : launchUsbms = true ;
usbmsWindow = new usbms_splash ( ) ;
usbmsWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
usbmsWindow - > setGeometry ( QRect ( QPoint ( 0 , 0 ) , screen ( ) - > geometry ( ) . size ( ) ) ) ;
usbmsWindow - > show ( ) ;
}
void settings : : quit_restart ( ) {
// If existing, cleaning bookconfig_mount mountpoint
string_writeconfig ( " /opt/ibxd " , " bookconfig_unmount \n " ) ;
// Restarting InkBox
QProcess process ;
process . startDetached ( " inkbox " , QStringList ( ) ) ;
qApp - > quit ( ) ;
}
2021-10-17 19:31:44 -07:00
void settings : : on_enableEncryptedStorageCheckBox_toggled ( bool checked )
{
2022-04-17 19:25:29 -07:00
QString settingString = " encrypted storage setting " ;
2021-10-17 19:31:44 -07:00
if ( checked = = true ) {
if ( enableEncryptedStorageUserChange = = true ) {
2022-04-17 19:25:29 -07:00
logEnabled ( settingString ) ;
2021-10-17 19:31:44 -07:00
setDefaultWorkDir ( ) ;
string_writeconfig ( " .config/18-encrypted_storage/initial_setup_done " , " false " ) ;
string_writeconfig ( " .config/18-encrypted_storage/status " , " true " ) ;
if ( QFile : : exists ( " .config/18-encrypted_storage/storage_list " ) ) {
QFile : : remove ( " .config/18-encrypted_storage/storage_list " ) ;
}
global : : settings : : settingsRebootDialog = true ;
2021-10-18 05:46:27 -07:00
global : : encfs : : enableStorageEncryptionDialog = true ;
2021-10-17 19:31:44 -07:00
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
else {
enableEncryptedStorageUserChange = true ;
}
}
else {
2022-04-17 19:25:29 -07:00
logDisabled ( settingString ) ;
2021-10-17 19:31:44 -07:00
global : : encfs : : disableStorageEncryptionDialog = true ;
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
connect ( generalDialogWindow , SIGNAL ( cancelDisableStorageEncryption ( ) ) , SLOT ( cancelDisableStorageEncryption ( ) ) ) ;
connect ( generalDialogWindow , SIGNAL ( disableStorageEncryption ( ) ) , SLOT ( disableStorageEncryption ( ) ) ) ;
}
}
void settings : : disableStorageEncryption ( ) {
2022-04-15 17:27:58 -07:00
log ( " Disabling encrypted storage " , className ) ;
2021-10-17 19:31:44 -07:00
setDefaultWorkDir ( ) ;
2021-11-09 19:31:54 -08:00
string_writeconfig ( " /external_root/run/encfs_stop_cleanup " , " true " ) ;
2021-10-17 19:31:44 -07:00
string_writeconfig ( " /opt/ibxd " , " encfs_stop \n " ) ;
QThread : : msleep ( 5000 ) ;
string_writeconfig ( " .config/18-encrypted_storage/status " , " false " ) ;
QFile : : remove ( " .config/18-encrypted_storage/initial_setup_done " ) ;
QFile : : remove ( " .config/18-encrypted_storage/storage_list " ) ;
QFile : : remove ( " /mnt/onboard/onboard/data.encfs " ) ;
QDir dumpDir ( " /mnt/onboard/onboard/encfs-dropbox " ) ;
dumpDir . removeRecursively ( ) ;
QDir decDir ( " /mnt/onboard/onboard/encfs-decrypted " ) ;
decDir . removeRecursively ( ) ;
global : : settings : : settingsRebootDialog = true ;
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
void settings : : cancelDisableStorageEncryption ( ) {
enableEncryptedStorageUserChange = false ;
ui - > enableEncryptedStorageCheckBox - > click ( ) ;
}
2021-11-14 18:22:58 -08:00
void settings : : on_repackBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Repack encrypted storage' button clicked " , className ) ;
2021-11-14 19:23:09 -08:00
QDir dir ( " /mnt/onboard/onboard/encfs-dropbox " ) ;
2021-11-14 18:22:58 -08:00
if ( dir . isEmpty ( ) ) {
2022-04-17 19:25:29 -07:00
log ( " Showing encrypted storage repack error dialog ('encfs-dropbox' directory is empty) " , className ) ;
2021-11-14 18:22:58 -08:00
global : : encfs : : errorNoBooksInDropboxDialog = true ;
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
else {
2022-04-17 19:25:29 -07:00
log ( " Showing encrypted storage repack dialog " , className ) ;
2021-11-14 18:22:58 -08:00
string_writeconfig ( " /external_root/run/encfs_repack " , " true " ) ;
2021-11-14 19:23:09 -08:00
quit_restart ( ) ;
2021-11-14 18:22:58 -08:00
}
}
2022-02-22 21:22:57 -08:00
void settings : : on_generateSystemReportBtn_clicked ( )
{
2022-04-17 19:25:29 -07:00
log ( " 'Generate system report' button clicked " , className ) ;
2022-04-15 17:27:58 -07:00
log ( " Generating system report " , className ) ;
2022-02-22 21:22:57 -08:00
string_writeconfig ( " /opt/ibxd " , " generate_system_report \n " ) ;
while ( true ) {
if ( QFile : : exists ( " /inkbox/systemReportDone " ) ) {
if ( checkconfig ( " /inkbox/systemReportDone " ) = = true ) {
2022-06-28 23:15:13 -07:00
QFile : : remove ( global : : localLibrary : : databasePath ) ;
2022-02-22 21:22:57 -08:00
emit showToast ( " System report generated successfully " ) ;
}
else {
emit showToast ( " Error in generating system report " ) ;
}
2022-02-26 20:43:17 -08:00
QFile : : remove ( " /inkbox/systemReportDone " ) ;
2022-03-01 20:41:38 -08:00
break ;
2022-02-22 21:22:57 -08:00
}
}
}
2022-03-13 11:06:29 -07:00
void settings : : on_tzComboBox_currentTextChanged ( const QString & arg1 )
{
if ( timezone_not_user_change = = true ) {
timezone_not_user_change = false ;
}
else {
2022-04-15 17:27:58 -07:00
log ( " Setting timezone to " + arg1 , className ) ;
2022-03-13 11:06:29 -07:00
setDefaultWorkDir ( ) ;
// Preventing unnecessary (e)MMC writes
if ( readFile ( " .config/19-timezone/config-name " ) ! = arg1 ) {
QProcess : : execute ( " ln " , QStringList ( ) < < " -sf " < < " /usr/share/zoneinfo/ " + arg1 < < " .config/19-timezone/config " ) ;
string_writeconfig ( " .config/19-timezone/config-name " , arg1 . toStdString ( ) ) ;
2022-04-15 17:27:58 -07:00
string_writeconfig ( " /opt/ibxd " , " gui_remount_localtime \n " ) ;
QThread : : msleep ( 500 ) ;
2022-03-13 11:06:29 -07:00
}
}
}
2022-04-17 19:25:29 -07:00
void settings : : logEnabled ( QString settingString ) {
log ( " Enabling " + settingString , className ) ;
}
void settings : : logDisabled ( QString settingString ) {
log ( " Disabling " + settingString , className ) ;
}