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.
This commit is contained in:
Nicolas Mailloux 2022-08-08 23:38:38 -04:00
parent 9c085d1b2c
commit 636a9eb97a
5 changed files with 78 additions and 28 deletions

View file

@ -990,12 +990,12 @@ namespace {
} }
} }
} }
QByteArray fileChecksum(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) { QString fileChecksum(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) {
QFile f(fileName); QFile f(fileName);
if (f.open(QFile::ReadOnly)) { if (f.open(QFile::ReadOnly)) {
QCryptographicHash hash(hashAlgorithm); QCryptographicHash hash(hashAlgorithm);
if (hash.addData(&f)) { if (hash.addData(&f)) {
return hash.result(); return hash.result().toHex();
} }
} }
} }

View file

@ -34,7 +34,7 @@ libraryWidget::libraryWidget(QWidget *parent) :
} }
QFont crimson(family); 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->setText("");
ui->previousBtn->setProperty("type", "borderless"); ui->previousBtn->setProperty("type", "borderless");
ui->nextBtn->setText(""); ui->nextBtn->setText("");
@ -62,7 +62,7 @@ libraryWidget::libraryWidget(QWidget *parent) :
ui->book6Btn->setText(""); ui->book6Btn->setText("");
ui->book7Btn->setText(""); ui->book7Btn->setText("");
ui->book8Btn->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->book9Btn->setText("");
ui->book10Btn->setText(""); ui->book10Btn->setText("");
ui->book11Btn->setText(""); ui->book11Btn->setText("");
@ -98,7 +98,7 @@ libraryWidget::libraryWidget(QWidget *parent) :
ui->book6Label->setStyleSheet("font-size: 8.5pt; font-style: italic"); ui->book6Label->setStyleSheet("font-size: 8.5pt; font-style: italic");
ui->book7Label->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"); 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->book9Label->setStyleSheet("font-size: 8.5pt; font-style: italic");
ui->book10Label->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"); ui->book11Label->setStyleSheet("font-size: 8.5pt; font-style: italic");
@ -134,7 +134,7 @@ libraryWidget::libraryWidget(QWidget *parent) :
ui->book6Label->setFont(crimson); ui->book6Label->setFont(crimson);
ui->book7Label->setFont(crimson); ui->book7Label->setFont(crimson);
ui->book8Label->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->book9Label->setFont(crimson);
ui->book10Label->setFont(crimson); ui->book10Label->setFont(crimson);
ui->book11Label->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->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->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")); 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->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->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")); 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->book7Btn->setIconSize(QSize(stdIconWidth, stdIconHeight));
ui->book8Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/8/cover.jpg")); ui->book8Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/8/cover.jpg"));
ui->book8Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); 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->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/9/cover.jpg"));
ui->book9Btn->setIconSize(QSize(stdIconWidth, stdIconHeight)); ui->book9Btn->setIconSize(QSize(stdIconWidth, stdIconHeight));
ui->book10Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/10/cover.jpg")); ui->book10Btn->setIcon(QIcon("/mnt/onboard/onboard/.inkbox/gutenberg-data/latest-books/10/cover.jpg"));

View file

@ -19,8 +19,8 @@ bookOptionsDialog::bookOptionsDialog(QWidget *parent) :
else { else {
ui->deleteBtn->setProperty("type", "borderless"); ui->deleteBtn->setProperty("type", "borderless");
} }
ui->wipeLocalReadingSettingsBtn->setProperty("type", "borderless");
ui->infoBtn->setProperty("type", "borderless"); ui->infoBtn->setProperty("type", "borderless");
this->adjustSize();
global::localLibrary::bookOptionsDialog::bookPinAction = false; global::localLibrary::bookOptionsDialog::bookPinAction = false;
@ -32,6 +32,17 @@ bookOptionsDialog::bookOptionsDialog(QWidget *parent) :
else { else {
bookPinned = false; 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() bookOptionsDialog::~bookOptionsDialog()
@ -208,3 +219,11 @@ bool bookOptionsDialog::isBookPinned(int bookID) {
} }
return bookPinned; 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();
}

View file

@ -17,12 +17,14 @@ public:
explicit bookOptionsDialog(QWidget *parent = nullptr); explicit bookOptionsDialog(QWidget *parent = nullptr);
~bookOptionsDialog(); ~bookOptionsDialog();
QString bookPath; QString bookPath;
QString bookChecksum;
bool bookPinned; bool bookPinned;
private slots: private slots:
void on_pinBtn_clicked(); void on_pinBtn_clicked();
void on_deleteBtn_clicked(); void on_deleteBtn_clicked();
void on_infoBtn_clicked(); void on_infoBtn_clicked();
void on_wipeLocalReadingSettingsBtn_clicked();
void pinBook(int bookID); void pinBook(int bookID);
void unpinBook(int bookID); void unpinBook(int bookID);
bool isBookPinned(int bookID); bool isBookPinned(int bookID);

View file

@ -28,7 +28,49 @@
</property> </property>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="4" column="0"> <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-left: 80px; padding-right: 80px; padding-top: 10px; padding-bottom: 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>
<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="6" column="0">
<widget class="QPushButton" name="infoBtn"> <widget class="QPushButton" name="infoBtn">
<property name="font"> <property name="font">
<font> <font>
@ -60,21 +102,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="4" column="0">
<widget class="Line" name="line"> <widget class="QPushButton" name="wipeLocalReadingSettingsBtn">
<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"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>
@ -85,12 +114,12 @@
<string notr="true">padding-left: 80px; padding-right: 80px; padding-top: 10px; padding-bottom: 10px</string> <string notr="true">padding-left: 80px; padding-right: 80px; padding-top: 10px; padding-bottom: 10px</string>
</property> </property>
<property name="text"> <property name="text">
<string>Delete</string> <string>Wipe reading settings</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="5" column="0">
<widget class="Line" name="line_2"> <widget class="Line" name="line_3">
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>