From bd5dd130e518a4b234772d11e0db8f8d68bc5201 Mon Sep 17 00:00:00 2001 From: Thom Troy Date: Sun, 10 Jun 2012 20:54:58 +0100 Subject: [PATCH] Add auto save on exit --- src/core/Config.cpp | 1 + src/gui/DatabaseTabWidget.cpp | 23 +++++++++++++++-------- src/gui/SettingsWidget.cpp | 13 +++++++++++++ src/gui/SettingsWidget.h | 1 + src/gui/SettingsWidgetGeneral.ui | 9 ++++++++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index d83de9988..ccbabc085 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -72,6 +72,7 @@ Config::Config() m_defaults.insert("RememberLastDatabases", true); m_defaults.insert("ModifiedOnExpandedStateChanges", true); m_defaults.insert("AutoSaveAfterEveryChange", false); + m_defaults.insert("AutoSaveOnExit", false); m_defaults.insert("security/clearclipboard", true); m_defaults.insert("security/clearclipboardtimeout", 10); } diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index c1f514b40..ee484d92c 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -210,16 +210,23 @@ bool DatabaseTabWidget::closeDatabase(Database* db) } } if (dbStruct.modified) { - QMessageBox::StandardButton result = - QMessageBox::question( - this, tr("Save changes?"), - tr("\"%1\" was modified.\nSave changes?").arg(dbName), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); - if (result == QMessageBox::Yes) { + if(config()->get("AutoSaveOnExit").toBool()) + { saveDatabase(db); } - else if (result == QMessageBox::Cancel) { - return false; + else + { + QMessageBox::StandardButton result = + QMessageBox::question( + this, tr("Save changes?"), + tr("\"%1\" was modified.\nSave changes?").arg(dbName), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); + if (result == QMessageBox::Yes) { + saveDatabase(db); + } + else if (result == QMessageBox::Cancel) { + return false; + } } } diff --git a/src/gui/SettingsWidget.cpp b/src/gui/SettingsWidget.cpp index c63bded93..b61ef2711 100644 --- a/src/gui/SettingsWidget.cpp +++ b/src/gui/SettingsWidget.cpp @@ -38,6 +38,9 @@ SettingsWidget::SettingsWidget(QWidget* parent) connect(this, SIGNAL(accepted()), SLOT(saveSettings())); connect(this, SIGNAL(rejected()), SLOT(reject())); + connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)), + this, SLOT(enableAutoSaveOnExit(bool))); + connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)), m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool))); } @@ -51,6 +54,7 @@ void SettingsWidget::loadSettings() m_generalUi->rememberLastDatabasesCheckBox->setChecked(config()->get("RememberLastDatabases").toBool()); m_generalUi->modifiedExpandedChangedCheckBox->setChecked(config()->get("ModifiedOnExpandedStateChanges").toBool()); m_generalUi->autoSaveAfterEveryChangeCheckBox->setChecked(config()->get("AutoSaveAfterEveryChange").toBool()); + m_generalUi->autoSaveOnExitCheckBox->setChecked(config()->get("AutoSaveOnExit").toBool()); m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool()); m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt()); @@ -62,6 +66,7 @@ void SettingsWidget::saveSettings() config()->set("RememberLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked()); config()->set("ModifiedOnExpandedStateChanges", m_generalUi->modifiedExpandedChangedCheckBox->isChecked()); config()->set("AutoSaveAfterEveryChange", m_generalUi->autoSaveAfterEveryChangeCheckBox->isChecked()); + config()->set("AutoSaveOnExit", m_generalUi->autoSaveOnExitCheckBox->isChecked()); config()->set("security/clearclipboard", m_secUi->clearClipboardCheckBox->isChecked()); config()->set("security/clearclipboardtimeout", m_secUi->clearClipboardSpinBox->value()); @@ -72,3 +77,11 @@ void SettingsWidget::reject() { Q_EMIT editFinished(false); } + +void SettingsWidget::enableAutoSaveOnExit(bool checked) +{ + if(checked) + m_generalUi->autoSaveOnExitCheckBox->setEnabled(false); + else + m_generalUi->autoSaveOnExitCheckBox->setEnabled(true); +} diff --git a/src/gui/SettingsWidget.h b/src/gui/SettingsWidget.h index 5b3796ce9..affdd0a90 100644 --- a/src/gui/SettingsWidget.h +++ b/src/gui/SettingsWidget.h @@ -40,6 +40,7 @@ Q_SIGNALS: private Q_SLOTS: void saveSettings(); void reject(); + void enableAutoSaveOnExit(bool checked); private: QWidget* const m_secWidget; diff --git a/src/gui/SettingsWidgetGeneral.ui b/src/gui/SettingsWidgetGeneral.ui index b3033eee0..0c492a535 100644 --- a/src/gui/SettingsWidgetGeneral.ui +++ b/src/gui/SettingsWidgetGeneral.ui @@ -31,13 +31,20 @@ - + Automatically save after every change + + + + Automatically save on exit + + +