Basic home screen + other improvements

This commit is contained in:
Nicolas Mailloux 2022-06-29 02:15:13 -04:00
parent 8eea1d0df5
commit 7822f65e02
14 changed files with 375 additions and 104 deletions

View file

@ -19,6 +19,7 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
#include <QJsonArray> #include <QJsonArray>
#include <QCryptographicHash>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
@ -52,6 +53,7 @@ namespace global {
namespace mainwindow { namespace mainwindow {
namespace tabSwitcher { namespace tabSwitcher {
inline bool repaint; inline bool repaint;
inline bool homePageWidgetCreated;
inline bool appsWidgetCreated; inline bool appsWidgetCreated;
inline bool appsWidgetSelected; inline bool appsWidgetSelected;
inline bool settingsChooserWidgetCreated; inline bool settingsChooserWidgetCreated;
@ -127,6 +129,7 @@ namespace global {
namespace localLibrary { namespace localLibrary {
static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw"; static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw";
static inline QString databasePath = "/mnt/onboard/onboard/.inkbox/LocalLibrary.db"; static inline QString databasePath = "/mnt/onboard/onboard/.inkbox/LocalLibrary.db";
static inline QString recentBooksDatabasePath = "/mnt/onboard/onboard/.inkbox/RecentBooks.db";
} }
namespace localStorage { namespace localStorage {
inline QStringList searchResultsPaths; inline QStringList searchResultsPaths;
@ -135,11 +138,14 @@ namespace global {
inline bool status; inline bool status;
} }
namespace userApps { namespace userApps {
inline bool appCompatibilityDialog; inline bool appCompatibilityDialog;
inline QString appCompatibilityText; inline QString appCompatibilityText;
inline bool appCompatibilityLastContinueStatus = true; // This is for RequiredFeatures to show only one dialog if 'Cancel' is clicked. inline bool appCompatibilityLastContinueStatus = true; // This is for RequiredFeatures to show only one dialog if 'Cancel' is clicked.
inline bool appInfoDialog; inline bool appInfoDialog;
inline bool launchApp; inline bool launchApp;
}
namespace homePageWidget {
inline int recentBooksNumber = 4;
} }
inline QString systemInfoText; inline QString systemInfoText;
inline bool forbidOpenSearchDialog; inline bool forbidOpenSearchDialog;
@ -959,6 +965,15 @@ namespace {
} }
} }
} }
QByteArray fileChecksum(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) {
QFile f(fileName);
if (f.open(QFile::ReadOnly)) {
QCryptographicHash hash(hashAlgorithm);
if (hash.addData(&f)) {
return hash.result();
}
}
}
} }
#endif // FUNCTIONS_H #endif // FUNCTIONS_H

117
homepagewidget.cpp Normal file
View file

