Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.cpp
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | 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 EffectStatusRole: | ||
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 16 Lines | 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 == EffectModel::EffectStatusRole) { | ||
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 = plugin.website(); | 302 | effect.website = 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 = pluginEffect.website(); | 365 | effect.website = 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 59 Lines • ▼ Show 20 Line(s) | 482 | { | |||
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); | ||
507 | } | 507 | } | ||
508 | 508 | | |||
509 | if (dirtyEffects.isEmpty()) { | 509 | if (dirtyEffects.isEmpty()) { | ||
510 | return; | 510 | return; | ||
511 | } | 511 | } | ||
512 | 512 | | |||
513 | kwinConfig.sync(); | 513 | kwinConfig.sync(); | ||
514 | 514 | | |||
515 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | 515 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||
516 | QStringLiteral("/Effects"), | 516 | QStringLiteral("/Effects"), | ||
517 | QDBusConnection::sessionBus()); | 517 | QDBusConnection::sessionBus()); | ||
518 | for (const EffectData &effect : dirtyEffects) { | 518 | for (const EffectData &effect : dirtyEffects) { | ||
519 | if (effect.effectStatus != Status::Disabled) { | 519 | if (effect.status != Status::Disabled) { | ||
520 | interface.loadEffect(effect.serviceName); | 520 | interface.loadEffect(effect.serviceName); | ||
521 | } else { | 521 | } else { | ||
522 | interface.unloadEffect(effect.serviceName); | 522 | interface.unloadEffect(effect.serviceName); | ||
523 | } | 523 | } | ||
524 | } | 524 | } | ||
525 | } | 525 | } | ||
526 | 526 | | |||
527 | void EffectModel::defaults() | 527 | void EffectModel::defaults() | ||
528 | { | 528 | { | ||
529 | for (int i = 0; i < m_effectsList.count(); ++i) { | 529 | for (int i = 0; i < m_effectsList.count(); ++i) { | ||
530 | const auto &effect = m_effectsList.at(i); | 530 | const auto &effect = m_effectsList.at(i); | ||
531 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | 531 | if (effect.enabledByDefaultFunction && effect.status != Status::EnabledUndeterminded) { | ||
532 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | 532 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | ||
533 | } else if ((bool)effect.effectStatus != effect.enabledByDefault) { | 533 | } else if ((bool)effect.status != effect.enabledByDefault) { | ||
534 | updateEffectStatus(index(i, 0), effect.enabledByDefault ? Status::Enabled : Status::Disabled); | 534 | updateEffectStatus(index(i, 0), effect.enabledByDefault ? Status::Enabled : Status::Disabled); | ||
535 | } | 535 | } | ||
536 | } | 536 | } | ||
537 | } | 537 | } | ||
538 | 538 | | |||
539 | bool EffectModel::needsSave() const | 539 | bool EffectModel::needsSave() const | ||
540 | { | 540 | { | ||
541 | return std::any_of(m_effectsList.constBegin(), m_effectsList.constEnd(), | 541 | return std::any_of(m_effectsList.constBegin(), m_effectsList.constEnd(), | ||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |