localLibraryWidget: Implement book options dialog (WIP)

This dialog will open if user keeps touch input active on a button from `bookBtnArray` for >= 500 ms.
'Pin' and 'More info' operations are currently not implemented.
This commit is contained in:
Nicolas Mailloux 2022-07-06 14:24:23 -04:00
parent 35fe0ae0e3
commit 80bdeb32ed
12 changed files with 393 additions and 119 deletions

View file

@ -42,125 +42,149 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <widget class="QStackedWidget" name="stackedWidget">
<property name="horizontalSpacing"> <property name="currentIndex">
<number>18</number> <number>0</number>
</property> </property>
<item row="0" column="1"> <widget class="QWidget" name="page">
<widget class="QLabel" name="bookCoverLabel"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="text"> <property name="leftMargin">
<string>Cover</string> <number>0</number>
</property> </property>
<property name="alignment"> <property name="topMargin">
<set>Qt::AlignCenter</set> <number>0</number>
</property> </property>
</widget> <property name="rightMargin">
</item> <number>0</number>
<item row="0" column="3">
<layout class="QGridLayout" name="gridLayout_2">
<property name="verticalSpacing">
<number>18</number>
</property> </property>
<item row="1" column="0"> <property name="bottomMargin">
<widget class="QLabel" name="bookTitleLabel"> <number>0</number>
<property name="font"> </property>
<font> <item>
<weight>75</weight> <layout class="QGridLayout" name="gridLayout">
<bold>true</bold> <property name="horizontalSpacing">
</font> <number>18</number>
</property> </property>
<property name="text"> <item row="0" column="1">
<string>Book title</string> <widget class="QLabel" name="bookCoverLabel">
</property> <property name="text">
<property name="alignment"> <string>Cover</string>
<set>Qt::AlignCenter</set> </property>
</property> <property name="alignment">
<property name="wordWrap"> <set>Qt::AlignCenter</set>
<bool>true</bool> </property>
</property> </widget>
</widget> </item>
</item> <item row="0" column="3">
<item row="2" column="0"> <layout class="QGridLayout" name="gridLayout_2">
<widget class="QPushButton" name="getBtn"> <property name="verticalSpacing">
<property name="font"> <number>18</number>
<font> </property>
<weight>75</weight> <item row="1" column="0">
<bold>true</bold> <widget class="QLabel" name="bookTitleLabel">
</font> <property name="font">
</property> <font>
<property name="text"> <weight>75</weight>
<string>GET</string> <bold>true</bold>
</property> </font>
</widget> </property>
</item> <property name="text">
<item row="3" column="0"> <string>Book title</string>
<spacer name="verticalSpacer"> </property>
<property name="orientation"> <property name="alignment">
<enum>Qt::Vertical</enum> <set>Qt::AlignCenter</set>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="wordWrap">
<size> <bool>true</bool>
<width>20</width> </property>
<height>40</height> </widget>
</size> </item>
</property> <item row="2" column="0">
</spacer> <widget class="QPushButton" name="getBtn">
</item> <property name="font">
<item row="0" column="0"> <font>
<spacer name="verticalSpacer_2"> <weight>75</weight>
<property name="orientation"> <bold>true</bold>
<enum>Qt::Vertical</enum> </font>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="text">
<size> <string>GET</string>
<width>20</width> </property>
<height>40</height> </widget>
</size> </item>
</property> <item row="3" column="0">
</spacer> <spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<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="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </widget>
<item row="0" column="4"> <widget class="QWidget" name="page_2"/>
<spacer name="horizontalSpacer_3"> </widget>
<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="2">
<spacer name="horizontalSpacer">
<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="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>

43
bookoptionsdialog.cpp Normal file
View file

@ -0,0 +1,43 @@
#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");
ui->deleteBtn->setProperty("type", "borderless");
ui->infoBtn->setProperty("type", "borderless");
bookPath = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID)["BookPath"].toString();
}
bookOptionsDialog::~bookOptionsDialog()
{
delete ui;
}
void bookOptionsDialog::on_pinBtn_clicked()
{
// TODO
}
void bookOptionsDialog::on_deleteBtn_clicked()
{
log("Deleting book '" + bookPath + "'", className);
QFile::remove(bookPath);
global::localLibrary::bookOptionsDialog::bookDeleted = true;
QFile::remove(global::localLibrary::databasePath);
ui->deleteBtn->setEnabled(false);
ui->deleteBtn->setStyleSheet("padding: 10px; color: lightGrey");
}
void bookOptionsDialog::on_infoBtn_clicked()
{
// TODO
}