@ -0,0 +1,117 @@
#include "homepagewidget.h"
#include "ui_homepagewidget.h"
#include <QScreen>
#include "functions.h"
homePageWidget::homePageWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::homePageWidget)
{
ui->setupUi(this);
verticalLayoutArray.resize(global::homePageWidget::recentBooksNumber);
bookBtnArray.resize(global::homePageWidget::recentBooksNumber);
bookTitleArray.resize(global::homePageWidget::recentBooksNumber);
// Getting the screen's size
sW = QGuiApplication::screens()[0]->size().width();
sH = QGuiApplication::screens()[0]->size().height();
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "kt\n") {
stdIconWidthDivider = 8;
stdIconHeightDivider = 8;
stdIconWidth = sW / stdIconWidthDivider;
stdIconHeight = sH / stdIconHeightDivider;
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
stdIconWidthDivider = 7;
stdIconHeightDivider = 7;
stdIconWidth = sW / stdIconWidthDivider;
stdIconWidth = sH / stdIconHeightDivider;
}
else if(global::deviceID == "n437\n") {
stdIconWidthDivider = 6.5;
stdIconHeightDivider = 6.5;
stdIconWidth = sW / stdIconWidthDivider;
stdIconHeight = sH / stdIconHeightDivider;
}
else if(global::deviceID == "n873\n") {
stdIconWidthDivider = 6;
stdIconHeightDivider = 6;
stdIconWidth = sW / stdIconWidthDivider;
stdIconHeight = sH / stdIconHeightDivider;
}
else {
stdIconWidthDivider = 8;
stdIconHeightDivider = 8;
stdIconWidth = sW / stdIconWidthDivider;
stdIconHeight = sH / stdIconHeightDivider;
}
log("Reading database", className);
QFile database(global::localLibrary::databasePath);
QByteArray data;
if(database.open(QIODevice::ReadOnly)) {
data = database.readAll();
database.close();
}
else {
QString function = __func__; log(function + ": Failed to open local library database file for reading at '" + database.fileName() + "'", className);
}
QJsonObject databaseJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data))).object();
QJsonArray databaseJsonArrayList = databaseJsonObject["database"].toArray();
int databaseBooksNumber = databaseJsonArrayList.size();
QJsonObject recentBooksJsonObject = QJsonDocument::fromJson(readFile(global::localLibrary::recentBooksDatabasePath).toUtf8()).object();
log("Setting up home page", className);
for(int i = 1; i <= global::homePageWidget::recentBooksNumber; i++) {
QString objectName = "Book" + QString::number(i);
QJsonObject jsonObject = recentBooksJsonObject[objectName].toObject();
QString bookPath = jsonObject.value("BookPath").toString();
bookBtnArray[i] = new QClickableLabel(this);
// Iterate until we find a book matching the recently opened book's "BookPath" key/value pair
for(int in = i; in <= databaseBooksNumber; in++) {
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
if(bookJsonObject["BookPath"] == bookPath) {
bookBtnArray[i]->setObjectName(QJsonDocument(bookJsonObject).toJson());
}
}
verticalLayoutArray[i] = new QVBoxLayout(this);
QObject::connect(bookBtnArray[i], &QClickableLabel::bookPath, this, &homePageWidget::openBook);
bookBtnArray[i]->setAlignment(Qt::AlignCenter);
bookBtnArray[i]->setFont(QFont("u001"));
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
QString bookIcon = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["CoverPath"].toString();
if(QFile::exists(bookIcon)) {
bookBtnArray[i]->setPixmap(QPixmap(bookIcon).scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
}
else {
bookBtnArray[i]->setPixmap(QPixmap(":/resources/cover_unavailable").scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
}
verticalLayoutArray[i]->addWidget(bookBtnArray[i]);
ui->horizontalLayout->addLayout(verticalLayoutArray[i]);
}
QTimer::singleShot(500, this, SLOT(refreshScreenNative()));
}
homePageWidget::~homePageWidget()
{
delete ui;
}
void homePageWidget::openBook(QString bookPath) {
emit openBookSignal(bookPath, false);
}
void homePageWidget::refreshScreenNative() {
emit refreshScreen();
}

42
homepagewidget.h Normal file
View file

@ -0,0 +1,42 @@
#ifndef HOMEPAGEWIDGET_H
#define HOMEPAGEWIDGET_H
#include <QWidget>
#include <QVBoxLayout>
#include "qclickablelabel.h"
namespace Ui {
class homePageWidget;
}
class homePageWidget : public QWidget
{
Q_OBJECT
public:
QString className = this->metaObject()->className();
explicit homePageWidget(QWidget *parent = nullptr);
~homePageWidget();
int sW;
int sH;
int stdIconWidth;
int stdIconHeight;
float stdIconWidthDivider;
float stdIconHeightDivider;
signals:
void openBookSignal(QString bookPath, bool relativePath);
void refreshScreen();
private slots:
void openBook(QString bookPath);
void refreshScreenNative();
private:
Ui::homePageWidget *ui;
QVector<QLabel*> bookTitleArray;
QVector<QVBoxLayout*> verticalLayoutArray;
QVector<QClickableLabel*> bookBtnArray;
};
#endif // HOMEPAGEWIDGET_H

76
homepagewidget.ui Normal file
View file

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>homePageWidget</class>
<widget class="QWidget" name="homePageWidget">
<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">
<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>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Inter</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Continue reading</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>25</number>
</property>
</layout>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -32,6 +32,7 @@ SOURCES += \
dictionarywidget.cpp \ dictionarywidget.cpp \
encryptionmanager.cpp \ encryptionmanager.cpp \
generaldialog.cpp \ generaldialog.cpp \
homepagewidget.cpp \
hourglassanimationwidget.cpp \ hourglassanimationwidget.cpp \
koboxappsdialog.cpp \ koboxappsdialog.cpp \
koboxsettings.cpp \ koboxsettings.cpp \
@ -65,6 +66,7 @@ HEADERS += \
encryptionmanager.h \ encryptionmanager.h \
functions.h \ functions.h \
generaldialog.h \ generaldialog.h \
homepagewidget.h \
hourglassanimationwidget.h \ hourglassanimationwidget.h \
koboxappsdialog.h \ koboxappsdialog.h \
koboxsettings.h \ koboxsettings.h \
@ -96,6 +98,7 @@ FORMS += \
dictionarywidget.ui \ dictionarywidget.ui \
encryptionmanager.ui \ encryptionmanager.ui \
generaldialog.ui \ generaldialog.ui \
homepagewidget.ui \
hourglassanimationwidget.ui \ hourglassanimationwidget.ui \
koboxappsdialog.ui \ koboxappsdialog.ui \
koboxsettings.ui \ koboxsettings.ui \

View file

@ -18,6 +18,7 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
ui->previousPageBtn->setIcon(QIcon(":/resources/chevron-left.png")); ui->previousPageBtn->setIcon(QIcon(":/resources/chevron-left.png"));
ui->nextPageBtn->setIcon(QIcon(":/resources/chevron-right.png")); ui->nextPageBtn->setIcon(QIcon(":/resources/chevron-right.png"));
ui->pageNumberLabel->setFont(QFont("Source Serif Pro")); ui->pageNumberLabel->setFont(QFont("Source Serif Pro"));
ui->pageNumberLabel->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding-left: 10px; padding-right: 10px");
ui->verticalLayout->setSpacing(4); ui->verticalLayout->setSpacing(4);
if(global::deviceID == "n705\n") { if(global::deviceID == "n705\n") {
@ -146,7 +147,7 @@ void localLibraryWidget::setupDatabase() {
QString prog("busybox-initrd"); QString prog("busybox-initrd");
QStringList args; QStringList args;
args << "env" << "icon_width_divider=" + QString::number(stdIconWidthDivider) << "icon_height_divider=" + QString::number(stdIconHeightDivider) << "./explore_local_library.sh" << booksList; args << "env" << "icon_width_divider=" + QString::number(stdIconWidthDivider - 1.5) << "icon_height_divider=" + QString::number(stdIconHeightDivider - 1.5) << "./explore_local_library.sh" << booksList;
QProcess *proc = new QProcess(); QProcess *proc = new QProcess();
proc->start(prog, args); proc->start(prog, args);
proc->waitForFinished(); proc->waitForFinished();
@ -210,7 +211,7 @@ void localLibraryWidget::setupBooksList(int pageNumber) {
if(!coverPath.isEmpty()) { if(!coverPath.isEmpty()) {
// Display book cover if found // Display book cover if found
QPixmap pixmap(coverPath); QPixmap pixmap(coverPath);
bookIconArray[in]->setPixmap(pixmap); bookIconArray[in]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
} }
else { else {
QPixmap pixmap(":/resources/cover_unavailable.png"); QPixmap pixmap(":/resources/cover_unavailable.png");
@ -260,6 +261,10 @@ void localLibraryWidget::on_previousPageBtn_clicked()
ui->previousPageBtn->setEnabled(false); ui->previousPageBtn->setEnabled(false);
ui->nextPageBtn->setEnabled(true); ui->nextPageBtn->setEnabled(true);
} }
else {
ui->previousPageBtn->setEnabled(true);
ui->nextPageBtn->setEnabled(true);
}
setupBooksList(currentPageNumber); setupBooksList(currentPageNumber);
pagesTurned = pagesTurned + 1; pagesTurned = pagesTurned + 1;
@ -277,6 +282,10 @@ void localLibraryWidget::on_nextPageBtn_clicked()
ui->previousPageBtn->setEnabled(true); ui->previousPageBtn->setEnabled(true);
ui->nextPageBtn->setEnabled(false); ui->nextPageBtn->setEnabled(false);
} }
else {
ui->previousPageBtn->setEnabled(true);
ui->nextPageBtn->setEnabled(true);
}
setupBooksList(currentPageNumber); setupBooksList(currentPageNumber);
pagesTurned = pagesTurned + 1; pagesTurned = pagesTurned + 1;

View file

@ -43,13 +43,27 @@
</property> </property>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="1"> <item row="0" column="6">
<spacer name="horizontalSpacer"> <widget class="QPushButton" name="nextPageBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QClickableLabel" name="pageNumberLabel">
<property name="text">
<string>Page</string>
</property>
</widget>
</item>
<item row="0" column="5">
<spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum> <enum>QSizePolicy::Maximum</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@ -59,40 +73,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="4">
<widget class="QLabel" name="pageNumberLabel">
<property name="text">
<string>Page</string>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QPushButton" name="nextPageBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="localLibraryLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;b&gt;Local library&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="previousPageBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="3"> <item row="0" column="3">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -109,13 +89,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="5"> <item row="0" column="1">
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Maximum</enum> <enum>QSizePolicy::MinimumExpanding</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@ -125,6 +105,26 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="2">
<widget class="QPushButton" name="previousPageBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="localLibraryLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;b&gt;Local library&lt;/b&gt;</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -151,6 +151,9 @@
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum> <enum>QLayout::SetNoConstraint</enum>
</property> </property>
<property name="topMargin">
<number>10</number>
</property>
</layout> </layout>
</item> </item>
</layout> </layout>

View file

@ -564,6 +564,9 @@ void MainWindow::resetWindow(bool resetStackedWidget) {
} }
// Destroy widgets // Destroy widgets
if(global::mainwindow::tabSwitcher::homePageWidgetCreated == true) {
homePageWidgetWindow->deleteLater();
}
if(global::mainwindow::tabSwitcher::appsWidgetCreated == true) { if(global::mainwindow::tabSwitcher::appsWidgetCreated == true) {
appsWindow->deleteLater(); appsWindow->deleteLater();
} }
@ -577,6 +580,7 @@ void MainWindow::resetWindow(bool resetStackedWidget) {
localLibraryWidgetWindow->deleteLater(); localLibraryWidgetWindow->deleteLater();
} }
global::mainwindow::tabSwitcher::homePageWidgetCreated = false;
global::mainwindow::tabSwitcher::appsWidgetCreated = false; global::mainwindow::tabSwitcher::appsWidgetCreated = false;
global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = false; global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = false;
global::mainwindow::tabSwitcher::appsWidgetSelected = false; global::mainwindow::tabSwitcher::appsWidgetSelected = false;
@ -1012,13 +1016,19 @@ void MainWindow::resetWifiIconClickedWhileReconnecting() {
void MainWindow::setupLocalLibraryWidget() { void MainWindow::setupLocalLibraryWidget() {
localLibraryWidgetWindow = new localLibraryWidget(this); localLibraryWidgetWindow = new localLibraryWidget(this);
connect(localLibraryWidgetWindow, SIGNAL(openBookSignal(QString, bool)), SLOT(openBookFile(QString, bool))); QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::openBookSignal, this, &MainWindow::openBookFile);
connect(localLibraryWidgetWindow, SIGNAL(refreshScreen()), SLOT(refreshScreen())); QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::refreshScreen, this, &MainWindow::refreshScreen);
localLibraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose); localLibraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
ui->homeStackedWidget->insertWidget(1, localLibraryWidgetWindow); ui->homeStackedWidget->insertWidget(1, localLibraryWidgetWindow);
ui->homeStackedWidget->setCurrentIndex(1); ui->homeStackedWidget->setCurrentIndex(1);
} }
void MainWindow::setupHomePageWidget() { void MainWindow::setupHomePageWidget() {
homePageWidgetWindow = new homePageWidget(this);
QObject::connect(homePageWidgetWindow, &homePageWidget::openBookSignal, this, &MainWindow::openBookFile);
QObject::connect(homePageWidgetWindow, &homePageWidget::refreshScreen, this, &MainWindow::refreshScreen);
homePageWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
ui->homeStackedWidget->insertWidget(2, homePageWidgetWindow);
ui->homeStackedWidget->setCurrentIndex(2); ui->homeStackedWidget->setCurrentIndex(2);
global::mainwindow::tabSwitcher::homePageWidgetCreated = true;
} }

