diff options
| author | Amish Naidu <[email protected]> | 2019-03-25 15:41:40 +0530 |
|---|---|---|
| committer | Amish Naidu <[email protected]> | 2019-03-26 14:23:42 +0530 |
| commit | 017cd2322a0ae4c57476871f7715904a7810c9d3 (patch) | |
| tree | 3f57953327c22a7dbaffd657d96e09171a917f3f | |
| parent | 3dec3ee09236fed44239b6a27d2c7041c49d2314 (diff) | |
Prompt user to save/discard changes upon closing config dialog
Summary:
When the configuration dialog is closed with unsaved changes,
a message box is prompted to save/discard them or cancel the event.
BUG: 391206
Reviewers: #dolphin, elvisangelaccio
Reviewed By: #dolphin, elvisangelaccio
Subscribers: ngraham, elvisangelaccio, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D19904
| -rw-r--r-- | src/settings/dolphinsettingsdialog.cpp | 35 | ||||
| -rw-r--r-- | src/settings/dolphinsettingsdialog.h | 4 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/settings/dolphinsettingsdialog.cpp b/src/settings/dolphinsettingsdialog.cpp index 6bddb861f..530ce9d75 100644 --- a/src/settings/dolphinsettingsdialog.cpp +++ b/src/settings/dolphinsettingsdialog.cpp @@ -32,12 +32,14 @@ #include <KAuthorized> #include <KLocalizedString> #include <KWindowConfig> +#include <KMessageBox> #include <QPushButton> DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent) : KPageDialog(parent), - m_pages() + m_pages(), + m_unsavedChanges(false) { const QSize minSize = minimumSize(); @@ -121,6 +123,7 @@ DolphinSettingsDialog::~DolphinSettingsDialog() void DolphinSettingsDialog::enableApply() { buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true); + m_unsavedChanges = true; } void DolphinSettingsDialog::applySettings() @@ -139,6 +142,7 @@ void DolphinSettingsDialog::applySettings() settings->save(); } buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false); + m_unsavedChanges = false; } void DolphinSettingsDialog::restoreDefaults() @@ -148,6 +152,35 @@ void DolphinSettingsDialog::restoreDefaults() } } +void DolphinSettingsDialog::closeEvent(QCloseEvent* event) +{ + if (!m_unsavedChanges) { + event->accept(); + return; + } + + const auto response = KMessageBox::warningYesNoCancel(this, + i18n("You have have unsaved changes. Do you want to apply the changes or discard them?"), + i18n("Warning"), + KStandardGuiItem::save(), + KStandardGuiItem::discard(), + KStandardGuiItem::cancel()); + switch (response) { + case KMessageBox::Yes: + applySettings(); + Q_FALLTHROUGH(); + case KMessageBox::No: + event->accept(); + break; + case KMessageBox::Cancel: + event->ignore(); + break; + default: + break; + } +} + + SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent) { if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) { diff --git a/src/settings/dolphinsettingsdialog.h b/src/settings/dolphinsettingsdialog.h index 4c8768fde..85871b12d 100644 --- a/src/settings/dolphinsettingsdialog.h +++ b/src/settings/dolphinsettingsdialog.h @@ -48,10 +48,14 @@ private slots: void applySettings(); void restoreDefaults(); +protected: + void closeEvent(QCloseEvent* event) override; + private: static SettingsPageBase *createTrashSettingsPage(QWidget *parent); QList<SettingsPageBase*> m_pages; + bool m_unsavedChanges; }; #endif |
