From 97bc34530cb38a8b7aebcf7bcbfbe47ccf4f6f4d Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Thu, 23 Jun 2022 11:10:38 -0400 Subject: [PATCH] Local library: First steps --- inkbox.pro | 3 + locallibrarywidget.cpp | 14 ++ locallibrarywidget.h | 22 +++ locallibrarywidget.ui | 32 ++++ mainwindow.cpp | 221 +----------------------- mainwindow.h | 7 +- mainwindow.ui | 372 ++++++++++++++++++----------------------- 7 files changed, 249 insertions(+), 422 deletions(-) create mode 100644 locallibrarywidget.cpp create mode 100644 locallibrarywidget.h create mode 100644 locallibrarywidget.ui diff --git a/inkbox.pro b/inkbox.pro index f41890e..3f632cb 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -36,6 +36,7 @@ SOURCES += \ koboxappsdialog.cpp \ koboxsettings.cpp \ librarywidget.cpp \ + locallibrarywidget.cpp \ main.cpp \ mainwindow.cpp \ otamanager.cpp \ @@ -67,6 +68,7 @@ HEADERS += \ koboxappsdialog.h \ koboxsettings.h \ librarywidget.h \ + locallibrarywidget.h \ mainwindow.h \ otamanager.h \ quit.h \ @@ -96,6 +98,7 @@ FORMS += \ koboxappsdialog.ui \ koboxsettings.ui \ librarywidget.ui \ + locallibrarywidget.ui \ mainwindow.ui \ otamanager.ui \ quit.ui \ diff --git a/locallibrarywidget.cpp b/locallibrarywidget.cpp new file mode 100644 index 0000000..2797f4d --- /dev/null +++ b/locallibrarywidget.cpp @@ -0,0 +1,14 @@ +#include "locallibrarywidget.h" +#include "ui_locallibrarywidget.h" + +localLibraryWidget::localLibraryWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::localLibraryWidget) +{ + ui->setupUi(this); +} + +localLibraryWidget::~localLibraryWidget() +{ + delete ui; +} diff --git a/locallibrarywidget.h b/locallibrarywidget.h new file mode 100644 index 0000000..071a794 --- /dev/null +++ b/locallibrarywidget.h @@ -0,0 +1,22 @@ +#ifndef LOCALLIBRARYWIDGET_H +#define LOCALLIBRARYWIDGET_H + +#include + +namespace Ui { +class localLibraryWidget; +} + +class localLibraryWidget : public QWidget +{ + Q_OBJECT + +public: + explicit localLibraryWidget(QWidget *parent = nullptr); + ~localLibraryWidget(); + +private: + Ui::localLibraryWidget *ui; +}; + +#endif // LOCALLIBRARYWIDGET_H diff --git a/locallibrarywidget.ui b/locallibrarywidget.ui new file mode 100644 index 0000000..0317ba1 --- /dev/null +++ b/locallibrarywidget.ui @@ -0,0 +1,32 @@ + + + localLibraryWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + Hello + + + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 21365d3..cd62e29 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -140,19 +140,6 @@ MainWindow::MainWindow(QWidget *parent) } setBatteryIcon(); - 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)); - 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"); - ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 8px; padding-right: 8px;"); ui->wifiBtn->setStyleSheet("font-size: 9pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px"); @@ -176,13 +163,6 @@ MainWindow::MainWindow(QWidget *parent) ui->timeLabel->setText(""); ui->batteryLabel->setStyleSheet("padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px"); - ui->book1Btn->hide(); - ui->book2Btn->hide(); - ui->book3Btn->hide(); - ui->book4Btn->hide(); - - ui->recentBooksLabel->hide(); - // Deleting/Hiding "Library" button if device is not WiFi-able // NOTE: Using deleteLater() on these elements causes a segmentation fault and aborts the whole program when the Settings, Apps or Home button is pressed. No idea why. if(global::device::isWifiAble == false && global::deviceID != "emu\n") { @@ -196,73 +176,8 @@ MainWindow::MainWindow(QWidget *parent) this->setStyleSheet(stylesheetFile.readAll()); stylesheetFile.close(); - // Running rootfs changes script if it's there - // 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. - if(checkconfig("/opt/inkbox_genuine") == true) { - if(checkconfig("/external_root/opt/update/inkbox_updated") == true) { - // 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(); - rootfs_internal_proc->deleteLater(); - - // 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(); - rootfs_proc->deleteLater(); - - // 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); - - // Rebooting if needed - if(reboot_after_update == true) { - reboot(false); - qApp->quit(); - } - else { - // Update process finished. - ; - } - } - } - else { - ; - } - // Custom settings // Reading from the config files and tweaking the program according to the options set - - // Safety mesure; /inkbox is a tmpfs - string_writeconfig("/tmp/skip_opendialog", "true"); - global::reader::skipOpenDialog = false; - // Demo setting, changes "Welcome to InkBox" label to "InkBox" if(checkconfig(".config/01-demo/config") == true) { ui->inkboxLabel->setText("InkBox"); @@ -354,19 +269,6 @@ MainWindow::MainWindow(QWidget *parent) } } - // 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="); - } - } - // Global reading settings string_checkconfig(".config/16-global_reading_settings/config"); if(checkconfig_str_val == "") { @@ -408,91 +310,10 @@ MainWindow::MainWindow(QWidget *parent) ui->quotePictureLabel->setPixmap(scaledPixmap); ui->quoteLabel->setText("“One of the saddest things in life, is the things one remembers.”\n― Agatha Christie"); } + ui->homeStackedWidget->setCurrentIndex(0); } else { - ui->gridLayout_4->deleteLater(); - ui->quotePictureLabel->deleteLater(); - ui->quoteLabel->deleteLater(); - ui->quoteHeadingLabel->setText("Books"); - ui->book1Btn->show(); - ui->book2Btn->show(); - ui->book3Btn->show(); - ui->book4Btn->show(); - - setRecentBooksLabelsTruncateThreshold(); - // Book 1 - string_checkconfig(".config/08-recent_books/1"); - if(checkconfig_str_val == "") { - ui->book1Btn->hide(); - } - else { - relative_path = checkconfig_str_val.split("/").last(); - if(relative_path.length() > truncateThreshold) { - relative_path.truncate(truncateThreshold); - 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(); - if(relative_path.length() > truncateThreshold) { - relative_path.truncate(truncateThreshold); - 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(); - if(relative_path.length() > truncateThreshold) { - relative_path.truncate(truncateThreshold); - 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(); - if(relative_path.length() > truncateThreshold) { - relative_path.truncate(truncateThreshold); - 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(); - } - else if(ui->book3Btn->text() == ui->book1Btn->text()) { - ui->book3Btn->hide(); - } - else if(ui->book4Btn->text() == ui->book1Btn->text()) { - ui->book4Btn->hide(); - } - else if(existing_recent_books == false) { - ui->recentBooksLabel->show(); - } - else { - ui->recentBooksLabel->hide(); - } + setupLocalLibraryWidget(); } // Check if it's the first boot since an update and confirm that it installed successfully @@ -703,38 +524,6 @@ void MainWindow::on_quitBtn_clicked() quitWindow->showFullScreen(); } -void MainWindow::on_book1Btn_clicked() -{ - global::reader::skipOpenDialog = true; - global::reader::bookNumber = 1; - - openReaderFramework(); -} - -void MainWindow::on_book2Btn_clicked() -{ - global::reader::skipOpenDialog = true; - global::reader::bookNumber = 2; - - openReaderFramework(); -} - -void MainWindow::on_book3Btn_clicked() -{ - global::reader::skipOpenDialog = true; - global::reader::bookNumber = 3; - - openReaderFramework(); -} - -void MainWindow::on_book4Btn_clicked() -{ - global::reader::skipOpenDialog = true; - global::reader::bookNumber = 4; - - openReaderFramework(); -} - void MainWindow::on_brightnessBtn_clicked() { log("Showing Brightness Dialog", className); @@ -1205,3 +994,9 @@ void MainWindow::checkForOtaUpdate() { void MainWindow::resetWifiIconClickedWhileReconnecting() { wifiIconClickedWhileReconnecting = false; } + +void MainWindow::setupLocalLibraryWidget() { + localLibraryWidgetWindow = new localLibraryWidget(); + libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose); + ui->stackedWidget->insertWidget(1, localLibraryWidgetWindow); +} diff --git a/mainwindow.h b/mainwindow.h index 447b937..585138e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,6 +18,7 @@ #include "toast.h" #include "otamanager.h" #include "librarywidget.h" +#include "locallibrarywidget.h" using namespace std; @@ -70,10 +71,6 @@ private slots: void on_pushButton_clicked(); void on_searchBtn_clicked(); void on_quitBtn_clicked(); - void on_book1Btn_clicked(); - void on_book2Btn_clicked(); - void on_book3Btn_clicked(); - void on_book4Btn_clicked(); void on_brightnessBtn_clicked(); void openUpdateDialog(); void openWifiDialog(); @@ -99,6 +96,7 @@ private slots: void resetFullWindow(); void setRecentBooksLabelsTruncateThreshold(); void resetWifiIconClickedWhileReconnecting(); + void setupLocalLibraryWidget(); private: Ui::MainWindow * ui; @@ -117,6 +115,7 @@ private: toast * toastWindow; otaManager * otaManagerWindow; libraryWidget * libraryWidgetWindow; + localLibraryWidget * localLibraryWidgetWindow; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 6f5eb65..7f76a4b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -193,213 +193,175 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - Inter - 11 - 75 - false - true - - - - Author's quote - - - Qt::AlignCenter - - - - - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Chivo - 11 - 50 - true - false - - - - Quote - - - Qt::AlignCenter - - - true - - - - - - - Picture - - - Qt::AlignCenter - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Chivo - 11 - 50 - true - false - - - - Recently read books will appear here. - - - Qt::AlignCenter - - - - - - - 0 - - - - - 0 - - - - - Book 1 - - - - - - - Book 2 - - - - - - - - - 0 - - - - - Book 3 - - - - - - - Book 4 - - - - - - - - - - Qt::Vertical + + + 0 - - - 20 - 40 - - - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Inter + 11 + 75 + false + true + + + + Author's quote + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Chivo + 11 + 50 + true + false + + + + Quote + + + Qt::AlignCenter + + + true + + + + + + + Picture + + + Qt::AlignCenter + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + +