bookID fix in bookOptionsDialog

This commit is contained in:
Nicolas Mailloux 2022-07-15 23:58:05 -04:00
parent b98fee4458
commit 54633f1dc9
4 changed files with 25 additions and 13 deletions

View file

@ -23,16 +23,21 @@ bookOptionsDialog::~bookOptionsDialog()
void bookOptionsDialog::on_pinBtn_clicked() void bookOptionsDialog::on_pinBtn_clicked()
{ {
// TODO // TODO
log("Pinned book with ID " + QString::number(global::localLibrary::bookOptionsDialog::bookID), className);
} }
void bookOptionsDialog::on_deleteBtn_clicked() void bookOptionsDialog::on_deleteBtn_clicked()
{ {
log("Deleting book '" + bookPath + "'", className); log("Deleting book '" + bookPath + "'", className);
QFile::remove(bookPath); global::toast::delay = 3000;
if(QFile::remove(bookPath)) {
emit showToast("Book deleted successfully");
global::localLibrary::bookOptionsDialog::bookDeleted = true; global::localLibrary::bookOptionsDialog::bookDeleted = true;
QFile::remove(global::localLibrary::databasePath); QFile::remove(global::localLibrary::databasePath);
ui->deleteBtn->setEnabled(false); }
ui->deleteBtn->setStyleSheet("padding: 10px; color: lightGrey"); else {
emit showToast("Failed to delete book");
}
} }
void bookOptionsDialog::on_infoBtn_clicked() void bookOptionsDialog::on_infoBtn_clicked()

View file

@ -25,6 +25,7 @@ private slots:
signals: signals:
void openLocalBookInfoDialog(); void openLocalBookInfoDialog();
void showToast(QString messageToDisplay);
private: private:
Ui::bookOptionsDialog *ui; Ui::bookOptionsDialog *ui;

View file

@ -358,11 +358,15 @@ void localLibraryWidget::showToast(QString messageToDisplay) {
toastWindow->show(); toastWindow->show();
} }
void localLibraryWidget::openBookOptionsDialog(int bookID) { void localLibraryWidget::openBookOptionsDialog(int pseudoBookID) {
log("Opening book options dialog for book with pseudo-ID " + QString::number(bookID), className); // 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; global::localLibrary::bookOptionsDialog::bookID = bookID;
bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this); bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog); QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::showToast, this, &localLibraryWidget::showToast);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion); QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion);
bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose); bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
@ -371,11 +375,13 @@ void localLibraryWidget::openBookOptionsDialog(int bookID) {
void localLibraryWidget::handlePossibleBookDeletion() { void localLibraryWidget::handlePossibleBookDeletion() {
if(global::localLibrary::bookOptionsDialog::bookDeleted == true) { if(global::localLibrary::bookOptionsDialog::bookDeleted == true) {
QTimer::singleShot(3100, this, [&]() {
global::localLibrary::bookOptionsDialog::bookDeleted = false; global::localLibrary::bookOptionsDialog::bookDeleted = false;
global::toast::modalToast = true; global::toast::modalToast = true;
global::toast::indefiniteToast = true; global::toast::indefiniteToast = true;
showToast("Generating database"); showToast("Generating database");
QTimer::singleShot(100, this, SLOT(setupDisplay())); QTimer::singleShot(100, this, SLOT(setupDisplay()));
});
} }
} }

View file

@ -54,7 +54,7 @@ private slots:
void goToPage(int page); void goToPage(int page);
void setupDisplay(); void setupDisplay();
void showToast(QString messageToDisplay); void showToast(QString messageToDisplay);
void openBookOptionsDialog(int bookID); void openBookOptionsDialog(int pseudoBookID);
void handlePossibleBookDeletion(); void handlePossibleBookDeletion();
void openLocalBookInfoDialog(); void openLocalBookInfoDialog();