mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Implement 'Generating database' toast; various improvements
This commit is contained in:
parent
5c50911642
commit
3be9608a10
7 changed files with 114 additions and 40 deletions
|
@ -130,6 +130,7 @@ namespace global {
|
|||
static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw";
|
||||
static inline QString databasePath = "/mnt/onboard/onboard/.inkbox/LocalLibrary.db";
|
||||
static inline QString recentBooksDatabasePath = "/mnt/onboard/onboard/.inkbox/RecentBooks.db";
|
||||
inline bool headless;
|
||||
}
|
||||
namespace localStorage {
|
||||
inline QStringList searchResultsPaths;
|
||||
|
@ -145,9 +146,9 @@ namespace global {
|
|||
inline bool launchApp;
|
||||
}
|
||||
namespace homePageWidget {
|
||||
inline int recentBooksNumber = 8;
|
||||
inline int recentBooksNumberPerRow = 4;
|
||||
inline int recentBooksRowNumber = global::homePageWidget::recentBooksNumber / global::homePageWidget::recentBooksNumberPerRow;
|
||||
static inline int recentBooksNumber = 8;
|
||||
static inline int recentBooksNumberPerRow = 4;
|
||||
static inline int recentBooksRowNumber = global::homePageWidget::recentBooksNumber / global::homePageWidget::recentBooksNumberPerRow;
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
|
|
|
@ -61,6 +61,35 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
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) {
|
||||
emit openBookSignal(bookPath, false);
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -90,10 +119,12 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
bookTitleArray[i] = new QToolTipLabel(this);
|
||||
|
||||
// Iterate until we find a book matching the recently opened book's "BookPath" key/value pair
|
||||
for(int in = i; in <= databaseBooksNumber; in++) {
|
||||
for(int in = 1; in <= databaseBooksNumber; in++) {
|
||||
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
|
||||
if(bookJsonObject["BookPath"] == bookPath) {
|
||||
bookBtnArray[i]->setObjectName(QJsonDocument(bookJsonObject).toJson());
|
||||
if(bookJsonObject["BookPath"].toString() == bookPath) {
|
||||
QByteArray data = qCompress(QJsonDocument(bookJsonObject).toJson()).toBase64();
|
||||
QString dataString = QString(data);
|
||||
bookBtnArray[i]->setObjectName(dataString);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +141,8 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
bookTitleArray[i]->setFont(QFont("u001"));
|
||||
bookTitleArray[i]->setStyleSheet("font-size: 7pt");
|
||||
|
||||
QString bookTitle = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["Title"].toString();
|
||||
QJsonObject uncompressedJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(bookBtnArray[i]->objectName().toUtf8()))).object();
|
||||
QString bookTitle = uncompressedJsonObject["Title"].toString();
|
||||
bookTitleArray[i]->setObjectName(bookTitle);
|
||||
|
||||
int localBookTitleTruncateThreshold;
|
||||
|
@ -126,7 +158,7 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
}
|
||||
bookTitleArray[i]->setText(bookTitle);
|
||||
|
||||
QString bookIcon = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["CoverPath"].toString();
|
||||
QString bookIcon = uncompressedJsonObject["CoverPath"].toString();
|
||||
if(QFile::exists(bookIcon)) {
|
||||
bookBtnArray[i]->setPixmap(QPixmap(bookIcon).scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
}
|
||||
|
@ -154,15 +186,21 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
QTimer::singleShot(500, this, SLOT(refreshScreenNative()));
|
||||
}
|
||||
|
||||
homePageWidget::~homePageWidget()
|
||||
{
|
||||
delete ui;
|
||||
void homePageWidget::setupDisplaySlot() {
|
||||
setupDisplay(true);
|
||||
}
|
||||
|
||||
void homePageWidget::openBook(QString bookPath) {
|
||||
emit openBookSignal(bookPath, false);
|
||||
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::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
void homePageWidget::showToast(QString messageToDisplay) {
|
||||
global::toast::message = messageToDisplay;
|
||||
toastWindow = new toast(this);
|
||||
toastWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
toastWindow->show();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <QVBoxLayout>
|
||||
#include "qclickablelabel.h"
|
||||
#include "qtooltiplabel.h"
|
||||
#include "locallibrarywidget.h"
|
||||
#include "toast.h"
|
||||
|
||||
namespace Ui {
|
||||
class homePageWidget;
|
||||
|
@ -33,9 +35,15 @@ signals:
|
|||
private slots:
|
||||
void openBook(QString bookPath);
|
||||
void refreshScreenNative();
|
||||
void setupDisplay(bool databaseGenerated);
|
||||
void setupDisplaySlot();
|
||||
void setupDisplayWithDatabase();
|
||||
void showToast(QString messageToDisplay);
|
||||
|
||||
private:
|
||||
Ui::homePageWidget *ui;
|
||||
localLibraryWidget * localLibraryWidgetWindow;
|
||||
toast * toastWindow;
|
||||
QVector<QToolTipLabel*> bookTitleArray;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QVBoxLayout*> verticalLayoutArray;
|
||||
|
|
|
@ -70,8 +70,8 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
|||
stdIconHeight = sH / stdIconHeightDivider;
|
||||
}
|
||||
else if(global::deviceID == "n873\n") {
|
||||
stdIconWidthDivider = 7.5;
|
||||
stdIconHeightDivider = 7.5;
|
||||
stdIconWidthDivider = 9.7;
|
||||
stdIconHeightDivider = 9.7;
|
||||
stdIconWidth = sW / stdIconWidthDivider;
|
||||
stdIconHeight = sH / stdIconHeightDivider;
|
||||
}
|
||||
|
@ -111,16 +111,13 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
|||
ui->booksVerticalLayout->addWidget(lineArray[i]);
|
||||
}
|
||||
}
|
||||
setupDatabase();
|
||||
if(noBooksInDatabase == false) {
|
||||
setupBooksList(currentPageNumber);
|
||||
}
|
||||
else {
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
ui->pageNumberLabel->setText("1 <i>of</i> 1");
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
|
||||
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()
|
||||
|
@ -151,13 +148,14 @@ void localLibraryWidget::setupDatabase() {
|
|||
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();
|
||||
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
|
||||
|
@ -190,6 +188,11 @@ void localLibraryWidget::setupDatabase() {
|
|||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(global::localLibrary::headless == true) {
|
||||
global::localLibrary::headless = false;
|
||||
localLibraryWidget::close();
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::setupBooksList(int pageNumber) {
|
||||
|
@ -253,19 +256,26 @@ void localLibraryWidget::setupBooksList(int pageNumber) {
|
|||
for(int i = 0; i <= 1; i++) {
|
||||
ui->verticalLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::on_previousPageBtn_clicked()
|
||||
{
|
||||
currentPageNumber--;
|
||||
// Set boundaries for 'Previous'/'Next' page turn buttons
|
||||
currentPageNumber = pageNumber;
|
||||
if(currentPageNumber - 1 < 1) {
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setEnabled(true);
|
||||
}
|
||||
else if(currentPageNumber + 1 > pagesNumber) {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::on_previousPageBtn_clicked()
|
||||
{
|
||||
currentPageNumber--;
|
||||
setupBooksList(currentPageNumber);
|
||||
|
||||
pagesTurned = pagesTurned + 1;
|
||||
|
@ -279,14 +289,6 @@ void localLibraryWidget::on_previousPageBtn_clicked()
|
|||
void localLibraryWidget::on_nextPageBtn_clicked()
|
||||
{
|
||||
currentPageNumber++;
|
||||
if(currentPageNumber + 1 > pagesNumber) {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(true);
|
||||
}
|
||||
setupBooksList(currentPageNumber);
|
||||
|
||||
pagesTurned = pagesTurned + 1;
|
||||
|
@ -331,3 +333,23 @@ void localLibraryWidget::goToPage(int page) {
|
|||
void localLibraryWidget::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
||||
void localLibraryWidget::setupDisplay() {
|
||||
setupDatabase();
|
||||
if(noBooksInDatabase == false) {
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "functions.h"
|
||||
#include "qclickablelabel.h"
|
||||
#include "generaldialog.h"
|
||||
#include "toast.h"
|
||||
|
||||
namespace Ui {
|
||||
class localLibraryWidget;
|
||||
|
@ -49,10 +50,13 @@ private slots:
|
|||
void refreshScreenNative();
|
||||
void openGoToPageDialog();
|
||||
void goToPage(int page);
|
||||
void setupDisplay();
|
||||
void showToast(QString messageToDisplay);
|
||||
|
||||
private:
|
||||
Ui::localLibraryWidget * ui;
|
||||
generalDialog * generalDialogWindow;
|
||||
toast * toastWindow;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QLabel*> bookIconArray;
|
||||
QVector<QClickableLabel*> bookBtnArray;
|
||||
|
|
|
@ -23,7 +23,7 @@ void QClickableLabel::mousePressEvent(QMouseEvent * event) {
|
|||
void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) {
|
||||
emit unclicked();
|
||||
emit bookID(objectName().toInt());
|
||||
emit bookPath(QJsonDocument::fromJson(objectName().toUtf8()).object()["BookPath"].toString());
|
||||
emit bookPath(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString());
|
||||
if(objectName() == "pageNumberLabel") {
|
||||
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
||||
}
|
||||
|
|
|
@ -622,6 +622,7 @@ reader::reader(QWidget *parent) :
|
|||
// Way to tell shell scripts that we're in the Reader framework
|
||||
string_writeconfig("/tmp/inkboxReading", "true");
|
||||
|
||||
// Maintain a 'Recent books' list
|
||||
QJsonObject recentBooksObject;
|
||||
if(QFile::exists(global::localLibrary::recentBooksDatabasePath)) {
|
||||
QJsonObject mainJsonObject = QJsonDocument::fromJson(readFile(global::localLibrary::recentBooksDatabasePath).toUtf8()).object();
|
||||
|
|
Loading…
Reference in a new issue