From 636a9eb97acfbe2ecc0ade0635d08523441c036c Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Mon, 8 Aug 2022 23:38:38 -0400 Subject: [PATCH] bookOptionsDialog: Add 'Wipe reading settings' option This will delete the local reading settings directory for a specified book, if applicable. If not, the option is hidden. --- src/functions.h | 4 +- src/onlineLibrary/librarywidget.cpp | 12 ++-- .../dialogs/library/bookoptionsdialog.cpp | 21 +++++- .../dialogs/library/bookoptionsdialog.h | 2 + .../dialogs/library/bookoptionsdialog.ui | 67 +++++++++++++------ 5 files changed, 78 insertions(+), 28 deletions(-) diff --git a/src/functions.h b/src/functions.h index 996c8bb..37d1db0 100644 --- a/src/functions.h +++ b/src/functions.h @@ -990,12 +990,12 @@ namespace { } } } - QByteArray fileChecksum(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) { + QString 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(); + return hash.result().toHex(); } } } diff --git a/src/onlineLibrary/librarywidget.cpp b/src/onlineLibrary/librarywidget.cpp index 394f2f1..0d075d1 100644 --- a/src/onlineLibrary/librarywidget.cpp +++ b/src/onlineLibrary/librarywidget.cpp @@ -34,7 +34,7 @@ libraryWidget::libraryWidget(QWidget *parent) : } QFont crimson(family); - if(global::deviceID != "n905\n" and global::deviceID != "kt\n") { + if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { ui->previousBtn->setText(""); ui->previousBtn->setProperty("type", "borderless"); ui->nextBtn->setText(""); @@ -62,7 +62,7 @@ libraryWidget::libraryWidget(QWidget *parent) : ui->book6Btn->setText(""); ui->book7Btn->setText(""); ui->book8Btn->setText(""); - if(global::deviceID != "n905\n" and global::deviceID != "kt\n") { + if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { ui->book9Btn->setText(""); ui->book10Btn->setText(""); ui->book11Btn->setText(""); @@ -98,7 +98,7 @@ libraryWidget::libraryWidget(QWidget *parent) : ui->book6Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); ui->book7Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); ui->book8Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); - if(global::deviceID != "n905\n" and global::deviceID != "kt\n") { + if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { ui->book9Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); ui->book10Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); ui->book11Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); @@ -134,7 +134,7 @@ libraryWidget::libraryWidget(QWidget *parent) : ui->book6Label->setFont(crimson); ui->book7Label->setFont(crimson); ui->book8Label->setFont(crimson); - if(global::deviceID != "n905\n" and global::deviceID != "kt\n") { + if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { ui->book9Label->setFont(crimson); ui->book10Label->setFont(crimson); ui->book11Label->setFont(crimson); @@ -186,7 +186,7 @@ void libraryWidget::setupView() { ui->book6Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/6/title")); ui->book7Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/7/title")); ui->book8Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/8/title")); - if(global::deviceID != "n905\n" and global::deviceID != "kt\n") { + if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { ui->book9Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/9/title")); ui->book10Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/10/title")); ui->book11Label->setText(readFile("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/11/title")); @@ -213,7 +213,7 @@ void libraryWidget::setupView() { ui->book7Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); ui->book8Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/8/cover.jpg")); ui->book8Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); - if(global::deviceID != "n905\n" and global::deviceID != "kt\n") { + if(global::deviceID != "n705\n" and global::deviceID != "n905\n" and global::deviceID != "kt\n") { ui->book9Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/9/cover.jpg")); ui->book9Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); ui->book10Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/10/cover.jpg")); diff --git a/src/widgets/dialogs/library/bookoptionsdialog.cpp b/src/widgets/dialogs/library/bookoptionsdialog.cpp index 4eaff9d..46a0caa 100644 --- a/src/widgets/dialogs/library/bookoptionsdialog.cpp +++ b/src/widgets/dialogs/library/bookoptionsdialog.cpp @@ -19,8 +19,8 @@ bookOptionsDialog::bookOptionsDialog(QWidget *parent) : else { ui->deleteBtn->setProperty("type", "borderless"); } + ui->wipeLocalReadingSettingsBtn->setProperty("type", "borderless"); ui->infoBtn->setProperty("type", "borderless"); - this->adjustSize(); global::localLibrary::bookOptionsDialog::bookPinAction = false; @@ -32,6 +32,17 @@ bookOptionsDialog::bookOptionsDialog(QWidget *parent) : else { bookPinned = false; } + + bookChecksum = fileChecksum(bookPath, QCryptographicHash::Sha256); + QDir localReadingSettingsPath("/mnt/onboard/onboard/." + bookChecksum); + if(!localReadingSettingsPath.exists()) { + ui->wipeLocalReadingSettingsBtn->hide(); + ui->line_3->hide(); + ui->wipeLocalReadingSettingsBtn->deleteLater(); + ui->line_3->deleteLater(); + } + + this->adjustSize(); } bookOptionsDialog::~bookOptionsDialog() @@ -208,3 +219,11 @@ bool bookOptionsDialog::isBookPinned(int bookID) { } return bookPinned; } + +void bookOptionsDialog::on_wipeLocalReadingSettingsBtn_clicked() +{ + log("Removing local reading settings directory for book '" + bookPath + "' at '/mnt/onboard/onboard/." + bookChecksum + "'", className); + QDir dir("/mnt/onboard/onboard/." + bookChecksum); + dir.removeRecursively(); + bookOptionsDialog::close(); +} diff --git a/src/widgets/dialogs/library/bookoptionsdialog.h b/src/widgets/dialogs/library/bookoptionsdialog.h index 18aae44..018a7ca 100644 --- a/src/widgets/dialogs/library/bookoptionsdialog.h +++ b/src/widgets/dialogs/library/bookoptionsdialog.h @@ -17,12 +17,14 @@ public: explicit bookOptionsDialog(QWidget *parent = nullptr); ~bookOptionsDialog(); QString bookPath; + QString bookChecksum; bool bookPinned; private slots: void on_pinBtn_clicked(); void on_deleteBtn_clicked(); void on_infoBtn_clicked(); + void on_wipeLocalReadingSettingsBtn_clicked(); void pinBook(int bookID); void unpinBook(int bookID); bool isBookPinned(int bookID); diff --git a/src/widgets/dialogs/library/bookoptionsdialog.ui b/src/widgets/dialogs/library/bookoptionsdialog.ui index c3a053d..9370a37 100644 --- a/src/widgets/dialogs/library/bookoptionsdialog.ui +++ b/src/widgets/dialogs/library/bookoptionsdialog.ui @@ -28,7 +28,49 @@ - + + + + + 75 + true + + + + padding-left: 80px; padding-right: 80px; padding-top: 10px; padding-bottom: 10px + + + Delete + + + + + + + QFrame::Plain + + + 4 + + + Qt::Horizontal + + + + + + + QFrame::Plain + + + 4 + + + Qt::Horizontal + + + + @@ -60,21 +102,8 @@ - - - - QFrame::Plain - - - 4 - - - Qt::Horizontal - - - - - + + 75 @@ -85,12 +114,12 @@ padding-left: 80px; padding-right: 80px; padding-top: 10px; padding-bottom: 10px - Delete + Wipe reading settings - - + + QFrame::Plain