View file

@ -19,6 +19,7 @@
#include "otamanager.h" #include "otamanager.h"
#include "librarywidget.h" #include "librarywidget.h"
#include "locallibrarywidget.h" #include "locallibrarywidget.h"
#include "homepagewidget.h"
using namespace std; using namespace std;
@ -116,6 +117,7 @@ private:
otaManager * otaManagerWindow; otaManager * otaManagerWindow;
libraryWidget * libraryWidgetWindow; libraryWidget * libraryWidgetWindow;
localLibraryWidget * localLibraryWidgetWindow; localLibraryWidget * localLibraryWidgetWindow;
homePageWidget * homePageWidgetWindow;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View file

@ -1,3 +1,6 @@
#include <QJsonDocument>
#include <QJsonObject>
#include "qclickablelabel.h" #include "qclickablelabel.h"
QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f) QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f)
@ -9,11 +12,22 @@ QClickableLabel::~QClickableLabel() {}
void QClickableLabel::mousePressEvent(QMouseEvent * event) { void QClickableLabel::mousePressEvent(QMouseEvent * event) {
emit clicked(); emit clicked();
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding: 10px"); if(objectName() == "pageNumberLabel") {
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding-left: 10px; padding-right: 10px");
}
else {
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding: 10px");
}
} }
void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) { void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) {
emit unclicked(); emit unclicked();
emit bookID(objectName().toInt()); emit bookID(objectName().toInt());
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px"); emit bookPath(QJsonDocument::fromJson(objectName().toUtf8()).object()["BookPath"].toString());
if(objectName() == "pageNumberLabel") {
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding-left: 10px; padding-right: 10px");
}
else {
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
}
} }