30
bookoptionsdialog.h Normal file
View file

@ -0,0 +1,30 @@
#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;
private slots:
void on_pinBtn_clicked();
void on_deleteBtn_clicked();
void on_infoBtn_clicked();
private:
Ui::bookOptionsDialog *ui;
};
#endif // BOOKOPTIONSDIALOG_H

111
bookoptionsdialog.ui Normal file
View 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>

View file

@ -128,9 +128,15 @@ namespace global {
} }
namespace localLibrary { namespace localLibrary {
static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw"; static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw";
static inline QString databasePath = "/mnt/onboard/onboard/.inkbox/LocalLibrary.db"; static inline QString databaseDirectoryPath = "/mnt/onboard/onboard/.database/";
static inline QString recentBooksDatabasePath = "/mnt/onboard/onboard/.inkbox/RecentBooks.db"; static inline QString databasePath = databaseDirectoryPath + "LocalLibrary.db";
static inline QString recentBooksDatabasePath = databaseDirectoryPath + "RecentBooks.db";
static inline QString pinnedBooksDatabasePath = databaseDirectoryPath + "PinnedBooks.db";
inline bool headless; inline bool headless;
namespace bookOptionsDialog {
inline int bookID;
inline bool bookDeleted;
}
} }
namespace localStorage { namespace localStorage {
inline QStringList searchResultsPaths; inline QStringList searchResultsPaths;
@ -977,6 +983,24 @@ namespace {
} }
} }
} }
QJsonObject getBookMetadata(int bookID) {
// Read library database from file
log("Reading database", "functions");
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();
}
} }
#endif // FUNCTIONS_H #endif // FUNCTIONS_H

View file

@ -78,7 +78,12 @@ homePageWidget::~homePageWidget()
} }
void homePageWidget::openBook(QString bookPath) { void homePageWidget::openBook(QString bookPath) {
emit openBookSignal(bookPath, false); if(!bookPath.isEmpty()) {
emit openBookSignal(bookPath, false);
}
else {
showToast("Book not found");
}
} }
void homePageWidget::refreshScreenNative() { void homePageWidget::refreshScreenNative() {

View file

@ -27,6 +27,7 @@ SOURCES += \
alert.cpp \ alert.cpp \
apps.cpp \ apps.cpp \
bookinfodialog.cpp \ bookinfodialog.cpp \
bookoptionsdialog.cpp \
brightnessdialog.cpp \ brightnessdialog.cpp \
calendarapp.cpp \ calendarapp.cpp \
dictionarywidget.cpp \ dictionarywidget.cpp \
@ -61,6 +62,7 @@ HEADERS += \
alert.h \ alert.h \
apps.h \ apps.h \
bookinfodialog.h \ bookinfodialog.h \
bookoptionsdialog.h \
brightnessdialog.h \ brightnessdialog.h \
calendarapp.h \ calendarapp.h \
dictionarywidget.h \ dictionarywidget.h \
@ -95,6 +97,7 @@ FORMS += \
alert.ui \ alert.ui \
apps.ui \ apps.ui \
bookinfodialog.ui \ bookinfodialog.ui \
bookoptionsdialog.ui \
brightnessdialog.ui \ brightnessdialog.ui \
calendarapp.ui \ calendarapp.ui \
dictionarywidget.ui \ dictionarywidget.ui \

View file

@ -93,7 +93,8 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
// Book button // Book button
bookBtnArray[i] = new QClickableLabel(this); bookBtnArray[i] = new QClickableLabel(this);
bookBtnArray[i]->setObjectName(QString::number(i)); bookBtnArray[i]->setObjectName(QString::number(i));
connect(bookBtnArray[i], SIGNAL(bookID(int)), SLOT(btnOpenBook(int))); QObject::connect(bookBtnArray[i], &QClickableLabel::bookID, this, &localLibraryWidget::btnOpenBook);
QObject::connect(bookBtnArray[i], &QClickableLabel::longPress, this, &localLibraryWidget::openBookOptionsDialog);
bookBtnArray[i]->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); bookBtnArray[i]->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px"); bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
bookBtnArray[i]->setFont(QFont("u001")); bookBtnArray[i]->setFont(QFont("u001"));
@ -356,3 +357,23 @@ void localLibraryWidget::showToast(QString messageToDisplay) {
toastWindow->setAttribute(Qt::WA_DeleteOnClose); toastWindow->setAttribute(Qt::WA_DeleteOnClose);
toastWindow->show(); toastWindow->show();
} }
void localLibraryWidget::openBookOptionsDialog(int bookID) {
log("Opening book options dialog for book with ID " + QString::number(bookID), className);
global::localLibrary::bookOptionsDialog::bookID = bookID;
bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this);
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) {
global::localLibrary::bookOptionsDialog::bookDeleted = false;
global::toast::modalToast = true;
global::toast::indefiniteToast = true;
showToast("Generating database");
QTimer::singleShot(100, this, SLOT(setupDisplay()));
}
}

