From d965cdee9951a56417552e7bbf30735e4a3b9991 Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Tue, 18 Sep 2007 19:00:23 +0000 Subject: [PATCH] Beginnings of confirmation dialog shown when critical compositing settings are changed. When user doesn't click Yes in 10 secs then changes are reverted. svn path=/trunk/KDE/kdebase/workspace/; revision=714104 --- kcmkwin/kwincompositing/main.cpp | 59 ++++++++++++++++++++++++++++++++ kcmkwin/kwincompositing/main.h | 20 +++++++++-- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/kcmkwin/kwincompositing/main.cpp b/kcmkwin/kwincompositing/main.cpp index e20c804b91..47a5bb2d34 100644 --- a/kcmkwin/kwincompositing/main.cpp +++ b/kcmkwin/kwincompositing/main.cpp @@ -23,6 +23,7 @@ License. See the file "COPYING" for the exact licensing terms. #include #include +#include #include #include @@ -35,6 +36,32 @@ namespace KWin { +ConfirmDialog::ConfirmDialog() : + QMessageBox(QMessageBox::Question, i18n("Compositing settings changed"), "", + QMessageBox::Yes | QMessageBox::No) + { + mSecondsToLive = 10+1; + advanceTimer(); + } + +void ConfirmDialog::advanceTimer() + { + mSecondsToLive--; + if(mSecondsToLive > 0) + { + QString text = i18n("Compositing settings have changed.\n" + "Do you want to keep the new settings?\n" + "They will be automatically reverted in %1 seconds", mSecondsToLive); + setText(text); + QTimer::singleShot(1000, this, SLOT(advanceTimer())); + } + else + { + reject(); + } +} + + KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList &) : KCModule( KWinCompositingConfigFactory::componentData(), parent), mKWinConfig(KSharedConfig::openConfig("kwinrc")) @@ -93,6 +120,26 @@ void KWinCompositingConfig::showAdvancedOptions() connect(dialog, SIGNAL(configSaved()), this, SLOT(configChanged())); } +void KWinCompositingConfig::showConfirmDialog() +{ + ConfirmDialog confirm; + int result = confirm.exec(); + kDebug() << "result:" << result; + if(result != QMessageBox::Yes) + { + // Revert settings + KConfigGroup config(mKWinConfig, "Compositing"); + config.deleteGroup(); + QMap::const_iterator i = mPreviousConfig.constBegin(); + while (i != mPreviousConfig.constEnd()) { + config.writeEntry(i.key(), i.value()); + ++i; + } + config.sync(); + load(); + } +} + void KWinCompositingConfig::initEffectSelector() { // Find all .desktop files of the effects @@ -138,6 +185,13 @@ void KWinCompositingConfig::save() kDebug() ; KConfigGroup config(mKWinConfig, "Compositing"); + // Save current config. We'll use this for restoring in case something + // goes wrong. + mPreviousConfig = config.entryMap(); + // Check if any critical settings that need confirmation have changed + bool confirm = false; + confirm |= (ui.useCompositing->isChecked() != config.readEntry("Enabled", mDefaultPrefs.enableCompositing())); + config.writeEntry("Enabled", ui.useCompositing->isChecked()); // Save effects @@ -158,6 +212,11 @@ void KWinCompositingConfig::save() emit changed( false ); configChanged(); + + if(confirm) + { + showConfirmDialog(); + } } void KWinCompositingConfig::configChanged() diff --git a/kcmkwin/kwincompositing/main.h b/kcmkwin/kwincompositing/main.h index cf659871f4..f0a5728a7a 100644 --- a/kcmkwin/kwincompositing/main.h +++ b/kcmkwin/kwincompositing/main.h @@ -16,6 +16,8 @@ License. See the file "COPYING" for the exact licensing terms. #include +#include + #include "ui_main.h" #include "compositingprefs.h" @@ -24,6 +26,19 @@ class KPluginSelector; namespace KWin { +class ConfirmDialog : public QMessageBox +{ +Q_OBJECT +public: + ConfirmDialog(); + +protected slots: + void advanceTimer(); + +private: + int mSecondsToLive; +}; + class KWinCompositingConfig : public KCModule { Q_OBJECT @@ -36,6 +51,7 @@ class KWinCompositingConfig : public KCModule public slots: virtual void compositingEnabled(bool enabled); virtual void showAdvancedOptions(); + virtual void showConfirmDialog(); virtual void load(); virtual void save(); @@ -45,12 +61,12 @@ class KWinCompositingConfig : public KCModule void configChanged(); void initEffectSelector(); - protected: - private: KSharedConfigPtr mKWinConfig; Ui::KWinCompositingConfig ui; CompositingPrefs mDefaultPrefs; + + QMap mPreviousConfig; }; } // namespace