View file

@ -16,6 +16,7 @@ signals:
void clicked(); void clicked();
void unclicked(); void unclicked();
void bookID(int id); void bookID(int id);
void bookPath(QString path);
protected: protected:
void mousePressEvent(QMouseEvent * event); void mousePressEvent(QMouseEvent * event);

View file

@ -15,8 +15,8 @@
#include <QFontDatabase> #include <QFontDatabase>
#include <QDirIterator> #include <QDirIterator>
#include <QTextCursor> #include <QTextCursor>
#include <QDebug>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QJsonDocument>
using namespace std; using namespace std;
@ -142,24 +142,6 @@ reader::reader(QWidget *parent) :
book_file = global::reader::bookFile; book_file = global::reader::bookFile;
global::reader::bookFile = ""; global::reader::bookFile = "";
} }
else {
if(global::reader::bookNumber == 1) {
string_checkconfig(".config/08-recent_books/1");
book_file = checkconfig_str_val;
}
if(global::reader::bookNumber == 2) {
string_checkconfig(".config/08-recent_books/2");
book_file = checkconfig_str_val;
}
if(global::reader::bookNumber == 3) {
string_checkconfig(".config/08-recent_books/3");
book_file = checkconfig_str_val;
}
if(global::reader::bookNumber == 4) {
string_checkconfig(".config/08-recent_books/4");
book_file = checkconfig_str_val;
}
}
} }
else { else {
if(checkconfig("/opt/inkbox_genuine") == true) { if(checkconfig("/opt/inkbox_genuine") == true) {
@ -640,40 +622,40 @@ reader::reader(QWidget *parent) :
// Way to tell shell scripts that we're in the Reader framework // Way to tell shell scripts that we're in the Reader framework
string_writeconfig("/tmp/inkboxReading", "true"); string_writeconfig("/tmp/inkboxReading", "true");
// Saving the book opened in the favorites list QJsonObject recentBooksObject;
string_checkconfig(".config/08-recent_books/1"); if(QFile::exists(global::localLibrary::recentBooksDatabasePath)) {
book_1 = checkconfig_str_val; QJsonObject mainJsonObject = QJsonDocument::fromJson(readFile(global::localLibrary::recentBooksDatabasePath).toUtf8()).object();
string str_book_1 = book_1.toStdString(); for(int i = 1; i <= global::homePageWidget::recentBooksNumber; i++) {
string_checkconfig(".config/08-recent_books/2"); QString objectName = "Book" + QString::number(i);
book_2 = checkconfig_str_val; QJsonObject jsonObject = mainJsonObject[objectName].toObject();
string str_book_2 = book_2.toStdString(); if(i == 1) {
string_checkconfig(".config/08-recent_books/3"); if(jsonObject.value("BookPath").toString() != book_file) {
book_3 = checkconfig_str_val; // Circular buffer
string str_book_3 = book_3.toStdString(); for(int i = global::homePageWidget::recentBooksNumber; i >= 2; i--) {
string_checkconfig(".config/08-recent_books/4"); mainJsonObject["Book" + QString::number(i)] = mainJsonObject["Book" + QString::number(i - 1)];
book_4 = checkconfig_str_val; }
std::string str_book_4 = book_4.toStdString(); jsonObject.insert("BookPath", QJsonValue(book_file));
mainJsonObject[objectName] = jsonObject;
// Don't mess up "Recently read books" with random "book.txt" buttons... }
if(wakeFromSleep == true) { }
string_checkconfig("/tmp/inkboxBookPath"); }
book_file_str = checkconfig_str_val.toStdString(); recentBooksObject = mainJsonObject;
} }
else { else {
book_file_str = book_file.toStdString(); QJsonObject mainJsonObject;
string_writeconfig("/tmp/inkboxBookPath", book_file_str); QJsonObject firstJsonObject;
} firstJsonObject.insert("BookPath", QJsonValue(book_file));
mainJsonObject["Book1"] = firstJsonObject;
if(book_1 == book_file) { for(int i = 2; i <= global::homePageWidget::recentBooksNumber; i++) {
; QJsonObject jsonObject;
} jsonObject.insert("BookPath", QJsonValue(""));
else { mainJsonObject["Book" + QString::number(i)] = jsonObject;
// Moves old items to the right and puts the new one at the left side }
string_writeconfig(".config/08-recent_books/1", book_file_str); recentBooksObject = mainJsonObject;
string_writeconfig(".config/08-recent_books/2", str_book_1);
string_writeconfig(".config/08-recent_books/3", str_book_2);
string_writeconfig(".config/08-recent_books/4", str_book_3);
} }
QFile::remove(global::localLibrary::recentBooksDatabasePath);
writeFile(global::localLibrary::recentBooksDatabasePath, QString(QJsonDocument(recentBooksObject).toJson()));
// USB mass storage prompt // USB mass storage prompt
if(global::reader::startUsbmsPrompt == true) { if(global::reader::startUsbmsPrompt == true) {

View file

@ -75,10 +75,6 @@ public:
bool wordwidgetLock; bool wordwidgetLock;
bool isNightModeActive; bool isNightModeActive;
bool goToSavedPageDone; bool goToSavedPageDone;
QString book_1;
QString book_2;
QString book_3;
QString book_4;
QString ittext; QString ittext;
QString book_file; QString book_file;
bool batt_status; bool batt_status;

View file

@ -1070,6 +1070,7 @@ void settings::on_generateSystemReportBtn_clicked()
while(true) { while(true) {
if(QFile::exists("/inkbox/systemReportDone")) { if(QFile::exists("/inkbox/systemReportDone")) {
if(checkconfig("/inkbox/systemReportDone") == true) { if(checkconfig("/inkbox/systemReportDone") == true) {
QFile::remove(global::localLibrary::databasePath);
emit showToast("System report generated successfully"); emit showToast("System report generated successfully");
} }
else { else {