Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.cpp
Show First 20 Lines • Show All 193 Lines • ▼ Show 20 Line(s) | 191 | { | |||
---|---|---|---|---|---|
194 | } | 194 | } | ||
195 | 195 | | |||
196 | if (role == EffectModel::EffectStatusRole) { | 196 | if (role == EffectModel::EffectStatusRole) { | ||
197 | // note: whenever the StatusRole is modified (even to the same value) the entry | 197 | // note: whenever the StatusRole is modified (even to the same value) the entry | ||
198 | // gets marked as changed and will get saved to the config file. This means the | 198 | // gets marked as changed and will get saved to the config file. This means the | ||
199 | // config file could get polluted | 199 | // config file could get polluted | ||
200 | EffectData &data = m_effectsList[index.row()]; | 200 | EffectData &data = m_effectsList[index.row()]; | ||
201 | data.effectStatus = Status(value.toInt()); | 201 | data.effectStatus = Status(value.toInt()); | ||
202 | data.changed = true; | 202 | data.changed = data.effectStatus != data.originalStatus; | ||
203 | emit dataChanged(index, index); | 203 | emit dataChanged(index, index); | ||
204 | 204 | | |||
205 | if (data.effectStatus == Status::Enabled && !data.exclusiveGroup.isEmpty()) { | 205 | if (data.effectStatus == Status::Enabled && !data.exclusiveGroup.isEmpty()) { | ||
206 | // need to disable all other exclusive effects in the same category | 206 | // need to disable all other exclusive effects in the same category | ||
207 | for (int i = 0; i < m_effectsList.size(); ++i) { | 207 | for (int i = 0; i < m_effectsList.size(); ++i) { | ||
208 | if (i == index.row()) { | 208 | if (i == index.row()) { | ||
209 | continue; | 209 | continue; | ||
210 | } | 210 | } | ||
211 | EffectData &otherData = m_effectsList[i]; | 211 | EffectData &otherData = m_effectsList[i]; | ||
212 | if (otherData.exclusiveGroup == data.exclusiveGroup) { | 212 | if (otherData.exclusiveGroup == data.exclusiveGroup) { | ||
213 | otherData.effectStatus = Status::Disabled; | 213 | otherData.effectStatus = Status::Disabled; | ||
214 | otherData.changed = true; | 214 | otherData.changed = otherData.effectStatus != otherData.originalStatus; | ||
215 | emit dataChanged(this->index(i, 0), this->index(i, 0)); | 215 | emit dataChanged(this->index(i, 0), this->index(i, 0)); | ||
216 | } | 216 | } | ||
217 | } | 217 | } | ||
218 | } | 218 | } | ||
219 | 219 | | |||
220 | return true; | 220 | return true; | ||
221 | } | 221 | } | ||
222 | 222 | | |||
Show All 21 Lines | 229 | for (auto builtin : builtins) { | |||
244 | const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); | 244 | const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); | ||
245 | if (kwinConfig.hasKey(enabledKey)) { | 245 | if (kwinConfig.hasKey(enabledKey)) { | ||
246 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | 246 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | ||
247 | } else if (data.enabledFunction != nullptr) { | 247 | } else if (data.enabledFunction != nullptr) { | ||
248 | effect.effectStatus = Status::EnabledUndeterminded; | 248 | effect.effectStatus = Status::EnabledUndeterminded; | ||
249 | } else { | 249 | } else { | ||
250 | effect.effectStatus = effectStatus(effect.enabledByDefault); | 250 | effect.effectStatus = effectStatus(effect.enabledByDefault); | ||
251 | } | 251 | } | ||
252 | effect.originalStatus = effect.effectStatus; | ||||
252 | effect.video = data.video; | 253 | effect.video = data.video; | ||
253 | effect.website = QUrl(); | 254 | effect.website = QUrl(); | ||
254 | effect.supported = true; | 255 | effect.supported = true; | ||
255 | effect.exclusiveGroup = data.exclusiveCategory; | 256 | effect.exclusiveGroup = data.exclusiveCategory; | ||
256 | effect.internal = data.internal; | 257 | effect.internal = data.internal; | ||
257 | effect.kind = Kind::BuiltIn; | 258 | effect.kind = Kind::BuiltIn; | ||
258 | 259 | | |||
259 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | 260 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | ||
Show All 24 Lines | 278 | for (const KPluginMetaData &metaData : plugins) { | |||
284 | effect.authorEmail = plugin.email(); | 285 | effect.authorEmail = plugin.email(); | ||
285 | effect.license = plugin.license(); | 286 | effect.license = plugin.license(); | ||
286 | effect.version = plugin.version(); | 287 | effect.version = plugin.version(); | ||
287 | effect.untranslatedCategory = plugin.category(); | 288 | effect.untranslatedCategory = plugin.category(); | ||
288 | effect.category = translatedCategory(plugin.category()); | 289 | effect.category = translatedCategory(plugin.category()); | ||
289 | effect.serviceName = plugin.pluginName(); | 290 | effect.serviceName = plugin.pluginName(); | ||
290 | effect.iconName = plugin.icon(); | 291 | effect.iconName = plugin.icon(); | ||
291 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", plugin.isPluginEnabledByDefault())); | 292 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", plugin.isPluginEnabledByDefault())); | ||
293 | effect.originalStatus = effect.effectStatus; | ||||
292 | effect.enabledByDefault = plugin.isPluginEnabledByDefault(); | 294 | effect.enabledByDefault = plugin.isPluginEnabledByDefault(); | ||
293 | effect.enabledByDefaultFunction = false; | 295 | effect.enabledByDefaultFunction = false; | ||
294 | effect.video = plugin.property(QStringLiteral("X-KWin-Video-Url")).toUrl(); | 296 | effect.video = plugin.property(QStringLiteral("X-KWin-Video-Url")).toUrl(); | ||
295 | effect.website = plugin.website(); | 297 | effect.website = plugin.website(); | ||
296 | effect.supported = true; | 298 | effect.supported = true; | ||
297 | effect.exclusiveGroup = plugin.property(QStringLiteral("X-KWin-Exclusive-Category")).toString(); | 299 | effect.exclusiveGroup = plugin.property(QStringLiteral("X-KWin-Exclusive-Category")).toString(); | ||
298 | effect.internal = plugin.property(QStringLiteral("X-KWin-Internal")).toBool(); | 300 | effect.internal = plugin.property(QStringLiteral("X-KWin-Internal")).toBool(); | ||
299 | effect.kind = Kind::Scripted; | 301 | effect.kind = Kind::Scripted; | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 325 | for (const KPluginMetaData &pluginEffect : pluginEffects) { | |||
361 | if (kwinConfig.hasKey(enabledKey)) { | 363 | if (kwinConfig.hasKey(enabledKey)) { | ||
362 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | 364 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | ||
363 | } else if (effect.enabledByDefaultFunction) { | 365 | } else if (effect.enabledByDefaultFunction) { | ||
364 | effect.effectStatus = Status::EnabledUndeterminded; | 366 | effect.effectStatus = Status::EnabledUndeterminded; | ||
365 | } else { | 367 | } else { | ||
366 | effect.effectStatus = effectStatus(effect.enabledByDefault); | 368 | effect.effectStatus = effectStatus(effect.enabledByDefault); | ||
367 | } | 369 | } | ||
368 | 370 | | |||
371 | effect.originalStatus = effect.effectStatus; | ||||
372 | | ||||
369 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | 373 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | ||
370 | [pluginEffect](const KPluginInfo &info) { | 374 | [pluginEffect](const KPluginInfo &info) { | ||
371 | return info.property(QStringLiteral("X-KDE-ParentComponents")).toString() == pluginEffect.pluginId(); | 375 | return info.property(QStringLiteral("X-KDE-ParentComponents")).toString() == pluginEffect.pluginId(); | ||
372 | } | 376 | } | ||
373 | ); | 377 | ); | ||
374 | 378 | | |||
375 | if (shouldStore(effect)) { | 379 | if (shouldStore(effect)) { | ||
376 | m_effectsList << effect; | 380 | m_effectsList << effect; | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 428 | for (int i = 0; i < effectNames.size(); ++i) { | |||
425 | const bool supportedValue = supportValues.at(i); | 429 | const bool supportedValue = supportValues.at(i); | ||
426 | const QString &effectName = effectNames.at(i); | 430 | const QString &effectName = effectNames.at(i); | ||
427 | auto it = std::find_if(m_effectsList.begin(), m_effectsList.end(), [effectName](const EffectData &data) { | 431 | auto it = std::find_if(m_effectsList.begin(), m_effectsList.end(), [effectName](const EffectData &data) { | ||
428 | return data.serviceName == effectName; | 432 | return data.serviceName == effectName; | ||
429 | }); | 433 | }); | ||
430 | if (it != m_effectsList.end()) { | 434 | if (it != m_effectsList.end()) { | ||
431 | if ((*it).supported != supportedValue) { | 435 | if ((*it).supported != supportedValue) { | ||
432 | (*it).supported = supportedValue; | 436 | (*it).supported = supportedValue; | ||
433 | QModelIndex i = index(findRowByServiceName(effectName), 0); | 437 | QModelIndex i = findByPluginId(effectName); | ||
434 | if (i.isValid()) { | 438 | if (i.isValid()) { | ||
435 | emit dataChanged(i, i, QVector<int>() << SupportedRole); | 439 | emit dataChanged(i, i, QVector<int>() << SupportedRole); | ||
436 | } | 440 | } | ||
437 | } | 441 | } | ||
438 | } | 442 | } | ||
439 | } | 443 | } | ||
440 | } | 444 | } | ||
441 | self->deleteLater(); | 445 | self->deleteLater(); | ||
442 | }); | 446 | }); | ||
443 | } | 447 | } | ||
444 | 448 | | |||
445 | m_effectsChanged = m_effectsList; | 449 | m_effectsChanged = m_effectsList; | ||
446 | endResetModel(); | 450 | endResetModel(); | ||
447 | } | 451 | } | ||
448 | 452 | | |||
449 | int EffectModel::findRowByServiceName(const QString &serviceName) | | |||
450 | { | | |||
451 | for (int it = 0; it < m_effectsList.size(); it++) { | | |||
452 | if (m_effectsList.at(it).serviceName == serviceName) { | | |||
453 | return it; | | |||
454 | } | | |||
455 | } | | |||
456 | return -1; | | |||
457 | } | | |||
458 | | ||||
459 | void EffectModel::syncEffectsToKWin() | 453 | void EffectModel::syncEffectsToKWin() | ||
460 | { | 454 | { | ||
461 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | 455 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||
462 | QStringLiteral("/Effects"), | 456 | QStringLiteral("/Effects"), | ||
463 | QDBusConnection::sessionBus()); | 457 | QDBusConnection::sessionBus()); | ||
464 | for (int it = 0; it < m_effectsList.size(); it++) { | 458 | for (int it = 0; it < m_effectsList.size(); it++) { | ||
465 | if (m_effectsList.at(it).effectStatus == m_effectsChanged.at(it).effectStatus) { | 459 | if (m_effectsList.at(it).effectStatus == m_effectsChanged.at(it).effectStatus) { | ||
466 | continue; | 460 | continue; | ||
Show All 18 Lines | 478 | { | |||
485 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | 479 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||
486 | 480 | | |||
487 | for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) { | 481 | for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) { | ||
488 | EffectData &effect = *(it); | 482 | EffectData &effect = *(it); | ||
489 | if (!effect.changed) { | 483 | if (!effect.changed) { | ||
490 | continue; | 484 | continue; | ||
491 | } | 485 | } | ||
492 | effect.changed = false; | 486 | effect.changed = false; | ||
487 | effect.originalStatus = effect.effectStatus; | ||||
493 | 488 | | |||
494 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | 489 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | ||
495 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | 490 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | ||
496 | const bool restoreToDefault = effect.enabledByDefaultFunction | 491 | const bool restoreToDefault = effect.enabledByDefaultFunction | ||
497 | ? effect.effectStatus == Status::EnabledUndeterminded | 492 | ? effect.effectStatus == Status::EnabledUndeterminded | ||
498 | : shouldEnable == effect.enabledByDefault; | 493 | : shouldEnable == effect.enabledByDefault; | ||
499 | if (restoreToDefault) { | 494 | if (restoreToDefault) { | ||
500 | kwinConfig.deleteEntry(key); | 495 | kwinConfig.deleteEntry(key); | ||
Show All 13 Lines | 507 | for (int i = 0; i < m_effectsList.count(); ++i) { | |||
514 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | 509 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | ||
515 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | 510 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | ||
516 | } else if ((bool)effect.effectStatus != effect.enabledByDefault) { | 511 | } else if ((bool)effect.effectStatus != effect.enabledByDefault) { | ||
517 | updateEffectStatus(index(i, 0), effect.enabledByDefault ? Status::Enabled : Status::Disabled); | 512 | updateEffectStatus(index(i, 0), effect.enabledByDefault ? Status::Enabled : Status::Disabled); | ||
518 | } | 513 | } | ||
519 | } | 514 | } | ||
520 | } | 515 | } | ||
521 | 516 | | |||
517 | bool EffectModel::needsSave() const | ||||
518 | { | ||||
519 | return std::any_of(m_effectsList.constBegin(), m_effectsList.constEnd(), | ||||
520 | [](const EffectData &data) { | ||||
521 | return data.changed; | ||||
522 | } | ||||
523 | ); | ||||
524 | } | ||||
525 | | ||||
526 | QModelIndex EffectModel::findByPluginId(const QString &pluginId) const | ||||
527 | { | ||||
528 | auto it = std::find_if(m_effectsList.constBegin(), m_effectsList.constEnd(), | ||||
529 | [pluginId](const EffectData &data) { | ||||
530 | return data.serviceName == pluginId; | ||||
531 | } | ||||
532 | ); | ||||
533 | if (it == m_effectsList.constEnd()) { | ||||
534 | return {}; | ||||
535 | } | ||||
536 | return index(std::distance(m_effectsList.constBegin(), it), 0); | ||||
537 | } | ||||
538 | | ||||
522 | bool EffectModel::shouldStore(const EffectData &data) const | 539 | bool EffectModel::shouldStore(const EffectData &data) const | ||
523 | { | 540 | { | ||
524 | Q_UNUSED(data) | 541 | Q_UNUSED(data) | ||
525 | return true; | 542 | return true; | ||
526 | } | 543 | } | ||
527 | 544 | | |||
528 | } | 545 | } |