View file

@ -9,6 +9,7 @@
#include "qclickablelabel.h" #include "qclickablelabel.h"
#include "generaldialog.h" #include "generaldialog.h"
#include "toast.h" #include "toast.h"
#include "bookoptionsdialog.h"
namespace Ui { namespace Ui {
class localLibraryWidget; class localLibraryWidget;
@ -52,10 +53,13 @@ private slots:
void goToPage(int page); void goToPage(int page);
void setupDisplay(); void setupDisplay();
void showToast(QString messageToDisplay); void showToast(QString messageToDisplay);
void openBookOptionsDialog(int bookID);
void handlePossibleBookDeletion();
private: private:
Ui::localLibraryWidget * ui; Ui::localLibraryWidget * ui;
generalDialog * generalDialogWindow; generalDialog * generalDialogWindow;
bookOptionsDialog * bookOptionsDialogWindow;
toast * toastWindow; toast * toastWindow;
QVector<QHBoxLayout*> horizontalLayoutArray; QVector<QHBoxLayout*> horizontalLayoutArray;
QVector<QLabel*> bookIconArray; QVector<QLabel*> bookIconArray;

View file

@ -11,6 +11,7 @@ QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f)
QClickableLabel::~QClickableLabel() {} QClickableLabel::~QClickableLabel() {}
void QClickableLabel::mousePressEvent(QMouseEvent * event) { void QClickableLabel::mousePressEvent(QMouseEvent * event) {
timeAtClick = QDateTime::currentMSecsSinceEpoch();
emit clicked(); emit clicked();
if(objectName() == "pageNumberLabel") { if(objectName() == "pageNumberLabel") {
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px"); QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");
@ -21,8 +22,13 @@ void QClickableLabel::mousePressEvent(QMouseEvent * event) {
} }
void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) { void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) {
emit unclicked(); if(QDateTime::currentMSecsSinceEpoch() >= timeAtClick + 500) {
emit bookID(objectName().toInt()); emit longPress(objectName().toInt());
}
else {
emit unclicked();
emit bookID(objectName().toInt());
}
emit bookPath(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString()); emit bookPath(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString());
if(objectName() == "pageNumberLabel") { if(objectName() == "pageNumberLabel") {
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px"); QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");

View file

@ -10,12 +10,14 @@ class QClickableLabel : public QLabel {
public: public:
explicit QClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); explicit QClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
~QClickableLabel(); ~QClickableLabel();
long long timeAtClick;
signals: signals:
void clicked(); void clicked();
void unclicked(); void unclicked();
void bookID(int id); void bookID(int id);
void bookPath(QString path); void bookPath(QString path);
void longPress(int id);
protected: protected:
void mousePressEvent(QMouseEvent * event); void mousePressEvent(QMouseEvent * event);

View file

@ -156,8 +156,9 @@ void userapps::on_launchBtn_clicked()
if(manageRequiredFeatures() == true) { if(manageRequiredFeatures() == true) {
if(global::userApps::launchApp == true) { if(global::userApps::launchApp == true) {
global::userApps::launchApp = false; global::userApps::launchApp = false;
QString message = "Launching user application at: "; QString message = "Launching user application at: '";
message.append("[" + appDir.path() + "]" + execPath.fileName()); message.append("[" + appDir.path() + "]" + execPath.fileName());
message.append("'");
log(message, className); log(message, className);
// Tell the OS that we're not running anymore // Tell the OS that we're not running anymore
string_writeconfig("/tmp/inkbox_running", "false"); string_writeconfig("/tmp/inkbox_running", "false");