Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 94 | { | |||
---|---|---|---|---|---|
97 | roleNames[DescriptionRole] = "DescriptionRole"; | 97 | roleNames[DescriptionRole] = "DescriptionRole"; | ||
98 | roleNames[AuthorNameRole] = "AuthorNameRole"; | 98 | roleNames[AuthorNameRole] = "AuthorNameRole"; | ||
99 | roleNames[AuthorEmailRole] = "AuthorEmailRole"; | 99 | roleNames[AuthorEmailRole] = "AuthorEmailRole"; | ||
100 | roleNames[LicenseRole] = "LicenseRole"; | 100 | roleNames[LicenseRole] = "LicenseRole"; | ||
101 | roleNames[VersionRole] = "VersionRole"; | 101 | roleNames[VersionRole] = "VersionRole"; | ||
102 | roleNames[CategoryRole] = "CategoryRole"; | 102 | roleNames[CategoryRole] = "CategoryRole"; | ||
103 | roleNames[ServiceNameRole] = "ServiceNameRole"; | 103 | roleNames[ServiceNameRole] = "ServiceNameRole"; | ||
104 | roleNames[IconNameRole] = "IconNameRole"; | 104 | roleNames[IconNameRole] = "IconNameRole"; | ||
105 | roleNames[EffectStatusRole] = "EffectStatusRole"; | 105 | roleNames[StatusRole] = "StatusRole"; | ||
106 | roleNames[VideoRole] = "VideoRole"; | 106 | roleNames[VideoRole] = "VideoRole"; | ||
107 | roleNames[WebsiteRole] = "WebsiteRole"; | 107 | roleNames[WebsiteRole] = "WebsiteRole"; | ||
108 | roleNames[SupportedRole] = "SupportedRole"; | 108 | roleNames[SupportedRole] = "SupportedRole"; | ||
109 | roleNames[ExclusiveRole] = "ExclusiveRole"; | 109 | roleNames[ExclusiveRole] = "ExclusiveRole"; | ||
110 | roleNames[ConfigurableRole] = "ConfigurableRole"; | 110 | roleNames[ConfigurableRole] = "ConfigurableRole"; | ||
111 | roleNames[ScriptedRole] = QByteArrayLiteral("ScriptedRole"); | 111 | roleNames[ScriptedRole] = QByteArrayLiteral("ScriptedRole"); | ||
112 | roleNames[EnabledByDefaultRole] = "EnabledByDefaultRole"; | 112 | roleNames[EnabledByDefaultRole] = "EnabledByDefaultRole"; | ||
113 | return roleNames; | 113 | return roleNames; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 146 | { | |||
164 | case VersionRole: | 164 | case VersionRole: | ||
165 | return effect.version; | 165 | return effect.version; | ||
166 | case CategoryRole: | 166 | case CategoryRole: | ||
167 | return effect.category; | 167 | return effect.category; | ||
168 | case ServiceNameRole: | 168 | case ServiceNameRole: | ||
169 | return effect.serviceName; | 169 | return effect.serviceName; | ||
170 | case IconNameRole: | 170 | case IconNameRole: | ||
171 | return effect.iconName; | 171 | return effect.iconName; | ||
172 | case EffectStatusRole: | 172 | case StatusRole: | ||
173 | return static_cast<int>(effect.effectStatus); | 173 | return static_cast<int>(effect.status); | ||
174 | case VideoRole: | 174 | case VideoRole: | ||
175 | return effect.video; | 175 | return effect.video; | ||
176 | case WebsiteRole: | 176 | case WebsiteRole: | ||
177 | return effect.website; | 177 | return effect.website; | ||
178 | case SupportedRole: | 178 | case SupportedRole: | ||
179 | return effect.supported; | 179 | return effect.supported; | ||
180 | case ExclusiveRole: | 180 | case ExclusiveRole: | ||
181 | return effect.exclusiveGroup; | 181 | return effect.exclusiveGroup; | ||
Show All 11 Lines | |||||
193 | } | 193 | } | ||
194 | 194 | | |||
195 | bool EffectModel::setData(const QModelIndex &index, const QVariant &value, int role) | 195 | bool EffectModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
196 | { | 196 | { | ||
197 | if (!index.isValid()) { | 197 | if (!index.isValid()) { | ||
198 | return QAbstractItemModel::setData(index, value, role); | 198 | return QAbstractItemModel::setData(index, value, role); | ||
199 | } | 199 | } | ||
200 | 200 | | |||
201 | if (role == EffectModel::EffectStatusRole) { | 201 | if (role == StatusRole) { | ||
202 | // note: whenever the StatusRole is modified (even to the same value) the entry | 202 | // note: whenever the StatusRole is modified (even to the same value) the entry | ||
203 | // gets marked as changed and will get saved to the config file. This means the | 203 | // gets marked as changed and will get saved to the config file. This means the | ||
204 | // config file could get polluted | 204 | // config file could get polluted | ||
205 | EffectData &data = m_effectsList[index.row()]; | 205 | EffectData &data = m_effectsList[index.row()]; | ||
206 | data.effectStatus = Status(value.toInt()); | 206 | data.status = Status(value.toInt()); | ||
207 | data.changed = data.effectStatus != data.originalStatus; | 207 | data.changed = data.status != data.originalStatus; | ||
208 | emit dataChanged(index, index); | 208 | emit dataChanged(index, index); | ||
209 | 209 | | |||
210 | if (data.effectStatus == Status::Enabled && !data.exclusiveGroup.isEmpty()) { | 210 | if (data.status == Status::Enabled && !data.exclusiveGroup.isEmpty()) { | ||
211 | // need to disable all other exclusive effects in the same category | 211 | // need to disable all other exclusive effects in the same category | ||
212 | for (int i = 0; i < m_effectsList.size(); ++i) { | 212 | for (int i = 0; i < m_effectsList.size(); ++i) { | ||
213 | if (i == index.row()) { | 213 | if (i == index.row()) { | ||
214 | continue; | 214 | continue; | ||
215 | } | 215 | } | ||
216 | EffectData &otherData = m_effectsList[i]; | 216 | EffectData &otherData = m_effectsList[i]; | ||
217 | if (otherData.exclusiveGroup == data.exclusiveGroup) { | 217 | if (otherData.exclusiveGroup == data.exclusiveGroup) { | ||
218 | otherData.effectStatus = Status::Disabled; | 218 | otherData.status = Status::Disabled; | ||
219 | otherData.changed = otherData.effectStatus != otherData.originalStatus; | 219 | otherData.changed = otherData.status != otherData.originalStatus; | ||
220 | emit dataChanged(this->index(i, 0), this->index(i, 0)); | 220 | emit dataChanged(this->index(i, 0), this->index(i, 0)); | ||
221 | } | 221 | } | ||
222 | } | 222 | } | ||
223 | } | 223 | } | ||
224 | 224 | | |||
225 | return true; | 225 | return true; | ||
226 | } | 226 | } | ||
227 | 227 | | |||
Show All 15 Lines | 234 | for (auto builtin : builtins) { | |||
243 | effect.untranslatedCategory = data.category; | 243 | effect.untranslatedCategory = data.category; | ||
244 | effect.category = translatedCategory(data.category); | 244 | effect.category = translatedCategory(data.category); | ||
245 | effect.serviceName = data.name; | 245 | effect.serviceName = data.name; | ||
246 | effect.iconName = QStringLiteral("preferences-system-windows"); | 246 | effect.iconName = QStringLiteral("preferences-system-windows"); | ||
247 | effect.enabledByDefault = data.enabled; | 247 | effect.enabledByDefault = data.enabled; | ||
248 | effect.enabledByDefaultFunction = (data.enabledFunction != nullptr); | 248 | effect.enabledByDefaultFunction = (data.enabledFunction != nullptr); | ||
249 | const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); | 249 | const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); | ||
250 | if (kwinConfig.hasKey(enabledKey)) { | 250 | if (kwinConfig.hasKey(enabledKey)) { | ||
251 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | 251 | effect.status = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | ||
252 | } else if (data.enabledFunction != nullptr) { | 252 | } else if (data.enabledFunction != nullptr) { | ||
253 | effect.effectStatus = Status::EnabledUndeterminded; | 253 | effect.status = Status::EnabledUndeterminded; | ||
254 | } else { | 254 | } else { | ||
255 | effect.effectStatus = effectStatus(effect.enabledByDefault); | 255 | effect.status = effectStatus(effect.enabledByDefault); | ||
256 | } | 256 | } | ||
257 | effect.originalStatus = effect.effectStatus; | 257 | effect.originalStatus = effect.status; | ||
258 | effect.video = data.video; | 258 | effect.video = data.video; | ||
259 | effect.website = QUrl(); | 259 | effect.website = QUrl(); | ||
260 | effect.supported = true; | 260 | effect.supported = true; | ||
261 | effect.exclusiveGroup = data.exclusiveCategory; | 261 | effect.exclusiveGroup = data.exclusiveCategory; | ||
262 | effect.internal = data.internal; | 262 | effect.internal = data.internal; | ||
263 | effect.kind = Kind::BuiltIn; | 263 | effect.kind = Kind::BuiltIn; | ||
264 | 264 | | |||
265 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | 265 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | ||
Show All 23 Lines | 283 | for (const KPluginMetaData &metaData : plugins) { | |||
289 | effect.authorName = plugin.author(); | 289 | effect.authorName = plugin.author(); | ||
290 | effect.authorEmail = plugin.email(); | 290 | effect.authorEmail = plugin.email(); | ||
291 | effect.license = plugin.license(); | 291 | effect.license = plugin.license(); | ||
292 | effect.version = plugin.version(); | 292 | effect.version = plugin.version(); | ||
293 | effect.untranslatedCategory = plugin.category(); | 293 | effect.untranslatedCategory = plugin.category(); | ||
294 | effect.category = translatedCategory(plugin.category()); | 294 | effect.category = translatedCategory(plugin.category()); | ||
295 | effect.serviceName = plugin.pluginName(); | 295 | effect.serviceName = plugin.pluginName(); | ||
296 | effect.iconName = plugin.icon(); | 296 | effect.iconName = plugin.icon(); | ||
297 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", plugin.isPluginEnabledByDefault())); | 297 | effect.status = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", plugin.isPluginEnabledByDefault())); | ||
298 | effect.originalStatus = effect.effectStatus; | 298 | effect.originalStatus = effect.status; | ||
299 | effect.enabledByDefault = plugin.isPluginEnabledByDefault(); | 299 | effect.enabledByDefault = plugin.isPluginEnabledByDefault(); | ||
300 | effect.enabledByDefaultFunction = false; | 300 | effect.enabledByDefaultFunction = false; | ||
301 | effect.video = plugin.property(QStringLiteral("X-KWin-Video-Url")).toUrl(); | 301 | effect.video = plugin.property(QStringLiteral("X-KWin-Video-Url")).toUrl(); | ||
302 | effect.website = QUrl(plugin.website()); | 302 | effect.website = QUrl(plugin.website()); | ||
303 | effect.supported = true; | 303 | effect.supported = true; | ||
304 | effect.exclusiveGroup = plugin.property(QStringLiteral("X-KWin-Exclusive-Category")).toString(); | 304 | effect.exclusiveGroup = plugin.property(QStringLiteral("X-KWin-Exclusive-Category")).toString(); | ||
305 | effect.internal = plugin.property(QStringLiteral("X-KWin-Internal")).toBool(); | 305 | effect.internal = plugin.property(QStringLiteral("X-KWin-Internal")).toBool(); | ||
306 | effect.kind = Kind::Scripted; | 306 | effect.kind = Kind::Scripted; | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 358 | if (pluginEffect.rawData().contains("org.kde.kwin.effect")) { | |||
361 | effect.video = QUrl::fromUserInput(d.value("video").toString()); | 361 | effect.video = QUrl::fromUserInput(d.value("video").toString()); | ||
362 | effect.enabledByDefaultFunction = d.value("enabledByDefaultMethod").toBool(); | 362 | effect.enabledByDefaultFunction = d.value("enabledByDefaultMethod").toBool(); | ||
363 | } | 363 | } | ||
364 | 364 | | |||
365 | effect.website = QUrl(pluginEffect.website()); | 365 | effect.website = QUrl(pluginEffect.website()); | ||
366 | 366 | | |||
367 | const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); | 367 | const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); | ||
368 | if (kwinConfig.hasKey(enabledKey)) { | 368 | if (kwinConfig.hasKey(enabledKey)) { | ||
369 | effect.effectStatus = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | 369 | effect.status = effectStatus(kwinConfig.readEntry(effect.serviceName + "Enabled", effect.enabledByDefault)); | ||
370 | } else if (effect.enabledByDefaultFunction) { | 370 | } else if (effect.enabledByDefaultFunction) { | ||
371 | effect.effectStatus = Status::EnabledUndeterminded; | 371 | effect.status = Status::EnabledUndeterminded; | ||
372 | } else { | 372 | } else { | ||
373 | effect.effectStatus = effectStatus(effect.enabledByDefault); | 373 | effect.status = effectStatus(effect.enabledByDefault); | ||
374 | } | 374 | } | ||
375 | 375 | | |||
376 | effect.originalStatus = effect.effectStatus; | 376 | effect.originalStatus = effect.status; | ||
377 | 377 | | |||
378 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | 378 | effect.configurable = std::any_of(configs.constBegin(), configs.constEnd(), | ||
379 | [pluginEffect](const KPluginInfo &info) { | 379 | [pluginEffect](const KPluginInfo &info) { | ||
380 | return info.property(QStringLiteral("X-KDE-ParentComponents")).toString() == pluginEffect.pluginId(); | 380 | return info.property(QStringLiteral("X-KDE-ParentComponents")).toString() == pluginEffect.pluginId(); | ||
381 | } | 381 | } | ||
382 | ); | 382 | ); | ||
383 | 383 | | |||
384 | if (shouldStore(effect)) { | 384 | if (shouldStore(effect)) { | ||
Show All 23 Lines | 404 | for (const EffectData &oldEffect : oldEffects) { | |||
408 | auto effectIt = std::find_if(m_effectsList.begin(), m_effectsList.end(), | 408 | auto effectIt = std::find_if(m_effectsList.begin(), m_effectsList.end(), | ||
409 | [serviceName = oldEffect.serviceName](const EffectData &data) { | 409 | [serviceName = oldEffect.serviceName](const EffectData &data) { | ||
410 | return data.serviceName == serviceName; | 410 | return data.serviceName == serviceName; | ||
411 | } | 411 | } | ||
412 | ); | 412 | ); | ||
413 | if (effectIt == m_effectsList.end()) { | 413 | if (effectIt == m_effectsList.end()) { | ||
414 | continue; | 414 | continue; | ||
415 | } | 415 | } | ||
416 | effectIt->effectStatus = oldEffect.effectStatus; | 416 | effectIt->status = oldEffect.status; | ||
417 | effectIt->changed = effectIt->effectStatus != effectIt->originalStatus; | 417 | effectIt->changed = effectIt->status != effectIt->originalStatus; | ||
418 | } | 418 | } | ||
419 | } | 419 | } | ||
420 | 420 | | |||
421 | qSort(m_effectsList.begin(), m_effectsList.end(), [](const EffectData &a, const EffectData &b) { | 421 | qSort(m_effectsList.begin(), m_effectsList.end(), [](const EffectData &a, const EffectData &b) { | ||
422 | if (a.category == b.category) { | 422 | if (a.category == b.category) { | ||
423 | if (a.exclusiveGroup == b.exclusiveGroup) { | 423 | if (a.exclusiveGroup == b.exclusiveGroup) { | ||
424 | return a.name < b.name; | 424 | return a.name < b.name; | ||
425 | } | 425 | } | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 435 | if (interface.isValid()) { | |||
470 | }); | 470 | }); | ||
471 | } | 471 | } | ||
472 | 472 | | |||
473 | endResetModel(); | 473 | endResetModel(); | ||
474 | } | 474 | } | ||
475 | 475 | | |||
476 | void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) | 476 | void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) | ||
477 | { | 477 | { | ||
478 | setData(rowIndex, static_cast<int>(effectState), EffectModel::EffectStatusRole); | 478 | setData(rowIndex, static_cast<int>(effectState), StatusRole); | ||
479 | } | 479 | } | ||
480 | 480 | | |||
481 | void EffectModel::save() | 481 | void EffectModel::save() | ||
482 | { | 482 | { | ||
483 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | 483 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||
484 | 484 | | |||
485 | QVector<EffectData> dirtyEffects; | 485 | QVector<EffectData> dirtyEffects; | ||
486 | 486 | | |||
487 | for (EffectData &effect : m_effectsList) { | 487 | for (EffectData &effect : m_effectsList) { | ||
488 | if (!effect.changed) { | 488 | if (!effect.changed) { | ||
489 | continue; | 489 | continue; | ||
490 | } | 490 | } | ||
491 | 491 | | |||
492 | effect.changed = false; | 492 | effect.changed = false; | ||
493 | effect.originalStatus = effect.effectStatus; | 493 | effect.originalStatus = effect.status; | ||
494 | 494 | | |||
495 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | 495 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | ||
496 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | 496 | const bool shouldEnable = (effect.status != Status::Disabled); | ||
497 | const bool restoreToDefault = effect.enabledByDefaultFunction | 497 | const bool restoreToDefault = effect.enabledByDefaultFunction | ||
498 | ? effect.effectStatus == Status::EnabledUndeterminded | 498 | ? effect.status == Status::EnabledUndeterminded | ||
499 | : shouldEnable == effect.enabledByDefault; | 499 | : shouldEnable == effect.enabledByDefault; | ||
500 | if (restoreToDefault) { | 500 | if (restoreToDefault) { | ||
501 | kwinConfig.deleteEntry(key); | 501 | kwinConfig.deleteEntry(key); | ||
502 | } else { | 502 | } else { | ||
503 | kwinConfig.writeEntry(key, shouldEnable); | 503 | kwinConfig.writeEntry(key, shouldEnable); | ||
504 | } | 504 | } | ||
505 | 505 | | |||
506 | dirtyEffects.append(effect); | 506 | dirtyEffects.append(effect); | ||
Show All 9 Lines | 515 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | |||
516 | QStringLiteral("/Effects"), | 516 | QStringLiteral("/Effects"), | ||
517 | QDBusConnection::sessionBus()); | 517 | QDBusConnection::sessionBus()); | ||
518 | 518 | | |||
519 | if (!interface.isValid()) { | 519 | if (!interface.isValid()) { | ||
520 | return; | 520 | return; | ||
521 | } | 521 | } | ||
522 | 522 | | |||
523 | for (const EffectData &effect : dirtyEffects) { | 523 | for (const EffectData &effect : dirtyEffects) { | ||
524 | if (effect.effectStatus != Status::Disabled) { | 524 | if (effect.status != Status::Disabled) { | ||
525 | interface.loadEffect(effect.serviceName); | 525 | interface.loadEffect(effect.serviceName); | ||
526 | } else { | 526 | } else { | ||
527 | interface.unloadEffect(effect.serviceName); | 527 | interface.unloadEffect(effect.serviceName); | ||
528 | } | 528 | } | ||
529 | } | 529 | } | ||
530 | } | 530 | } | ||
531 | 531 | | |||
532 | void EffectModel::defaults() | 532 | void EffectModel::defaults() | ||
533 | { | 533 | { | ||
534 | for (int i = 0; i < m_effectsList.count(); ++i) { | 534 | for (int i = 0; i < m_effectsList.count(); ++i) { | ||
535 | const auto &effect = m_effectsList.at(i); | 535 | const auto &effect = m_effectsList.at(i); | ||
536 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | 536 | if (effect.enabledByDefaultFunction && effect.status != Status::EnabledUndeterminded) { | ||
537 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | 537 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | ||
538 | } else if ((bool)effect.effectStatus != effect.enabledByDefault) { | 538 | } else if ((bool)effect.status != effect.enabledByDefault) { | ||
539 | updateEffectStatus(index(i, 0), effect.enabledByDefault ? Status::Enabled : Status::Disabled); | 539 | updateEffectStatus(index(i, 0), effect.enabledByDefault ? Status::Enabled : Status::Disabled); | ||
540 | } | 540 | } | ||
541 | } | 541 | } | ||
542 | } | 542 | } | ||
543 | 543 | | |||
544 | bool EffectModel::needsSave() const | 544 | bool EffectModel::needsSave() const | ||
545 | { | 545 | { | ||
546 | return std::any_of(m_effectsList.constBegin(), m_effectsList.constEnd(), | 546 | return std::any_of(m_effectsList.constBegin(), m_effectsList.constEnd(), | ||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |