Merge pull request #772 from ctrlaltca/trice_saveonclose_2ndtry

cockatrice: ask to save modified decks on close; fix #759
This commit is contained in:
Zach 2015-02-25 17:09:53 -05:00
commit b0fe2ef9d3
5 changed files with 33 additions and 6 deletions

View file

@ -379,6 +379,7 @@ void TabDeckEditor::updateHash()
bool TabDeckEditor::confirmClose() bool TabDeckEditor::confirmClose()
{ {
if (modified) { if (modified) {
tabSupervisor->setCurrentWidget(this);
QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"), QMessageBox::StandardButton ret = QMessageBox::warning(this, tr("Are you sure?"),
tr("The decklist has been modified.\nDo you want to save the changes?"), tr("The decklist has been modified.\nDo you want to save the changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);

View file

@ -75,7 +75,6 @@ private:
void offsetCountAtIndex(const QModelIndex &idx, int offset); void offsetCountAtIndex(const QModelIndex &idx, int offset);
void decrementCardHelper(QString zoneName); void decrementCardHelper(QString zoneName);
void recursiveExpand(const QModelIndex &index); void recursiveExpand(const QModelIndex &index);
bool confirmClose();
CardDatabaseModel *databaseModel; CardDatabaseModel *databaseModel;
CardDatabaseDisplayModel *databaseDisplayModel; CardDatabaseDisplayModel *databaseDisplayModel;
@ -110,6 +109,7 @@ public:
QString getTabText() const; QString getTabText() const;
void setDeck(DeckLoader *_deckLoader); void setDeck(DeckLoader *_deckLoader);
void setModified(bool _windowModified); void setModified(bool _windowModified);
bool confirmClose();
public slots: public slots:
void closeRequest(); void closeRequest();
signals: signals:

View file

@ -15,6 +15,7 @@
#include "settingscache.h" #include "settingscache.h"
#include <QDebug> #include <QDebug>
#include <QPainter> #include <QPainter>
#include <QMessageBox>
#include "pb/room_commands.pb.h" #include "pb/room_commands.pb.h"
#include "pb/room_event.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 AbstractClient *TabSupervisor::getClient() const
{ {
return localClients.isEmpty() ? client : localClients.first(); return localClients.isEmpty() ? client : localClients.first();

View file

@ -71,6 +71,7 @@ public:
AbstractClient *getClient() const; AbstractClient *getClient() const;
const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; } const QMap<int, TabRoom *> &getRoomTabs() const { return roomTabs; }
bool getAdminLocked() const; bool getAdminLocked() const;
bool closeRequest();
signals: signals:
void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>()); void setMenu(const QList<QMenu *> &newMenuList = QList<QMenu *>());
void localGameEnded(); void localGameEnded();

View file

@ -423,12 +423,19 @@ MainWindow::~MainWindow()
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
if (tabSupervisor->getGameCount()) { // workaround Qt bug where closeEvent gets called twice
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) { static bool bClosingDown=false;
event->ignore(); if(bClosingDown)
return; return;
} bClosingDown=true;
if (!tabSupervisor->closeRequest())
{
event->ignore();
bClosingDown=false;
return;
} }
event->accept(); event->accept();
settingsCache->setMainWindowGeometry(saveGeometry()); settingsCache->setMainWindowGeometry(saveGeometry());
tabSupervisor->deleteLater(); tabSupervisor->deleteLater();