Never mind

What an idiot am I...
This commit is contained in:
Nicolas Mailloux 2021-04-22 10:10:47 -04:00
parent 51fad25719
commit edb1203d7e
10 changed files with 153 additions and 60 deletions

View file

@ -19,10 +19,6 @@ alert::alert(QWidget *parent) :
float stdIconWidth = sW / 1.7; float stdIconWidth = sW / 1.7;
float stdIconHeight = sH / 1.7; float stdIconHeight = sH / 1.7;
QPixmap pixmap(":/resources/alert.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->alertIconLabel->setPixmap(scaledPixmap);
// General stylesheet // General stylesheet
QFile stylesheetFile(":/resources/eink_dark.qss"); QFile stylesheetFile(":/resources/eink_dark.qss");
stylesheetFile.open(QFile::ReadOnly); stylesheetFile.open(QFile::ReadOnly);
@ -31,19 +27,31 @@ alert::alert(QWidget *parent) :
// Checking if the update's signature is untrusted. The signature error will always take precedence over the downgrade one (c.f. update.sh script) // Checking if the update's signature is untrusted. The signature error will always take precedence over the downgrade one (c.f. update.sh script)
if(checkconfig("/external_root/boot/flags/ALERT_SIGN") == true) { if(checkconfig("/external_root/boot/flags/ALERT_SIGN") == true) {
QPixmap pixmap(":/resources/alert.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->alertIconLabel->setPixmap(scaledPixmap);
signatureError = true; signatureError = true;
ui->securityLabel->setText("Failed to update InkBox."); ui->securityLabel->setText("Failed to update InkBox.");
ui->messageLabel->setText("The digital signature of the update is untrusted.\nFor security reasons, it cannot be installed."); ui->messageLabel->setText("The digital signature of the update is untrusted.\nFor security reasons, it cannot be installed.");
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
} }
if(checkconfig("/external_root/boot/flags/ALERT_DOWNGRADE") == true) { if(checkconfig("/external_root/boot/flags/ALERT_DOWNGRADE") == true) {
QPixmap pixmap(":/resources/alert.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->alertIconLabel->setPixmap(scaledPixmap);
downgradeError = true; downgradeError = true;
ui->securityLabel->setText("Failed to update InkBox."); ui->securityLabel->setText("Failed to update InkBox.");
ui->messageLabel->setText("An error occured during the update process.\nThe update package's version is lower than the actual installed version."); ui->messageLabel->setText("An error occured during the update process.\nThe update package's version is lower than the actual installed version.");
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
} }
if(global_static::battery::showCriticalBatteryAlert == true) { if(global::battery::showCriticalBatteryAlert == true) {
global_static::battery::showCriticalBatteryAlert = false; QPixmap pixmap(":/resources/battery_alert.png");
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->alertIconLabel->setPixmap(scaledPixmap);
global::battery::showCriticalBatteryAlert = false;
criticalBattery = true; criticalBattery = true;
ui->securityLabel->setText("Please charge your eReader."); ui->securityLabel->setText("Please charge your eReader.");
ui->messageLabel->setText("The battery level is very low. To prevent damage to the filesystem, your device has been turned off.\nPlease consider charging it."); ui->messageLabel->setText("The battery level is very low. To prevent damage to the filesystem, your device has been turned off.\nPlease consider charging it.");

View file

@ -37,5 +37,6 @@
<file>resources/check.png</file> <file>resources/check.png</file>
<file>resources/minus.png</file> <file>resources/minus.png</file>
<file>resources/plus.png</file> <file>resources/plus.png</file>
<file>resources/battery_alert.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -9,15 +9,21 @@
#include <QProcess> #include <QProcess>
#include <regex> #include <regex>
// WoW, static variables and namespaces are awesome // WoW, global variables and namespaces are awesome
namespace global_static { namespace global {
namespace battery { namespace battery {
static bool showLowBatteryDialog = true; inline bool showLowBatteryDialog;
static bool showCriticalBatteryAlert = false; inline bool showCriticalBatteryAlert;
inline bool batteryAlertLock;
} }
namespace reader { namespace reader {
static int pageNumber; inline int pageNumber;
static bool skipOpenDialog = false; inline int bookNumber;
inline bool skipOpenDialog;
}
namespace mainwindow {
inline bool updateDialog;
inline bool lowBatteryDialog;
} }
} }

View file

@ -70,7 +70,7 @@ generalDialog::generalDialog(QWidget *parent) :
this->adjustSize(); this->adjustSize();
string_writeconfig("/inkbox/settingsRebootDialog", "false"); string_writeconfig("/inkbox/settingsRebootDialog", "false");
} }
if(mainwindow_static::lowBatteryDialog == true) { if(global::mainwindow::lowBatteryDialog == true) {
lowBatteryDialog = true; lowBatteryDialog = true;
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
get_battery_level(); get_battery_level();
@ -155,9 +155,9 @@ void generalDialog::on_acceptBtn_clicked()
generalDialog::close(); generalDialog::close();
if(lowBatteryDialog == true) { if(lowBatteryDialog == true) {
mainwindow_static::lowBatteryDialog = false; global::mainwindow::lowBatteryDialog = false;
reader_static::batteryAlertLock = false; global::battery::batteryAlertLock = false;
global_static::battery::showLowBatteryDialog = false; global::battery::showLowBatteryDialog = false;
} }
if(settingsRebootDialog == true) { if(settingsRebootDialog == true) {

View file

@ -2,7 +2,7 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 CONFIG += c++11 c++17
QMAKE_CXXFLAGS += -Wno-unused-function -Wno-unused-parameter QMAKE_CXXFLAGS += -Wno-unused-function -Wno-unused-parameter

View file

@ -247,8 +247,7 @@ MainWindow::MainWindow(QWidget *parent)
// Reading from the config files and tweaking the program according to the options set // Reading from the config files and tweaking the program according to the options set
// Safety mesure; /inkbox is a tmpfs // Safety mesure; /inkbox is a tmpfs
checked_box = false; global::reader::skipOpenDialog = false;
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog=");
// Demo setting, changes "Welcome to InkBox" label to "InkBox" // Demo setting, changes "Welcome to InkBox" label to "InkBox"
if(checkconfig(".config/01-demo/config") == true) { if(checkconfig(".config/01-demo/config") == true) {
@ -453,7 +452,7 @@ MainWindow::~MainWindow()
} }
void MainWindow::openUpdateDialog() { void MainWindow::openUpdateDialog() {
mainwindow_static::updateDialog = true; global::mainwindow::updateDialog = true;
// We write to a temporary file to show a "Reset" prompt // We write to a temporary file to show a "Reset" prompt
string_writeconfig("/inkbox/updateDialog", "true"); string_writeconfig("/inkbox/updateDialog", "true");
@ -465,7 +464,7 @@ void MainWindow::openUpdateDialog() {
} }
void MainWindow::openLowBatteryDialog() { void MainWindow::openLowBatteryDialog() {
mainwindow_static::lowBatteryDialog = true; global::mainwindow::lowBatteryDialog = true;
generalDialogWindow = new generalDialog(this); generalDialogWindow = new generalDialog(this);
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
@ -511,10 +510,8 @@ void MainWindow::on_quitBtn_clicked()
void MainWindow::on_book1Btn_clicked() void MainWindow::on_book1Btn_clicked()
{ {
checked_box = true; global::reader::skipOpenDialog = true;
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog="); global::reader::bookNumber = 1;
string_writeconfig("/inkbox/book_number", "1");
readerWindow = new reader(); readerWindow = new reader();
readerWindow->setAttribute(Qt::WA_DeleteOnClose); readerWindow->setAttribute(Qt::WA_DeleteOnClose);
@ -523,10 +520,8 @@ void MainWindow::on_book1Btn_clicked()
void MainWindow::on_book2Btn_clicked() void MainWindow::on_book2Btn_clicked()
{ {
checked_box = true; global::reader::skipOpenDialog = true;
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog="); global::reader::bookNumber = 2;
string_writeconfig("/inkbox/book_number", "2");
readerWindow = new reader(); readerWindow = new reader();
readerWindow->setAttribute(Qt::WA_DeleteOnClose); readerWindow->setAttribute(Qt::WA_DeleteOnClose);
@ -535,10 +530,8 @@ void MainWindow::on_book2Btn_clicked()
void MainWindow::on_book3Btn_clicked() void MainWindow::on_book3Btn_clicked()
{ {
checked_box = true; global::reader::skipOpenDialog = true;
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog="); global::reader::bookNumber = 3;
string_writeconfig("/inkbox/book_number", "3");
readerWindow = new reader(); readerWindow = new reader();
readerWindow->setAttribute(Qt::WA_DeleteOnClose); readerWindow->setAttribute(Qt::WA_DeleteOnClose);
@ -547,10 +540,8 @@ void MainWindow::on_book3Btn_clicked()
void MainWindow::on_book4Btn_clicked() void MainWindow::on_book4Btn_clicked()
{ {
checked_box = true; global::reader::skipOpenDialog = true;
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog="); global::reader::bookNumber = 4;
string_writeconfig("/inkbox/book_number", "4");
readerWindow = new reader(); readerWindow = new reader();
readerWindow->setAttribute(Qt::WA_DeleteOnClose); readerWindow->setAttribute(Qt::WA_DeleteOnClose);

View file

@ -12,11 +12,6 @@
#include "generaldialog.h" #include "generaldialog.h"
using namespace std; using namespace std;
namespace mainwindow_static {
static bool updateDialog = false;
static bool lowBatteryDialog = false;
}
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
QT_END_NAMESPACE QT_END_NAMESPACE

View file

@ -213,12 +213,12 @@ reader::reader(QWidget *parent) :
get_battery_level(); get_battery_level();
ui->batteryLabel->setText(batt_level); ui->batteryLabel->setText(batt_level);
ui->timeLabel->setText(time); ui->timeLabel->setText(time);
if(global_static::battery::showLowBatteryDialog != true) { if(global::battery::showLowBatteryDialog != true) {
// Do nothing, since a dialog should already have been displayed and (probably) dismissed // Do nothing, since a dialog should already have been displayed and (probably) dismissed
; ;
} }
else { else {
if(reader_static::batteryAlertLock == true) { if(global::battery::batteryAlertLock == true) {
; ;
} }
else { else {
@ -243,12 +243,12 @@ reader::reader(QWidget *parent) :
get_battery_level(); get_battery_level();
ui->batteryLabel->setText(batt_level); ui->batteryLabel->setText(batt_level);
ui->timeLabel->setText(time); ui->timeLabel->setText(time);
if(global_static::battery::showLowBatteryDialog != true) { if(global::battery::showLowBatteryDialog != true) {
// Do nothing, since a dialog should already have been displayed and (probably) dismissed // Do nothing, since a dialog should already have been displayed and (probably) dismissed
; ;
} }
else { else {
if(reader_static::batteryAlertLock == true) { if(global::battery::batteryAlertLock == true) {
; ;
} }
else { else {
@ -305,7 +305,7 @@ reader::reader(QWidget *parent) :
} ); } );
select_t->start(); select_t->start();
if(checkconfig("/inkbox/skip_opendialog") == true) { if(global::reader::skipOpenDialog == true) {
// We have to get the file's path // We have to get the file's path
if(checkconfig("/tmp/suspendBook") == true) { if(checkconfig("/tmp/suspendBook") == true) {
wakeFromSleep = true; wakeFromSleep = true;
@ -314,20 +314,19 @@ reader::reader(QWidget *parent) :
book_file = "/inkbox/book/book.txt"; book_file = "/inkbox/book/book.txt";
} }
else { else {
string_checkconfig("/inkbox/book_number"); if(global::reader::bookNumber == 1) {
if(checkconfig_str_val == "1") {
string_checkconfig(".config/08-recent_books/1"); string_checkconfig(".config/08-recent_books/1");
book_file = checkconfig_str_val; book_file = checkconfig_str_val;
} }
if(checkconfig_str_val == "2") { if(global::reader::bookNumber == 2) {
string_checkconfig(".config/08-recent_books/2"); string_checkconfig(".config/08-recent_books/2");
book_file = checkconfig_str_val; book_file = checkconfig_str_val;
} }
if(checkconfig_str_val == "3") { if(global::reader::bookNumber == 3) {
string_checkconfig(".config/08-recent_books/3"); string_checkconfig(".config/08-recent_books/3");
book_file = checkconfig_str_val; book_file = checkconfig_str_val;
} }
if(checkconfig_str_val == "4") { if(global::reader::bookNumber == 4) {
string_checkconfig(".config/08-recent_books/4"); string_checkconfig(".config/08-recent_books/4");
book_file = checkconfig_str_val; book_file = checkconfig_str_val;
} }
@ -486,6 +485,102 @@ reader::~reader()
delete ui; delete ui;
} }
int reader::setup_book(QString book, int i, bool run_parser) {
// Parse ebook
if(remount != false) {
QString mount_prog ("sh");
QStringList mount_args;
mount_args << "split.sh";
QProcess *mount_proc = new QProcess();
mount_proc->start(mount_prog, mount_args);
mount_proc->waitForFinished();
remount = false;
}
else {
string_writeconfig("/inkbox/remount", "false");
QString mount_prog ("sh");
QStringList mount_args;
mount_args << "split.sh";
QProcess *mount_proc = new QProcess();
mount_proc->start(mount_prog, mount_args);
mount_proc->waitForFinished();
}
if(booktostr_ran != true) {
if(epub_file_match(book) == true) {
// Parsing ePUBs with epub2txt, thanks to GitHub:kevinboone
QString epubProg ("sh");
QStringList epubArgs;
epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << book;
QProcess *epubProc = new QProcess();
epubProc->start(epubProg, epubArgs);
epubProc->waitForFinished();
is_epub = true;
booktostr_ran = true;
}
else {
// This is likely not an ePUB.
// Copying book specified in the function call
QFile::copy(book, "/inkbox/book/book.txt");
is_epub = false;
booktostr_ran = true;
}
}
// Checking if the user has defined an option for the number of words per page; if not, then setting the default.
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
string_checkconfig(".config/07-words_number/config");
if(checkconfig_str_val == "") {
string_writeconfig(".config/07-words_number/config", "100");
string_checkconfig(".config/07-words_number/config");
}
// Parsing file
if(parser_ran != true) {
if(is_epub == true) {
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
parser_ran = true;
}
else {
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split-txt.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
parser_ran = true;
}
}
// Changing current working directory
QDir::setCurrent("/inkbox/book");
// Reading file
if(run_parser == true) {
QDirIterator it("/inkbox/book/split");
while (it.hasNext()) {
QFile f(it.next());
f.open(QIODevice::ReadOnly);
content << f.readAll();
f.close();
}
return content.size();
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
}
else {
ittext = content[i];
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
}
return 0;
}
void reader::on_nextBtn_clicked() void reader::on_nextBtn_clicked()
{ {
if(split_total - 1 == 1 or split_total - 1 == 0) { if(split_total - 1 == 1 or split_total - 1 == 0) {
@ -908,7 +1003,7 @@ void reader::batteryWatchdog() {
} }
void reader::openLowBatteryDialog() { void reader::openLowBatteryDialog() {
reader_static::batteryAlertLock = true; global::battery::batteryAlertLock = true;
generalDialogWindow = new generalDialog(this); generalDialogWindow = new generalDialog(this);
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
@ -917,7 +1012,7 @@ void reader::openLowBatteryDialog() {
} }
void reader::openCriticalBatteryAlertWindow() { void reader::openCriticalBatteryAlertWindow() {
global_static::battery::showCriticalBatteryAlert = true; global::battery::showCriticalBatteryAlert = true;
alertWindow = new alert(this); alertWindow = new alert(this);
alertWindow->setAttribute(Qt::WA_DeleteOnClose); alertWindow->setAttribute(Qt::WA_DeleteOnClose);

View file

@ -15,10 +15,6 @@
using namespace std; using namespace std;
namespace reader_static {
static bool batteryAlertLock = false;
}
namespace Ui { namespace Ui {
class reader; class reader;
} }
@ -67,7 +63,8 @@ public:
QList<QString> content; QList<QString> content;
explicit reader(QWidget *parent = nullptr); explicit reader(QWidget *parent = nullptr);
~reader(); ~reader();
int setup_book(QString book, int i, bool run_parser) { int setup_book(QString book, int i, bool run_parser);
/*int setup_book(QString book, int i, bool run_parser) {
// Parse ebook // Parse ebook
if(remount != false) { if(remount != false) {
QString mount_prog ("sh"); QString mount_prog ("sh");
@ -161,7 +158,7 @@ public:
QDir::setCurrent("/mnt/onboard/.adds/inkbox"); QDir::setCurrent("/mnt/onboard/.adds/inkbox");
} }
return 0; return 0;
} }*/
void checkwords() { void checkwords() {
QFile words_list(".config/06-words/config"); QFile words_list(".config/06-words/config");
words_list.open(QIODevice::ReadWrite); words_list.open(QIODevice::ReadWrite);

BIN
resources/battery_alert.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB