From 399d4bf516423ac6e05231abda3e39e1444024f5 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 21 Feb 2015 15:19:25 +0100 Subject: [PATCH 1/2] cockatrice: ask to save modified decks on close; fix #759 --- cockatrice/src/tab_deck_editor.cpp | 1 + cockatrice/src/tab_deck_editor.h | 2 +- cockatrice/src/tab_supervisor.cpp | 18 ++++++++++++++++++ cockatrice/src/tab_supervisor.h | 1 + cockatrice/src/window_main.cpp | 10 +++++----- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index fdd41967..0b190afb 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -379,6 +379,7 @@ void TabDeckEditor::updateHash() bool TabDeckEditor::confirmClose() { if (modified) { + tabSupervisor->setCurrentWidget(this); QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"), tr("The decklist has been modified.\nDo you want to save the changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 8db00e73..24497e80 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -75,7 +75,6 @@ private: void offsetCountAtIndex(const QModelIndex &idx, int offset); void decrementCardHelper(QString zoneName); void recursiveExpand(const QModelIndex &index); - bool confirmClose(); CardDatabaseModel *databaseModel; CardDatabaseDisplayModel *databaseDisplayModel; @@ -110,6 +109,7 @@ public: QString getTabText() const; void setDeck(DeckLoader *_deckLoader); void setModified(bool _windowModified); + bool confirmClose(); public slots: void closeRequest(); signals: diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 20579b6e..45f7a25c 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -15,6 +15,7 @@ #include "settingscache.h" #include #include +#include #include "pb/room_commands.pb.h" #include "pb/room_event.pb.h" @@ -130,6 +131,23 @@ void TabSupervisor::retranslateUi() } } +bool TabSupervisor::closeRequest() +{ + if (getGameCount()) { + if (QMessageBox::question(this, tr("Are you sure?"), tr("There are still open games. Are you sure you want to quit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) { + return false; + } + } + + foreach(TabDeckEditor *tab, deckEditorTabs) + { + if(!tab->confirmClose()) + return false; + } + + return true; +} + AbstractClient *TabSupervisor::getClient() const { return localClients.isEmpty() ? client : localClients.first(); diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index 48af3c8a..0ee686c6 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -71,6 +71,7 @@ public: AbstractClient *getClient() const; const QMap &getRoomTabs() const { return roomTabs; } bool getAdminLocked() const; + bool closeRequest(); signals: void setMenu(const QList &newMenuList = QList()); void localGameEnded(); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index ee482b24..bf770504 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -423,12 +423,12 @@ MainWindow::~MainWindow() void MainWindow::closeEvent(QCloseEvent *event) { - if (tabSupervisor->getGameCount()) { - if (QMessageBox::question(this, tr("Are you sure?"), tr("There are still open games. Are you sure you want to quit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) { - event->ignore(); - return; - } + if (!tabSupervisor->closeRequest()) + { + event->ignore(); + return; } + event->accept(); settingsCache->setMainWindowGeometry(saveGeometry()); tabSupervisor->deleteLater(); From 061fd5a830f557625b8c4da39258b883599ea2f5 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Wed, 25 Feb 2015 18:32:33 +0100 Subject: [PATCH 2/2] Workaround for duplicated dialogs on close --- cockatrice/src/window_main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index bf770504..b0878340 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -423,9 +423,16 @@ MainWindow::~MainWindow() void MainWindow::closeEvent(QCloseEvent *event) { + // workaround Qt bug where closeEvent gets called twice + static bool bClosingDown=false; + if(bClosingDown) + return; + bClosingDown=true; + if (!tabSupervisor->closeRequest()) { event->ignore(); + bClosingDown=false; return; }