Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.cpp
Show First 20 Lines • Show All 388 Lines • ▼ Show 20 Line(s) | |||||
389 | 389 | | |||
390 | void EffectModel::load(LoadOptions options) | 390 | void EffectModel::load(LoadOptions options) | ||
391 | { | 391 | { | ||
392 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | 392 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||
393 | 393 | | |||
394 | const QVector<EffectData> oldEffects = m_effectsList; | 394 | const QVector<EffectData> oldEffects = m_effectsList; | ||
395 | 395 | | |||
396 | beginResetModel(); | 396 | beginResetModel(); | ||
397 | m_effectsChanged.clear(); | | |||
398 | m_effectsList.clear(); | 397 | m_effectsList.clear(); | ||
399 | const KPluginInfo::List configs = KPluginTrader::self()->query(QStringLiteral("kwin/effects/configs/")); | 398 | const KPluginInfo::List configs = KPluginTrader::self()->query(QStringLiteral("kwin/effects/configs/")); | ||
400 | loadBuiltInEffects(kwinConfig, configs); | 399 | loadBuiltInEffects(kwinConfig, configs); | ||
401 | loadJavascriptEffects(kwinConfig); | 400 | loadJavascriptEffects(kwinConfig); | ||
402 | loadPluginEffects(kwinConfig, configs); | 401 | loadPluginEffects(kwinConfig, configs); | ||
403 | 402 | | |||
404 | if (options == LoadOptions::KeepDirty) { | 403 | if (options == LoadOptions::KeepDirty) { | ||
405 | for (const EffectData &oldEffect : oldEffects) { | 404 | for (const EffectData &oldEffect : oldEffects) { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 458 | if (it != m_effectsList.end()) { | |||
466 | } | 465 | } | ||
467 | } | 466 | } | ||
468 | } | 467 | } | ||
469 | } | 468 | } | ||
470 | self->deleteLater(); | 469 | self->deleteLater(); | ||
471 | }); | 470 | }); | ||
472 | } | 471 | } | ||
473 | 472 | | |||
474 | m_effectsChanged = m_effectsList; | | |||
475 | endResetModel(); | 473 | endResetModel(); | ||
476 | } | 474 | } | ||
477 | 475 | | |||
478 | void EffectModel::syncEffectsToKWin() | | |||
479 | { | | |||
480 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | | |||
481 | QStringLiteral("/Effects"), | | |||
482 | QDBusConnection::sessionBus()); | | |||
483 | for (int it = 0; it < m_effectsList.size(); it++) { | | |||
484 | if (m_effectsList.at(it).effectStatus == m_effectsChanged.at(it).effectStatus) { | | |||
485 | continue; | | |||
486 | } | | |||
487 | if (m_effectsList.at(it).effectStatus != Status::Disabled) { | | |||
488 | interface.loadEffect(m_effectsList.at(it).serviceName); | | |||
489 | } else { | | |||
490 | interface.unloadEffect(m_effectsList.at(it).serviceName); | | |||
491 | } | | |||
492 | } | | |||
493 | | ||||
494 | m_effectsChanged = m_effectsList; | | |||
495 | } | | |||
496 | | ||||
497 | void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) | 476 | void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) | ||
498 | { | 477 | { | ||
499 | setData(rowIndex, static_cast<int>(effectState), EffectModel::EffectStatusRole); | 478 | setData(rowIndex, static_cast<int>(effectState), EffectModel::EffectStatusRole); | ||
500 | } | 479 | } | ||
501 | 480 | | |||
502 | void EffectModel::save() | 481 | void EffectModel::save() | ||
503 | { | 482 | { | ||
504 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | 483 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||
505 | 484 | | |||
506 | for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) { | 485 | QVector<EffectData> dirtyEffects; | ||
507 | EffectData &effect = *(it); | 486 | | ||
487 | for (EffectData &effect : m_effectsList) { | ||||
508 | if (!effect.changed) { | 488 | if (!effect.changed) { | ||
509 | continue; | 489 | continue; | ||
510 | } | 490 | } | ||
491 | | ||||
511 | effect.changed = false; | 492 | effect.changed = false; | ||
512 | effect.originalStatus = effect.effectStatus; | 493 | effect.originalStatus = effect.effectStatus; | ||
513 | 494 | | |||
514 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | 495 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | ||
515 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | 496 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | ||
516 | const bool restoreToDefault = effect.enabledByDefaultFunction | 497 | const bool restoreToDefault = effect.enabledByDefaultFunction | ||
517 | ? effect.effectStatus == Status::EnabledUndeterminded | 498 | ? effect.effectStatus == Status::EnabledUndeterminded | ||
518 | : shouldEnable == effect.enabledByDefault; | 499 | : shouldEnable == effect.enabledByDefault; | ||
519 | if (restoreToDefault) { | 500 | if (restoreToDefault) { | ||
520 | kwinConfig.deleteEntry(key); | 501 | kwinConfig.deleteEntry(key); | ||
521 | } else { | 502 | } else { | ||
522 | kwinConfig.writeEntry(key, shouldEnable); | 503 | kwinConfig.writeEntry(key, shouldEnable); | ||
523 | } | 504 | } | ||
505 | | ||||
506 | dirtyEffects.append(effect); | ||||
507 | } | ||||
508 | | ||||
509 | if (dirtyEffects.isEmpty()) { | ||||
510 | return; | ||||
524 | } | 511 | } | ||
525 | 512 | | |||
526 | kwinConfig.sync(); | 513 | kwinConfig.sync(); | ||
527 | syncEffectsToKWin(); | 514 | | ||
515 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||||
516 | QStringLiteral("/Effects"), | ||||
517 | QDBusConnection::sessionBus()); | ||||
518 | | ||||
519 | if (!interface.isValid()) { | ||||
520 | return; | ||||
521 | } | ||||
522 | | ||||
523 | for (const EffectData &effect : dirtyEffects) { | ||||
524 | if (effect.effectStatus != Status::Disabled) { | ||||
525 | interface.loadEffect(effect.serviceName); | ||||
526 | } else { | ||||
527 | interface.unloadEffect(effect.serviceName); | ||||
528 | } | ||||
529 | } | ||||
528 | } | 530 | } | ||
529 | 531 | | |||
530 | void EffectModel::defaults() | 532 | void EffectModel::defaults() | ||
531 | { | 533 | { | ||
532 | for (int i = 0; i < m_effectsList.count(); ++i) { | 534 | for (int i = 0; i < m_effectsList.count(); ++i) { | ||
533 | const auto &effect = m_effectsList.at(i); | 535 | const auto &effect = m_effectsList.at(i); | ||
534 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | 536 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | ||
535 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | 537 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |