mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Merge branch 'localLibraryWidget' into 'master'
This commit is contained in:
commit
7cf0f92698
38 changed files with 2794 additions and 949 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1 +1,8 @@
|
|||
inkbox.pro.user
|
||||
inkbox
|
||||
*.o
|
||||
ui_*
|
||||
moc_*
|
||||
qrc_*
|
||||
.qmake.stash
|
||||
.vscode
|
||||
|
|
1
apps.cpp
1
apps.cpp
|
@ -25,6 +25,7 @@ apps::apps(QWidget *parent) :
|
|||
ui->reversiLaunchBtn->setProperty("type", "borderless");
|
||||
ui->g2048LaunchBtn->setProperty("type", "borderless");
|
||||
|
||||
ui->label->setStyleSheet("padding-top: 2px; padding-bottom: 5px");
|
||||
ui->koboxAppsOpenButton->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px");
|
||||
ui->scribbleLaunchBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px");
|
||||
ui->lightmapsLaunchBtn->setStyleSheet("background: lightGrey; font-size: 9pt; padding: 8px");
|
||||
|
|
360
apps.ui
360
apps.ui
|
@ -52,9 +52,9 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>-30</y>
|
||||
<width>407</width>
|
||||
<height>541</height>
|
||||
<y>0</y>
|
||||
<width>428</width>
|
||||
<height>542</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
|
@ -76,7 +76,7 @@
|
|||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="topMargin">
|
||||
<number>8</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
|
@ -84,90 +84,18 @@
|
|||
<property name="bottomMargin">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>KoBox apps</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0">
|
||||
<widget class="QLabel" name="vncViewerLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>VNC viewer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="scribbleLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Inter</family>
|
||||
<weight>75</weight>
|
||||
<italic>false</italic>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Saved words</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="scribbleLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Scribble</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Calculator</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QPushButton" name="calendarLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -181,7 +109,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>KoBox apps</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="koboxAppsOpenButton">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -195,46 +136,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Light Maps</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="reversiLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reversi</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="reversiLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QPushButton" name="savedWordsLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -248,7 +150,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="reversiLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="calculatorLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -262,20 +177,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="g2048Label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>2048</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="g2048LaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -288,21 +190,72 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="1">
|
||||
<widget class="QPushButton" name="vncLaunchBtn">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Inter</family>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
<string>Saved words</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="1">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="reversiLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reversi</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="g2048Label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>2048</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="scribbleLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Scribble</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Calculator</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QPushButton" name="lightmapsLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -317,7 +270,22 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="scribbleLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Inter</family>
|
||||
<weight>75</weight>
|
||||
<italic>false</italic>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="calendarLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
|
@ -330,6 +298,77 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Light Maps</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QPushButton" name="vncLaunchBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Inter</family>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Launch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="vncViewerLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>VNC viewer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Built-in apps</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -492,35 +531,6 @@ No user apps currently available</string>
|
|||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Built-in apps</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -30,6 +30,7 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) :
|
|||
stdIconWidth = sW / 4;
|
||||
stdIconHeight = sH / 4;
|
||||
|
||||
if(global::bookInfoDialog::localInfoDialog == false) {
|
||||
if(global::library::isLatestBook == true) {
|
||||
QString bookNumberQstr = QString::number(global::library::latestBookNumber);
|
||||
|
||||
|
@ -77,10 +78,46 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) :
|
|||
}
|
||||
|
||||
log("Setting up book info dialog, ID: " + QString::number(global::library::bookId) + ", title: " + global::library::bookTitle, className);
|
||||
}
|
||||
else {
|
||||
QJsonObject bookJsonObject = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID);
|
||||
QString bookInfo;
|
||||
QString title = bookJsonObject["Title"].toString();
|
||||
QString author = bookJsonObject["Author"].toString();
|
||||
QString publicationDate = bookJsonObject["PublicationDate"].toString();
|
||||
QString path = bookJsonObject["BookPath"].toString();
|
||||
if(!title.isEmpty()) {
|
||||
bookInfo.append("<b>Title:</b> " + title + "<br>");
|
||||
}
|
||||
if(!author.isEmpty()) {
|
||||
bookInfo.append("<b>Author:</b> " + author + "<br>");
|
||||
}
|
||||
if(!publicationDate.isEmpty()) {
|
||||
bookInfo.append("<b>Publication date:</b> " + publicationDate + "<br>");
|
||||
}
|
||||
if(!path.isEmpty()) {
|
||||
bookInfo.append("<b>Path:</b> " + path + "<br>");
|
||||
}
|
||||
|
||||
global::text::textBrowserContents = bookInfo;
|
||||
textwidget * textwidgetWindow = new textwidget(this);
|
||||
ui->stackedWidget->insertWidget(1, textwidgetWindow);
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
|
||||
{
|
||||
int wx = screenGeometry.width();
|
||||
|
||||
int x = wx - 25;
|
||||
int y = this->height() * determineYIncrease();
|
||||
this->setFixedWidth(x);
|
||||
this->setFixedHeight(y);
|
||||
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
// Centering dialog
|
||||
this->adjustSize();
|
||||
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
|
||||
int x = (screenGeometry.width() - this->width()) / 2;
|
||||
int y = (screenGeometry.height() - this->height()) / 2;
|
||||
this->move(x, y);
|
||||
|
@ -94,6 +131,7 @@ bookInfoDialog::~bookInfoDialog()
|
|||
void bookInfoDialog::on_closeBtn_clicked()
|
||||
{
|
||||
global::library::bookTitle = "";
|
||||
global::bookInfoDialog::localInfoDialog = false;
|
||||
bookInfoDialog::close();
|
||||
}
|
||||
|
||||
|
@ -122,6 +160,7 @@ void bookInfoDialog::waitForBookFetch() {
|
|||
QString function = __func__; log(function + ": Download successful", className);
|
||||
emit showToast("Download successful");
|
||||
QFile::remove("/inkbox/gutenberg/getBookDone");
|
||||
QFile::remove(global::localLibrary::databasePath);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QDialog>
|
||||
|
||||
#include "textwidget.h"
|
||||
|
||||
namespace Ui {
|
||||
class bookInfoDialog;
|
||||
}
|
||||
|
@ -30,7 +32,8 @@ signals:
|
|||
void closeIndefiniteToast();
|
||||
|
||||
private:
|
||||
Ui::bookInfoDialog *ui;
|
||||
Ui::bookInfoDialog * ui;
|
||||
textwidget * textwidgetWindow;
|
||||
};
|
||||
|
||||
#endif // BOOKINFODIALOG_H
|
||||
|
|
|
@ -41,6 +41,25 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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">
|
||||
<property name="horizontalSpacing">
|
||||
|
@ -164,6 +183,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
205
bookoptionsdialog.cpp
Normal file
205
bookoptionsdialog.cpp
Normal file
|
@ -0,0 +1,205 @@
|
|||
#include "bookoptionsdialog.h"
|
||||
#include "ui_bookoptionsdialog.h"
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
bookOptionsDialog::bookOptionsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::bookOptionsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->pinBtn->setProperty("type", "borderless");
|
||||
if(global::localLibrary::bookOptionsDialog::deleteOption == false) {
|
||||
global::localLibrary::bookOptionsDialog::deleteOption = true;
|
||||
ui->deleteBtn->hide();
|
||||
ui->line_2->hide();
|
||||
ui->deleteBtn->deleteLater();
|
||||
ui->line_2->deleteLater();
|
||||
this->adjustSize();
|
||||
}
|
||||
else {
|
||||
ui->deleteBtn->setProperty("type", "borderless");
|
||||
}
|
||||
ui->infoBtn->setProperty("type", "borderless");
|
||||
|
||||
global::localLibrary::bookOptionsDialog::bookPinAction = false;
|
||||
|
||||
bookPath = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID)["BookPath"].toString();
|
||||
if(isBookPinned(global::localLibrary::bookOptionsDialog::bookID)) {
|
||||
bookPinned = true;
|
||||
ui->pinBtn->setText("Unpin");
|
||||
}
|
||||
else {
|
||||
bookPinned = false;
|
||||
}
|
||||
}
|
||||
|
||||
bookOptionsDialog::~bookOptionsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void bookOptionsDialog::on_pinBtn_clicked()
|
||||
{
|
||||
if(bookPinned == false) {
|
||||
pinBook(global::localLibrary::bookOptionsDialog::bookID);
|
||||
}
|
||||
else {
|
||||
unpinBook(global::localLibrary::bookOptionsDialog::bookID);
|
||||
}
|
||||
}
|
||||
|
||||
void bookOptionsDialog::on_deleteBtn_clicked()
|
||||
{
|
||||
log("Deleting book '" + bookPath + "'", className);
|
||||
global::toast::delay = 3000;
|
||||
if(QFile::remove(bookPath)) {
|
||||
emit showToast("Book deleted successfully");
|
||||
global::localLibrary::bookOptionsDialog::bookDeleted = true;
|
||||
QFile::remove(global::localLibrary::databasePath);
|
||||
}
|
||||
else {
|
||||
emit showToast("Failed to delete book");
|
||||
}
|
||||
}
|
||||
|
||||
void bookOptionsDialog::on_infoBtn_clicked()
|
||||
{
|
||||
emit openLocalBookInfoDialog();
|
||||
}
|
||||
|
||||
void bookOptionsDialog::pinBook(int bookID) {
|
||||
QJsonObject pinnedBooksObject;
|
||||
if(QFile::exists(global::localLibrary::pinnedBooksDatabasePath)) {
|
||||
QString function = __func__; log(function + ": Reading pinned books database", className);
|
||||
QFile database(global::localLibrary::pinnedBooksDatabasePath);
|
||||
QByteArray data;
|
||||
if(database.open(QIODevice::ReadOnly)) {
|
||||
data = database.readAll();
|
||||
database.close();
|
||||
}
|
||||
else {
|
||||
QString function = __func__; log(function + ": Failed to open pinned books library database file for reading at '" + database.fileName() + "'", className);
|
||||
}
|
||||
pinnedBooksObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data))).object();
|
||||
bool bookIsAlreadyPinned = false;
|
||||
bool foundSpaceForBook = false;
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
QString pinnedBookPath = getBookMetadata(bookID)["BookPath"].toString();
|
||||
if(pinnedBooksObject["Book" + QString::number(i)].toObject().value("BookPath").toString() == pinnedBookPath) {
|
||||
bookIsAlreadyPinned = true;
|
||||
}
|
||||
else {
|
||||
if(pinnedBooksObject["Book" + QString::number(i)].toObject().value("BookPath").toString().isEmpty() && foundSpaceForBook == false) {
|
||||
foundSpaceForBook = true;
|
||||
QJsonObject jsonObject;
|
||||
jsonObject.insert("BookPath", pinnedBookPath);
|
||||
pinnedBooksObject["Book" + QString::number(i)] = jsonObject;
|
||||
|
||||
QString function = __func__; log(function + ": Pinned book with ID " + QString::number(global::localLibrary::bookOptionsDialog::bookID), className);
|
||||
global::toast::delay = 3000;
|
||||
emit showToast("Book pinned successfully");
|
||||
global::localLibrary::bookOptionsDialog::bookPinAction = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundSpaceForBook == false && bookIsAlreadyPinned == false) {
|
||||
global::localLibrary::bookOptionsDialog::bookPinAction = false;
|
||||
emit showToast("No space left for pinning book");
|
||||
}
|
||||
else if(bookIsAlreadyPinned == true) {
|
||||
global::localLibrary::bookOptionsDialog::bookPinAction = false;
|
||||
emit showToast("Book is already pinned");
|
||||
}
|
||||
}
|
||||
else {
|
||||
QJsonObject mainJsonObject;
|
||||
QJsonObject firstJsonObject;
|
||||
firstJsonObject.insert("BookPath", QJsonValue(getBookMetadata(bookID)["BookPath"].toString()));
|
||||
mainJsonObject["Book1"] = firstJsonObject;
|
||||
|
||||
for(int i = 2; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
QJsonObject jsonObject;
|
||||
jsonObject.insert("BookPath", QJsonValue(""));
|
||||
mainJsonObject["Book" + QString::number(i)] = jsonObject;
|
||||
}
|
||||
pinnedBooksObject = mainJsonObject;
|
||||
}
|
||||
// Writing database to file
|
||||
QFile::remove(global::localLibrary::pinnedBooksDatabasePath);
|
||||
writeFile(global::localLibrary::pinnedBooksDatabasePath, qCompress(QJsonDocument(pinnedBooksObject).toJson()).toBase64());
|
||||
}
|
||||
|
||||
void bookOptionsDialog::unpinBook(int bookID) {
|
||||
QJsonObject pinnedBooksObject;
|
||||
QString function = __func__; log(function + ": Reading pinned books database", className);
|
||||
QFile database(global::localLibrary::pinnedBooksDatabasePath);
|
||||
QByteArray data;
|
||||
if(database.open(QIODevice::ReadOnly)) {
|
||||
data = database.readAll();
|
||||
database.close();
|
||||
}
|
||||
else {
|
||||
QString function = __func__; log(function + ": Failed to open pinned books library database file for reading at '" + database.fileName() + "'", className);
|
||||
}
|
||||
pinnedBooksObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data))).object();
|
||||
|
||||
QJsonObject mainJsonObject;
|
||||
|
||||
// Removing pinned book associated to requested ID from database
|
||||
int bookToUnpin;
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
if(pinnedBooksObject["Book" + QString::number(i)].toObject().value("BookPath").toString() == getBookMetadata(bookID)["BookPath"].toString()) {
|
||||
bookToUnpin = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Recreating pinned books database without previously pinned book
|
||||
QString pinnedBookPath;
|
||||
int recreationIndex = 1;
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
pinnedBookPath = pinnedBooksObject["Book" + QString::number(i)].toObject().value("BookPath").toString();
|
||||
if(i != bookToUnpin) {
|
||||
QJsonObject jsonObject;
|
||||
jsonObject.insert("BookPath", QJsonValue(pinnedBookPath));
|
||||
mainJsonObject["Book" + QString::number(recreationIndex)] = jsonObject;
|
||||
recreationIndex++;
|
||||
}
|
||||
}
|
||||
log(function + ": Unpinned book with ID " + bookID, className);
|
||||
emit showToast("Book unpinned successfully");
|
||||
global::localLibrary::bookOptionsDialog::bookPinAction = true;
|
||||
|
||||
// Writing database to file
|
||||
pinnedBooksObject = mainJsonObject;
|
||||
QFile::remove(global::localLibrary::pinnedBooksDatabasePath);
|
||||
writeFile(global::localLibrary::pinnedBooksDatabasePath, qCompress(QJsonDocument(pinnedBooksObject).toJson()).toBase64());
|
||||
}
|
||||
|
||||
bool bookOptionsDialog::isBookPinned(int bookID) {
|
||||
QJsonObject pinnedBooksObject;
|
||||
if(QFile::exists(global::localLibrary::pinnedBooksDatabasePath)) {
|
||||
QString function = __func__; log(function + ": Reading pinned books database", className);
|
||||
QFile database(global::localLibrary::pinnedBooksDatabasePath);
|
||||
QByteArray data;
|
||||
if(database.open(QIODevice::ReadOnly)) {
|
||||
data = database.readAll();
|
||||
database.close();
|
||||
}
|
||||
else {
|
||||
QString function = __func__; log(function + ": Failed to open pinned books library database file for reading at '" + database.fileName() + "'", className);
|
||||
}
|
||||
pinnedBooksObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data))).object();
|
||||
}
|
||||
QString pinnedBookPath = getBookMetadata(bookID)["BookPath"].toString();
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
if(pinnedBooksObject["Book" + QString::number(i)].toObject().value("BookPath").toString() == pinnedBookPath) {
|
||||
bookPinned = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
bookPinned = false;
|
||||
}
|
||||
}
|
||||
return bookPinned;
|
||||
}
|
38
bookoptionsdialog.h
Normal file
38
bookoptionsdialog.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef BOOKOPTIONSDIALOG_H
|
||||
#define BOOKOPTIONSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace Ui {
|
||||
class bookOptionsDialog;
|
||||
}
|
||||
|
||||
class bookOptionsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString className = this->metaObject()->className();
|
||||
explicit bookOptionsDialog(QWidget *parent = nullptr);
|
||||
~bookOptionsDialog();
|
||||
QString bookPath;
|
||||
bool bookPinned;
|
||||
|
||||
private slots:
|
||||
void on_pinBtn_clicked();
|
||||
void on_deleteBtn_clicked();
|
||||
void on_infoBtn_clicked();
|
||||
void pinBook(int bookID);
|
||||
void unpinBook(int bookID);
|
||||
bool isBookPinned(int bookID);
|
||||
|
||||
signals:
|
||||
void openLocalBookInfoDialog();
|
||||
void showToast(QString messageToDisplay);
|
||||
|
||||
private:
|
||||
Ui::bookOptionsDialog *ui;
|
||||
};
|
||||
|
||||
#endif // BOOKOPTIONSDIALOG_H
|
111
bookoptionsdialog.ui
Normal file
111
bookoptionsdialog.ui
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>bookOptionsDialog</class>
|
||||
<widget class="QDialog" name="bookOptionsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>18</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>22</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>18</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>22</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0">
|
||||
<widget class="QPushButton" name="infoBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">padding: 10px</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>More info</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pinBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">padding: 10px</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="deleteBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">padding: 10px</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
3
eink.qrc
3
eink.qrc
|
@ -76,5 +76,8 @@
|
|||
<file>resources/tzlist</file>
|
||||
<file>resources/edit.png</file>
|
||||
<file>resources/save.png</file>
|
||||
<file>resources/book_inverted.png</file>
|
||||
<file>resources/arrow-left.png</file>
|
||||
<file>resources/arrow-right.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
83
functions.h
83
functions.h
|
@ -19,6 +19,7 @@
|
|||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonArray>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -52,12 +53,15 @@ namespace global {
|
|||
namespace mainwindow {
|
||||
namespace tabSwitcher {
|
||||
inline bool repaint;
|
||||
inline bool homePageWidgetCreated;
|
||||
inline bool appsWidgetCreated;
|
||||
inline bool appsWidgetSelected;
|
||||
inline bool settingsChooserWidgetCreated;
|
||||
inline bool settingsChooserWidgetSelected;
|
||||
inline bool libraryWidgetCreated;
|
||||
inline bool libraryWidgetSelected;
|
||||
inline bool localLibraryWidgetCreated;
|
||||
inline bool localLibraryWidgetSelected;
|
||||
}
|
||||
inline bool updateDialog;
|
||||
inline bool lowBatteryDialog;
|
||||
|
@ -122,6 +126,23 @@ namespace global {
|
|||
inline bool librarySearchDialog;
|
||||
inline bool libraryResults;
|
||||
}
|
||||
namespace bookInfoDialog {
|
||||
inline bool localInfoDialog;
|
||||
}
|
||||
namespace localLibrary {
|
||||
static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw";
|
||||
static inline QString databaseDirectoryPath = "/mnt/onboard/onboard/.database/";
|
||||
static inline QString databasePath = databaseDirectoryPath + "LocalLibrary.db";
|
||||
static inline QString recentBooksDatabasePath = databaseDirectoryPath + "RecentBooks.db";
|
||||
static inline QString pinnedBooksDatabasePath = databaseDirectoryPath + "PinnedBooks.db";
|
||||
inline bool headless;
|
||||
namespace bookOptionsDialog {
|
||||
inline int bookID;
|
||||
inline bool deleteOption = true;
|
||||
inline bool bookDeleted;
|
||||
inline bool bookPinAction;
|
||||
}
|
||||
}
|
||||
namespace localStorage {
|
||||
inline QStringList searchResultsPaths;
|
||||
}
|
||||
|
@ -135,6 +156,14 @@ namespace global {
|
|||
inline bool appInfoDialog;
|
||||
inline bool launchApp;
|
||||
}
|
||||
namespace homePageWidget {
|
||||
static inline int recentBooksNumber = 8;
|
||||
static inline int recentBooksNumberPerRow = 4;
|
||||
static inline int recentBooksRowNumber = global::homePageWidget::recentBooksNumber / global::homePageWidget::recentBooksNumberPerRow;
|
||||
static inline int pinnedBooksNumber = 4;
|
||||
static inline int pinnedBooksNumberPerRow = 4;
|
||||
static inline int pinnedBooksRowNumber = global::homePageWidget::pinnedBooksNumber / global::homePageWidget::pinnedBooksNumberPerRow;
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
inline bool isN705 = false;
|
||||
|
@ -163,7 +192,7 @@ namespace {
|
|||
int defaultPdfPageHeight;
|
||||
bool checked_box = false;
|
||||
QFile logFile("/external_root/var/log/inkbox-gui.log");
|
||||
void log(QString message, QString className, bool applicationStart = false) {
|
||||
void log(QString message, QString className = "undefined", bool applicationStart = false) {
|
||||
if(global::logger::status == true) {
|
||||
QString initialTime;
|
||||
if(applicationStart == true) {
|
||||
|
@ -282,6 +311,16 @@ namespace {
|
|||
return quoteNumber;
|
||||
return 0;
|
||||
}
|
||||
void writeFile(QString filename, QString content) {
|
||||
QFile file(filename);
|
||||
if(file.open(QIODevice::ReadWrite)) {
|
||||
QTextStream stream(&file);
|
||||
stream << content;
|
||||
}
|
||||
else {
|
||||
QString function = __func__; log(function + ": Failed to write string '" + content + "' to file '" + filename + "'", "functions");
|
||||
}
|
||||
}
|
||||
void string_writeconfig(std::string file, std::string config_option) {
|
||||
std::ofstream fhandler;
|
||||
fhandler.open(file);
|
||||
|
@ -568,7 +607,7 @@ namespace {
|
|||
global::systemInfoText = "<b>InkBox OS version ";
|
||||
string_checkconfig_ro("/external_root/opt/isa/version");
|
||||
global::systemInfoText.append(checkconfig_str_val);
|
||||
global::systemInfoText.append("</b>");
|
||||
global::systemInfoText.append("</b><br>Copyright <font face='Inter'>©</font> 2021-2022 Nicolas Mailloux and contributors");
|
||||
global::systemInfoText.append("<br><b>Git:</b> ");
|
||||
global::systemInfoText.append(GIT_VERSION);
|
||||
global::systemInfoText.append("<br><b>Device UID:</b> ");
|
||||
|
@ -943,6 +982,46 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
QJsonObject getBookMetadata(int bookID) {
|
||||
// Read library database from file
|
||||
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() + "'", "functions");
|
||||
}
|
||||
|
||||
// Parse JSON data
|
||||
QJsonObject jsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data))).object();
|
||||
QJsonArray jsonArrayList = jsonObject["database"].toArray();
|
||||
return jsonArrayList.at(bookID - 1).toObject();
|
||||
}
|
||||
float determineYIncrease() {
|
||||
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
|
||||
return 2;
|
||||
}
|
||||
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
|
||||
return 2.6;
|
||||
}
|
||||
else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") {
|
||||
return 3;
|
||||
}
|
||||
else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // FUNCTIONS_H
|
||||
|
|
|
@ -241,6 +241,10 @@ void generalDialog::on_cancelBtn_clicked()
|
|||
global::kobox::resetKoboxDialog = false;
|
||||
generalDialog::close();
|
||||
}
|
||||
else if(keypadDialog == true) {
|
||||
global::keyboard::keypadDialog = false;
|
||||
generalDialog::close();
|
||||
}
|
||||
else if(global::encfs::disableStorageEncryptionDialog == true) {
|
||||
emit cancelDisableStorageEncryption();
|
||||
global::encfs::disableStorageEncryptionDialog = false;
|
||||
|
@ -703,7 +707,7 @@ void generalDialog::syncGutenbergCatalog() {
|
|||
|
||||
string_writeconfig("/opt/ibxd", "gutenberg_sync\n");
|
||||
QTimer * syncCheckTimer = new QTimer(this);
|
||||
syncCheckTimer->setInterval(100);
|
||||
syncCheckTimer->setInterval(500);
|
||||
connect(syncCheckTimer, &QTimer::timeout, [&]() {
|
||||
if(QFile::exists("/inkbox/gutenbergSyncDone") == true) {
|
||||
if(checkconfig("/inkbox/gutenbergSyncDone") == true) {
|
||||
|
|
409
homepagewidget.cpp
Normal file
409
homepagewidget.cpp
Normal file
|
@ -0,0 +1,409 @@
|
|||
#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);
|
||||
|
||||
horizontalLayoutArray.resize(global::homePageWidget::recentBooksRowNumber);
|
||||
verticalLayoutArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
bookBtnArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
bookTitleArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
pinnedBooksHorizontalLayoutArray.resize(global::homePageWidget::pinnedBooksRowNumber);
|
||||
pinnedBooksVerticalLayoutArray.resize(global::homePageWidget::pinnedBooksNumber);
|
||||
pinnedBooksBtnArray.resize(global::homePageWidget::pinnedBooksNumber);
|
||||
pinnedBooksTitleArray.resize(global::homePageWidget::pinnedBooksNumber);
|
||||
|
||||
if(global::deviceID == "n705\n") {
|
||||
bookTitleTruncateThreshold = 20;
|
||||
}
|
||||
else if(global::deviceID == "n873\n") {
|
||||
bookTitleTruncateThreshold = 35;
|
||||
}
|
||||
else {
|
||||
bookTitleTruncateThreshold = 25;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
if(!QFile::exists(global::localLibrary::databasePath)) {
|
||||
global::toast::modalToast = true;
|
||||
global::toast::indefiniteToast = true;
|
||||
showToast("Generating database");
|
||||
QTimer::singleShot(100, this, SLOT(setupDisplayWithDatabase()));
|
||||
}
|
||||
else {
|
||||
setupDisplay(false);
|
||||
}
|
||||
}
|
||||
|
||||
homePageWidget::~homePageWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void homePageWidget::openBook(QString bookPath) {
|
||||
if(!bookPath.isEmpty()) {
|
||||
emit openBookSignal(bookPath, false);
|
||||
}
|
||||
else {
|
||||
showToast("Book not found");
|
||||
}
|
||||
}
|
||||
|
||||
void homePageWidget::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
||||
void homePageWidget::setupDisplay(bool databaseGenerated) {
|
||||
if(databaseGenerated == true) {
|
||||
toastWindow->close();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* Recent books */
|
||||
log("Reading recent books database", className);
|
||||
QFile recentBooksDatabase(global::localLibrary::recentBooksDatabasePath);
|
||||
QByteArray recentBooksData;
|
||||
if(recentBooksDatabase.open(QIODevice::ReadOnly)) {
|
||||
recentBooksData = recentBooksDatabase.readAll();
|
||||
recentBooksDatabase.close();
|
||||
}
|
||||
else {
|
||||
QString function = __func__; log(function + ": Failed to open recent books database file for reading at '" + recentBooksDatabase.fileName() + "'", className);
|
||||
}
|
||||
|
||||
QJsonObject databaseJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data))).object();
|
||||
QJsonArray databaseJsonArrayList = databaseJsonObject["database"].toArray();
|
||||
int databaseBooksNumber = databaseJsonArrayList.size();
|
||||
QJsonObject recentBooksJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(recentBooksData))).object();
|
||||
|
||||
log("Setting up home page", className);
|
||||
|
||||
if(!recentBooksJsonObject["Book1"].toObject().value("BookPath").toString().isEmpty()) {
|
||||
int in = 0;
|
||||
bool newRow = false;
|
||||
for(int i = 1; i <= (global::homePageWidget::recentBooksNumber + 1); i++) {
|
||||
if(in < global::homePageWidget::recentBooksRowNumber) {
|
||||
QString objectName = "Book" + QString::number(i);
|
||||
QJsonObject jsonObject = recentBooksJsonObject[objectName].toObject();
|
||||
QString bookPath = jsonObject.value("BookPath").toString();
|
||||
bookBtnArray[i] = new QClickableLabel(this);
|
||||
bookTitleArray[i] = new QToolTipLabel(this);
|
||||
|
||||
// Iterate until we find a book matching the recently opened book's "BookPath" key/value pair
|
||||
for(int in = 1; in <= databaseBooksNumber; in++) {
|
||||
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
|
||||
if(bookJsonObject["BookPath"].toString() == bookPath) {
|
||||
QByteArray data = qCompress(QJsonDocument(bookJsonObject).toJson()).toBase64();
|
||||
QString dataString = QString(data);
|
||||
bookBtnArray[i]->setObjectName(dataString);
|
||||
}
|
||||
}
|
||||
QJsonObject uncompressedJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(bookBtnArray[i]->objectName().toUtf8()))).object();
|
||||
|
||||
verticalLayoutArray[i] = new QVBoxLayout();
|
||||
|
||||
// Book icon button
|
||||
QObject::connect(bookBtnArray[i], &QClickableLabel::bookPath, this, &homePageWidget::openBook);
|
||||
QObject::connect(bookBtnArray[i], &QClickableLabel::longPressString, this, &homePageWidget::openBookOptionsDialog);
|
||||
bookBtnArray[i]->setAlignment(Qt::AlignCenter);
|
||||
bookBtnArray[i]->setFont(QFont("u001"));
|
||||
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
// Book title label
|
||||
bookTitleArray[i]->setWordWrap(true);
|
||||
bookTitleArray[i]->setAlignment(Qt::AlignCenter);
|
||||
bookTitleArray[i]->setFont(QFont("u001"));
|
||||
bookTitleArray[i]->setStyleSheet("font-size: 7pt");
|
||||
|
||||
QString bookTitle = uncompressedJsonObject["Title"].toString();
|
||||
bookTitleArray[i]->setObjectName(bookTitle);
|
||||
|
||||
int localBookTitleTruncateThreshold;
|
||||
if(!bookTitle.contains(" ")) {
|
||||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold - 10;
|
||||
}
|
||||
else {
|
||||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold;
|
||||
}
|
||||
if(bookTitle.length() > localBookTitleTruncateThreshold) {
|
||||
bookTitleArray[i]->setProperty("showToolTip", "true");
|
||||
bookTitle.truncate(localBookTitleTruncateThreshold);
|
||||
bookTitle.append("...");
|
||||
}
|
||||
bookTitleArray[i]->setText(bookTitle);
|
||||
|
||||
QString bookIcon = uncompressedJsonObject["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]);
|
||||
verticalLayoutArray[i]->addWidget(bookTitleArray[i]);
|
||||
}
|
||||
|
||||
if(newRow == true) {
|
||||
newRow = false;
|
||||
horizontalLayoutArray[in] = new QHBoxLayout();
|
||||
for(int n = ((i - 1) - (global::homePageWidget::recentBooksNumberPerRow - 1)); n < (((i - 1) - (global::homePageWidget::recentBooksNumberPerRow - 1)) + global::homePageWidget::recentBooksNumberPerRow); n++) {
|
||||
horizontalLayoutArray[in]->addLayout(verticalLayoutArray[n]);
|
||||
}
|
||||
ui->booksVerticalLayout->addLayout(horizontalLayoutArray[in]);
|
||||
}
|
||||
if(!(i % global::homePageWidget::recentBooksNumberPerRow)) {
|
||||
newRow = true;
|
||||
in++;
|
||||
}
|
||||
}
|
||||
|
||||
// Hiding books that don't exist/are not in the database
|
||||
// If you think this is not an efficient way to do it, try to teach the code above not to create the button if the book does not exist and arrange layouts so that it looks linear
|
||||
for(int i = 1; i <= global::homePageWidget::recentBooksNumber; i++) {
|
||||
QString bookPath = recentBooksJsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString();
|
||||
if(bookPath.isEmpty()) {
|
||||
bookBtnArray[i]->hide();
|
||||
bookTitleArray[i]->hide();
|
||||
bookBtnArray[i]->deleteLater();
|
||||
bookTitleArray[i]->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log("No books found in recent books database", className);
|
||||
QLabel * noRecentBooksLabel = new QLabel(this);
|
||||
noRecentBooksLabel->setFont(QFont("Chivo"));
|
||||
noRecentBooksLabel->setAlignment(Qt::AlignCenter);
|
||||
noRecentBooksLabel->setStyleSheet("padding: 30px");
|
||||
noRecentBooksLabel->setText("Recently read books will appear here");
|
||||
ui->booksVerticalLayout->addWidget(noRecentBooksLabel);
|
||||
}
|
||||
|
||||
/* Pinned books */
|
||||
if(QFile::exists(global::localLibrary::pinnedBooksDatabasePath)) {
|
||||
log("Reading pinned books database", className);
|
||||
QFile pinnedBooksDatabase(global::localLibrary::pinnedBooksDatabasePath);
|
||||
QByteArray pinnedBooksData;
|
||||
if(pinnedBooksDatabase.open(QIODevice::ReadOnly)) {
|
||||
pinnedBooksData = pinnedBooksDatabase.readAll();
|
||||
pinnedBooksDatabase.close();
|
||||
}
|
||||
else {
|
||||
QString function = __func__; log(function + ": Failed to open pinned books database file for reading at '" + pinnedBooksDatabase.fileName() + "'", className);
|
||||
}
|
||||
QJsonObject pinnedBooksJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(pinnedBooksData))).object();
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
if(!pinnedBooksJsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString().isEmpty()) {
|
||||
pinnedBooksDatabaseEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(pinnedBooksDatabaseEmpty == false) {
|
||||
QHBoxLayout * pinnedBooksHorizontalLayoutArray = new QHBoxLayout();
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
pinnedBooksBtnArray[i] = new QClickableLabel(this);
|
||||
pinnedBooksTitleArray[i] = new QToolTipLabel(this);
|
||||
pinnedBooksVerticalLayoutArray[i] = new QVBoxLayout();
|
||||
|
||||
// Book icon button
|
||||
QObject::connect(pinnedBooksBtnArray[i], &QClickableLabel::bookPath, this, &homePageWidget::openBook);
|
||||
QObject::connect(pinnedBooksBtnArray[i], &QClickableLabel::longPressString, this, &homePageWidget::openBookOptionsDialog);
|
||||
pinnedBooksBtnArray[i]->setAlignment(Qt::AlignCenter);
|
||||
pinnedBooksBtnArray[i]->setFont(QFont("u001"));
|
||||
pinnedBooksBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
// Book title label
|
||||
pinnedBooksTitleArray[i]->setWordWrap(true);
|
||||
pinnedBooksTitleArray[i]->setAlignment(Qt::AlignCenter);
|
||||
pinnedBooksTitleArray[i]->setFont(QFont("u001"));
|
||||
pinnedBooksTitleArray[i]->setStyleSheet("font-size: 7pt");
|
||||
|
||||
// Iterate until we find a book matching the pinned book's "BookPath" key/value pair
|
||||
for(int in = 1; in <= databaseBooksNumber; in++) {
|
||||
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
|
||||
QString bookPath = pinnedBooksJsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString();
|
||||
if(bookJsonObject["BookPath"].toString() == bookPath) {
|
||||
QByteArray data = qCompress(QJsonDocument(bookJsonObject).toJson()).toBase64();
|
||||
QString dataString = QString(data);
|
||||
pinnedBooksBtnArray[i]->setObjectName(dataString);
|
||||
}
|
||||
}
|
||||
QJsonObject uncompressedJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(pinnedBooksBtnArray[i]->objectName().toUtf8()))).object();
|
||||
|
||||
QString bookTitle = uncompressedJsonObject["Title"].toString();
|
||||
pinnedBooksTitleArray[i]->setObjectName(bookTitle);
|
||||
|
||||
int localBookTitleTruncateThreshold;
|
||||
if(!bookTitle.contains(" ")) {
|
||||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold - 10;
|
||||
}
|
||||
else {
|
||||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold;
|
||||
}
|
||||
if(bookTitle.length() > localBookTitleTruncateThreshold) {
|
||||
pinnedBooksTitleArray[i]->setProperty("showToolTip", "true");
|
||||
bookTitle.truncate(localBookTitleTruncateThreshold);
|
||||
bookTitle.append("...");
|
||||
}
|
||||
pinnedBooksTitleArray[i]->setText(bookTitle);
|
||||
|
||||
QString bookIcon = uncompressedJsonObject["CoverPath"].toString();
|
||||
if(QFile::exists(bookIcon)) {
|
||||
pinnedBooksBtnArray[i]->setPixmap(QPixmap(bookIcon).scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
}
|
||||
else {
|
||||
pinnedBooksBtnArray[i]->setPixmap(QPixmap(":/resources/cover_unavailable").scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
}
|
||||
|
||||
pinnedBooksVerticalLayoutArray[i]->addWidget(pinnedBooksBtnArray[i]);
|
||||
pinnedBooksVerticalLayoutArray[i]->addWidget(pinnedBooksTitleArray[i]);
|
||||
pinnedBooksHorizontalLayoutArray->addLayout(pinnedBooksVerticalLayoutArray[i]);
|
||||
}
|
||||
ui->pinnedBooksVerticalLayout->addLayout(pinnedBooksHorizontalLayoutArray);
|
||||
|
||||
// Hiding books that don't exist/are not in the database
|
||||
for(int i = 1; i <= global::homePageWidget::pinnedBooksNumber; i++) {
|
||||
QString bookPath = pinnedBooksJsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString();
|
||||
if(bookPath.isEmpty()) {
|
||||
pinnedBooksBtnArray[i]->hide();
|
||||
pinnedBooksTitleArray[i]->hide();
|
||||
pinnedBooksBtnArray[i]->deleteLater();
|
||||
pinnedBooksTitleArray[i]->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pinnedBooksDatabaseEmpty == true) {
|
||||
log("No books found in pinned books database", className);
|
||||
QLabel * noPinnedBooksLabel = new QLabel(this);
|
||||
noPinnedBooksLabel->setFont(QFont("Chivo"));
|
||||
noPinnedBooksLabel->setAlignment(Qt::AlignCenter);
|
||||
noPinnedBooksLabel->setStyleSheet("padding: 30px");
|
||||
noPinnedBooksLabel->setText("Pinned books will appear here");
|
||||
ui->pinnedBooksVerticalLayout->addWidget(noPinnedBooksLabel);
|
||||
}
|
||||
QTimer::singleShot(500, this, SLOT(refreshScreenNative()));
|
||||
}
|
||||
|
||||
void homePageWidget::setupDisplaySlot() {
|
||||
setupDisplay(true);
|
||||
}
|
||||
|
||||
void homePageWidget::setupDisplayWithDatabase() {
|
||||
global::localLibrary::headless = true;
|
||||
localLibraryWidget * localLibraryWidgetWindow = new localLibraryWidget(this);
|
||||
localLibraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
localLibraryWidgetWindow->hide();
|
||||
QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::destroyed, this, &homePageWidget::setupDisplaySlot);
|
||||
}
|
||||
|
||||
void homePageWidget::showToast(QString messageToDisplay) {
|
||||
global::toast::message = messageToDisplay;
|
||||
toastWindow = new toast(this);
|
||||
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
toastWindow->show();
|
||||
}
|
||||
|
||||
void homePageWidget::openBookOptionsDialog(QString bookPath) {
|
||||
int bookID;
|
||||
|
||||
// Finding bookID from bookPath
|
||||
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();
|
||||
for(int in = 1; in <= databaseBooksNumber; in++) {
|
||||
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
|
||||
if(bookJsonObject["BookPath"].toString() == bookPath) {
|
||||
// Because 'bookID = bookJsonObject["BookID"].toInt();' always returns value 0 ;)
|
||||
QString bookIDStr = bookJsonObject["BookID"].toString();
|
||||
bookID = bookIDStr.toInt();
|
||||
}
|
||||
}
|
||||
|
||||
log("Opening book options dialog for book with path '" + bookPath + "', ID " + QString::number(bookID), className);
|
||||
global::localLibrary::bookOptionsDialog::bookID = bookID;
|
||||
global::localLibrary::bookOptionsDialog::deleteOption = false;
|
||||
bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this);
|
||||
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &homePageWidget::openLocalBookInfoDialog);
|
||||
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::showToast, this, &homePageWidget::showToast);
|
||||
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &homePageWidget::handlePossibleBookPin);
|
||||
bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
|
||||
bookOptionsDialogWindow->show();
|
||||
}
|
||||
|
||||
void homePageWidget::openLocalBookInfoDialog() {
|
||||
global::bookInfoDialog::localInfoDialog = true;
|
||||
bookInfoDialog * bookInfoDialogWindow = new bookInfoDialog(this);
|
||||
bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
bookInfoDialogWindow->show();
|
||||
}
|
||||
|
||||
void homePageWidget::handlePossibleBookPin() {
|
||||
if(global::localLibrary::bookOptionsDialog::bookPinAction == true) {
|
||||
QTimer::singleShot(3100, this, [&]() {
|
||||
emit relaunchHomePageWidget();
|
||||
});
|
||||
}
|
||||
}
|
66
homepagewidget.h
Normal file
66
homepagewidget.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef HOMEPAGEWIDGET_H
|
||||
#define HOMEPAGEWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include "qclickablelabel.h"
|
||||
#include "qtooltiplabel.h"
|
||||
#include "locallibrarywidget.h"
|
||||
#include "toast.h"
|
||||
#include "bookoptionsdialog.h"
|
||||
#include "bookinfodialog.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;
|
||||
int bookTitleTruncateThreshold;
|
||||
bool pinnedBooksDatabaseEmpty = true;
|
||||
|
||||
signals:
|
||||
void openBookSignal(QString bookPath, bool relativePath);
|
||||
void refreshScreen();
|
||||
void relaunchHomePageWidget();
|
||||
|
||||
private slots:
|
||||
void openBook(QString bookPath);
|
||||
void refreshScreenNative();
|
||||
void setupDisplay(bool databaseGenerated);
|
||||
void setupDisplaySlot();
|
||||
void setupDisplayWithDatabase();
|
||||
void showToast(QString messageToDisplay);
|
||||
void openBookOptionsDialog(QString bookPath);
|
||||
void openLocalBookInfoDialog();
|
||||
void handlePossibleBookPin();
|
||||
|
||||
private:
|
||||
Ui::homePageWidget *ui;
|
||||
localLibraryWidget * localLibraryWidgetWindow;
|
||||
toast * toastWindow;
|
||||
bookOptionsDialog * bookOptionsDialogWindow;
|
||||
bookInfoDialog * bookInfoDialogWindow;
|
||||
QVector<QToolTipLabel*> bookTitleArray;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QVBoxLayout*> verticalLayoutArray;
|
||||
QVector<QClickableLabel*> bookBtnArray;
|
||||
QVector<QToolTipLabel*> pinnedBooksTitleArray;
|
||||
QVector<QHBoxLayout*> pinnedBooksHorizontalLayoutArray;
|
||||
QVector<QVBoxLayout*> pinnedBooksVerticalLayoutArray;
|
||||
QVector<QClickableLabel*> pinnedBooksBtnArray;
|
||||
};
|
||||
|
||||
#endif // HOMEPAGEWIDGET_H
|
174
homepagewidget.ui
Normal file
174
homepagewidget.ui
Normal file
|
@ -0,0 +1,174 @@
|
|||
<?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="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="booksVerticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pinned books</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_3">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="pinnedBooksVerticalLayout"/>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
13
inkbox.pro
13
inkbox.pro
|
@ -27,18 +27,23 @@ SOURCES += \
|
|||
alert.cpp \
|
||||
apps.cpp \
|
||||
bookinfodialog.cpp \
|
||||
bookoptionsdialog.cpp \
|
||||
brightnessdialog.cpp \
|
||||
calendarapp.cpp \
|
||||
dictionarywidget.cpp \
|
||||
encryptionmanager.cpp \
|
||||
generaldialog.cpp \
|
||||
homepagewidget.cpp \
|
||||
hourglassanimationwidget.cpp \
|
||||
koboxappsdialog.cpp \
|
||||
koboxsettings.cpp \
|
||||
librarywidget.cpp \
|
||||
locallibrarywidget.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
otamanager.cpp \
|
||||
qclickablelabel.cpp \
|
||||
qtooltiplabel.cpp \
|
||||
quit.cpp \
|
||||
reader.cpp \
|
||||
savedwords.cpp \
|
||||
|
@ -57,18 +62,23 @@ HEADERS += \
|
|||
alert.h \
|
||||
apps.h \
|
||||
bookinfodialog.h \
|
||||
bookoptionsdialog.h \
|
||||
brightnessdialog.h \
|
||||
calendarapp.h \
|
||||
dictionarywidget.h \
|
||||
encryptionmanager.h \
|
||||
functions.h \
|
||||
generaldialog.h \
|
||||
homepagewidget.h \
|
||||
hourglassanimationwidget.h \
|
||||
koboxappsdialog.h \
|
||||
koboxsettings.h \
|
||||
librarywidget.h \
|
||||
locallibrarywidget.h \
|
||||
mainwindow.h \
|
||||
otamanager.h \
|
||||
qclickablelabel.h \
|
||||
qtooltiplabel.h \
|
||||
quit.h \
|
||||
reader.h \
|
||||
savedwords.h \
|
||||
|
@ -87,15 +97,18 @@ FORMS += \
|
|||
alert.ui \
|
||||
apps.ui \
|
||||
bookinfodialog.ui \
|
||||
bookoptionsdialog.ui \
|
||||
brightnessdialog.ui \
|
||||
calendarapp.ui \
|
||||
dictionarywidget.ui \
|
||||
encryptionmanager.ui \
|
||||
generaldialog.ui \
|
||||
homepagewidget.ui \
|
||||
hourglassanimationwidget.ui \
|
||||
koboxappsdialog.ui \
|
||||
koboxsettings.ui \
|
||||
librarywidget.ui \
|
||||
locallibrarywidget.ui \
|
||||
mainwindow.ui \
|
||||
otamanager.ui \
|
||||
quit.ui \
|
||||
|
|
|
@ -53,7 +53,7 @@ koboxAppsDialog::koboxAppsDialog(QWidget *parent) :
|
|||
this->move(x, y);
|
||||
|
||||
checkApps();
|
||||
QStringListModel* model = new QStringListModel(this);
|
||||
QStringListModel * model = new QStringListModel(this);
|
||||
QStringList list = apps.split("\n", QString::SkipEmptyParts);
|
||||
|
||||
// Apps that aren't extensions
|
||||
|
|
|
@ -254,7 +254,7 @@ void libraryWidget::syncCatalog() {
|
|||
|
||||
string_writeconfig("/opt/ibxd", "gutenberg_sync\n");
|
||||
QTimer * syncCheckTimer = new QTimer(this);
|
||||
syncCheckTimer->setInterval(100);
|
||||
syncCheckTimer->setInterval(500);
|
||||
connect(syncCheckTimer, &QTimer::timeout, [&]() {
|
||||
if(syncDone == false) {
|
||||
if(QFile::exists("/inkbox/gutenbergSyncDone") == true) {
|
||||
|
|
|
@ -411,19 +411,6 @@
|
|||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="recentlyAddedLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Recently added books on Gutenberg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
@ -437,19 +424,12 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="previousBtn">
|
||||
<property name="text">
|
||||
<string>Previous</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
|
@ -462,7 +442,27 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<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="4">
|
||||
<widget class="QLabel" name="pageLabel">
|
||||
<property name="text">
|
||||
<string>1 of 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<widget class="QPushButton" name="nextBtn">
|
||||
<property name="text">
|
||||
<string>Next</string>
|
||||
|
@ -470,14 +470,30 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="pageLabel">
|
||||
<widget class="QPushButton" name="previousBtn">
|
||||
<property name="text">
|
||||
<string>1 of 2</string>
|
||||
<string>Previous</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="recentlyAddedLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Inter</family>
|
||||
<pointsize>10</pointsize>
|
||||
<weight>75</weight>
|
||||
<italic>false</italic>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Project Gutenberg's latest books</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
|
399
locallibrarywidget.cpp
Normal file
399
locallibrarywidget.cpp
Normal file
|
@ -0,0 +1,399 @@
|
|||
#include "locallibrarywidget.h"
|
||||
#include "ui_locallibrarywidget.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QSpacerItem>
|
||||
#include <QScreen>
|
||||
|
||||
localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::localLibraryWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setFont(QFont("u001"));
|
||||
QObject::connect(ui->pageNumberLabel, &QClickableLabel::clicked, this, &localLibraryWidget::openGoToPageDialog);
|
||||
|
||||
ui->previousPageBtn->setProperty("type", "borderless");
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setProperty("type", "borderless");
|
||||
ui->previousPageBtn->setIcon(QIcon(":/resources/chevron-left.png"));
|
||||
ui->nextPageBtn->setIcon(QIcon(":/resources/chevron-right.png"));
|
||||
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);
|
||||
|
||||
if(global::deviceID == "n705\n") {
|
||||
buttonsNumber = 3;
|
||||
}
|
||||
else if(global::deviceID == "n873\n") {
|
||||
buttonsNumber = 5;
|
||||
}
|
||||
else {
|
||||
buttonsNumber = 4;
|
||||
}
|
||||
|
||||
if(global::deviceID == "n705\n") {
|
||||
bookTitleTruncateThreshold = 30;
|
||||
}
|
||||
else if(global::deviceID == "n873\n") {
|
||||
bookTitleTruncateThreshold = 45;
|
||||
}
|
||||
else {
|
||||
bookTitleTruncateThreshold = 35;
|
||||
}
|
||||
|
||||
bookIconArray.resize(buttonsNumber);
|
||||
bookBtnArray.resize(buttonsNumber);
|
||||
horizontalLayoutArray.resize(buttonsNumber);
|
||||
lineArray.resize(buttonsNumber);
|
||||
|
||||
// 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 = 9.5;
|
||||
stdIconHeightDivider = 9.5;
|
||||
stdIconWidth = sW / stdIconWidthDivider;
|
||||
stdIconHeight = sH / stdIconHeightDivider;
|
||||
}
|
||||
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
|
||||
stdIconWidthDivider = 8.5;
|
||||
stdIconHeightDivider = 8.5;
|
||||
stdIconWidth = sW / stdIconWidthDivider;
|
||||
stdIconWidth = sH / stdIconHeightDivider;
|
||||
}
|
||||
else if(global::deviceID == "n437\n") {
|
||||
stdIconWidthDivider = 8;
|
||||
stdIconHeightDivider = 8;
|
||||
stdIconWidth = sW / stdIconWidthDivider;
|
||||
stdIconHeight = sH / stdIconHeightDivider;
|
||||
}
|
||||
else if(global::deviceID == "n873\n") {
|
||||
stdIconWidthDivider = 9.7;
|
||||
stdIconHeightDivider = 9.7;
|
||||
stdIconWidth = sW / stdIconWidthDivider;
|
||||
stdIconHeight = sH / stdIconHeightDivider;
|
||||
}
|
||||
else {
|
||||
stdIconWidthDivider = 9.5;
|
||||
stdIconHeightDivider = 9.5;
|
||||
stdIconWidth = sW / stdIconWidthDivider;
|
||||
stdIconHeight = sH / stdIconHeightDivider;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= buttonsNumber; i++) {
|
||||
// Horizontal layout that will contain the book button and its icon
|
||||
horizontalLayoutArray[i] = new QHBoxLayout(this);
|
||||
|
||||
// Book icon label
|
||||
bookIconArray[i] = new QLabel(this);
|
||||
bookIconArray[i]->setStyleSheet("padding: 10px");
|
||||
|
||||
// Book button
|
||||
bookBtnArray[i] = new QClickableLabel(this);
|
||||
bookBtnArray[i]->setObjectName(QString::number(i));
|
||||
QObject::connect(bookBtnArray[i], &QClickableLabel::bookID, this, &localLibraryWidget::btnOpenBook);
|
||||
QObject::connect(bookBtnArray[i], &QClickableLabel::longPressInt, this, &localLibraryWidget::openBookOptionsDialog);
|
||||
bookBtnArray[i]->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
bookBtnArray[i]->setFont(QFont("u001"));
|
||||
|
||||
horizontalLayoutArray[i]->addWidget(bookIconArray[i]);
|
||||
horizontalLayoutArray[i]->addWidget(bookBtnArray[i]);
|
||||
ui->booksVerticalLayout->addLayout(horizontalLayoutArray[i]);
|
||||
|
||||
// Line
|
||||
if(i < buttonsNumber) {
|
||||
lineArray[i] = new QFrame(this);
|
||||
lineArray[i]->setFrameShape(QFrame::HLine);
|
||||
lineArray[i]->setFrameShadow(QFrame::Plain);
|
||||
lineArray[i]->setLineWidth(1);
|
||||
ui->booksVerticalLayout->addWidget(lineArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!QFile::exists(global::localLibrary::databasePath)) {
|
||||
global::toast::modalToast = true;
|
||||
global::toast::indefiniteToast = true;
|
||||
showToast("Generating database");
|
||||
}
|
||||
QTimer::singleShot(100, this, SLOT(setupDisplay()));
|
||||
}
|
||||
|
||||
localLibraryWidget::~localLibraryWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void localLibraryWidget::setupDatabase() {
|
||||
setDefaultWorkDir();
|
||||
if(!QFile::exists(global::localLibrary::databasePath)) {
|
||||
log("Generating database", className);
|
||||
QStringList booksList;
|
||||
QDir dir("/mnt/onboard/onboard");
|
||||
|
||||
QDirIterator dirIt(dir, QDirIterator::Subdirectories);
|
||||
while(dirIt.hasNext()) {
|
||||
dirIt.next();
|
||||
if(QFileInfo(dirIt.filePath()).isFile()) {
|
||||
QString suffix = QFileInfo(dirIt.filePath()).suffix();
|
||||
if(suffix == "epub" || suffix == "EPUB") {
|
||||
booksList << dirIt.filePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString prog("busybox-initrd");
|
||||
QStringList args;
|
||||
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();
|
||||
proc->start(prog, args);
|
||||
proc->waitForFinished(-1);
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(readFile(global::localLibrary::rawDatabasePath).toUtf8());
|
||||
QFile::remove(global::localLibrary::rawDatabasePath);
|
||||
proc->deleteLater();
|
||||
|
||||
// Write database in compressed form, encoded in Base64 format
|
||||
writeFile(global::localLibrary::databasePath, qCompress(jsonDocument.toJson()).toBase64());
|
||||
toastWindow->close();
|
||||
}
|
||||
|
||||
// Read library database from file
|
||||
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);
|
||||
}
|
||||
|
||||
// Uncompress data from Base64 encoding
|
||||
databaseJsonDocument = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(data)));
|
||||
// Parse JSON data
|
||||
databaseJsonObject = databaseJsonDocument.object();
|
||||
databaseJsonArrayList = databaseJsonObject["database"].toArray();
|
||||
// Determine maximum page number
|
||||
booksNumber = databaseJsonArrayList.size();
|
||||
pagesNumber = std::ceil((double)booksNumber / buttonsNumber);
|
||||
if(databaseJsonArrayList.isEmpty()) {
|
||||
log("Database is empty", className);
|
||||
noBooksInDatabase = true;
|
||||
}
|
||||
else {
|
||||
noBooksInDatabase = false;
|
||||
if(pagesNumber == 1) {
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(global::localLibrary::headless == true) {
|
||||
global::localLibrary::headless = false;
|
||||
localLibraryWidget::close();
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::setupBooksList(int pageNumber) {
|
||||
idList.clear();
|
||||
int in = 1;
|
||||
for(int i = (1 * pageNumber * buttonsNumber) - (buttonsNumber - 1); i <= (1 * pageNumber * buttonsNumber); i++) {
|
||||
// Read database info for each book and display the corresponding information on each button
|
||||
bookIconArray[in]->show();
|
||||
bookBtnArray[in]->show();
|
||||
if(buttonsNumber - in > 0) {
|
||||
lineArray[in]->show();
|
||||
}
|
||||
|
||||
QJsonObject jsonObject = databaseJsonArrayList.at(i - 1).toObject();
|
||||
QString bookTitle = jsonObject["Title"].toString();
|
||||
QString bookAuthor = jsonObject["Author"].toString();
|
||||
QString coverPath = jsonObject["CoverPath"].toString();
|
||||
QString bookID = jsonObject["BookID"].toString();
|
||||
|
||||
if(!coverPath.isEmpty()) {
|
||||
// Display book cover if found
|
||||
QPixmap pixmap(coverPath);
|
||||
bookIconArray[in]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
}
|
||||
else {
|
||||
QPixmap pixmap(":/resources/cover_unavailable.png");
|
||||
bookIconArray[in]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight));
|
||||
}
|
||||
|
||||
// Display book title
|
||||
idList.append(bookID.toInt());
|
||||
if(bookTitle.length() > bookTitleTruncateThreshold) {
|
||||
bookTitle.truncate(bookTitleTruncateThreshold);
|
||||
bookTitle.append("...");
|
||||
}
|
||||
if(!bookAuthor.isEmpty()) {
|
||||
// Book is likely an ePUB
|
||||
bookBtnArray[in]->setText("<font face='Inter'><b>" + bookTitle + "</b></font>" + "<br>" + bookAuthor);
|
||||
}
|
||||
else {
|
||||
// Book is likely a PDF or a picture
|
||||
bookBtnArray[in]->setText("<font face='Inter'><b>" + bookTitle + "</b></font>");
|
||||
}
|
||||
|
||||
if(!bookID.isEmpty()) {
|
||||
in++;
|
||||
}
|
||||
}
|
||||
if(in <= buttonsNumber) {
|
||||
for(int i = in; i <= buttonsNumber; i++) {
|
||||
bookIconArray[i]->hide();
|
||||
bookBtnArray[i]->hide();
|
||||
if(i - 1 < buttonsNumber) {
|
||||
lineArray[(i - 1)]->hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
ui->pageNumberLabel->setText(QString::number(pageNumber) + " <i>of</i> " + QString::number(pagesNumber));
|
||||
// NOTICE: Memory leak?
|
||||
// Do it twice, otherwise the layout doesn't show as intended
|
||||
for(int i = 0; i <= 1; i++) {
|
||||
ui->verticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
|
||||
}
|
||||
|
||||
// Set boundaries for 'Previous'/'Next' page turn buttons
|
||||
currentPageNumber = pageNumber;
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(true);
|
||||
if(currentPageNumber - 1 < 1) {
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setEnabled(true);
|
||||
}
|
||||
if(currentPageNumber + 1 > pagesNumber) {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
if(currentPageNumber - 1 < 1 and currentPageNumber + 1 > pagesNumber) {
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::on_previousPageBtn_clicked()
|
||||
{
|
||||
currentPageNumber--;
|
||||
setupBooksList(currentPageNumber);
|
||||
|
||||
pagesTurned = pagesTurned + 1;
|
||||
if(pagesTurned >= 3) {
|
||||
emit refreshScreen();
|
||||
pagesTurned = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void localLibraryWidget::on_nextPageBtn_clicked()
|
||||
{
|
||||
currentPageNumber++;
|
||||
setupBooksList(currentPageNumber);
|
||||
|
||||
pagesTurned = pagesTurned + 1;
|
||||
if(pagesTurned >= 3) {
|
||||
emit refreshScreen();
|
||||
pagesTurned = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::openBook(int bookID) {
|
||||
QJsonObject jsonObject = databaseJsonArrayList.at(bookID - 1).toObject();
|
||||
QString bookPath = jsonObject["BookPath"].toString();
|
||||
log("Opening book with ID " + QString::number(bookID) + ", path '" + bookPath + "'", className);
|
||||
emit openBookSignal(bookPath, false);
|
||||
}
|
||||
|
||||
void localLibraryWidget::btnOpenBook(int buttonNumber) {
|
||||
int id = idList.at(buttonNumber - 1);
|
||||
openBook(id);
|
||||
localLibraryWidget::close();
|
||||
}
|
||||
|
||||
void localLibraryWidget::openGoToPageDialog() {
|
||||
log("Showing 'Go to page' dialog", className);
|
||||
global::keyboard::keypadDialog = true;
|
||||
generalDialogWindow = new generalDialog();
|
||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QObject::connect(generalDialogWindow, &generalDialog::gotoPageSelected, this, &localLibraryWidget::goToPage);
|
||||
}
|
||||
|
||||
void localLibraryWidget::goToPage(int page) {
|
||||
if(page > pagesNumber or page <= 0) {
|
||||
log("Page number specified (" + QString::number(page) + ") is out of range", className);
|
||||
showToast("Request is beyond page range");
|
||||
}
|
||||
else {
|
||||
log("Going to page " + QString::number(page), className);
|
||||
setupBooksList(page);
|
||||
emit refreshScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
||||
void localLibraryWidget::setupDisplay() {
|
||||
setupDatabase();
|
||||
if(noBooksInDatabase == false) {
|
||||
// Prevent segmentation fault if a book was the last of its page
|
||||
if(currentPageNumber > pagesNumber) {
|
||||
setupBooksList(currentPageNumber - 1);
|
||||
}
|
||||
else {
|
||||
setupBooksList(currentPageNumber);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
ui->pageNumberLabel->setText("1 <i>of</i> 1");
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::showToast(QString messageToDisplay) {
|
||||
global::toast::message = messageToDisplay;
|
||||
toastWindow = new toast(this);
|
||||
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
toastWindow->show();
|
||||
}
|
||||
|
||||
void localLibraryWidget::openBookOptionsDialog(int pseudoBookID) {
|
||||
// Determine book ID from the book's button number
|
||||
int bookID = ((currentPageNumber * buttonsNumber) - (buttonsNumber - 1)) + (pseudoBookID - 1);
|
||||
|
||||
log("Opening book options dialog for book with pseudo-ID " + QString::number(pseudoBookID) + ", ID " + QString::number(bookID), className);
|
||||
global::localLibrary::bookOptionsDialog::bookID = bookID;
|
||||
bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this);
|
||||
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog);
|
||||
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::showToast, this, &localLibraryWidget::showToast);
|
||||
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion);
|
||||
bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
|
||||
bookOptionsDialogWindow->show();
|
||||
}
|
||||
|
||||
void localLibraryWidget::handlePossibleBookDeletion() {
|
||||
if(global::localLibrary::bookOptionsDialog::bookDeleted == true) {
|
||||
QTimer::singleShot(3100, this, [&]() {
|
||||
global::localLibrary::bookOptionsDialog::bookDeleted = false;
|
||||
global::toast::modalToast = true;
|
||||
global::toast::indefiniteToast = true;
|
||||
showToast("Generating database");
|
||||
QTimer::singleShot(100, this, SLOT(setupDisplay()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::openLocalBookInfoDialog() {
|
||||
global::bookInfoDialog::localInfoDialog = true;
|
||||
bookInfoDialog * bookInfoDialogWindow = new bookInfoDialog(this);
|
||||
bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
bookInfoDialogWindow->show();
|
||||
}
|
77
locallibrarywidget.h
Normal file
77
locallibrarywidget.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
#ifndef LOCALLIBRARYWIDGET_H
|
||||
#define LOCALLIBRARYWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "functions.h"
|
||||
#include "qclickablelabel.h"
|
||||
#include "generaldialog.h"
|
||||
#include "toast.h"
|
||||
#include "bookoptionsdialog.h"
|
||||
#include "bookinfodialog.h"
|
||||
|
||||
namespace Ui {
|
||||
class localLibraryWidget;
|
||||
}
|
||||
|
||||
class localLibraryWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString className = this->metaObject()->className();
|
||||
explicit localLibraryWidget(QWidget *parent = nullptr);
|
||||
~localLibraryWidget();
|
||||
int buttonsNumber;
|
||||
int sW;
|
||||
int sH;
|
||||
float stdIconWidthDivider;
|
||||
float stdIconHeightDivider;
|
||||
int stdIconWidth;
|
||||
int stdIconHeight;
|
||||
QJsonDocument databaseJsonDocument;
|
||||
QJsonObject databaseJsonObject;
|
||||
QJsonArray databaseJsonArrayList;
|
||||
int currentPageNumber = 1;
|
||||
int pagesNumber;
|
||||
int pagesTurned = 0;
|
||||
int booksNumber;
|
||||
int bookTitleTruncateThreshold;
|
||||
QVector<int> idList;
|
||||
bool noBooksInDatabase = true;
|
||||
|
||||
private slots:
|
||||
void setupDatabase();
|
||||
void setupBooksList(int pageNumber);
|
||||
void on_previousPageBtn_clicked();
|
||||
void on_nextPageBtn_clicked();
|
||||
void openBook(int id);
|
||||
void btnOpenBook(int buttonNumber);
|
||||
void refreshScreenNative();
|
||||
void openGoToPageDialog();
|
||||
void goToPage(int page);
|
||||
void setupDisplay();
|
||||
void showToast(QString messageToDisplay);
|
||||
void openBookOptionsDialog(int pseudoBookID);
|
||||
void handlePossibleBookDeletion();
|
||||
void openLocalBookInfoDialog();
|
||||
|
||||
private:
|
||||
Ui::localLibraryWidget * ui;
|
||||
generalDialog * generalDialogWindow;
|
||||
bookOptionsDialog * bookOptionsDialogWindow;
|
||||
toast * toastWindow;
|
||||
bookInfoDialog * bookInfoDialogWindow;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QLabel*> bookIconArray;
|
||||
QVector<QClickableLabel*> bookBtnArray;
|
||||
QVector<QFrame*> lineArray;
|
||||
|
||||
signals:
|
||||
void openBookSignal(QString bookFile, bool relativePath);
|
||||
void refreshScreen();
|
||||
};
|
||||
|
||||
#endif // LOCALLIBRARYWIDGET_H
|
217
locallibrarywidget.ui
Normal file
217
locallibrarywidget.ui
Normal file
|
@ -0,0 +1,217 @@
|
|||
<?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="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Inter</family>
|
||||
<pointsize>10</pointsize>
|
||||
<weight>75</weight>
|
||||
<italic>false</italic>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</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>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="6">
|
||||
<widget class="QPushButton" name="nextPageBtn">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QClickableLabel" name="pageNumberLabel" native="true">
|
||||
<property name="text" stdset="0">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Maximum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Maximum</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="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</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><b>Local library</b></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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="QVBoxLayout" name="booksVerticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<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_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="noBooksInLibraryLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Chivo</family>
|
||||
<pointsize>10</pointsize>
|
||||
<weight>50</weight>
|
||||
<italic>true</italic>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>There are no books in your eReader yet.
|
||||
Add some via USB or explore the Online Library.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QClickableLabel</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qclickablelabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
288
mainwindow.cpp
288
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();
|
||||
}
|
||||
setupHomePageWidget();
|
||||
}
|
||||
|
||||
// Check if it's the first boot since an update and confirm that it installed successfully
|
||||
|
@ -686,7 +507,23 @@ void MainWindow::on_appsBtn_clicked()
|
|||
|
||||
void MainWindow::on_pushButton_clicked()
|
||||
{
|
||||
openReaderFramework();
|
||||
resetFullWindowException = true;
|
||||
resetWindow(false);
|
||||
if(global::mainwindow::tabSwitcher::localLibraryWidgetSelected != true) {
|
||||
ui->pushButton->setStyleSheet("background: black; color: white");
|
||||
ui->pushButton->setIcon(QIcon(":/resources/book_inverted.png"));
|
||||
|
||||
// Create widget
|
||||
setupLocalLibraryWidget();
|
||||
global::mainwindow::tabSwitcher::localLibraryWidgetCreated = true;
|
||||
|
||||
// Switch tab
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
global::mainwindow::tabSwitcher::localLibraryWidgetSelected = true;
|
||||
|
||||
// Repaint
|
||||
this->repaint();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_searchBtn_clicked()
|
||||
|
@ -703,38 +540,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);
|
||||
|
@ -746,7 +551,13 @@ void MainWindow::on_brightnessBtn_clicked()
|
|||
void MainWindow::on_homeBtn_clicked()
|
||||
{
|
||||
log("Showing home screen", className);
|
||||
if(global::localLibrary::bookOptionsDialog::bookPinAction == true) {
|
||||
global::localLibrary::bookOptionsDialog::bookPinAction = false;
|
||||
global::mainwindow::tabSwitcher::repaint = false;
|
||||
}
|
||||
else {
|
||||
global::mainwindow::tabSwitcher::repaint = true;
|
||||
}
|
||||
resetFullWindowException = true;
|
||||
resetWindow(true);
|
||||
}
|
||||
|
@ -754,10 +565,14 @@ void MainWindow::on_homeBtn_clicked()
|
|||
void MainWindow::resetWindow(bool resetStackedWidget) {
|
||||
// Reset layout
|
||||
if(resetStackedWidget == true) {
|
||||
ui->homeStackedWidget->setCurrentIndex(2);
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
// Destroy widgets
|
||||
if(global::mainwindow::tabSwitcher::homePageWidgetCreated == true) {
|
||||
homePageWidgetWindow->deleteLater();
|
||||
}
|
||||
if(global::mainwindow::tabSwitcher::appsWidgetCreated == true) {
|
||||
appsWindow->deleteLater();
|
||||
}
|
||||
|
@ -767,19 +582,28 @@ void MainWindow::resetWindow(bool resetStackedWidget) {
|
|||
if(global::mainwindow::tabSwitcher::libraryWidgetCreated == true) {
|
||||
libraryWidgetWindow->deleteLater();
|
||||
}
|
||||
if(global::mainwindow::tabSwitcher::localLibraryWidgetCreated == true) {
|
||||
localLibraryWidgetWindow->deleteLater();
|
||||
}
|
||||
|
||||
global::mainwindow::tabSwitcher::homePageWidgetCreated = false;
|
||||
global::mainwindow::tabSwitcher::appsWidgetCreated = false;
|
||||
global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = false;
|
||||
global::mainwindow::tabSwitcher::appsWidgetSelected = false;
|
||||
global::mainwindow::tabSwitcher::settingsChooserWidgetSelected = false;
|
||||
global::mainwindow::tabSwitcher::libraryWidgetCreated = false;
|
||||
global::mainwindow::tabSwitcher::libraryWidgetSelected = false;
|
||||
global::mainwindow::tabSwitcher::localLibraryWidgetCreated = false;
|
||||
global::mainwindow::tabSwitcher::localLibraryWidgetSelected = false;
|
||||
|
||||
resetIcons();
|
||||
setBatteryIcon();
|
||||
if(global::mainwindow::tabSwitcher::repaint == true) {
|
||||
this->repaint();
|
||||
}
|
||||
if(resetStackedWidget == true) {
|
||||
setupHomePageWidget();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::resetIcons() {
|
||||
|
@ -790,6 +614,8 @@ void MainWindow::resetIcons() {
|
|||
ui->settingsBtn->setIcon(QIcon(":/resources/settings.png"));
|
||||
ui->libraryButton->setStyleSheet("background: white");
|
||||
ui->libraryButton->setIcon(QIcon(":/resources/online-library.png"));
|
||||
ui->pushButton->setStyleSheet("background: white");
|
||||
ui->pushButton->setIcon(QIcon(":/resources/book.png"));
|
||||
}
|
||||
|
||||
void MainWindow::setBatteryIcon() {
|
||||
|
@ -1138,7 +964,7 @@ void MainWindow::on_libraryButton_clicked()
|
|||
{
|
||||
log("Launching Online Library", className);
|
||||
if(testPing(true) == 0 or global::deviceID == "emu\n") {
|
||||
resetFullWindowException = false;
|
||||
resetFullWindowException = true;
|
||||
resetWindow(false);
|
||||
if(global::mainwindow::tabSwitcher::libraryWidgetSelected != true) {
|
||||
ui->libraryButton->setStyleSheet("background: black; color: white");
|
||||
|
@ -1173,18 +999,6 @@ void MainWindow::resetFullWindow() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::setRecentBooksLabelsTruncateThreshold() {
|
||||
if(global::deviceID == "n705\n" or global::deviceID == "n905\n" or global::deviceID == "kt\n") {
|
||||
truncateThreshold = 12;
|
||||
}
|
||||
else if(global::deviceID == "n613\n" or global::deviceID == "n873\n" or global::deviceID == "n236\n" or global::deviceID == "n437\n" or global::deviceID == "n306\n"){
|
||||
truncateThreshold = 20;
|
||||
}
|
||||
else {
|
||||
truncateThreshold = 12;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::checkForOtaUpdate() {
|
||||
if(global::network::isConnected == true) {
|
||||
string_checkconfig_ro("/external_root/opt/storage/update/last_sync");
|
||||
|
@ -1205,3 +1019,23 @@ void MainWindow::checkForOtaUpdate() {
|
|||
void MainWindow::resetWifiIconClickedWhileReconnecting() {
|
||||
wifiIconClickedWhileReconnecting = false;
|
||||
}
|
||||
|
||||
void MainWindow::setupLocalLibraryWidget() {
|
||||
localLibraryWidgetWindow = new localLibraryWidget(this);
|
||||
QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::openBookSignal, this, &MainWindow::openBookFile);
|
||||
QObject::connect(localLibraryWidgetWindow, &localLibraryWidget::refreshScreen, this, &MainWindow::refreshScreen);
|
||||
localLibraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->homeStackedWidget->insertWidget(1, localLibraryWidgetWindow);
|
||||
ui->homeStackedWidget->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
void MainWindow::setupHomePageWidget() {
|
||||
homePageWidgetWindow = new homePageWidget(this);
|
||||
QObject::connect(homePageWidgetWindow, &homePageWidget::openBookSignal, this, &MainWindow::openBookFile);
|
||||
QObject::connect(homePageWidgetWindow, &homePageWidget::refreshScreen, this, &MainWindow::refreshScreen);
|
||||
QObject::connect(homePageWidgetWindow, &homePageWidget::relaunchHomePageWidget, this, &MainWindow::on_homeBtn_clicked);
|
||||
homePageWidgetWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->homeStackedWidget->insertWidget(2, homePageWidgetWindow);
|
||||
ui->homeStackedWidget->setCurrentIndex(2);
|
||||
global::mainwindow::tabSwitcher::homePageWidgetCreated = true;
|
||||
}
|
||||
|
|
11
mainwindow.h
11
mainwindow.h
|
@ -18,6 +18,8 @@
|
|||
#include "toast.h"
|
||||
#include "otamanager.h"
|
||||
#include "librarywidget.h"
|
||||
#include "locallibrarywidget.h"
|
||||
#include "homepagewidget.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -70,10 +72,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();
|
||||
|
@ -97,8 +95,9 @@ private slots:
|
|||
void on_libraryButton_clicked();
|
||||
void resetWindow(bool resetStackedWidget);
|
||||
void resetFullWindow();
|
||||
void setRecentBooksLabelsTruncateThreshold();
|
||||
void resetWifiIconClickedWhileReconnecting();
|
||||
void setupLocalLibraryWidget();
|
||||
void setupHomePageWidget();
|
||||
|
||||
private:
|
||||
Ui::MainWindow * ui;
|
||||
|
@ -117,6 +116,8 @@ private:
|
|||
toast * toastWindow;
|
||||
otaManager * otaManagerWindow;
|
||||
libraryWidget * libraryWidgetWindow;
|
||||
localLibraryWidget * localLibraryWidgetWindow;
|
||||
homePageWidget * homePageWidgetWindow;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
151
mainwindow.ui
151
mainwindow.ui
|
@ -191,21 +191,41 @@
|
|||
</property>
|
||||
<widget class="QWidget" name="page">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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_3">
|
||||
<item row="0" column="0">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<item row="5" column="0">
|
||||
<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>
|
||||
<widget class="QWidget" name="page_5">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<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">
|
||||
|
@ -225,7 +245,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<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>
|
||||
|
@ -320,75 +353,7 @@
|
|||
</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>
|
||||
|
@ -405,6 +370,29 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_6">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_7"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
|
@ -460,6 +448,9 @@
|
|||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
|
|
@ -20,11 +20,11 @@ otaManager::otaManager(QWidget *parent) :
|
|||
connect(otaCheckTimer, &QTimer::timeout, [&]() {
|
||||
if(QFile::exists("/run/can_ota_update") == true) {
|
||||
if(checkconfig("/run/can_ota_update") == true) {
|
||||
log("OTA update is available!", className);
|
||||
log("OTA update is available", className);
|
||||
emit canOtaUpdate(true);
|
||||
}
|
||||
else {
|
||||
log("No OTA update available.", className);
|
||||
log("No OTA update available", className);
|
||||
emit canOtaUpdate(false);
|
||||
}
|
||||
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
|
||||
|
@ -44,12 +44,12 @@ otaManager::otaManager(QWidget *parent) :
|
|||
connect(otaDownloadTimer, &QTimer::timeout, [&]() {
|
||||
if(QFile::exists("/run/can_install_ota_update") == true) {
|
||||
if(checkconfig("/run/can_install_ota_update") == true) {
|
||||
log("Download succeeded.", className);
|
||||
log("Download succeeded", className);
|
||||
emit downloadedOtaUpdate(true);
|
||||
global::otaUpdate::downloadOta = false;
|
||||
}
|
||||
else {
|
||||
log("Download failed.", className);
|
||||
log("Download failed", className);
|
||||
emit downloadedOtaUpdate(false);
|
||||
global::otaUpdate::downloadOta = false;
|
||||
}
|
||||
|
|
42
qclickablelabel.cpp
Normal file
42
qclickablelabel.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "qclickablelabel.h"
|
||||
|
||||
QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(parent) {}
|
||||
|
||||
QClickableLabel::~QClickableLabel() {}
|
||||
|
||||
void QClickableLabel::mousePressEvent(QMouseEvent * event) {
|
||||
timeAtClick = QDateTime::currentMSecsSinceEpoch();
|
||||
emit clicked();
|
||||
if(objectName() == "pageNumberLabel") {
|
||||
QClickableLabel::setStyleSheet("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) {
|
||||
if(QDateTime::currentMSecsSinceEpoch() >= timeAtClick + 500) {
|
||||
if(objectName().toInt()) {
|
||||
emit longPressInt(objectName().toInt());
|
||||
}
|
||||
else {
|
||||
emit longPressString(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString());
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit unclicked();
|
||||
emit bookID(objectName().toInt());
|
||||
emit bookPath(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString());
|
||||
}
|
||||
if(objectName() == "pageNumberLabel") {
|
||||
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
||||
}
|
||||
else {
|
||||
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
}
|
||||
}
|
29
qclickablelabel.h
Normal file
29
qclickablelabel.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef QCLICKABLELABEL_H
|
||||
#define QCLICKABLELABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
class QClickableLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~QClickableLabel();
|
||||
long long timeAtClick;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
void unclicked();
|
||||
void bookID(int id);
|
||||
void bookPath(QString path);
|
||||
void longPressInt(int id);
|
||||
void longPressString(QString bookPath);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent * event);
|
||||
void mouseReleaseEvent(QMouseEvent * event);
|
||||
|
||||
};
|
||||
|
||||
#endif // CLICKABLELABEL_H
|
21
qtooltiplabel.cpp
Normal file
21
qtooltiplabel.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <QToolTip>
|
||||
#include <QVariant>
|
||||
|
||||
#include "qtooltiplabel.h"
|
||||
|
||||
QToolTipLabel::QToolTipLabel(QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(parent) {
|
||||
this->setStyleSheet("QToolTip { font-size: 40pt }");
|
||||
}
|
||||
|
||||
QToolTipLabel::~QToolTipLabel() {}
|
||||
|
||||
void QToolTipLabel::mousePressEvent(QMouseEvent * event) {
|
||||
if(QToolTipLabel::property("showToolTip").toString() == "true") {
|
||||
QToolTip::showText(mapToGlobal(QPoint(0, 0)), "<font face='u001' size=-2>" + objectName() + "</font>");
|
||||
}
|
||||
}
|
||||
|
||||
void QToolTipLabel::mouseReleaseEvent(QMouseEvent * event) {
|
||||
|
||||
}
|
20
qtooltiplabel.h
Normal file
20
qtooltiplabel.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef QTOOLTIPLABEL_H
|
||||
#define QTOOLTIPLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
class QToolTipLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QToolTipLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~QToolTipLabel();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent * event);
|
||||
void mouseReleaseEvent(QMouseEvent * event);
|
||||
|
||||
};
|
||||
|
||||
#endif // CLICKABLELABEL_H
|
106
reader.cpp
106
reader.cpp
|
@ -15,8 +15,8 @@
|
|||
#include <QFontDatabase>
|
||||
#include <QDirIterator>
|
||||
#include <QTextCursor>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsScene>
|
||||
#include <QJsonDocument>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -104,6 +104,12 @@ reader::reader(QWidget *parent) :
|
|||
ui->decreaseScaleBtn->setIcon(QIcon(":/resources/zoom-out.png"));
|
||||
ui->quitBtn->setText("");
|
||||
ui->quitBtn->setIcon(QIcon(":/resources/power.png"));
|
||||
ui->previousBtn->setText("");
|
||||
ui->previousBtn->setIcon(QIcon(":/resources/arrow-left.png"));
|
||||
ui->optionsBtn->setText("");
|
||||
ui->optionsBtn->setIcon(QIcon(":/resources/settings.png"));
|
||||
ui->nextBtn->setText("");
|
||||
ui->nextBtn->setIcon(QIcon(":/resources/arrow-right.png"));
|
||||
|
||||
// On the Mini with QT_FONT_DPI set to 187 (default for this device), quitBtn makes the UI go beyond the limits of the screen when the menu bar is shown
|
||||
if(global::deviceID == "n705\n") {
|
||||
|
@ -142,24 +148,6 @@ reader::reader(QWidget *parent) :
|
|||
book_file = 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 {
|
||||
if(checkconfig("/opt/inkbox_genuine") == true) {
|
||||
|
@ -310,6 +298,11 @@ reader::reader(QWidget *parent) :
|
|||
ui->previousBtn->setStyleSheet("padding: 13.5px");
|
||||
ui->optionsBtn->setStyleSheet("padding: 13.5px");
|
||||
}
|
||||
else if(global::deviceID == "n437\n") {
|
||||
ui->nextBtn->setStyleSheet("padding: 12.5px");
|
||||
ui->previousBtn->setStyleSheet("padding: 12.5px");
|
||||
ui->optionsBtn->setStyleSheet("padding: 12.5px");
|
||||
}
|
||||
ui->sizeValueLabel->setStyleSheet("font-size: 9pt; font-weight: bold");
|
||||
ui->homeBtn->setStyleSheet("font-size: 9pt; padding: 5px");
|
||||
ui->aboutBtn->setStyleSheet("font-size: 9pt; padding: 5px");
|
||||
|
@ -640,40 +633,51 @@ reader::reader(QWidget *parent) :
|
|||
// Way to tell shell scripts that we're in the Reader framework
|
||||
string_writeconfig("/tmp/inkboxReading", "true");
|
||||
|
||||
// Saving the book opened in the favorites list
|
||||
string_checkconfig(".config/08-recent_books/1");
|
||||
book_1 = checkconfig_str_val;
|
||||
string str_book_1 = book_1.toStdString();
|
||||
string_checkconfig(".config/08-recent_books/2");
|
||||
book_2 = checkconfig_str_val;
|
||||
string str_book_2 = book_2.toStdString();
|
||||
string_checkconfig(".config/08-recent_books/3");
|
||||
book_3 = checkconfig_str_val;
|
||||
string str_book_3 = book_3.toStdString();
|
||||
string_checkconfig(".config/08-recent_books/4");
|
||||
book_4 = checkconfig_str_val;
|
||||
std::string str_book_4 = book_4.toStdString();
|
||||
|
||||
// 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();
|
||||
// Maintain a 'Recent books' list
|
||||
QJsonObject recentBooksObject;
|
||||
if(QFile::exists(global::localLibrary::recentBooksDatabasePath)) {
|
||||
log("Reading recent books database", className);
|
||||
QFile recentBooksDatabase(global::localLibrary::recentBooksDatabasePath);
|
||||
QByteArray recentBooksData;
|
||||
if(recentBooksDatabase.open(QIODevice::ReadOnly)) {
|
||||
recentBooksData = recentBooksDatabase.readAll();
|
||||
recentBooksDatabase.close();
|
||||
}
|
||||
else {
|
||||
book_file_str = book_file.toStdString();
|
||||
string_writeconfig("/tmp/inkboxBookPath", book_file_str);
|
||||
QString function = __func__; log(function + ": Failed to open recent books database file for reading at '" + recentBooksDatabase.fileName() + "'", className);
|
||||
}
|
||||
|
||||
if(book_1 == book_file) {
|
||||
;
|
||||
QJsonObject mainJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(recentBooksData))).object();
|
||||
for(int i = 1; i <= global::homePageWidget::recentBooksNumber; i++) {
|
||||
QString objectName = "Book" + QString::number(i);
|
||||
QJsonObject jsonObject = mainJsonObject[objectName].toObject();
|
||||
if(i == 1) {
|
||||
if(jsonObject.value("BookPath").toString() != book_file) {
|
||||
// Circular buffer
|
||||
for(int i = global::homePageWidget::recentBooksNumber; i >= 2; i--) {
|
||||
mainJsonObject["Book" + QString::number(i)] = mainJsonObject["Book" + QString::number(i - 1)];
|
||||
}
|
||||
jsonObject.insert("BookPath", QJsonValue(book_file));
|
||||
mainJsonObject[objectName] = jsonObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
recentBooksObject = mainJsonObject;
|
||||
}
|
||||
else {
|
||||
// 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);
|
||||
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);
|
||||
QJsonObject mainJsonObject;
|
||||
QJsonObject firstJsonObject;
|
||||
firstJsonObject.insert("BookPath", QJsonValue(book_file));
|
||||
mainJsonObject["Book1"] = firstJsonObject;
|
||||
|
||||
for(int i = 2; i <= global::homePageWidget::recentBooksNumber; i++) {
|
||||
QJsonObject jsonObject;
|
||||
jsonObject.insert("BookPath", QJsonValue(""));
|
||||
mainJsonObject["Book" + QString::number(i)] = jsonObject;
|
||||
}
|
||||
recentBooksObject = mainJsonObject;
|
||||
}
|
||||
QFile::remove(global::localLibrary::recentBooksDatabasePath);
|
||||
writeFile(global::localLibrary::recentBooksDatabasePath, qCompress(QJsonDocument(recentBooksObject).toJson()).toBase64());
|
||||
|
||||
// USB mass storage prompt
|
||||
if(global::reader::startUsbmsPrompt == true) {
|
||||
|
@ -1158,9 +1162,13 @@ void reader::on_optionsBtn_clicked()
|
|||
if(global::deviceID == "n873\n") {
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black; padding: 13.5px");
|
||||
}
|
||||
else if(global::deviceID == "n437\n") {
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black; padding: 12.5px");
|
||||
}
|
||||
else {
|
||||
ui->optionsBtn->setStyleSheet("background: white; color: black");
|
||||
}
|
||||
ui->optionsBtn->setIcon(QIcon(":/resources/settings.png"));
|
||||
// The Glo HD (N437) has a newer platform plugin that doesn't need this
|
||||
if(global::deviceID != "n437\n") {
|
||||
QTimer::singleShot(500, this, SLOT(repaint()));
|
||||
|
@ -1172,9 +1180,13 @@ void reader::on_optionsBtn_clicked()
|
|||
if(global::deviceID == "n873\n") {
|
||||
ui->optionsBtn->setStyleSheet("background: black; color: white; padding: 13.5px");
|
||||
}
|
||||
else if(global::deviceID == "n437\n") {
|
||||
ui->optionsBtn->setStyleSheet("background: black; color: white; padding: 12.5px");
|
||||
}
|
||||
else {
|
||||
ui->optionsBtn->setStyleSheet("background: black; color: white");
|
||||
}
|
||||
ui->optionsBtn->setIcon(QIcon(":/resources/settings-inverted.png"));
|
||||
this->repaint();
|
||||
menubar_shown = true;
|
||||
}
|
||||
|
|
4
reader.h
4
reader.h
|
@ -75,10 +75,6 @@ public:
|
|||
bool wordwidgetLock;
|
||||
bool isNightModeActive;
|
||||
bool goToSavedPageDone;
|
||||
QString book_1;
|
||||
QString book_2;
|
||||
QString book_3;
|
||||
QString book_4;
|
||||
QString ittext;
|
||||
QString book_file;
|
||||
bool batt_status;
|
||||
|
|
BIN
resources/arrow-left.png
Normal file
BIN
resources/arrow-left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
resources/arrow-right.png
Normal file
BIN
resources/arrow-right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
resources/book_inverted.png
Normal file
BIN
resources/book_inverted.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
|
@ -822,9 +822,7 @@ void settings::on_showSystemInfoBtn_clicked()
|
|||
// Show a system info dialog
|
||||
log("Showing system info dialog", className);
|
||||
generalDialogWindow = new generalDialog();
|
||||
if(global::deviceID == "n306\n") {
|
||||
generalDialogWindow->yIncrease = 2.6;
|
||||
}
|
||||
generalDialogWindow->yIncrease = determineYIncrease();
|
||||
generalDialogWindow->increaseSize();
|
||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
}
|
||||
|
@ -1061,6 +1059,7 @@ void settings::on_generateSystemReportBtn_clicked()
|
|||
while(true) {
|
||||
if(QFile::exists("/inkbox/systemReportDone")) {
|
||||
if(checkconfig("/inkbox/systemReportDone") == true) {
|
||||
QFile::remove(global::localLibrary::databasePath);
|
||||
emit showToast("System report generated successfully");
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -216,6 +216,8 @@ void usbms_splash::restartServices() {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Re-generate local library on next launch
|
||||
QFile::remove(global::localLibrary::databasePath);
|
||||
|
||||
quit_restart();
|
||||
}
|
||||
|
|
|
@ -156,8 +156,9 @@ void userapps::on_launchBtn_clicked()
|
|||
if(manageRequiredFeatures() == true) {
|
||||
if(global::userApps::launchApp == true) {
|
||||
global::userApps::launchApp = false;
|
||||
QString message = "Launching user application at: ";
|
||||
QString message = "Launching user application at: '";
|
||||
message.append("[" + appDir.path() + "]" + execPath.fileName());
|
||||
message.append("'");
|
||||
log(message, className);
|
||||
// Tell the OS that we're not running anymore
|
||||
string_writeconfig("/tmp/inkbox_running", "false");
|
||||
|
|
Loading…
Reference in a new issue