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
This commit is contained in:
parent
a5737b553e
commit
2b1a487428
@ -25,6 +25,7 @@
|
||||
#include <kservice.h>
|
||||
#include <kservicetypetrader.h>
|
||||
#include <kplugintrader.h>
|
||||
#include <KPluginLoader>
|
||||
#include <kpackage/packageloader.h>
|
||||
|
||||
#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<KPluginMetaData> 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<Plasma::DataEngine>(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<Plasma::DataEngine>(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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user