mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 07:37:21 -08:00
Various fixes; compress RecentBooks.db
This commit is contained in:
parent
3be9608a10
commit
35fe0ae0e3
7 changed files with 144 additions and 77 deletions
|
@ -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;
|
||||
|
|
|
@ -101,13 +101,25 @@ void homePageWidget::setupDisplay(bool databaseGenerated) {
|
|||
QString function = __func__; log(function + ": Failed to open local library database file for reading at '" + database.fileName() + "'", className);
|
||||
}
|
||||
|
||||
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(readFile(global::localLibrary::recentBooksDatabasePath).toUtf8()).object();
|
||||
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++) {
|
||||
|
@ -127,6 +139,7 @@ void homePageWidget::setupDisplay(bool databaseGenerated) {
|
|||
bookBtnArray[i]->setObjectName(dataString);
|
||||
}
|
||||
}
|
||||
QJsonObject uncompressedJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(bookBtnArray[i]->objectName().toUtf8()))).object();
|
||||
|
||||
verticalLayoutArray[i] = new QVBoxLayout();
|
||||
|
||||
|
@ -141,7 +154,6 @@ void homePageWidget::setupDisplay(bool databaseGenerated) {
|
|||
bookTitleArray[i]->setFont(QFont("u001"));
|
||||
bookTitleArray[i]->setStyleSheet("font-size: 7pt");
|
||||
|
||||
QJsonObject uncompressedJsonObject = QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(bookBtnArray[i]->objectName().toUtf8()))).object();
|
||||
QString bookTitle = uncompressedJsonObject["Title"].toString();
|
||||
bookTitleArray[i]->setObjectName(bookTitle);
|
||||
|
||||
|
@ -153,6 +165,7 @@ void homePageWidget::setupDisplay(bool databaseGenerated) {
|
|||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold;
|
||||
}
|
||||
if(bookTitle.length() > localBookTitleTruncateThreshold) {
|
||||
bookTitleArray[i]->setProperty("showToolTip", "true");
|
||||
bookTitle.truncate(localBookTitleTruncateThreshold);
|
||||
bookTitle.append("...");
|
||||
}
|
||||
|
@ -183,6 +196,33 @@ void homePageWidget::setupDisplay(bool databaseGenerated) {
|
|||
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 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);
|
||||
QFrame * line = new QFrame(this);
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Plain);
|
||||
line->setLineWidth(1);
|
||||
ui->booksVerticalLayout->addWidget(line);
|
||||
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);
|
||||
}
|
||||
QTimer::singleShot(500, this, SLOT(refreshScreenNative()));
|
||||
}
|
||||
|
||||
|
|
|
@ -259,17 +259,19 @@ void localLibraryWidget::setupBooksList(int pageNumber) {
|
|||
|
||||
// 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);
|
||||
}
|
||||
else if(currentPageNumber + 1 > pagesNumber) {
|
||||
if(currentPageNumber + 1 > pagesNumber) {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
ui->previousPageBtn->setEnabled(true);
|
||||
ui->nextPageBtn->setEnabled(true);
|
||||
if(currentPageNumber - 1 < 1 and currentPageNumber + 1 > pagesNumber) {
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
ui->nextPageBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,6 +324,7 @@ void localLibraryWidget::openGoToPageDialog() {
|
|||
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);
|
||||
|
|
|
@ -51,9 +51,9 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QClickableLabel" name="pageNumberLabel">
|
||||
<property name="text">
|
||||
<string>Page</string>
|
||||
<widget class="QClickableLabel" name="pageNumberLabel" native="true">
|
||||
<property name="text" stdset="0">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -205,6 +205,13 @@ Add some via USB or explore the Online Library.</string>
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QClickableLabel</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qclickablelabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -13,7 +13,7 @@ QClickableLabel::~QClickableLabel() {}
|
|||
void QClickableLabel::mousePressEvent(QMouseEvent * event) {
|
||||
emit clicked();
|
||||
if(objectName() == "pageNumberLabel") {
|
||||
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
||||
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
||||
}
|
||||
else {
|
||||
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding: 10px");
|
||||
|
@ -25,7 +25,7 @@ void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) {
|
|||
emit bookID(objectName().toInt());
|
||||
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");
|
||||
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
||||
}
|
||||
else {
|
||||
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <QToolTip>
|
||||
#include <QVariant>
|
||||
|
||||
#include "qtooltiplabel.h"
|
||||
|
||||
|
@ -10,7 +11,9 @@ QToolTipLabel::QToolTipLabel(QWidget* parent, Qt::WindowFlags f)
|
|||
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) {
|
||||
|
|
14
reader.cpp
14
reader.cpp
|
@ -625,7 +625,17 @@ reader::reader(QWidget *parent) :
|
|||
// Maintain a 'Recent books' list
|
||||
QJsonObject recentBooksObject;
|
||||
if(QFile::exists(global::localLibrary::recentBooksDatabasePath)) {
|
||||
QJsonObject mainJsonObject = QJsonDocument::fromJson(readFile(global::localLibrary::recentBooksDatabasePath).toUtf8()).object();
|
||||
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 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();
|
||||
|
@ -656,7 +666,7 @@ reader::reader(QWidget *parent) :
|
|||
recentBooksObject = mainJsonObject;
|
||||
}
|
||||
QFile::remove(global::localLibrary::recentBooksDatabasePath);
|
||||
writeFile(global::localLibrary::recentBooksDatabasePath, QString(QJsonDocument(recentBooksObject).toJson()));
|
||||
writeFile(global::localLibrary::recentBooksDatabasePath, qCompress(QJsonDocument(recentBooksObject).toJson()).toBase64());
|
||||
|
||||
// USB mass storage prompt
|
||||
if(global::reader::startUsbmsPrompt == true) {
|
||||
|
|
Loading…
Reference in a new issue