2021-03-25 05:00:19 -07:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
# include "settings.h"
# include "ui_settings.h"
# include "apps.h"
# include "ui_apps.h"
2021-04-05 06:50:58 -07:00
# include "functions.h"
2021-03-25 05:00:19 -07:00
# include <QTime>
# include <QDateTime>
# include <QTimer>
2021-04-22 10:56:29 -07:00
# include <QDebug>
2021-03-25 05:00:19 -07:00
# include <QMessageBox>
# include <QString>
# include <QFile>
# include <string>
# include <iostream>
# include <fstream>
# include <QTextStream>
# include <QPixmap>
# include <QScreen>
2021-03-29 18:47:21 -07:00
# include <QFont>
# include <QFontDatabase>
2021-03-25 05:00:19 -07:00
using namespace std ;
MainWindow : : MainWindow ( QWidget * parent )
: QMainWindow ( parent )
, ui ( new Ui : : MainWindow )
{
ui - > setupUi ( this ) ;
ui - > settingsBtn - > setProperty ( " type " , " borderless " ) ;
ui - > appsBtn - > setProperty ( " type " , " borderless " ) ;
ui - > quitBtn - > setProperty ( " type " , " borderless " ) ;
ui - > searchBtn - > setProperty ( " type " , " borderless " ) ;
ui - > pushButton - > setProperty ( " type " , " borderless " ) ;
2021-12-25 20:34:46 -08:00
ui - > libraryButton - > setProperty ( " type " , " borderless " ) ;
2021-03-28 19:18:48 -07:00
ui - > brightnessBtn - > setProperty ( " type " , " borderless " ) ;
2021-04-23 19:23:24 -07:00
ui - > homeBtn - > setProperty ( " type " , " borderless " ) ;
2021-07-13 12:18:59 -07:00
ui - > wifiBtn - > setProperty ( " type " , " borderless " ) ;
2021-03-25 05:00:19 -07:00
ui - > settingsBtn - > setText ( " " ) ;
ui - > appsBtn - > setText ( " " ) ;
2021-12-25 20:34:46 -08:00
ui - > pushButton - > setText ( " \t \t Reader " ) ;
ui - > libraryButton - > setText ( " \t \t Library " ) ;
2021-03-25 05:00:19 -07:00
ui - > quitBtn - > setText ( " " ) ;
ui - > searchBtn - > setText ( " " ) ;
2021-03-28 19:18:48 -07:00
ui - > brightnessBtn - > setText ( " " ) ;
2021-04-23 19:23:24 -07:00
ui - > homeBtn - > setText ( " " ) ;
2021-04-24 06:34:35 -07:00
ui - > quoteLabel - > setText ( " " ) ;
2021-07-13 12:18:59 -07:00
ui - > wifiBtn - > setText ( " " ) ;
2021-04-24 06:34:35 -07:00
ui - > quotePictureLabel - > setText ( " " ) ;
2021-03-25 05:00:19 -07:00
2021-04-23 19:23:24 -07:00
ui - > quoteHeadingLabel - > setStyleSheet ( " padding: 30px " ) ;
2021-04-24 06:34:35 -07:00
ui - > homeBtn - > setStyleSheet ( " padding: 5px " ) ;
2021-04-23 05:47:05 -07:00
2021-05-13 18:40:05 -07:00
// Initializing some variables
2021-04-23 05:47:05 -07:00
global : : battery : : showLowBatteryDialog = true ;
global : : battery : : showCriticalBatteryAlert = true ;
2021-05-09 11:07:05 -07:00
global : : usbms : : showUsbmsDialog = true ;
global : : usbms : : launchUsbms = false ;
2021-05-13 18:40:05 -07:00
global : : usbms : : koboxExportExtensions = false ;
2021-04-24 06:34:35 -07:00
global : : mainwindow : : tabSwitcher : : repaint = true ;
2021-04-23 05:47:05 -07:00
2021-03-25 05:00:19 -07:00
// Getting the screen's size
2021-04-23 19:23:24 -07:00
sW = QGuiApplication : : screens ( ) [ 0 ] - > size ( ) . width ( ) ;
sH = QGuiApplication : : screens ( ) [ 0 ] - > size ( ) . height ( ) ;
2021-03-25 05:00:19 -07:00
2021-04-23 19:23:24 -07:00
// Defining what the default icon size will be
2021-05-16 19:28:08 -07:00
string_checkconfig_ro ( " /opt/inkbox_device " ) ;
2021-03-25 05:00:19 -07:00
if ( checkconfig_str_val = = " n705 \n " ) {
stdIconWidth = sW / 12 ;
stdIconHeight = sH / 12 ;
2021-03-29 05:04:46 -07:00
brightnessIconWidth = sW / 24 ;
brightnessIconHeight = sH / 24 ;
2021-04-23 19:23:24 -07:00
homeIconWidth = sW / 18 ;
homeIconHeight = sW / 18 ;
2021-07-13 22:24:30 -07:00
wifiIconWidth = sW / 20.5 ;
wifiIconHeight = sH / 20.5 ;
2021-03-25 05:00:19 -07:00
}
2021-06-26 07:09:51 -07:00
else if ( checkconfig_str_val = = " n905 \n " ) {
2021-03-25 05:00:19 -07:00
stdIconWidth = sW / 14 ;
stdIconHeight = sH / 14 ;
2021-03-29 05:04:46 -07:00
brightnessIconWidth = sW / 26 ;
brightnessIconHeight = sH / 26 ;
2021-04-23 19:23:24 -07:00
homeIconWidth = sW / 20 ;
homeIconHeight = sW / 20 ;
2021-07-13 22:24:30 -07:00
wifiIconWidth = sW / 22.5 ;
wifiIconHeight = sH / 22.5 ;
2021-03-25 05:00:19 -07:00
}
2021-12-25 10:50:30 -08:00
else if ( checkconfig_str_val = = " n613 \n " or checkconfig_str_val = = " emu \n " ) {
2021-06-26 07:09:51 -07:00
stdIconWidth = sW / 12.5 ;
stdIconHeight = sH / 12.5 ;
brightnessIconWidth = sW / 24.5 ;
brightnessIconHeight = sH / 24.5 ;
homeIconWidth = sW / 18.5 ;
homeIconHeight = sW / 18.5 ;
2021-07-13 22:24:30 -07:00
wifiIconWidth = sW / 21 ;
wifiIconHeight = sH / 21 ;
2021-06-26 07:09:51 -07:00
}
2021-06-27 08:07:43 -07:00
else {
stdIconWidth = sW / 14 ;
stdIconHeight = sH / 14 ;
brightnessIconWidth = sW / 26 ;
brightnessIconHeight = sH / 26 ;
homeIconWidth = sW / 20 ;
homeIconHeight = sW / 20 ;
2021-07-13 22:24:30 -07:00
wifiIconWidth = sW / 22.5 ;
wifiIconHeight = sH / 22.5 ;
2021-06-27 08:07:43 -07:00
}
2021-03-25 05:00:19 -07:00
// Setting icons up
ui - > pushButton - > setIcon ( QIcon ( " :/resources/book.png " ) ) ;
ui - > pushButton - > setIconSize ( QSize ( stdIconWidth , stdIconHeight ) ) ;
2021-12-25 20:34:46 -08:00
ui - > libraryButton - > setIcon ( QIcon ( " :/resources/online-library.png " ) ) ;
ui - > libraryButton - > setIconSize ( QSize ( stdIconWidth , stdIconHeight ) ) ;
2021-03-25 05:00:19 -07:00
ui - > searchBtn - > setIcon ( QIcon ( " :/resources/search.png " ) ) ;
ui - > searchBtn - > setIconSize ( QSize ( stdIconWidth , stdIconHeight ) ) ;
ui - > settingsBtn - > setIcon ( QIcon ( " :/resources/settings.png " ) ) ;
ui - > settingsBtn - > setIconSize ( QSize ( stdIconWidth , stdIconHeight ) ) ;
ui - > appsBtn - > setIcon ( QIcon ( " :/resources/apps.png " ) ) ;
ui - > appsBtn - > setIconSize ( QSize ( stdIconWidth , stdIconHeight ) ) ;
ui - > quitBtn - > setIcon ( QIcon ( " :/resources/power.png " ) ) ;
ui - > quitBtn - > setIconSize ( QSize ( stdIconWidth , stdIconHeight ) ) ;
2021-04-23 19:23:24 -07:00
ui - > homeBtn - > setIcon ( QIcon ( " :/resources/home.png " ) ) ;
ui - > homeBtn - > setIconSize ( QSize ( homeIconWidth , homeIconHeight ) ) ;
2021-03-28 19:18:48 -07:00
ui - > brightnessBtn - > setIcon ( QIcon ( " :/resources/frontlight.png " ) ) ;
ui - > brightnessBtn - > setIconSize ( QSize ( brightnessIconWidth , brightnessIconHeight ) ) ;
2021-07-13 12:18:59 -07:00
setWifiIcon ( ) ;
2021-07-16 13:41:36 -07:00
if ( global : : device : : isWifiAble = = true ) {
updateWifiIcon ( 0 ) ;
}
2021-06-23 08:26:00 -07:00
setBatteryIcon ( ) ;
2021-03-29 05:04:46 -07:00
2021-03-29 18:47:21 -07:00
int id = QFontDatabase : : addApplicationFont ( " :/resources/fonts/CrimsonPro-Regular.ttf " ) ;
QString family = QFontDatabase : : applicationFontFamilies ( id ) . at ( 0 ) ;
QFont crimson ( family ) ;
ui - > book1Btn - > setFont ( QFont ( crimson ) ) ;
ui - > book2Btn - > setFont ( QFont ( crimson ) ) ;
ui - > book3Btn - > setFont ( QFont ( crimson ) ) ;
ui - > book4Btn - > setFont ( QFont ( crimson ) ) ;
2021-03-25 05:00:19 -07:00
ui - > book1Btn - > setStyleSheet ( " font-size: 11pt; padding: 25px " ) ;
ui - > book2Btn - > setStyleSheet ( " font-size: 11pt; padding: 25px " ) ;
ui - > book3Btn - > setStyleSheet ( " font-size: 11pt; padding: 25px " ) ;
ui - > book4Btn - > setStyleSheet ( " font-size: 11pt; padding: 25px " ) ;
2021-03-29 05:04:46 -07:00
ui - > brightnessBtn - > setStyleSheet ( " font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 8px; padding-right: 8px; " ) ;
2021-07-13 12:18:59 -07:00
ui - > wifiBtn - > setStyleSheet ( " font-size: 9pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px " ) ;
2021-03-30 04:35:58 -07:00
2021-04-09 17:54:20 -07:00
// Checking if we have a Mini or Touch there
2021-03-30 04:35:58 -07:00
string_checkconfig_ro ( " /opt/inkbox_device " ) ;
2021-04-09 17:54:20 -07:00
if ( checkconfig_str_val = = " n705 \n " or checkconfig_str_val = = " n905 \n " ) {
2021-03-30 04:35:58 -07:00
ui - > batteryIcon - > setStyleSheet ( " font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 1px; padding-right: 1px; " ) ;
}
2021-06-26 07:09:51 -07:00
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; " ) ;
}
2021-07-13 12:18:59 -07:00
else if ( checkconfig_str_val = = " n873 \n " ) {
ui - > batteryIcon - > setStyleSheet ( " font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; " ) ;
}
2021-03-30 04:35:58 -07:00
else {
ui - > batteryIcon - > setStyleSheet ( " font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px; " ) ;
}
2021-03-29 05:04:46 -07:00
ui - > line_7 - > setStyleSheet ( " padding: 0px " ) ;
2021-03-28 19:18:48 -07:00
ui - > batteryIcon - > setText ( " " ) ;
2021-03-29 05:04:46 -07:00
ui - > batteryLabel - > setText ( " " ) ;
ui - > timeLabel - > setText ( " " ) ;
ui - > batteryLabel - > setStyleSheet ( " padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px " ) ;
2021-03-28 19:18:48 -07:00
2021-03-25 05:00:19 -07:00
ui - > book1Btn - > hide ( ) ;
ui - > book2Btn - > hide ( ) ;
ui - > book3Btn - > hide ( ) ;
ui - > book4Btn - > hide ( ) ;
ui - > recentBooksLabel - > hide ( ) ;
2021-12-30 17:37:39 -08:00
// Deleting/Hiding "Library" button if device is not WiFi-able
if ( global : : device : : isWifiAble = = false & & readFile ( " /opt/inkbox_device " ) ! = " emu \n " ) {
ui - > libraryButton - > deleteLater ( ) ;
ui - > line_10 - > deleteLater ( ) ;
}
2021-03-25 05:00:19 -07:00
// Stylesheet
QFile stylesheetFile ( " :/resources/eink.qss " ) ;
stylesheetFile . open ( QFile : : ReadOnly ) ;
this - > setStyleSheet ( stylesheetFile . readAll ( ) ) ;
stylesheetFile . close ( ) ;
// Running rootfs changes script if it's there
2021-04-04 18:02:08 -07:00
// Not a big security flaw anymore. InkBox OS verifies the digital signature of the update package and aborts the update if it's not genuine.
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
if ( checkconfig ( " /external_root/opt/update/inkbox_updated " ) = = true ) {
2021-03-27 12:13:37 -07:00
// Checking if we need to reboot after running the two scripts
if ( checkconfig ( " /mnt/onboard/onboard/.inkbox/reboot " ) = = true ) {
reboot_after_update = true ;
QFile : : remove ( " /mnt/onboard/onboard/.inkbox/reboot " ) ;
}
else {
reboot_after_update = false ;
}
QFile : : copy ( " /mnt/onboard/onboard/.inkbox/rootfs.sh " , " /external_root/tmp/rootfs.sh " ) ;
QFile : : copy ( " /mnt/onboard/onboard/.inkbox/rootfs-internal.sh " , " /tmp/rootfs-internal.sh " ) ;
// First script
QString rootfs_internal_prog ( " sh " ) ;
QStringList rootfs_internal_args ;
rootfs_internal_args < < " /tmp/rootfs-internal.sh " ;
// Removing script
QFile : : remove ( " /mnt/onboard/onboard/.inkbox/rootfs-internal.sh " ) ;
QProcess * rootfs_internal_proc = new QProcess ( ) ;
rootfs_internal_proc - > start ( rootfs_internal_prog , rootfs_internal_args ) ;
rootfs_internal_proc - > waitForFinished ( ) ;
2021-08-29 12:05:07 -07:00
rootfs_internal_proc - > deleteLater ( ) ;
2021-03-27 12:13:37 -07:00
2021-04-01 14:36:42 -07:00
// Second script
QString rootfs_prog ( " chroot " ) ;
QStringList rootfs_args ;
rootfs_args < < " /external_root " < < " /tmp/rootfs.sh " ;
// Removing script
QFile : : remove ( " /mnt/onboard/onboard/.inkbox/rootfs.sh " ) ;
QProcess * rootfs_proc = new QProcess ( ) ;
rootfs_proc - > start ( rootfs_prog , rootfs_args ) ;
rootfs_proc - > waitForFinished ( ) ;
2021-08-29 12:05:07 -07:00
rootfs_proc - > deleteLater ( ) ;
2021-04-01 14:36:42 -07:00
2021-04-25 08:27:51 -07:00
// Removing update directory contents
QDir dir ( " /mnt/onboard/onboard/.inkbox " ) ;
dir . removeRecursively ( ) ;
// Re-creating update directory
QString path ( " /mnt/onboard/onboard/.inkbox " ) ;
dir . mkpath ( path ) ;
2021-03-27 12:13:37 -07:00
// Rebooting if needed
if ( reboot_after_update = = true ) {
2021-04-22 04:38:54 -07:00
reboot ( false ) ;
2021-03-27 12:13:37 -07:00
}
else {
// Update process finished.
;
}
2021-03-25 05:00:19 -07:00
}
}
else {
;
}
// Custom settings
// Reading from the config files and tweaking the program according to the options set
// Safety mesure; /inkbox is a tmpfs
2021-04-23 05:47:05 -07:00
string_writeconfig ( " /tmp/skip_opendialog " , " true " ) ;
2021-04-22 07:10:47 -07:00
global : : reader : : skipOpenDialog = false ;
2021-03-25 05:00:19 -07:00
// Demo setting, changes "Welcome to InkBox" label to "InkBox"
if ( checkconfig ( " .config/01-demo/config " ) = = true ) {
ui - > inkboxLabel - > setText ( " InkBox " ) ;
}
2021-04-23 05:47:05 -07:00
// Dark mode; write to the Kobo Nightmode FIFO
2021-04-05 12:35:25 -07:00
if ( checkconfig ( " .config/10-dark_mode/config " ) = = true ) {
string_writeconfig ( " /tmp/invertScreen " , " y " ) ;
}
else {
string_writeconfig ( " /tmp/invertScreen " , " n " ) ;
2021-03-25 05:00:19 -07:00
}
// Clock setting to show seconds
if ( checkconfig ( " .config/02-clock/config " ) = = true ) {
QTimer * t = new QTimer ( this ) ;
t - > setInterval ( 500 ) ;
connect ( t , & QTimer : : timeout , [ & ] ( ) {
QString time = QTime : : currentTime ( ) . toString ( " hh:mm:ss " ) ;
2021-03-28 19:18:48 -07:00
get_battery_level ( ) ;
2021-03-25 05:00:19 -07:00
ui - > timeLabel - > setText ( time ) ;
2021-03-28 19:18:48 -07:00
ui - > batteryLabel - > setText ( batt_level ) ;
2021-03-25 05:00:19 -07:00
} ) ;
t - > start ( ) ;
}
else {
QTimer * t = new QTimer ( this ) ;
t - > setInterval ( 500 ) ;
connect ( t , & QTimer : : timeout , [ & ] ( ) {
QString time = QTime : : currentTime ( ) . toString ( " hh:mm " ) ;
2021-03-28 19:18:48 -07:00
get_battery_level ( ) ;
2021-03-25 05:00:19 -07:00
ui - > timeLabel - > setText ( time ) ;
2021-03-28 19:18:48 -07:00
ui - > batteryLabel - > setText ( batt_level ) ;
2021-03-25 05:00:19 -07:00
} ) ;
t - > start ( ) ;
}
2021-04-23 16:22:53 -07:00
// Battery watchdog
2021-04-23 05:47:05 -07:00
QTimer * batteryWatchdog = new QTimer ( this ) ;
batteryWatchdog - > setInterval ( 2000 ) ;
connect ( batteryWatchdog , & QTimer : : timeout , [ & ] ( ) {
// Checking if battery level is low
if ( global : : battery : : showCriticalBatteryAlert ! = true ) {
;
}
else {
if ( isBatteryCritical ( ) = = true ) {
2021-06-28 09:26:04 -07:00
string_checkconfig_ro ( " /sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status " ) ;
if ( checkconfig_str_val = = " Charging \n " ) {
;
}
else {
qDebug ( ) < < " Warning! Battery is at a critical charge level! " ;
openCriticalBatteryAlertWindow ( ) ;
}
2021-04-23 05:47:05 -07:00
}
}
if ( global : : battery : : showLowBatteryDialog ! = true ) {
// Do nothing, since a dialog should already have been displayed and (probably) dismissed
;
}
else {
if ( isBatteryLow ( ) = = true ) {
if ( global : : battery : : batteryAlertLock = = true ) {
;
}
else {
qDebug ( ) < < " Warning! Battery is low! " ;
string_checkconfig_ro ( " /sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status " ) ;
if ( checkconfig_str_val = = " Charging \n " ) {
;
}
else {
openLowBatteryDialog ( ) ;
}
}
}
}
} ) ;
2021-12-25 07:36:38 -08:00
batteryWatchdog - > start ( ) ;
2021-04-23 05:47:05 -07:00
2021-05-07 22:03:25 -07:00
// USB mass storage prompt
QTimer * usbmsPrompt = new QTimer ( this ) ;
2021-06-29 09:26:30 -07:00
usbmsPrompt - > setInterval ( 500 ) ;
2021-05-07 22:03:25 -07:00
connect ( usbmsPrompt , & QTimer : : timeout , [ & ] ( ) {
2021-05-09 11:07:05 -07:00
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
if ( global : : usbms : : showUsbmsDialog ! = true ) {
2021-06-29 07:19:21 -07:00
string_checkconfig_ro ( " /sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status " ) ;
if ( usbmsStatus ! = checkconfig_str_val ) {
global : : usbms : : showUsbmsDialog = true ;
}
2021-05-07 22:03:25 -07:00
}
else {
2021-06-29 07:19:21 -07:00
string_checkconfig_ro ( " /sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status " ) ;
usbmsStatus = checkconfig_str_val ;
if ( usbmsStatus ! = " Charging \n " ) {
2021-05-09 11:07:05 -07:00
// Loop again...
;
}
else {
// An USB cable is connected!
2021-07-13 22:24:30 -07:00
setBatteryIcon ( ) ;
2021-05-09 11:07:05 -07:00
openUsbmsDialog ( ) ;
}
2021-05-07 22:03:25 -07:00
}
}
2021-05-09 11:07:05 -07:00
else {
// Do nothing, we're running along with Nickel & friends...
;
}
2021-05-07 22:03:25 -07:00
} ) ;
2021-06-29 07:19:21 -07:00
usbmsPrompt - > start ( ) ;
2021-05-07 22:03:25 -07:00
2021-03-25 05:00:19 -07:00
// We set the brightness level saved in the config file
2021-06-28 16:57:40 -07:00
QTimer : : singleShot ( 2000 , this , SLOT ( setInitialBrightness ( ) ) ) ;
2021-03-25 05:00:19 -07:00
2021-10-18 05:46:27 -07:00
// If new files are found in /mnt/onboard/onboard/encfs-dropbox, ask if user wants to encrypt them
if ( checkconfig ( " .config/18-encrypted_storage/status " ) = = true ) {
QDir encfsDropboxDir ( " /mnt/onboard/onboard/encfs-dropbox " ) ;
2021-12-31 12:50:59 -08:00
if ( ! encfsDropboxDir . isEmpty ( ) ) {
QTimer : : singleShot ( 1000 , this , SLOT ( openEncfsRepackDialog ( ) ) ) ;
2021-10-18 05:46:27 -07:00
}
}
2021-03-25 05:00:19 -07:00
// Display quote if requested; otherwise, display recent books
string_checkconfig ( " .config/05-quote/config " ) ;
if ( checkconfig_str_val = = " " ) {
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
checked_box = true ;
writeconfig ( " .config/05-quote/config " , " DisableQuote= " ) ;
}
else {
checked_box = false ;
writeconfig ( " .config/05-quote/config " , " DisableQuote= " ) ;
}
}
2021-08-05 21:50:28 -07:00
// Global reading settings
string_checkconfig ( " .config/16-global_reading_settings/config " ) ;
if ( checkconfig_str_val = = " " ) {
checked_box = true ;
writeconfig ( " .config/16-global_reading_settings/config " , " GlobalReadingSettings= " ) ;
}
2021-03-25 05:00:19 -07:00
if ( checkconfig ( " .config/05-quote/config " ) = = false ) {
int quote_value = display_quote ( ) ;
if ( quote_value = = 1 ) {
QPixmap pm ( " :/resources/chesterton.jpg " ) ;
ui - > quotePictureLabel - > setPixmap ( pm ) ;
ui - > quotePictureLabel - > setScaledContents ( true ) ;
ui - > quoteLabel - > setText ( " “A good novel tells us the truth about its hero; but a bad novel tells us the truth about its author.” \n ― G.K. Chesterton " ) ;
}
if ( quote_value = = 2 ) {
QPixmap pm ( " :/resources/alcott.jpg " ) ;
ui - > quotePictureLabel - > setPixmap ( pm ) ;
ui - > quotePictureLabel - > setScaledContents ( true ) ;
ui - > quoteLabel - > setText ( " “I've got the key to my castle in the air, but whether I can unlock the door remains to be seen.” \n ― Louisa May Alcott " ) ;
}
if ( quote_value = = 3 ) {
QPixmap pm ( " :/resources/king.jpg " ) ;
ui - > quotePictureLabel - > setPixmap ( pm ) ;
ui - > quotePictureLabel - > setScaledContents ( true ) ;
ui - > quoteLabel - > setText ( " “Quiet people have the loudest minds” \n ― Stephen King " ) ;
}
if ( quote_value = = 4 ) {
QPixmap pm ( " :/resources/davies.jpg " ) ;
ui - > quotePictureLabel - > setPixmap ( pm ) ;
ui - > quotePictureLabel - > setScaledContents ( true ) ;
ui - > quoteLabel - > setText ( " “Authors like cats because they are such quiet, lovable, wise creatures, and cats like authors for the same reasons.” \n ― Robertson Davies " ) ;
}
if ( quote_value = = 5 ) {
QPixmap pm ( " :/resources/christie.png " ) ;
ui - > quotePictureLabel - > setPixmap ( pm ) ;
ui - > quotePictureLabel - > setScaledContents ( true ) ;
ui - > quoteLabel - > setText ( " “One of the saddest things in life, is the things one remembers.” \n ― Agatha Christie " ) ;
}
}
else {
2021-04-24 06:34:35 -07:00
ui - > gridLayout_4 - > deleteLater ( ) ;
ui - > quotePictureLabel - > deleteLater ( ) ;
ui - > quoteLabel - > deleteLater ( ) ;
2021-03-25 05:00:19 -07:00
ui - > quoteHeadingLabel - > setText ( " Books " ) ;
ui - > book1Btn - > show ( ) ;
ui - > book2Btn - > show ( ) ;
ui - > book3Btn - > show ( ) ;
ui - > book4Btn - > show ( ) ;
// Book 1
string_checkconfig ( " .config/08-recent_books/1 " ) ;
if ( checkconfig_str_val = = " " ) {
ui - > book1Btn - > hide ( ) ;
}
else {
relative_path = checkconfig_str_val . split ( " / " ) . last ( ) ;
relative_path . prepend ( " " ) ;
relative_path . append ( " " ) ;
ui - > book1Btn - > setText ( relative_path ) ;
existing_recent_books = true ;
}
// Book 2
string_checkconfig ( " .config/08-recent_books/2 " ) ;
if ( checkconfig_str_val = = " " ) {
ui - > book2Btn - > hide ( ) ;
}
else {
relative_path = checkconfig_str_val . split ( " / " ) . last ( ) ;
relative_path . prepend ( " " ) ;
relative_path . append ( " " ) ;
ui - > book2Btn - > setText ( relative_path ) ;
existing_recent_books = true ;
}
// Book 3
string_checkconfig ( " .config/08-recent_books/3 " ) ;
if ( checkconfig_str_val = = " " ) {
ui - > book3Btn - > hide ( ) ;
}
else {
relative_path = checkconfig_str_val . split ( " / " ) . last ( ) ;
relative_path . prepend ( " " ) ;
relative_path . append ( " " ) ;
ui - > book3Btn - > setText ( relative_path ) ;
existing_recent_books = true ;
}
// Book 4
string_checkconfig ( " .config/08-recent_books/4 " ) ;
if ( checkconfig_str_val = = " " ) {
ui - > book4Btn - > hide ( ) ;
}
else {
relative_path = checkconfig_str_val . split ( " / " ) . last ( ) ;
relative_path . prepend ( " " ) ;
relative_path . append ( " " ) ;
ui - > book4Btn - > setText ( relative_path ) ;
existing_recent_books = true ;
}
// Preventing from having the same label two times
if ( ui - > book2Btn - > text ( ) = = ui - > book1Btn - > text ( ) ) {
ui - > book2Btn - > hide ( ) ;
}
2021-04-30 20:19:54 -07:00
else if ( ui - > book3Btn - > text ( ) = = ui - > book1Btn - > text ( ) ) {
2021-03-25 05:00:19 -07:00
ui - > book3Btn - > hide ( ) ;
}
2021-04-30 20:19:54 -07:00
else if ( ui - > book4Btn - > text ( ) = = ui - > book1Btn - > text ( ) ) {
2021-03-25 05:00:19 -07:00
ui - > book4Btn - > hide ( ) ;
}
2021-04-30 20:19:54 -07:00
else if ( existing_recent_books = = false ) {
2021-03-25 05:00:19 -07:00
ui - > recentBooksLabel - > show ( ) ;
}
else {
ui - > recentBooksLabel - > hide ( ) ;
}
}
2021-04-01 05:58:37 -07:00
// Check for an update and ask if the user wants to install it
2021-09-26 13:46:25 -07:00
checkForUpdate ( ) ;
2021-04-01 05:58:37 -07:00
2021-03-25 05:00:19 -07:00
// Check if it's the first boot since an update and confirm that it installed successfully
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
if ( checkconfig ( " /external_root/opt/update/inkbox_updated " ) = = true ) {
string_checkconfig_ro ( " /external_root/opt/isa/version " ) ;
QString updatemsg = " InkBox update to v " ;
updatemsg = updatemsg . append ( checkconfig_str_val ) ;
updatemsg = updatemsg . remove ( QRegExp ( " [ \n ] " ) ) ;
updatemsg = updatemsg . append ( " completed successfully. \n \n Changelog: \n " ) ;
string_checkconfig_ro ( " /external_root/opt/isa/changelog " ) ;
updatemsg = updatemsg . append ( checkconfig_str_val ) ;
QMessageBox : : information ( this , tr ( " Information " ) , updatemsg ) ;
string_writeconfig ( " /external_root/opt/update/inkbox_updated " , " false " ) ;
}
}
2021-05-13 17:42:50 -07:00
2021-06-29 10:08:58 -07:00
// If the DEVKEY file is present, install a developer key
2021-06-30 21:37:30 -07:00
if ( QFile : : exists ( " /mnt/onboard/onboard/.inkbox/DEVKEY " ) = = true & & QFile : : exists ( " /mnt/onboard/onboard/.inkbox/DEVKEY.dgst " ) = = true ) {
2021-06-29 10:08:58 -07:00
string_checkconfig_ro ( " /mnt/onboard/onboard/.inkbox/DEVKEY " ) ;
QString developerKey = checkconfig_str_val . left ( 256 ) ;
setDefaultWorkDir ( ) ;
QString prog ( " sh " ) ;
QStringList args ;
args < < " install_developer-key.sh " < < developerKey < < " /mnt/onboard/onboard/.inkbox/DEVKEY.dgst " ;
QProcess * proc = new QProcess ( ) ;
proc - > start ( prog , args ) ;
2021-06-30 21:37:30 -07:00
proc - > waitForFinished ( ) ;
2021-08-29 12:05:07 -07:00
proc - > deleteLater ( ) ;
2021-06-29 10:08:58 -07:00
2021-06-29 11:42:51 -07:00
QFile : : remove ( " /mnt/onboard/onboard/.inkbox/DEVKEY " ) ;
QFile : : remove ( " /mnt/onboard/onboard/.inkbox/DEVKEY.dgst " ) ;
2021-06-29 10:08:58 -07:00
reboot ( true ) ;
2021-05-13 17:42:50 -07:00
}
2021-03-25 05:00:19 -07:00
}
MainWindow : : ~ MainWindow ( )
{
delete ui ;
}
2021-04-01 05:58:37 -07:00
void MainWindow : : openUpdateDialog ( ) {
2021-04-22 07:10:47 -07:00
global : : mainwindow : : updateDialog = true ;
2021-08-25 10:16:41 -07:00
// Write to a temporary file to show an "Update" prompt
2021-04-01 05:58:37 -07:00
string_writeconfig ( " /inkbox/updateDialog " , " true " ) ;
2021-04-24 09:44:57 -07:00
// Show the dialog
2021-04-01 05:58:37 -07:00
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
generalDialogWindow - > show ( ) ;
QApplication : : processEvents ( ) ;
}
2021-04-22 04:38:54 -07:00
void MainWindow : : openLowBatteryDialog ( ) {
2021-04-22 07:10:47 -07:00
global : : mainwindow : : lowBatteryDialog = true ;
2021-04-23 05:47:05 -07:00
global : : battery : : batteryAlertLock = true ;
2021-04-22 04:38:54 -07:00
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
generalDialogWindow - > show ( ) ;
QApplication : : processEvents ( ) ;
}
2021-05-09 11:07:05 -07:00
void MainWindow : : openUsbmsDialog ( ) {
global : : usbms : : showUsbmsDialog = false ;
global : : usbms : : usbmsDialog = true ;
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
generalDialogWindow - > show ( ) ;
QApplication : : processEvents ( ) ;
}
2021-04-23 05:47:05 -07:00
void MainWindow : : openCriticalBatteryAlertWindow ( ) {
global : : battery : : showCriticalBatteryAlert = true ;
global : : battery : : showLowBatteryDialog = false ;
alertWindow = new alert ( ) ;
alertWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
alertWindow - > setGeometry ( QRect ( QPoint ( 0 , 0 ) , screen ( ) - > geometry ( ) . size ( ) ) ) ;
alertWindow - > show ( ) ;
}
2021-03-25 05:00:19 -07:00
void MainWindow : : on_settingsBtn_clicked ( )
{
2021-04-24 06:34:35 -07:00
resetWindow ( false ) ;
2021-04-24 09:44:57 -07:00
if ( global : : mainwindow : : tabSwitcher : : settingsChooserWidgetSelected ! = true ) {
2021-04-24 06:34:35 -07:00
ui - > settingsBtn - > setStyleSheet ( " background: black " ) ;
ui - > settingsBtn - > setIcon ( QIcon ( " :/resources/settings-inverted.png " ) ) ;
2021-08-25 10:32:33 -07:00
// Create widget and make necessary connections
2021-04-24 09:44:57 -07:00
settingsChooserWindow = new settingsChooser ( ) ;
2021-08-25 10:32:33 -07:00
connect ( settingsChooserWindow , SIGNAL ( showToast ( QString ) ) , SLOT ( showToast ( QString ) ) ) ;
connect ( settingsChooserWindow , SIGNAL ( closeIndefiniteToast ( ) ) , SLOT ( closeIndefiniteToast ( ) ) ) ;
2021-04-24 09:44:57 -07:00
ui - > stackedWidget - > insertWidget ( 2 , settingsChooserWindow ) ;
global : : mainwindow : : tabSwitcher : : settingsChooserWidgetCreated = true ;
2021-04-24 06:34:35 -07:00
// Switch tab
ui - > stackedWidget - > setCurrentIndex ( 2 ) ;
2021-04-24 09:44:57 -07:00
global : : mainwindow : : tabSwitcher : : settingsChooserWidgetSelected = true ;
2021-04-24 06:34:35 -07:00
// Repaint
this - > repaint ( ) ;
}
else {
;
}
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_appsBtn_clicked ( )
{
2021-04-24 06:34:35 -07:00
resetWindow ( false ) ;
if ( global : : mainwindow : : tabSwitcher : : appsWidgetSelected ! = true ) {
ui - > appsBtn - > setStyleSheet ( " background: black " ) ;
ui - > appsBtn - > setIcon ( QIcon ( " :/resources/apps-inverted.png " ) ) ;
2021-04-24 09:44:57 -07:00
// Create widget
appsWindow = new apps ( ) ;
2021-07-05 21:13:11 -07:00
connect ( appsWindow , SIGNAL ( refreshScreen ( ) ) , SLOT ( refreshScreen ( ) ) ) ;
2021-04-24 09:44:57 -07:00
ui - > stackedWidget - > insertWidget ( 1 , appsWindow ) ;
global : : mainwindow : : tabSwitcher : : appsWidgetCreated = true ;
2021-04-24 06:34:35 -07:00
// Switch tab
ui - > stackedWidget - > setCurrentIndex ( 1 ) ;
global : : mainwindow : : tabSwitcher : : appsWidgetSelected = true ;
2021-04-23 19:23:24 -07:00
2021-04-24 06:34:35 -07:00
// Repaint
this - > repaint ( ) ;
}
else {
;
}
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_pushButton_clicked ( )
{
2021-09-05 08:47:09 -07:00
openReaderFramework ( ) ;
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_searchBtn_clicked ( )
{
2021-07-05 19:21:20 -07:00
global : : forbidOpenSearchDialog = false ;
setupSearchDialog ( ) ;
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_quitBtn_clicked ( )
{
quitWindow = new quit ( ) ;
quitWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
quitWindow - > showFullScreen ( ) ;
}
void MainWindow : : on_book1Btn_clicked ( )
{
2021-04-22 07:10:47 -07:00
global : : reader : : skipOpenDialog = true ;
global : : reader : : bookNumber = 1 ;
2021-03-25 05:00:19 -07:00
2021-09-05 08:47:09 -07:00
openReaderFramework ( ) ;
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_book2Btn_clicked ( )
{
2021-04-22 07:10:47 -07:00
global : : reader : : skipOpenDialog = true ;
global : : reader : : bookNumber = 2 ;
2021-03-25 05:00:19 -07:00
2021-09-05 08:47:09 -07:00
openReaderFramework ( ) ;
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_book3Btn_clicked ( )
{
2021-04-22 07:10:47 -07:00
global : : reader : : skipOpenDialog = true ;
global : : reader : : bookNumber = 3 ;
2021-03-25 05:00:19 -07:00
2021-09-05 08:47:09 -07:00
openReaderFramework ( ) ;
2021-03-25 05:00:19 -07:00
}
void MainWindow : : on_book4Btn_clicked ( )
{
2021-04-22 07:10:47 -07:00
global : : reader : : skipOpenDialog = true ;
global : : reader : : bookNumber = 4 ;
2021-03-25 05:00:19 -07:00
2021-09-05 08:47:09 -07:00
openReaderFramework ( ) ;
2021-03-25 05:00:19 -07:00
}
2021-03-29 18:47:21 -07:00
void MainWindow : : on_brightnessBtn_clicked ( )
{
brightnessDialogWindow = new brightnessDialog ( ) ;
brightnessDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
brightnessDialogWindow - > show ( ) ;
}
2021-04-23 19:23:24 -07:00
void MainWindow : : on_homeBtn_clicked ( )
{
2021-04-24 06:34:35 -07:00
global : : mainwindow : : tabSwitcher : : repaint = true ;
resetWindow ( true ) ;
2021-04-23 19:23:24 -07:00
}
2021-04-24 06:34:35 -07:00
void MainWindow : : resetWindow ( bool resetStackedWidget ) {
2021-04-23 19:23:24 -07:00
// Reset layout
2021-04-24 06:34:35 -07:00
if ( resetStackedWidget = = true ) {
ui - > stackedWidget - > setCurrentIndex ( 0 ) ;
}
2021-04-24 09:44:57 -07:00
// Destroy widgets
if ( global : : mainwindow : : tabSwitcher : : appsWidgetCreated = = true ) {
appsWindow - > deleteLater ( ) ;
}
if ( global : : mainwindow : : tabSwitcher : : settingsChooserWidgetCreated = = true ) {
settingsChooserWindow - > deleteLater ( ) ;
}
2021-12-26 05:36:29 -08:00
if ( global : : mainwindow : : tabSwitcher : : libraryWidgetCreated = = true ) {
libraryWidgetWindow - > deleteLater ( ) ;
}
2021-04-24 09:44:57 -07:00
global : : mainwindow : : tabSwitcher : : appsWidgetCreated = false ;
global : : mainwindow : : tabSwitcher : : settingsChooserWidgetCreated = false ;
2021-04-24 06:34:35 -07:00
global : : mainwindow : : tabSwitcher : : appsWidgetSelected = false ;
2021-04-24 09:44:57 -07:00
global : : mainwindow : : tabSwitcher : : settingsChooserWidgetSelected = false ;
2021-12-26 05:36:29 -08:00
global : : mainwindow : : tabSwitcher : : libraryWidgetCreated = false ;
global : : mainwindow : : tabSwitcher : : libraryWidgetSelected = false ;
2021-04-24 09:44:57 -07:00
2021-04-23 19:23:24 -07:00
resetIcons ( ) ;
2021-06-23 08:26:00 -07:00
setBatteryIcon ( ) ;
2021-04-24 06:34:35 -07:00
if ( global : : mainwindow : : tabSwitcher : : repaint = = true ) {
this - > repaint ( ) ;
}
2021-04-23 19:23:24 -07:00
}
void MainWindow : : resetIcons ( ) {
// Reset icons
ui - > appsBtn - > setStyleSheet ( " background: white " ) ;
ui - > appsBtn - > setIcon ( QIcon ( " :/resources/apps.png " ) ) ;
2021-04-24 06:34:35 -07:00
ui - > settingsBtn - > setStyleSheet ( " background: white " ) ;
ui - > settingsBtn - > setIcon ( QIcon ( " :/resources/settings.png " ) ) ;
2021-12-26 05:36:29 -08:00
ui - > libraryButton - > setStyleSheet ( " background: white " ) ;
ui - > libraryButton - > setIcon ( QIcon ( " :/resources/online-library.png " ) ) ;
2021-04-23 19:23:24 -07:00
}
2021-06-23 08:26:00 -07:00
void MainWindow : : setBatteryIcon ( ) {
// Battery
string_checkconfig_ro ( " /opt/inkbox_device " ) ;
2021-07-10 22:08:38 -07:00
if ( checkconfig_str_val = = " n705 \n " or checkconfig_str_val = = " n905 \n " or checkconfig_str_val = = " n613 \n " or checkconfig_str_val = = " n873 \n " ) {
2021-06-26 07:09:51 -07:00
// 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 ( ) ;
}
2021-06-23 08:26:00 -07:00
// Setting icons up
stdIconWidth = sW / 16 ;
stdIconHeight = sH / 16 ;
2021-06-26 07:09:51 -07:00
2021-06-23 08:26:00 -07:00
QPixmap chargingPixmap ( " :/resources/battery_charging.png " ) ;
QPixmap scaledChargingPixmap = chargingPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
QPixmap fullPixmap ( " :/resources/battery_full.png " ) ;
QPixmap scaledFullPixmap = fullPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
QPixmap halfPixmap ( " :/resources/battery_half.png " ) ;
QPixmap scaledHalfPixmap = halfPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
QPixmap emptyPixmap ( " :/resources/battery_empty.png " ) ;
QPixmap scaledEmptyPixmap = emptyPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro ( " /sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status " ) ;
if ( checkconfig_str_val = = " Charging \n " ) {
ui - > batteryIcon - > setPixmap ( scaledChargingPixmap ) ;
}
else {
get_battery_level ( ) ;
if ( batt_level_int > = 75 & & batt_level_int < = 100 ) {
ui - > batteryIcon - > setPixmap ( scaledFullPixmap ) ;
}
else if ( batt_level_int > = 25 & & batt_level_int < = 74 ) {
ui - > batteryIcon - > setPixmap ( scaledHalfPixmap ) ;
}
else if ( batt_level_int > = 0 & & batt_level_int < = 24 ) {
ui - > batteryIcon - > setPixmap ( scaledEmptyPixmap ) ;
}
}
}
else {
// Setting icons up
stdIconWidth = sW / 19 ;
stdIconHeight = sH / 19 ;
QPixmap chargingPixmap ( " :/resources/battery_charging.png " ) ;
QPixmap scaledChargingPixmap = chargingPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
QPixmap fullPixmap ( " :/resources/battery_full.png " ) ;
QPixmap scaledFullPixmap = fullPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
QPixmap halfPixmap ( " :/resources/battery_half.png " ) ;
QPixmap scaledHalfPixmap = halfPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
QPixmap emptyPixmap ( " :/resources/battery_empty.png " ) ;
QPixmap scaledEmptyPixmap = emptyPixmap . scaled ( stdIconWidth , stdIconHeight , Qt : : KeepAspectRatio ) ;
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro ( " /sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status " ) ;
if ( checkconfig_str_val = = " Charging \n " ) {
ui - > batteryIcon - > setPixmap ( scaledChargingPixmap ) ;
}
else {
get_battery_level ( ) ;
if ( batt_level_int > = 75 & & batt_level_int < = 100 ) {
ui - > batteryIcon - > setPixmap ( scaledFullPixmap ) ;
}
else if ( batt_level_int > = 25 & & batt_level_int < = 74 ) {
ui - > batteryIcon - > setPixmap ( scaledHalfPixmap ) ;
}
else if ( batt_level_int > = 0 & & batt_level_int < = 24 ) {
ui - > batteryIcon - > setPixmap ( scaledEmptyPixmap ) ;
}
}
}
}
2021-06-28 16:57:40 -07:00
void MainWindow : : setInitialBrightness ( ) {
2021-07-16 13:41:36 -07:00
string_checkconfig_ro ( " /opt/inkbox_device " ) ;
if ( checkconfig_str_val = = " n873 \n " ) {
int warmth ;
string_checkconfig_ro ( " .config/03-brightness/config-warmth " ) ;
if ( checkconfig_str_val = = " " ) {
warmth = 0 ;
}
else {
warmth = checkconfig_str_val . toInt ( ) ;
}
set_warmth ( warmth ) ;
}
2021-08-18 16:46:32 -07:00
int brightness_value = brightness_checkconfig ( " .config/03-brightness/config " ) ;
if ( checkconfig ( " /tmp/oobe-inkbox_completed " ) = = true or checkconfig ( " /tmp/inkbox-cinematicBrightness_ran " ) = = true ) {
// Coming from OOBE setup; not doing that fancy stuff again ;p
QFile : : remove ( " /tmp/oobe-inkbox_completed " ) ;
pre_set_brightness ( brightness_value ) ;
}
else {
// Fancy brightness fade-in
string_writeconfig ( " /tmp/inkbox-cinematicBrightness_ran " , " true " ) ;
cinematicBrightness ( brightness_value , 0 ) ;
}
2021-06-28 16:57:40 -07:00
}
2021-07-05 13:01:32 -07:00
void MainWindow : : refreshScreen ( ) {
this - > repaint ( ) ;
}
2021-07-05 19:21:20 -07:00
void MainWindow : : setupSearchDialog ( ) {
if ( global : : forbidOpenSearchDialog = = false ) {
global : : keyboard : : keyboardDialog = true ;
global : : keyboard : : searchDialog = true ;
global : : keyboard : : keyboardText = " " ;
generalDialogWindow = new generalDialog ( ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
connect ( generalDialogWindow , SIGNAL ( destroyed ( QObject * ) ) , SLOT ( setupSearchDialog ( ) ) ) ;
2021-09-05 06:37:07 -07:00
connect ( generalDialogWindow , SIGNAL ( refreshScreen ( ) ) , SLOT ( refreshScreen ( ) ) ) ;
connect ( generalDialogWindow , SIGNAL ( showToast ( QString ) ) , SLOT ( showToast ( QString ) ) ) ;
2021-12-29 20:09:51 -08:00
connect ( generalDialogWindow , SIGNAL ( closeIndefiniteToast ( ) ) , SLOT ( closeIndefiniteToast ( ) ) ) ;
2021-09-05 06:37:07 -07:00
connect ( generalDialogWindow , SIGNAL ( openBookFile ( QString , bool ) ) , SLOT ( openBookFile ( QString , bool ) ) ) ;
2021-07-05 19:21:20 -07:00
generalDialogWindow - > show ( ) ;
}
else {
;
}
}
2021-07-13 12:18:59 -07:00
int MainWindow : : testPing ( ) {
QString pingProg = " ping " ;
QStringList pingArgs ;
pingArgs < < " -c " < < " 1 " < < " 1.1.1.1 " ;
QProcess * pingProcess = new QProcess ( ) ;
pingProcess - > start ( pingProg , pingArgs ) ;
pingProcess - > waitForFinished ( ) ;
2021-09-01 19:07:30 -07:00
int exitCode = pingProcess - > exitCode ( ) ;
pingProcess - > deleteLater ( ) ;
return exitCode ;
2021-07-13 12:18:59 -07:00
}
void MainWindow : : updateWifiIcon ( int mode ) {
/* Usage:
* mode 0 : auto
* mode 1 : off
* mode 2 : standby
* mode 3 : connected
*/
if ( mode = = 0 ) {
QTimer * wifiIconTimer = new QTimer ( this ) ;
wifiIconTimer - > setInterval ( 60000 ) ;
connect ( wifiIconTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( setWifiIcon ( ) ) ) ;
wifiIconTimer - > start ( ) ;
}
if ( mode = = 1 ) {
ui - > wifiBtn - > setIcon ( QIcon ( " :/resources/wifi-off.png " ) ) ;
ui - > wifiBtn - > setIconSize ( QSize ( wifiIconWidth , wifiIconHeight ) ) ;
}
if ( mode = = 2 ) {
ui - > wifiBtn - > setIcon ( QIcon ( " :/resources/wifi-standby.png " ) ) ;
ui - > wifiBtn - > setIconSize ( QSize ( wifiIconWidth , wifiIconHeight ) ) ;
}
if ( mode = = 3 ) {
ui - > wifiBtn - > setIcon ( QIcon ( " :/resources/wifi-connected.png " ) ) ;
ui - > wifiBtn - > setIconSize ( QSize ( wifiIconWidth , wifiIconHeight ) ) ;
}
}
bool MainWindow : : checkWifiState ( ) {
/* Return value:
* true : interface UP
* false : interface DOWN
*/
string_checkconfig_ro ( " /sys/class/net/eth0/operstate " ) ;
if ( checkconfig_str_val = = " up \n " ) {
return true ;
}
else {
return false ;
}
}
void MainWindow : : setWifiIcon ( ) {
2021-07-16 13:41:36 -07:00
if ( checkconfig ( " /run/wifi_able " ) = = true ) {
global : : device : : isWifiAble = true ;
if ( checkWifiState ( ) = = true ) {
if ( testPing ( ) = = 0 ) {
ui - > wifiBtn - > setIcon ( QIcon ( " :/resources/wifi-connected.png " ) ) ;
ui - > wifiBtn - > setIconSize ( QSize ( wifiIconWidth , wifiIconHeight ) ) ;
}
else {
ui - > wifiBtn - > setIcon ( QIcon ( " :/resources/wifi-standby.png " ) ) ;
ui - > wifiBtn - > setIconSize ( QSize ( wifiIconWidth , wifiIconHeight ) ) ;
}
2021-07-13 12:18:59 -07:00
}
else {
2021-07-16 13:41:36 -07:00
ui - > wifiBtn - > setIcon ( QIcon ( " :/resources/wifi-off.png " ) ) ;
2021-07-13 12:18:59 -07:00
ui - > wifiBtn - > setIconSize ( QSize ( wifiIconWidth , wifiIconHeight ) ) ;
}
}
else {
2021-07-16 13:41:36 -07:00
global : : device : : isWifiAble = false ;
ui - > wifiBtn - > hide ( ) ;
ui - > line_9 - > hide ( ) ;
2021-07-13 12:18:59 -07:00
}
}
2021-07-13 22:24:30 -07:00
void MainWindow : : openWifiDialog ( ) {
global : : toast : : wifiToast = true ;
showToast ( " Searching for networks " ) ;
}
void MainWindow : : on_wifiBtn_clicked ( )
{
openWifiDialog ( ) ;
}
void MainWindow : : showToast ( QString messageToDisplay ) {
global : : toast : : message = messageToDisplay ;
toastWindow = new toast ( this ) ;
toastWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
connect ( toastWindow , SIGNAL ( updateWifiIconSig ( int ) ) , SLOT ( updateWifiIcon ( int ) ) ) ;
2021-07-14 15:23:54 -07:00
connect ( toastWindow , SIGNAL ( refreshScreen ( ) ) , SLOT ( refreshScreen ( ) ) ) ;
connect ( toastWindow , SIGNAL ( showToast ( QString ) ) , SLOT ( showToast ( QString ) ) ) ;
connect ( toastWindow , SIGNAL ( closeIndefiniteToast ( ) ) , SLOT ( closeIndefiniteToast ( ) ) ) ;
2021-07-13 22:24:30 -07:00
toastWindow - > show ( ) ;
2021-07-20 20:27:32 -07:00
2021-08-19 05:23:18 -07:00
if ( messageToDisplay = = " Connection successful " ) {
2021-08-25 10:16:41 -07:00
// Give the toast some time to vanish away, then launch OTA updater
2021-08-19 08:11:16 -07:00
QTimer : : singleShot ( 5000 , this , SLOT ( launchOtaUpdater ( ) ) ) ;
2021-08-19 05:23:18 -07:00
}
2021-07-13 22:24:30 -07:00
}
void MainWindow : : hello ( int testNumber ) {
qDebug ( ) < < " Hello " < < testNumber ;
}
2021-07-14 15:23:54 -07:00
void MainWindow : : closeIndefiniteToast ( ) {
// Warning: use with caution
toastWindow - > close ( ) ;
}
2021-07-20 20:27:32 -07:00
void MainWindow : : openUpdateDialogOTA ( bool open ) {
if ( open = = true ) {
2021-08-19 05:23:18 -07:00
global : : otaUpdate : : isUpdateOta = true ;
2021-07-20 20:27:32 -07:00
openUpdateDialog ( ) ;
}
else {
;
}
}
2021-08-19 08:11:16 -07:00
void MainWindow : : launchOtaUpdater ( ) {
otaManagerWindow = new otaManager ( this ) ;
connect ( otaManagerWindow , SIGNAL ( canOtaUpdate ( bool ) ) , SLOT ( openUpdateDialogOTA ( bool ) ) ) ;
otaManagerWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
}
2021-09-04 20:46:47 -07:00
2021-09-05 06:37:07 -07:00
void MainWindow : : openBookFile ( QString book , bool relativePath ) {
if ( relativePath = = true ) {
if ( checkconfig ( " /opt/inkbox_genuine " ) = = true ) {
book . prepend ( " /mnt/onboard/onboard/ " ) ;
}
else {
book . prepend ( " /mnt/onboard/ " ) ;
}
}
2021-09-04 20:46:47 -07:00
global : : reader : : skipOpenDialog = true ;
global : : reader : : bookFile = book ;
2021-09-05 08:47:09 -07:00
openReaderFramework ( ) ;
}
void MainWindow : : openReaderFramework ( ) {
2021-09-04 20:46:47 -07:00
readerWindow = new reader ( ) ;
readerWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2021-09-05 08:47:09 -07:00
connect ( readerWindow , SIGNAL ( openBookFile ( QString , bool ) ) , SLOT ( openBookFile ( QString , bool ) ) ) ;
2021-09-04 20:46:47 -07:00
readerWindow - > showFullScreen ( ) ;
}
2021-09-26 13:46:25 -07:00
void MainWindow : : checkForUpdate ( ) {
if ( checkconfig ( " /mnt/onboard/onboard/.inkbox/can_update " ) = = true ) {
if ( checkconfig ( " /tmp/cancelUpdateDialog " ) = = false ) {
// I'm sorry.
qDebug ( ) < < " An update is available. " ;
QTimer : : singleShot ( 2000 , this , SLOT ( openUpdateDialog ( ) ) ) ;
}
else {
qDebug ( ) < < " Not showing update dialog, user dismissed it... " ;
}
}
}
2021-10-18 05:46:27 -07:00
2021-12-31 12:50:59 -08:00
void MainWindow : : openEncfsRepackDialog ( ) {
global : : encfs : : repackDialog = true ;
generalDialogWindow = new generalDialog ( this ) ;
generalDialogWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
generalDialogWindow - > show ( ) ;
2021-10-18 05:46:27 -07:00
}
2021-12-26 05:36:29 -08:00
void MainWindow : : on_libraryButton_clicked ( )
{
resetWindow ( false ) ;
if ( global : : mainwindow : : tabSwitcher : : libraryWidgetSelected ! = true ) {
ui - > libraryButton - > setStyleSheet ( " background: black; color: white " ) ;
ui - > libraryButton - > setIcon ( QIcon ( " :/resources/online-library-inverted.png " ) ) ;
// Create widget
libraryWidgetWindow = new libraryWidget ( ) ;
2022-01-04 16:06:47 -08:00
connect ( libraryWidgetWindow , SIGNAL ( destroyed ( QObject * ) ) , SLOT ( resetFullWindow ( ) ) ) ;
2021-12-26 10:28:43 -08:00
libraryWidgetWindow - > setAttribute ( Qt : : WA_DeleteOnClose ) ;
2021-12-26 05:36:29 -08:00
ui - > stackedWidget - > insertWidget ( 3 , libraryWidgetWindow ) ;
global : : mainwindow : : tabSwitcher : : libraryWidgetCreated = true ;
// Switch tab
ui - > stackedWidget - > setCurrentIndex ( 3 ) ;
global : : mainwindow : : tabSwitcher : : libraryWidgetSelected = true ;
// Repaint
this - > repaint ( ) ;
}
else {
;
}
}
2022-01-04 16:06:47 -08:00
void MainWindow : : resetFullWindow ( ) {
resetWindow ( true ) ;
}