From 2b1a48742876a5fb548a71e7a6a52717dcb55ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Wed, 8 Apr 2015 04:21:09 +0200 Subject: [PATCH] Use KPluginLoader to load dataengines KPluginLoader has all the needed machinery to identify a plugin by its pluginId. No need to use the query parser here, replace it with a lambda. Look for C++ dataengines first. These are much more common, especially in essential cases. By looking up the plugins through KPluginLoader first, we can save querying ksycoca. REVIEW:123297 CHANGELOG:Use KPluginLoader instead of ksycoca for loading C++ dataengines --- src/plasma/pluginloader.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp index a5999916b..0ce349a7e 100644 --- a/src/plasma/pluginloader.cpp +++ b/src/plasma/pluginloader.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "config-plasma.h" @@ -251,6 +252,27 @@ DataEngine *PluginLoader::loadDataEngine(const QString &name) return engine; } + // Look for C++ plugins first + auto filter = [&name](const KPluginMetaData &md) -> bool + { + return md.pluginId() == name; + }; + QVector plugins = KPluginLoader::findPlugins(d->dataEnginePluginDir, filter); + + if (plugins.count()) { + KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins); + KPluginLoader loader(lst.first().libraryPath()); + const QVariantList argsWithMetaData = QVariantList() << loader.metaData().toVariantMap(); + KPluginFactory *factory = loader.factory(); + if (factory) { + engine = factory->create(0, argsWithMetaData); + } + } + if (engine) { + return engine; + } + + // Fall back to querying scripted plugins QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name); // First check with KServiceTypeTrader as that is where scripted engines will be @@ -258,10 +280,7 @@ DataEngine *PluginLoader::loadDataEngine(const QString &name) if (!offers.isEmpty()) { const QString api = offers.first()->property("X-Plasma-API").toString(); - if (api.isEmpty()) { - // it is a C++ plugin, fetch it with KPluginTrader - engine = KPluginTrader::createInstanceFromQuery(d->dataEnginePluginDir, "Plasma/DataEngine", constraint, 0); - } else { + if (!api.isEmpty()) { // it is a scripted plugin, load it via a package engine = new DataEngine(KPluginInfo(offers.first()), 0); }