From bc34a9d65379905ecebd190f4248ceed0a947594 Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Sun, 3 Feb 2019 18:06:05 +0200 Subject: [PATCH] [kcmkwin] Don't discard unsaved changes when reloading effects model Summary: If an effect is installed or removed, then all not yet committed changes will be lost. This is undesired behaviour. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D18705 --- kcmkwin/common/effectmodel.cpp | 24 ++++++++++++++++++++++-- kcmkwin/common/effectmodel.h | 13 ++++++++++++- kcmkwin/kwineffects/kcm.cpp | 2 +- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/kcmkwin/common/effectmodel.cpp b/kcmkwin/common/effectmodel.cpp index 9ca380876b..8ee9bbc330 100644 --- a/kcmkwin/common/effectmodel.cpp +++ b/kcmkwin/common/effectmodel.cpp @@ -387,10 +387,12 @@ void EffectModel::loadPluginEffects(const KConfigGroup &kwinConfig, const KPlugi } } -void EffectModel::load() +void EffectModel::load(LoadOptions options) { KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); + const QVector oldEffects = m_effectsList; + beginResetModel(); m_effectsChanged.clear(); m_effectsList.clear(); @@ -399,6 +401,24 @@ void EffectModel::load() loadJavascriptEffects(kwinConfig); loadPluginEffects(kwinConfig, configs); + if (options == LoadOptions::KeepDirty) { + for (const EffectData &oldEffect : oldEffects) { + if (!oldEffect.changed) { + continue; + } + auto effectIt = std::find_if(m_effectsList.begin(), m_effectsList.end(), + [serviceName = oldEffect.serviceName](const EffectData &data) { + return data.serviceName == serviceName; + } + ); + if (effectIt == m_effectsList.end()) { + continue; + } + effectIt->effectStatus = oldEffect.effectStatus; + effectIt->changed = effectIt->effectStatus != effectIt->originalStatus; + } + } + qSort(m_effectsList.begin(), m_effectsList.end(), [](const EffectData &a, const EffectData &b) { if (a.category == b.category) { if (a.exclusiveGroup == b.exclusiveGroup) { @@ -461,7 +481,7 @@ void EffectModel::syncEffectsToKWin() QStringLiteral("/Effects"), QDBusConnection::sessionBus()); for (int it = 0; it < m_effectsList.size(); it++) { - if (m_effectsList.at(it).effectStatus == m_effectsChanged.at(it).effectStatus) { + if (!m_effectsList.at(it).changed) { continue; } if (m_effectsList.at(it).effectStatus != Status::Disabled) { diff --git a/kcmkwin/common/effectmodel.h b/kcmkwin/common/effectmodel.h index bbbaf9689f..5923ca5adb 100644 --- a/kcmkwin/common/effectmodel.h +++ b/kcmkwin/common/effectmodel.h @@ -159,12 +159,23 @@ public: **/ void updateEffectStatus(const QModelIndex &rowIndex, Status effectState); + /** + * This enum type is used to specify load options. + **/ + enum class LoadOptions { + None, + /** + * Do not discard unsaved changes when reloading the model. + **/ + KeepDirty + }; + /** * Loads effects. * * You have to call this method in order to populate the model. **/ - void load(); + void load(LoadOptions options = LoadOptions::None); /** * Saves status of each modified effect. diff --git a/kcmkwin/kwineffects/kcm.cpp b/kcmkwin/kwineffects/kcm.cpp index d35a38621a..1bac16512b 100644 --- a/kcmkwin/kwineffects/kcm.cpp +++ b/kcmkwin/kwineffects/kcm.cpp @@ -93,7 +93,7 @@ void DesktopEffectsKCM::openGHNS(QQuickItem *context) if (dialog->exec() == QDialog::Accepted) { if (!dialog->changedEntries().isEmpty()) { - m_model->load(); + m_model->load(EffectModel::LoadOptions::KeepDirty); } }