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
This commit is contained in:
Rivo Laks 2007-09-18 19:00:23 +00:00
parent 1112d7fd69
commit d965cdee99
2 changed files with 77 additions and 2 deletions

View file

@ -23,6 +23,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include <kservice.h>
#include <QtDBus/QtDBus>
#include <QTimer>
#include <KPluginFactory>
#include <KPluginLoader>
@ -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<QString, QString>::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()

View file

@ -16,6 +16,8 @@ License. See the file "COPYING" for the exact licensing terms.
#include <ksharedconfig.h>
#include <QMessageBox>
#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<QString, QString> mPreviousConfig;
};
} // namespace