From 39b61238e54818c17b4975ee2d0d150ed61d46dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 17 Mar 2014 19:23:46 +0100 Subject: [PATCH] Load generic scripted config plugin for scripted effects We check whether the effect is scripted and provides a config. If that is the case our normal approach for getting the config plugin fails and we use this case to try to load it again through the generic scripted config plugin. REVIEW: 116863 BUG: 332186 --- kcmkwin/kwincompositing/effectconfig.cpp | 25 ++++++++++++++++++++---- kcmkwin/kwincompositing/effectconfig.h | 2 +- kcmkwin/kwincompositing/model.cpp | 8 ++++++++ kcmkwin/kwincompositing/model.h | 4 +++- kcmkwin/kwincompositing/qml/Effect.qml | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/kcmkwin/kwincompositing/effectconfig.cpp b/kcmkwin/kwincompositing/effectconfig.cpp index 6505efcc8e..b119d31634 100644 --- a/kcmkwin/kwincompositing/effectconfig.cpp +++ b/kcmkwin/kwincompositing/effectconfig.cpp @@ -32,6 +32,8 @@ #include #include +static const QString s_pluginDir = QStringLiteral("kf5/kwin/effects/configs/"); + namespace KWin { namespace Compositing { @@ -40,15 +42,30 @@ EffectConfig::EffectConfig(QObject *parent) { } -void EffectConfig::openConfig(const QString &serviceName) +void EffectConfig::openConfig(const QString &serviceName, bool scripted) { //setup the UI QDialog dialog; // create the KCModule through the plugintrader - KCModule *kcm = KPluginTrader::createInstanceFromQuery(QStringLiteral("kf5/kwin/effects/configs/"), QString(), - QStringLiteral("[X-KDE-ParentComponents] == '%1'").arg(serviceName), - &dialog); + KCModule *kcm = nullptr; + if (scripted) { + // try generic module for scripted + const auto offers = KPluginTrader::self()->query(s_pluginDir, QString(), + QStringLiteral("[X-KDE-Library] == 'kcm_kwin4_genericscripted'")); + if (!offers.isEmpty()) { + const KPluginInfo &generic = offers.first(); + KPluginLoader loader(generic.libraryPath()); + KPluginFactory *factory = loader.factory(); + if (factory) { + kcm = factory->create(serviceName, &dialog); + } + } + } else { + kcm = KPluginTrader::createInstanceFromQuery(s_pluginDir, QString(), + QStringLiteral("[X-KDE-ParentComponents] == '%1'").arg(serviceName), + &dialog); + } if (!kcm) { return; } diff --git a/kcmkwin/kwincompositing/effectconfig.h b/kcmkwin/kwincompositing/effectconfig.h index 3032a7b2a5..09967e8ca4 100644 --- a/kcmkwin/kwincompositing/effectconfig.h +++ b/kcmkwin/kwincompositing/effectconfig.h @@ -36,7 +36,7 @@ public: explicit EffectConfig(QObject *parent = 0); QString serviceName(const QString &serviceName); - Q_INVOKABLE void openConfig(const QString &effectName); + Q_INVOKABLE void openConfig(const QString &effectName, bool scripted); Q_INVOKABLE void openGHNS(); Q_SIGNALS: diff --git a/kcmkwin/kwincompositing/model.cpp b/kcmkwin/kwincompositing/model.cpp index 07dc0d4413..12a0cfb3bb 100644 --- a/kcmkwin/kwincompositing/model.cpp +++ b/kcmkwin/kwincompositing/model.cpp @@ -69,6 +69,7 @@ QHash< int, QByteArray > EffectModel::roleNames() const roleNames[SupportedRole] = "SupportedRole"; roleNames[ExclusiveRole] = "ExclusiveRole"; roleNames[ConfigurableRole] = "ConfigurableRole"; + roleNames[ScriptedRole] = QByteArrayLiteral("ScriptedRole"); return roleNames; } @@ -139,6 +140,8 @@ QVariant EffectModel::data(const QModelIndex &index, int role) const return m_effectsList.at(index.row()).internal; case ConfigurableRole: return m_effectsList.at(index.row()).configurable; + case ScriptedRole: + return m_effectsList.at(index.row()).scripted; default: return QVariant(); } @@ -207,11 +210,16 @@ void EffectModel::loadEffects() effect.supported = true; effect.exclusiveGroup = service->property(QStringLiteral("X-KWin-Exclusive-Category"), QVariant::String).toString(); effect.internal = service->property(QStringLiteral("X-KWin-Internal"), QVariant::Bool).toBool(); + effect.scripted = service->property(QStringLiteral("X-Plasma-API"), QVariant::String).toString().toLower() == QStringLiteral("javascript"); auto it = std::find_if(configs.begin(), configs.end(), [&plugin](const KPluginInfo &info) { return info.property(QStringLiteral("X-KDE-ParentComponents")).toString() == plugin.pluginName(); }); effect.configurable = it != configs.end(); + if (!effect.configurable && effect.scripted && !service->pluginKeyword().isEmpty()) { + // scripted effects have their pluginName() as the keyword + effect.configurable = service->property(QStringLiteral("X-KDE-ParentComponents")).toString() == service->pluginKeyword(); + } m_effectsList << effect; } diff --git a/kcmkwin/kwincompositing/model.h b/kcmkwin/kwincompositing/model.h index 4a97aa3974..2bbb04568b 100644 --- a/kcmkwin/kwincompositing/model.h +++ b/kcmkwin/kwincompositing/model.h @@ -50,6 +50,7 @@ struct EffectData { QString exclusiveGroup; bool internal; bool configurable; + bool scripted; }; class EffectModel : public QAbstractItemModel @@ -73,7 +74,8 @@ public: SupportedRole, ExclusiveRole, InternalRole, - ConfigurableRole + ConfigurableRole, + ScriptedRole }; explicit EffectModel(QObject *parent = 0); diff --git a/kcmkwin/kwincompositing/qml/Effect.qml b/kcmkwin/kwincompositing/qml/Effect.qml index 014f8b22c6..8848cc06cd 100644 --- a/kcmkwin/kwincompositing/qml/Effect.qml +++ b/kcmkwin/kwincompositing/qml/Effect.qml @@ -130,7 +130,7 @@ Rectangle { enabled: effectStatusCheckBox.checked iconName: "configure" onClicked: { - effectConfig.openConfig(model.ServiceNameRole); + effectConfig.openConfig(model.ServiceNameRole, model.ScriptedRole); } }