From ca14073b543105e4ca7e0a5811578b18d966befe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 6 Jul 2015 16:50:33 +0200 Subject: [PATCH] Port scripted effect loading from KService to KPackage Advantage: no more ksycoca cache for loading scripted effects. --- CMakeLists.txt | 2 + autotests/CMakeLists.txt | 3 ++ autotests/test_builtin_effectloader.cpp | 2 +- autotests/test_plugin_effectloader.cpp | 2 +- autotests/test_scripted_effectloader.cpp | 9 ++-- effectloader.cpp | 52 ++++++++++++------------ effectloader.h | 10 ++--- effects.h | 2 - scripting/scriptedeffect.cpp | 9 ++-- scripting/scriptedeffect.h | 4 +- 10 files changed, 52 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 735cd8105c..a94bbe6e8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Init Notifications Service + Package Plasma WidgetsAddons WindowSystem @@ -502,6 +503,7 @@ set(kwin_KDE_LIBS KF5::I18n KF5::Notifications KF5::Service + KF5::Package KF5::Plasma KF5::WindowSystem KDecoration2::KDecoration diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 502fd510cb..037462401e 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -124,6 +124,7 @@ add_executable( testBuiltInEffectLoader ${testBuiltInEffectLoader_SRCS}) target_link_libraries(testBuiltInEffectLoader Qt5::Concurrent Qt5::Test + KF5::Package kwineffects kwin4_effect_builtins ) @@ -151,6 +152,7 @@ target_link_libraries(testScriptedEffectLoader KF5::ConfigGui KF5::GlobalAccel KF5::I18n + KF5::Package kwineffects kwin4_effect_builtins ) @@ -171,6 +173,7 @@ add_executable( testPluginEffectLoader ${testPluginEffectLoader_SRCS}) target_link_libraries(testPluginEffectLoader Qt5::Concurrent Qt5::Test + KF5::Package kwineffects kwin4_effect_builtins ) diff --git a/autotests/test_builtin_effectloader.cpp b/autotests/test_builtin_effectloader.cpp index 1ee2be36d4..ce91501107 100644 --- a/autotests/test_builtin_effectloader.cpp +++ b/autotests/test_builtin_effectloader.cpp @@ -38,7 +38,7 @@ Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core") namespace KWin { -ScriptedEffect *ScriptedEffect::create(KService::Ptr) +ScriptedEffect *ScriptedEffect::create(const KPluginMetaData&) { return nullptr; } diff --git a/autotests/test_plugin_effectloader.cpp b/autotests/test_plugin_effectloader.cpp index c34a97aec6..ed24105c1e 100644 --- a/autotests/test_plugin_effectloader.cpp +++ b/autotests/test_plugin_effectloader.cpp @@ -37,7 +37,7 @@ Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core") namespace KWin { -ScriptedEffect *ScriptedEffect::create(KService::Ptr) +ScriptedEffect *ScriptedEffect::create(const KPluginMetaData&) { return nullptr; } diff --git a/autotests/test_scripted_effectloader.cpp b/autotests/test_scripted_effectloader.cpp index e7ab7c8db1..532c085dcb 100644 --- a/autotests/test_scripted_effectloader.cpp +++ b/autotests/test_scripted_effectloader.cpp @@ -26,7 +26,7 @@ along with this program. If not, see . // KDE #include #include -#include +#include // Qt #include #include @@ -262,8 +262,11 @@ void TestScriptedEffectLoader::testLoadScriptedEffect() KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); - const auto services = KServiceTypeTrader::self()->query(QStringLiteral("KWin/Effect"), - QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(name)); + const auto services = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Effect"), QStringLiteral("kwin/effects"), + [name] (const KPluginMetaData &metadata) { + return metadata.pluginId().compare(name, Qt::CaseInsensitive) == 0; + } + ); QCOMPARE(services.count(), 1); qRegisterMetaType(); diff --git a/effectloader.cpp b/effectloader.cpp index 73a7c9a54e..a50319a944 100644 --- a/effectloader.cpp +++ b/effectloader.cpp @@ -28,7 +28,8 @@ along with this program. If not, see . // KDE #include #include -#include +#include +#include // Qt #include #include @@ -183,7 +184,7 @@ static const QString s_serviceType = QStringLiteral("KWin/Effect"); ScriptedEffectLoader::ScriptedEffectLoader(QObject *parent) : AbstractEffectLoader(parent) - , m_queue(new EffectLoadQueue(this)) + , m_queue(new EffectLoadQueue(this)) { } @@ -193,7 +194,7 @@ ScriptedEffectLoader::~ScriptedEffectLoader() bool ScriptedEffectLoader::hasEffect(const QString &name) const { - return findEffect(name); + return findEffect(name).isValid(); } bool ScriptedEffectLoader::isEffectSupported(const QString &name) const @@ -204,26 +205,26 @@ bool ScriptedEffectLoader::isEffectSupported(const QString &name) const QStringList ScriptedEffectLoader::listOfKnownEffects() const { - const KService::List effects = findAllEffects(); + const auto effects = findAllEffects(); QStringList result; - for (KService::Ptr service : effects) { - result << service->property(s_nameProperty).toString(); + for (const auto &service : effects) { + result << service.pluginId(); } return result; } bool ScriptedEffectLoader::loadEffect(const QString &name) { - KService::Ptr effect = findEffect(name); - if (!effect) { + auto effect = findEffect(name); + if (!effect.isValid()) { return false; } return loadEffect(effect, LoadEffectFlag::Load); } -bool ScriptedEffectLoader::loadEffect(KService::Ptr effect, LoadEffectFlags flags) +bool ScriptedEffectLoader::loadEffect(const KPluginMetaData &effect, LoadEffectFlags flags) { - const QString name = effect->property(s_nameProperty).toString(); + const QString name = effect.pluginId(); if (!flags.testFlag(LoadEffectFlag::Load)) { qCDebug(KWIN_CORE) << "Loading flags disable effect: " << name; return false; @@ -253,13 +254,12 @@ bool ScriptedEffectLoader::loadEffect(KService::Ptr effect, LoadEffectFlags flag void ScriptedEffectLoader::queryAndLoadAll() { // perform querying for the services in a thread - QFutureWatcher *watcher = new QFutureWatcher(this); - connect(watcher, &QFutureWatcher::finished, this, + QFutureWatcher> *watcher = new QFutureWatcher>(this); + connect(watcher, &QFutureWatcher>::finished, this, [this, watcher]() { - const KService::List effects = watcher->result(); - for (KService::Ptr effect : effects) { - const LoadEffectFlags flags = readConfig(effect->property(s_nameProperty).toString(), - effect->property(QStringLiteral("X-KDE-PluginInfo-EnabledByDefault")).toBool()); + const auto effects = watcher->result(); + for (auto effect : effects) { + const LoadEffectFlags flags = readConfig(effect.pluginId(), effect.isEnabledByDefault()); if (flags.testFlag(LoadEffectFlag::Load)) { m_queue->enqueue(qMakePair(effect, flags)); } @@ -270,20 +270,22 @@ void ScriptedEffectLoader::queryAndLoadAll() watcher->setFuture(QtConcurrent::run(this, &ScriptedEffectLoader::findAllEffects)); } -KService::List ScriptedEffectLoader::findAllEffects() const +QList ScriptedEffectLoader::findAllEffects() const { - return KServiceTypeTrader::self()->query(s_serviceType, s_jsConstraint); + return KPackage::PackageLoader::self()->listPackages(s_serviceType, QStringLiteral("kwin/effects")); } -KService::Ptr ScriptedEffectLoader::findEffect(const QString &name) const +KPluginMetaData ScriptedEffectLoader::findEffect(const QString &name) const { - const QString constraint = QStringLiteral("%1 and [%2] == '%3'").arg(s_jsConstraint).arg(s_nameProperty).arg(name.toLower()); - const KService::List services = KServiceTypeTrader::self()->query(s_serviceType, - constraint); - if (!services.isEmpty()) { - return services.first(); + const auto plugins = KPackage::PackageLoader::self()->findPackages(s_serviceType, QStringLiteral("kwin/effects"), + [name] (const KPluginMetaData &metadata) { + return metadata.pluginId().compare(name, Qt::CaseInsensitive) == 0; + } + ); + if (!plugins.isEmpty()) { + return plugins.first(); } - return KService::Ptr(); + return KPluginMetaData(); } diff --git a/effectloader.h b/effectloader.h index ca463d6262..4ed0017896 100644 --- a/effectloader.h +++ b/effectloader.h @@ -20,8 +20,8 @@ along with this program. If not, see . #ifndef KWIN_EFFECT_LOADER_H #define KWIN_EFFECT_LOADER_H // KDE +#include #include -#include // Qt #include #include @@ -304,13 +304,13 @@ public: void queryAndLoadAll() override; bool loadEffect(const QString &name) override; - bool loadEffect(KService::Ptr effect, LoadEffectFlags flags); + bool loadEffect(const KPluginMetaData &effect, LoadEffectFlags flags); private: - KService::List findAllEffects() const; - KService::Ptr findEffect(const QString &name) const; + QList findAllEffects() const; + KPluginMetaData findEffect(const QString &name) const; QStringList m_loadedEffects; - EffectLoadQueue< ScriptedEffectLoader, KService::Ptr > *m_queue; + EffectLoadQueue< ScriptedEffectLoader, KPluginMetaData > *m_queue; }; class PluginEffectLoader : public AbstractEffectLoader diff --git a/effects.h b/effects.h index d50d690dd9..59f4abd28c 100644 --- a/effects.h +++ b/effects.h @@ -30,7 +30,6 @@ along with this program. If not, see . #include #include -#include namespace Plasma { class Theme; @@ -38,7 +37,6 @@ class Theme; class QDBusPendingCallWatcher; class QDBusServiceWatcher; -class KService; class OrgFreedesktopScreenSaverInterface; diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp index e565ac7df8..c4f2be90f7 100644 --- a/scripting/scriptedeffect.cpp +++ b/scripting/scriptedeffect.cpp @@ -26,6 +26,7 @@ along with this program. If not, see . // KDE #include #include +#include // Qt #include #include @@ -384,10 +385,10 @@ void fpx2FromScriptValue(const QScriptValue &value, KWin::FPx2 &fpx2) } } -ScriptedEffect *ScriptedEffect::create(KService::Ptr effect) +ScriptedEffect *ScriptedEffect::create(const KPluginMetaData &effect) { - const QString name = effect->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString(); - const QString scriptName = effect->property(QStringLiteral("X-Plasma-MainScript")).toString(); + const QString name = effect.pluginId(); + const QString scriptName = effect.value(QStringLiteral("X-Plasma-MainScript")); if (scriptName.isEmpty()) { qDebug() << "X-Plasma-MainScript not set"; return nullptr; @@ -398,7 +399,7 @@ ScriptedEffect *ScriptedEffect::create(KService::Ptr effect) qDebug() << "Could not locate the effect script"; return nullptr; } - return ScriptedEffect::create(name, scriptFile, effect->property(QStringLiteral("X-KDE-Ordering")).toInt()); + return ScriptedEffect::create(name, scriptFile, effect.value(QStringLiteral("X-KDE-Ordering")).toInt()); } ScriptedEffect *ScriptedEffect::create(const QString& effectName, const QString& pathToScript, int chainPosition) diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h index e0a247e911..2a77a2f302 100644 --- a/scripting/scriptedeffect.h +++ b/scripting/scriptedeffect.h @@ -22,9 +22,9 @@ along with this program. If not, see . #define KWIN_SCRIPTEDEFFECT_H #include -#include class KConfigLoader; +class KPluginMetaData; class QScriptEngine; class QScriptValue; @@ -65,8 +65,8 @@ public: } QString activeConfig() const; void setActiveConfig(const QString &name); - static ScriptedEffect *create(KService::Ptr effect); static ScriptedEffect *create(const QString &effectName, const QString &pathToScript, int chainPosition); + static ScriptedEffect *create(const KPluginMetaData &effect); virtual ~ScriptedEffect(); /** * Whether another effect has grabbed the @p w with the given @p grabRole.