mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
Never mind
What an idiot am I...
This commit is contained in:
parent
51fad25719
commit
edb1203d7e
10 changed files with 153 additions and 60 deletions
20
alert.cpp
20
alert.cpp
|
@ -19,10 +19,6 @@ alert::alert(QWidget *parent) :
|
|||
float stdIconWidth = sW / 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
|
||||
QFile stylesheetFile(":/resources/eink_dark.qss");
|
||||
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)
|
||||
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;
|
||||
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->stackedWidget->setCurrentIndex(1);
|
||||
}
|
||||
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;
|
||||
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->stackedWidget->setCurrentIndex(1);
|
||||
}
|
||||
if(global_static::battery::showCriticalBatteryAlert == true) {
|
||||
global_static::battery::showCriticalBatteryAlert = false;
|
||||
if(global::battery::showCriticalBatteryAlert == true) {
|
||||
QPixmap pixmap(":/resources/battery_alert.png");
|
||||
QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
|
||||
ui->alertIconLabel->setPixmap(scaledPixmap);
|
||||
|
||||
global::battery::showCriticalBatteryAlert = false;
|
||||
criticalBattery = true;
|
||||
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.");
|
||||
|
|
1
eink.qrc
1
eink.qrc
|
@ -37,5 +37,6 @@
|
|||
<file>resources/check.png</file>
|
||||
<file>resources/minus.png</file>
|
||||
<file>resources/plus.png</file>
|
||||
<file>resources/battery_alert.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
18
functions.h
18
functions.h
|
@ -9,15 +9,21 @@
|
|||
#include <QProcess>
|
||||
#include <regex>
|
||||
|
||||
// WoW, static variables and namespaces are awesome
|
||||
namespace global_static {
|
||||
// WoW, global variables and namespaces are awesome
|
||||
namespace global {
|
||||
namespace battery {
|
||||
static bool showLowBatteryDialog = true;
|
||||
static bool showCriticalBatteryAlert = false;
|
||||
inline bool showLowBatteryDialog;
|
||||
inline bool showCriticalBatteryAlert;
|
||||
inline bool batteryAlertLock;
|
||||
}
|
||||
namespace reader {
|
||||
static int pageNumber;
|
||||
static bool skipOpenDialog = false;
|
||||
inline int pageNumber;
|
||||
inline int bookNumber;
|
||||
inline bool skipOpenDialog;
|
||||
}
|
||||
namespace mainwindow {
|
||||
inline bool updateDialog;
|
||||
inline bool lowBatteryDialog;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ generalDialog::generalDialog(QWidget *parent) :
|
|||
this->adjustSize();
|
||||
string_writeconfig("/inkbox/settingsRebootDialog", "false");
|
||||
}
|
||||
if(mainwindow_static::lowBatteryDialog == true) {
|
||||
if(global::mainwindow::lowBatteryDialog == true) {
|
||||
lowBatteryDialog = true;
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
get_battery_level();
|
||||
|
@ -155,9 +155,9 @@ void generalDialog::on_acceptBtn_clicked()
|
|||
generalDialog::close();
|
||||
|
||||
if(lowBatteryDialog == true) {
|
||||
mainwindow_static::lowBatteryDialog = false;
|
||||
reader_static::batteryAlertLock = false;
|
||||
global_static::battery::showLowBatteryDialog = false;
|
||||
global::mainwindow::lowBatteryDialog = false;
|
||||
global::battery::batteryAlertLock = false;
|
||||
global::battery::showLowBatteryDialog = false;
|
||||
}
|
||||
|
||||
if(settingsRebootDialog == true) {
|
||||
|
|
|
@ -2,7 +2,7 @@ QT += core gui
|
|||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11
|
||||
CONFIG += c++11 c++17
|
||||
|
||||
QMAKE_CXXFLAGS += -Wno-unused-function -Wno-unused-parameter
|
||||
|
||||
|
|
|
@ -247,8 +247,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
// Reading from the config files and tweaking the program according to the options set
|
||||
|
||||
// Safety mesure; /inkbox is a tmpfs
|
||||
checked_box = false;
|
||||
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog=");
|
||||
global::reader::skipOpenDialog = false;
|
||||
|
||||
// Demo setting, changes "Welcome to InkBox" label to "InkBox"
|
||||
if(checkconfig(".config/01-demo/config") == true) {
|
||||
|
@ -453,7 +452,7 @@ MainWindow::~MainWindow()
|
|||
}
|
||||
|
||||
void MainWindow::openUpdateDialog() {
|
||||
mainwindow_static::updateDialog = true;
|
||||
global::mainwindow::updateDialog = true;
|
||||
// We write to a temporary file to show a "Reset" prompt
|
||||
string_writeconfig("/inkbox/updateDialog", "true");
|
||||
|
||||
|
@ -465,7 +464,7 @@ void MainWindow::openUpdateDialog() {
|
|||
}
|
||||
|
||||
void MainWindow::openLowBatteryDialog() {
|
||||
mainwindow_static::lowBatteryDialog = true;
|
||||
global::mainwindow::lowBatteryDialog = true;
|
||||
|
||||
generalDialogWindow = new generalDialog(this);
|
||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -511,10 +510,8 @@ void MainWindow::on_quitBtn_clicked()
|
|||
|
||||
void MainWindow::on_book1Btn_clicked()
|
||||
{
|
||||
checked_box = true;
|
||||
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog=");
|
||||
|
||||
string_writeconfig("/inkbox/book_number", "1");
|
||||
global::reader::skipOpenDialog = true;
|
||||
global::reader::bookNumber = 1;
|
||||
|
||||
readerWindow = new reader();
|
||||
readerWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -523,10 +520,8 @@ void MainWindow::on_book1Btn_clicked()
|
|||
|
||||
void MainWindow::on_book2Btn_clicked()
|
||||
{
|
||||
checked_box = true;
|
||||
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog=");
|
||||
|
||||
string_writeconfig("/inkbox/book_number", "2");
|
||||
global::reader::skipOpenDialog = true;
|
||||
global::reader::bookNumber = 2;
|
||||
|
||||
readerWindow = new reader();
|
||||
readerWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -535,10 +530,8 @@ void MainWindow::on_book2Btn_clicked()
|
|||
|
||||
void MainWindow::on_book3Btn_clicked()
|
||||
{
|
||||
checked_box = true;
|
||||
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog=");
|
||||
|
||||
string_writeconfig("/inkbox/book_number", "3");
|
||||
global::reader::skipOpenDialog = true;
|
||||
global::reader::bookNumber = 3;
|
||||
|
||||
readerWindow = new reader();
|
||||
readerWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -547,10 +540,8 @@ void MainWindow::on_book3Btn_clicked()
|
|||
|
||||
void MainWindow::on_book4Btn_clicked()
|
||||
{
|
||||
checked_box = true;
|
||||
writeconfig("/inkbox/skip_opendialog", "SkipOpenDialog=");
|
||||
|
||||
string_writeconfig("/inkbox/book_number", "4");
|
||||
global::reader::skipOpenDialog = true;
|
||||
global::reader::bookNumber = 4;
|
||||
|
||||
readerWindow = new reader();
|
||||
readerWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
|
|
@ -12,11 +12,6 @@
|
|||
#include "generaldialog.h"
|
||||
using namespace std;
|
||||
|
||||
namespace mainwindow_static {
|
||||
static bool updateDialog = false;
|
||||
static bool lowBatteryDialog = false;
|
||||
}
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
|
119
reader.cpp
119
reader.cpp
|
@ -213,12 +213,12 @@ reader::reader(QWidget *parent) :
|
|||
get_battery_level();
|
||||
ui->batteryLabel->setText(batt_level);
|
||||
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
|
||||
;
|
||||
}
|
||||
else {
|
||||
if(reader_static::batteryAlertLock == true) {
|
||||
if(global::battery::batteryAlertLock == true) {
|
||||
;
|
||||
}
|
||||
else {
|
||||
|
@ -243,12 +243,12 @@ reader::reader(QWidget *parent) :
|
|||
get_battery_level();
|
||||
ui->batteryLabel->setText(batt_level);
|
||||
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
|
||||
;
|
||||
}
|
||||
else {
|
||||
if(reader_static::batteryAlertLock == true) {
|
||||
if(global::battery::batteryAlertLock == true) {
|
||||
;
|
||||
}
|
||||
else {
|
||||
|
@ -305,7 +305,7 @@ reader::reader(QWidget *parent) :
|
|||
} );
|
||||
select_t->start();
|
||||
|
||||
if(checkconfig("/inkbox/skip_opendialog") == true) {
|
||||
if(global::reader::skipOpenDialog == true) {
|
||||
// We have to get the file's path
|
||||
if(checkconfig("/tmp/suspendBook") == true) {
|
||||
wakeFromSleep = true;
|
||||
|
@ -314,20 +314,19 @@ reader::reader(QWidget *parent) :
|
|||
book_file = "/inkbox/book/book.txt";
|
||||
}
|
||||
else {
|
||||
string_checkconfig("/inkbox/book_number");
|
||||
if(checkconfig_str_val == "1") {
|
||||
if(global::reader::bookNumber == 1) {
|
||||
string_checkconfig(".config/08-recent_books/1");
|
||||
book_file = checkconfig_str_val;
|
||||
}
|
||||
if(checkconfig_str_val == "2") {
|
||||
if(global::reader::bookNumber == 2) {
|
||||
string_checkconfig(".config/08-recent_books/2");
|
||||
book_file = checkconfig_str_val;
|
||||
}
|
||||
if(checkconfig_str_val == "3") {
|
||||
if(global::reader::bookNumber == 3) {
|
||||
string_checkconfig(".config/08-recent_books/3");
|
||||
book_file = checkconfig_str_val;
|
||||
}
|
||||
if(checkconfig_str_val == "4") {
|
||||
if(global::reader::bookNumber == 4) {
|
||||
string_checkconfig(".config/08-recent_books/4");
|
||||
book_file = checkconfig_str_val;
|
||||
}
|
||||
|
@ -486,6 +485,102 @@ reader::~reader()
|
|||
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()
|
||||
{
|
||||
if(split_total - 1 == 1 or split_total - 1 == 0) {
|
||||
|
@ -908,7 +1003,7 @@ void reader::batteryWatchdog() {
|
|||
}
|
||||
|
||||
void reader::openLowBatteryDialog() {
|
||||
reader_static::batteryAlertLock = true;
|
||||
global::battery::batteryAlertLock = true;
|
||||
|
||||
generalDialogWindow = new generalDialog(this);
|
||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -917,7 +1012,7 @@ void reader::openLowBatteryDialog() {
|
|||
}
|
||||
|
||||
void reader::openCriticalBatteryAlertWindow() {
|
||||
global_static::battery::showCriticalBatteryAlert = true;
|
||||
global::battery::showCriticalBatteryAlert = true;
|
||||
|
||||
alertWindow = new alert(this);
|
||||
alertWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
|
9
reader.h
9
reader.h
|
@ -15,10 +15,6 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace reader_static {
|
||||
static bool batteryAlertLock = false;
|
||||
}
|
||||
|
||||
namespace Ui {
|
||||
class reader;
|
||||
}
|
||||
|
@ -67,7 +63,8 @@ public:
|
|||
QList<QString> content;
|
||||
explicit reader(QWidget *parent = nullptr);
|
||||
~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
|
||||
if(remount != false) {
|
||||
QString mount_prog ("sh");
|
||||
|
@ -161,7 +158,7 @@ public:
|
|||
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
void checkwords() {
|
||||
QFile words_list(".config/06-words/config");
|
||||
words_list.open(QIODevice::ReadWrite);
|
||||
|
|
BIN
resources/battery_alert.png
Normal file
BIN
resources/battery_alert.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Loading…
Reference in a new issue