From 54633f1dc974d7f11591da305727e803aa654c68 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Fri, 15 Jul 2022 23:58:05 -0400 Subject: [PATCH] bookID fix in bookOptionsDialog --- bookoptionsdialog.cpp | 15 ++++++++++----- bookoptionsdialog.h | 1 + locallibrarywidget.cpp | 20 +++++++++++++------- locallibrarywidget.h | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/bookoptionsdialog.cpp b/bookoptionsdialog.cpp index 7b79e0b..f756a43 100644 --- a/bookoptionsdialog.cpp +++ b/bookoptionsdialog.cpp @@ -23,16 +23,21 @@ bookOptionsDialog::~bookOptionsDialog() void bookOptionsDialog::on_pinBtn_clicked() { // TODO + log("Pinned book with ID " + QString::number(global::localLibrary::bookOptionsDialog::bookID), className); } 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"); + global::toast::delay = 3000; + if(QFile::remove(bookPath)) { + emit showToast("Book deleted successfully"); + global::localLibrary::bookOptionsDialog::bookDeleted = true; + QFile::remove(global::localLibrary::databasePath); + } + else { + emit showToast("Failed to delete book"); + } } void bookOptionsDialog::on_infoBtn_clicked() diff --git a/bookoptionsdialog.h b/bookoptionsdialog.h index 37d5053..d3c70cd 100644 --- a/bookoptionsdialog.h +++ b/bookoptionsdialog.h @@ -25,6 +25,7 @@ private slots: signals: void openLocalBookInfoDialog(); + void showToast(QString messageToDisplay); private: Ui::bookOptionsDialog *ui; diff --git a/locallibrarywidget.cpp b/locallibrarywidget.cpp index a880f4f..c0dd762 100644 --- a/locallibrarywidget.cpp +++ b/locallibrarywidget.cpp @@ -358,11 +358,15 @@ void localLibraryWidget::showToast(QString messageToDisplay) { toastWindow->show(); } -void localLibraryWidget::openBookOptionsDialog(int bookID) { - log("Opening book options dialog for book with pseudo-ID " + QString::number(bookID), className); +void localLibraryWidget::openBookOptionsDialog(int pseudoBookID) { + // Determine book ID from the book's button number + int bookID = ((currentPageNumber * buttonsNumber) - (buttonsNumber - 1)) + (pseudoBookID - 1); + + log("Opening book options dialog for book with pseudo-ID " + QString::number(pseudoBookID) + ", ID " + QString::number(bookID), className); global::localLibrary::bookOptionsDialog::bookID = bookID; bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this); QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog); + QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::showToast, this, &localLibraryWidget::showToast); QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion); bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose); bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); @@ -371,11 +375,13 @@ void localLibraryWidget::openBookOptionsDialog(int bookID) { 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())); + QTimer::singleShot(3100, this, [&]() { + global::localLibrary::bookOptionsDialog::bookDeleted = false; + global::toast::modalToast = true; + global::toast::indefiniteToast = true; + showToast("Generating database"); + QTimer::singleShot(100, this, SLOT(setupDisplay())); + }); } } diff --git a/locallibrarywidget.h b/locallibrarywidget.h index e20370f..e2dd159 100644 --- a/locallibrarywidget.h +++ b/locallibrarywidget.h @@ -54,7 +54,7 @@ private slots: void goToPage(int page); void setupDisplay(); void showToast(QString messageToDisplay); - void openBookOptionsDialog(int bookID); + void openBookOptionsDialog(int pseudoBookID); void handlePossibleBookDeletion(); void openLocalBookInfoDialog();