Local library: First steps

This commit is contained in:
Nicolas Mailloux 2022-06-23 11:10:38 -04:00
parent 0dfcc20409
commit 97bc34530c
7 changed files with 249 additions and 422 deletions

View file

@ -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 \

14
locallibrarywidget.cpp Normal file
View file

@ -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;
}

22
locallibrarywidget.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef LOCALLIBRARYWIDGET_H
#define LOCALLIBRARYWIDGET_H
#include <QWidget>
namespace Ui {
class localLibraryWidget;
}
class localLibraryWidget : public QWidget
{
Q_OBJECT
public:
explicit localLibraryWidget(QWidget *parent = nullptr);
~localLibraryWidget();
private:
Ui::localLibraryWidget *ui;
};
#endif // LOCALLIBRARYWIDGET_H

32
locallibrarywidget.ui Normal file
View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>localLibraryWidget</class>
<widget class="QWidget" name="localLibraryWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Hello</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -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);
}

View file

@ -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

View file

@ -193,213 +193,175 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="quoteHeadingLabel">
<property name="font">
<font>
<family>Inter</family>
<pointsize>11</pointsize>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Author's quote</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="4" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="1">
<widget class="QLabel" name="quoteLabel">
<property name="font">
<font>
<family>Chivo</family>
<pointsize>11</pointsize>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Quote</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="quotePictureLabel">
<property name="text">
<string>Picture</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="recentBooksLabel">
<property name="font">
<font>
<family>Chivo</family>
<pointsize>11</pointsize>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Recently read books will appear here.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<layout class="QGridLayout" name="gridLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_6">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="book1Btn">
<property name="text">
<string>Book 1</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="book2Btn">
<property name="text">
<string>Book 2</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_8">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="book3Btn">
<property name="text">
<string>Book 3</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="book4Btn">
<property name="text">
<string>Book 4</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QStackedWidget" name="homeStackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
<widget class="QWidget" name="page_5">
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="0">
<widget class="QLabel" name="quoteHeadingLabel">
<property name="font">
<font>
<family>Inter</family>
<pointsize>11</pointsize>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Author's quote</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="1">
<widget class="QLabel" name="quoteLabel">
<property name="font">
<font>
<family>Chivo</family>
<pointsize>11</pointsize>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Quote</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="quotePictureLabel">
<property name="text">
<string>Picture</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_6">
<layout class="QVBoxLayout" name="verticalLayout_7"/>
</widget>
</widget>
</item>
</layout>
</item>