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
#include <KAuthorized>
#include <KLocalizedString>
#include <KWindowConfig>
#include <KAuthorized>
#include <KLocalizedString>
#include <KWindowConfig>
#include <QPushButton>
DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent) :
KPageDialog(parent),
#include <QPushButton>
DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent) :
KPageDialog(parent),
+ m_pages(),
+ m_unsavedChanges(false)
{
const QSize minSize = minimumSize();
{
const QSize minSize = minimumSize();
void DolphinSettingsDialog::enableApply()
{
buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
void DolphinSettingsDialog::enableApply()
{
buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(true);
+ m_unsavedChanges = true;
}
void DolphinSettingsDialog::applySettings()
}
void DolphinSettingsDialog::applySettings()
settings->save();
}
buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
settings->save();
}
buttonBox()->button(QDialogButtonBox::Apply)->setEnabled(false);
+ m_unsavedChanges = false;
}
void DolphinSettingsDialog::restoreDefaults()
}
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"))) {
SettingsPageBase *DolphinSettingsDialog::createTrashSettingsPage(QWidget *parent)
{
if (!KAuthorized::authorizeControlModule(QStringLiteral("kcmtrash.desktop"))) {
void applySettings();
void restoreDefaults();
void applySettings();
void restoreDefaults();
+protected:
+ void closeEvent(QCloseEvent* event) override;
+
private:
static SettingsPageBase *createTrashSettingsPage(QWidget *parent);
QList<SettingsPageBase*> m_pages;
private:
static SettingsPageBase *createTrashSettingsPage(QWidget *parent);
QList<SettingsPageBase*> m_pages;