[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
This commit is contained in:
Vlad Zagorodniy 2019-02-03 18:06:05 +02:00
parent 1faa861bd5
commit bc34a9d653
3 changed files with 35 additions and 4 deletions

View file

@ -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<EffectData> 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) {

View file

@ -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.

View file

@ -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);
}
}