From 7a28a7442ecd9acff5b2d9225a8eb8f424df165a Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Sun, 3 Feb 2019 18:44:06 +0200 Subject: [PATCH] [kcmkwin] Simplify EffectModel::save Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18706 --- kcmkwin/common/effectmodel.cpp | 50 ++++++++++++++++++---------------- kcmkwin/common/effectmodel.h | 2 -- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/kcmkwin/common/effectmodel.cpp b/kcmkwin/common/effectmodel.cpp index 8ee9bbc330..12a51e71b1 100644 --- a/kcmkwin/common/effectmodel.cpp +++ b/kcmkwin/common/effectmodel.cpp @@ -394,7 +394,6 @@ void EffectModel::load(LoadOptions options) const QVector oldEffects = m_effectsList; beginResetModel(); - m_effectsChanged.clear(); m_effectsList.clear(); const KPluginInfo::List configs = KPluginTrader::self()->query(QStringLiteral("kwin/effects/configs/")); loadBuiltInEffects(kwinConfig, configs); @@ -471,29 +470,9 @@ void EffectModel::load(LoadOptions options) }); } - m_effectsChanged = m_effectsList; endResetModel(); } -void EffectModel::syncEffectsToKWin() -{ - OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), - QStringLiteral("/Effects"), - QDBusConnection::sessionBus()); - for (int it = 0; it < m_effectsList.size(); it++) { - if (!m_effectsList.at(it).changed) { - continue; - } - if (m_effectsList.at(it).effectStatus != Status::Disabled) { - interface.loadEffect(m_effectsList.at(it).serviceName); - } else { - interface.unloadEffect(m_effectsList.at(it).serviceName); - } - } - - m_effectsChanged = m_effectsList; -} - void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) { setData(rowIndex, static_cast(effectState), EffectModel::EffectStatusRole); @@ -503,11 +482,13 @@ void EffectModel::save() { KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); - for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) { - EffectData &effect = *(it); + QVector dirtyEffects; + + for (EffectData &effect : m_effectsList) { if (!effect.changed) { continue; } + effect.changed = false; effect.originalStatus = effect.effectStatus; @@ -521,10 +502,31 @@ void EffectModel::save() } else { kwinConfig.writeEntry(key, shouldEnable); } + + dirtyEffects.append(effect); + } + + if (dirtyEffects.isEmpty()) { + return; } kwinConfig.sync(); - syncEffectsToKWin(); + + OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), + QStringLiteral("/Effects"), + QDBusConnection::sessionBus()); + + if (!interface.isValid()) { + return; + } + + for (const EffectData &effect : dirtyEffects) { + if (effect.effectStatus != Status::Disabled) { + interface.loadEffect(effect.serviceName); + } else { + interface.unloadEffect(effect.serviceName); + } + } } void EffectModel::defaults() diff --git a/kcmkwin/common/effectmodel.h b/kcmkwin/common/effectmodel.h index 5923ca5adb..7eb3a1e9ac 100644 --- a/kcmkwin/common/effectmodel.h +++ b/kcmkwin/common/effectmodel.h @@ -251,10 +251,8 @@ private: void loadBuiltInEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs); void loadJavascriptEffects(const KConfigGroup &kwinConfig); void loadPluginEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs); - void syncEffectsToKWin(); QVector m_effectsList; - QVector m_effectsChanged; Q_DISABLE_COPY(EffectModel) };