From 9846f4b0afa9601ee2d56a504581b718536ce1b7 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 30 Apr 2015 18:44:51 +0200 Subject: [PATCH] port away from sycoca everything possible use package and kplugin listing instead of sycoca to list layout templates and wallpapers --- shell/CMakeLists.txt | 1 + shell/scripting/applet.cpp | 10 +--------- shell/scripting/scriptengine.cpp | 15 ++++----------- shell/shellcorona.cpp | 30 +++++++++++++++++------------- 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index c90f6dcd1..3c431cc12 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -82,6 +82,7 @@ target_link_libraries(plasmashell KF5::Screen KF5::Declarative KF5::XmlGui + KF5::Package ) target_include_directories(plasmashell PRIVATE "${CMAKE_BINARY_DIR}") target_compile_definitions(plasmashell PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") diff --git a/shell/scripting/applet.cpp b/shell/scripting/applet.cpp index 02a3aabd1..ea3271e69 100644 --- a/shell/scripting/applet.cpp +++ b/shell/scripting/applet.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -233,14 +232,7 @@ QString Applet::version() const return QString(); } - QString type = app->pluginInfo().pluginName(); - KService::List services = KServiceTypeTrader::self()->query("Plasma/Applet", "[X-KDE-PluginInfo-Name] == '" + type + "'"); - if (services.isEmpty()) { - return QString(); - } - - KPluginInfo info(services.first()); - return info.version(); + return app->pluginInfo().version(); } void Applet::setLocked(bool locked) diff --git a/shell/scripting/scriptengine.cpp b/shell/scripting/scriptengine.cpp index c4c60a124..537ed6034 100644 --- a/shell/scripting/scriptengine.cpp +++ b/shell/scripting/scriptengine.cpp @@ -730,17 +730,10 @@ QScriptValue ScriptEngine::knownWallpaperPlugins(QScriptContext *context, QScrip constraint.append("[X-Plasma-FormFactors] ~~ '").append(formFactor).append("'"); } - KService::List services = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint); - QScriptValue rv = engine->newArray(services.size()); - foreach (const KService::Ptr service, services) { - QList modeActions = service->actions(); - QScriptValue modes = engine->newArray(modeActions.size()); - int i = 0; - foreach (const KServiceAction &action, modeActions) { - modes.setProperty(i++, action.name()); - } - - rv.setProperty(service->name(), modes); + QList wallpapers = KPackage::PackageLoader::self()->listPackages("Plasma/Wallpaper", QString()); + QScriptValue rv = engine->newArray(wallpapers.size()); + for (auto wp : wallpapers) { + rv.setProperty(wp.name(), engine->newArray(0)); } return rv; diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index 0164ed890..558788daa 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -1284,9 +1283,12 @@ void ShellCorona::checkAddPanelAction(const QStringList &sycocaChanges) m_addPanelsMenu = 0; KPluginInfo::List panelContainmentPlugins = Plasma::PluginLoader::listContainmentsOfType("Panel"); - const QString constraint = QString("[X-Plasma-Shell] == '%1' and 'panel' ~in [X-Plasma-ContainmentCategories]") - .arg(qApp->applicationName()); - KService::List templates = KServiceTypeTrader::self()->query("Plasma/LayoutTemplate", constraint); + + auto filter = [](const KPluginMetaData &md) -> bool + { + return md.value("X-Plasma-Shell") == qApp->applicationName() && md.value("X-Plasma-ContainmentCategories").contains("panel"); + }; + QList templates = KPackage::PackageLoader::self()->findPackages("Plasma/LayoutTemplate", QString(), filter); if (panelContainmentPlugins.count() + templates.count() == 1) { m_addPanelAction = new QAction(i18n("Add Panel"), this); @@ -1314,23 +1316,25 @@ void ShellCorona::populateAddPanelsMenu() const KPluginInfo emptyInfo; KPluginInfo::List panelContainmentPlugins = Plasma::PluginLoader::listContainmentsOfType("Panel"); - QMap > sorted; + QMap > sorted; foreach (const KPluginInfo &plugin, panelContainmentPlugins) { - sorted.insert(plugin.name(), qMakePair(plugin, KService::Ptr(0))); + sorted.insert(plugin.name(), qMakePair(plugin, KPluginMetaData())); } - const QString constraint = QString("[X-Plasma-Shell] == '%1' and 'panel' in [X-Plasma-ContainmentCategories]") - .arg(qApp->applicationName()); - KService::List templates = KServiceTypeTrader::self()->query("Plasma/LayoutTemplate", constraint); - foreach (const KService::Ptr &service, templates) { - sorted.insert(service->name(), qMakePair(emptyInfo, service)); + auto filter = [](const KPluginMetaData &md) -> bool + { + return md.value("X-Plasma-Shell") == qApp->applicationName() && md.value("X-Plasma-ContainmentCategories").contains("panel"); + }; + QList templates = KPackage::PackageLoader::self()->findPackages("Plasma/LayoutTemplate", QString(), filter); + for (auto tpl : templates) { + sorted.insert(tpl.name(), qMakePair(emptyInfo, tpl)); } - QMapIterator > it(sorted); + QMapIterator > it(sorted); KPackage::Package package = KPackage::PackageLoader::self()->loadPackage("Plasma/LayoutTemplate"); while (it.hasNext()) { it.next(); - QPair pair = it.value(); + QPair pair = it.value(); if (pair.first.isValid()) { KPluginInfo plugin = pair.first; QAction *action = m_addPanelsMenu->addAction(i18n("Empty %1", plugin.name()));