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()
{
// 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()

View file

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

View file

@ -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()));
});
}
}

View file

@ -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();