plasma-framework/src/plasma/pluginloader.cpp

897 lines
30 KiB
C++
Raw Normal View History

/*
* Copyright 2010 Ryan Rix <ry@n.rix.si>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "pluginloader.h"
#include <QStandardPaths>
2013-07-29 19:05:59 +02:00
#include <QDebug>
#include <kservice.h>
#include <kservicetypetrader.h>
2013-09-12 01:31:37 +02:00
#include <kplugintrader.h>
#include <KPluginLoader>
#include <kpackage/packageloader.h>
#include "config-plasma.h"
2012-08-24 03:16:04 +02:00
#if !PLASMA_NO_KIO
#include <kio/job.h>
#endif
#include "applet.h"
#include "containment.h"
2011-07-19 21:39:51 +02:00
#include "containmentactions.h"
#include "dataengine.h"
#include "package.h"
#include "private/applet_p.h"
#include "private/service_p.h" // for NullService
#include "private/storage_p.h"
#include "private/package_p.h"
#include "private/packagestructure_p.h"
#include <plasma/version.h>
#include "debug_p.h"
2014-04-26 01:45:47 +02:00
namespace Plasma
{
static PluginLoader *s_pluginLoader = 0;
2011-04-21 16:25:10 +02:00
class PluginLoaderPrivate
{
public:
PluginLoaderPrivate()
: isDefaultLoader(false),
packageRE("[^a-zA-Z0-9\\-_]")
{
}
static QSet<QString> knownCategories();
static QString parentAppConstraint(const QString &parentApp = QString());
static QSet<QString> s_customCategories;
QHash<QString, QWeakPointer<PackageStructure> > structures;
bool isDefaultLoader;
static QString s_dataEnginePluginDir;
static QString s_packageStructurePluginDir;
static QString s_plasmoidsPluginDir;
static QString s_servicesPluginDir;
static QString s_containmentActionsPluginDir;
QRegExp packageRE;
2011-04-21 16:25:10 +02:00
};
QSet<QString> PluginLoaderPrivate::s_customCategories;
2015-11-27 20:03:48 +00:00
QString PluginLoaderPrivate::s_dataEnginePluginDir = QStringLiteral("plasma/dataengine");
QString PluginLoaderPrivate::s_packageStructurePluginDir = QStringLiteral("plasma/packagestructure");
QString PluginLoaderPrivate::s_plasmoidsPluginDir = QStringLiteral("plasma/applets");
QString PluginLoaderPrivate::s_servicesPluginDir = QStringLiteral("plasma/services");
QString PluginLoaderPrivate::s_containmentActionsPluginDir = QStringLiteral("plasma/containmentactions");
QSet<QString> PluginLoaderPrivate::knownCategories()
{
// this is to trick the tranlsation tools into making the correct
// strings for translation
QSet<QString> categories = s_customCategories;
categories << QStringLiteral(I18N_NOOP("Accessibility")).toLower()
<< QStringLiteral(I18N_NOOP("Application Launchers")).toLower()
<< QStringLiteral(I18N_NOOP("Astronomy")).toLower()
<< QStringLiteral(I18N_NOOP("Date and Time")).toLower()
<< QStringLiteral(I18N_NOOP("Development Tools")).toLower()
<< QStringLiteral(I18N_NOOP("Education")).toLower()
<< QStringLiteral(I18N_NOOP("Environment and Weather")).toLower()
<< QStringLiteral(I18N_NOOP("Examples")).toLower()
<< QStringLiteral(I18N_NOOP("File System")).toLower()
<< QStringLiteral(I18N_NOOP("Fun and Games")).toLower()
<< QStringLiteral(I18N_NOOP("Graphics")).toLower()
<< QStringLiteral(I18N_NOOP("Language")).toLower()
<< QStringLiteral(I18N_NOOP("Mapping")).toLower()
<< QStringLiteral(I18N_NOOP("Miscellaneous")).toLower()
<< QStringLiteral(I18N_NOOP("Multimedia")).toLower()
<< QStringLiteral(I18N_NOOP("Online Services")).toLower()
<< QStringLiteral(I18N_NOOP("Productivity")).toLower()
<< QStringLiteral(I18N_NOOP("System Information")).toLower()
<< QStringLiteral(I18N_NOOP("Utilities")).toLower()
2016-03-09 12:44:00 +01:00
<< QStringLiteral(I18N_NOOP("Windows and Tasks")).toLower()
<< QStringLiteral(I18N_NOOP("Clipboard")).toLower()
<< QStringLiteral(I18N_NOOP("Tasks")).toLower();
return categories;
}
QString PluginLoaderPrivate::parentAppConstraint(const QString &parentApp)
{
if (parentApp.isEmpty()) {
QCoreApplication *app = QCoreApplication::instance();
if (!app) {
return QString();
}
2015-11-27 20:03:48 +00:00
return QStringLiteral("((not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '') or [X-KDE-ParentApp] == '%1')")
2014-04-26 01:45:47 +02:00
.arg(app->applicationName());
}
2015-11-27 20:03:48 +00:00
return QStringLiteral("[X-KDE-ParentApp] == '%1'").arg(parentApp);
}
PluginLoader::PluginLoader()
: d(new PluginLoaderPrivate)
{
}
PluginLoader::~PluginLoader()
{
typedef QWeakPointer<PackageStructure> pswp;
foreach (pswp wp, d->structures) {
delete wp.data();
}
delete d;
}
2014-04-26 01:45:47 +02:00
void PluginLoader::setPluginLoader(PluginLoader *loader)
{
if (!s_pluginLoader) {
s_pluginLoader = loader;
} else {
#ifndef NDEBUG
// qCDebug(LOG_PLASMA) << "Cannot set pluginLoader, already set!" << s_pluginLoader;
#endif
}
}
PluginLoader *PluginLoader::self()
{
if (!s_pluginLoader) {
// we have been called before any PluginLoader was set, so just use the default
// implementation. this prevents plugins from nefariously injecting their own
// plugin loader if the app doesn't
s_pluginLoader = new PluginLoader;
s_pluginLoader->d->isDefaultLoader = true;
}
return s_pluginLoader;
}
Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVariantList &args)
{
if (name.isEmpty()) {
return 0;
}
Applet *applet = d->isDefaultLoader ? 0 : internalLoadApplet(name, appletId, args);
if (applet) {
return applet;
}
if (appletId == 0) {
appletId = ++AppletPrivate::s_maxAppletId;
}
//if name wasn't a path, pluginName == name
const QString pluginName = name.split('/').last();
// Look for C++ plugins first
auto filter = [&pluginName](const KPluginMetaData &md) -> bool
{
return md.pluginId() == pluginName;
};
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_plasmoidsPluginDir, filter);
if (plugins.isEmpty()) {
// COMPAT CODE for applets installed into the toplevel plugins dir by mistake.
plugins = KPluginLoader::findPlugins(QString(), filter);
}
if (!plugins.isEmpty()) {
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
KPluginLoader loader(lst.first().libraryPath());
if (!isPluginVersionCompatible(loader)) {
return 0;
}
KPluginFactory *factory = loader.factory();
if (factory) {
QVariantList allArgs;
allArgs << loader.metaData().toVariantMap() << appletId << args;
applet = factory->create<Plasma::Applet>(0, allArgs);
}
}
if (applet) {
return applet;
}
2013-02-05 15:50:37 +01:00
2015-11-27 20:03:48 +00:00
KPackage::Package p = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), name);
if (!p.isValid()) {
//some applets have actually the root path from another package, such as icontasks
//try to do a fallback package with X-Plasma-RootPath root
p.setRequired("mainscript", false);
p.setPath(name);
KPluginMetaData md(p.filePath("metadata"));
2015-11-27 20:03:48 +00:00
const KPackage::Package fp = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), md.value(QStringLiteral("X-Plasma-RootPath")));
p.setFallbackPackage(fp);
if (!fp.isValid()) {
qCWarning(LOG_PLASMA) << "invalid fallback path in " << p.path();
return 0;
}
}
if (!applet) {
//qCDebug(LOG_PLASMA) << name << "not a C++ applet: Falling back to an empty one";
QVariantList allArgs;
allArgs << p.metadata().fileName() << appletId << args;
2015-11-27 20:03:48 +00:00
if (p.metadata().serviceTypes().contains(QStringLiteral("Plasma/Containment"))) {
return new Containment(0, allArgs);
} else {
return new Applet(0, allArgs);
}
}
return applet;
}
DataEngine *PluginLoader::loadDataEngine(const QString &name)
{
DataEngine *engine = d->isDefaultLoader ? 0 : internalLoadDataEngine(name);
if (engine) {
return engine;
}
// Look for C++ plugins first
auto filter = [&name](const KPluginMetaData &md) -> bool
{
return md.pluginId() == name;
};
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter);
if (!plugins.isEmpty()) {
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;
}
2015-11-27 20:03:48 +00:00
const KPackage::Package p = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/DataEngine"), name);
if (!p.isValid()) {
return 0;
}
return new DataEngine(KPluginInfo(p.metadata().fileName()), 0);
}
QStringList PluginLoader::listAllEngines(const QString &parentApp)
{
QStringList engines;
// Look for C++ plugins first
auto filter = [&parentApp](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
return md.value(QStringLiteral("X-KDE-ParentApp")) == parentApp;
};
QVector<KPluginMetaData> plugins;
if (parentApp.isEmpty()) {
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir);
} else {
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter);
}
foreach (auto& plugin, plugins) {
engines << plugin.pluginId();
}
const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/DataEngine"));
for (auto& plugin : packagePlugins) {
engines << plugin.pluginId();
}
return engines;
}
KPluginInfo::List PluginLoader::listEngineInfo(const QString &parentApp)
{
return PluginLoader::self()->listDataEngineInfo(parentApp);
}
KPluginInfo::List PluginLoader::listEngineInfoByCategory(const QString &category, const QString &parentApp)
{
KPluginInfo::List list;
// Look for C++ plugins first
auto filterNormal = [&category](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
return md.value(QStringLiteral("X-KDE-PluginInfo-Category")) == category;
};
auto filterParentApp = [&category, &parentApp](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
return md.value(QStringLiteral("X-KDE-ParentApp")) == parentApp
&& md.value(QStringLiteral("X-KDE-PluginInfo-Category")) == category;
};
QVector<KPluginMetaData> plugins;
if (parentApp.isEmpty()) {
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filterNormal);
} else {
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filterParentApp);
}
list = KPluginInfo::fromMetaData(plugins);
//TODO FIXME: PackageLoader needs to have a function to inject packageStructures
const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/DataEngine"));
list << KPluginInfo::fromMetaData(packagePlugins.toVector());
return list;
}
Service *PluginLoader::loadService(const QString &name, const QVariantList &args, QObject *parent)
2011-07-13 20:20:36 +02:00
{
Service *service = d->isDefaultLoader ? 0 : internalLoadService(name, args, parent);
if (service) {
return service;
}
//TODO: scripting API support
if (name.isEmpty()) {
return new NullService(QString(), parent);
2015-11-27 20:03:48 +00:00
} else if (name == QLatin1String("org.kde.servicestorage")) {
return new Storage(parent);
}
// Look for C++ plugins first
auto filter = [&name](const KPluginMetaData &md) -> bool
{
return md.pluginId() == name;
};
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_servicesPluginDir, filter);
if (!plugins.isEmpty()) {
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
KPluginLoader loader(lst.first().libraryPath());
if (!isPluginVersionCompatible(loader)) {
return 0;
}
KPluginFactory *factory = loader.factory();
if (factory) {
service = factory->create<Plasma::Service>(0, args);
}
}
if (service) {
if (service->name().isEmpty()) {
service->setName(name);
}
return service;
} else {
return new NullService(name, parent);
}
}
2011-07-19 21:39:51 +02:00
ContainmentActions *PluginLoader::loadContainmentActions(Containment *parent, const QString &name, const QVariantList &args)
{
if (name.isEmpty()) {
return 0;
}
ContainmentActions *actions = d->isDefaultLoader ? 0 : internalLoadContainmentActions(parent, name, args);
if (actions) {
return actions;
}
// Look for C++ plugins first
auto filter = [&name](const KPluginMetaData &md) -> bool
{
return md.pluginId() == name;
};
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_containmentActionsPluginDir, filter);
if (!plugins.isEmpty()) {
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
KPluginLoader loader(lst.first().libraryPath());
const QVariantList argsWithMetaData = QVariantList() << loader.metaData().toVariantMap();
KPluginFactory *factory = loader.factory();
if (factory) {
actions = factory->create<Plasma::ContainmentActions>(0, argsWithMetaData);
}
}
if (actions) {
return actions;
}
//FIXME: this is only for backwards compatibility, but probably will have to stay
//for the time being
2015-11-27 20:03:48 +00:00
QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(name);
KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint);
2011-07-19 21:39:51 +02:00
if (offers.isEmpty()) {
#ifndef NDEBUG
qCDebug(LOG_PLASMA) << "offers is empty for " << name;
#endif
2011-07-19 21:39:51 +02:00
return 0;
}
KService::Ptr offer = offers.first();
KPluginLoader plugin(*offer);
if (!isPluginVersionCompatible(plugin)) {
2011-07-19 21:39:51 +02:00
return 0;
}
QVariantList allArgs;
allArgs << offer->storageId() << args;
QString error;
actions = offer->createInstance<Plasma::ContainmentActions>(parent, allArgs, &error);
if (!actions) {
#ifndef NDEBUG
// qCDebug(LOG_PLASMA) << "Couldn't load containmentActions \"" << name << "\"! reason given: " << error;
#endif
2011-07-19 21:39:51 +02:00
}
return actions;
}
Package PluginLoader::loadPackage(const QString &packageFormat, const QString &specialization)
2011-07-13 20:20:36 +02:00
{
2011-07-19 21:39:51 +02:00
if (!d->isDefaultLoader) {
Package p = internalLoadPackage(packageFormat, specialization);
if (p.hasValidStructure()) {
return p;
}
2011-07-13 20:20:36 +02:00
}
if (packageFormat.isEmpty()) {
return Package();
}
const QString hashkey = packageFormat + '%' + specialization;
PackageStructure *structure = d->structures.value(hashkey).data();
if (structure) {
return Package(structure);
}
KPackage::PackageStructure *internalStructure = KPackage::PackageLoader::self()->loadPackageStructure(packageFormat);
if (internalStructure) {
structure = new PackageStructure();
structure->d->internalStructure = internalStructure;
//fallback to old structures
} else {
const QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(packageFormat);
structure = KPluginTrader::createInstanceFromQuery<Plasma::PackageStructure>(PluginLoaderPrivate::s_packageStructurePluginDir, QStringLiteral("Plasma/PackageStructure"), constraint, 0);
if (structure) {
structure->d->internalStructure = new PackageStructureWrapper(structure);
}
}
if (structure) {
d->structures.insert(hashkey, structure);
return Package(structure);
}
#ifndef NDEBUG
// qCDebug(LOG_PLASMA) << "Couldn't load Package for" << packageFormat << "! reason given: " << error;
#endif
return Package();
2011-07-13 20:20:36 +02:00
}
KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp)
{
KPluginInfo::List list;
if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) {
list = internalAppletInfo(category);
}
//FIXME: this assumes we are always use packages.. no pure c++
if (category.isEmpty()) { //use all but the excluded categories
KConfigGroup group(KSharedConfig::openConfig(), "General");
QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
auto filter = [&excluded, &parentApp](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
const QString pa = md.value(QStringLiteral("X-KDE-ParentApp"));
return (pa.isEmpty() || pa == parentApp) && !excluded.contains(md.category());
};
//NOTE: it still produces kplugininfos from KServices because some user code expects
//info.sevice() to be valid and would crash ohtherwise
auto plugins = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter);
foreach (auto& md, plugins) {
auto pi = KPluginInfo(KService::serviceByStorageId(md.metaDataFileName()));
if (!pi.isValid()) {
qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin";
continue;
}
list << pi;
}
return list;
} else { //specific category (this could be an excluded one - is that bad?)
auto filter = [&category, &parentApp](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
const QString pa = md.value(QStringLiteral("X-KDE-ParentApp"));
if (category == QLatin1String("Miscellaneous")) {
return (pa.isEmpty() || pa == parentApp) && (md.category() == category || md.category().isEmpty());
} else {
return (pa.isEmpty() || pa == parentApp) && md.category() == category;
}
};
//NOTE: it still produces kplugininfos from KServices because some user code expects
//info.sevice() to be valid and would crash ohtherwise
const auto plugins = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter);
foreach (auto& md, plugins) {
auto pi = KPluginInfo(KService::serviceByStorageId(md.metaDataFileName()));
if (!pi.isValid()) {
qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin";
continue;
}
list << pi;
}
return list;
}
}
KPluginInfo::List PluginLoader::listAppletInfoForMimeType(const QString &mimeType)
{
auto filter = [&mimeType](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
return md.value(QStringLiteral("X-Plasma-DropMimeTypes")).contains(mimeType);
};
return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector());
}
KPluginInfo::List PluginLoader::listAppletInfoForUrl(const QUrl &url)
{
QString parentApp;
QCoreApplication *app = QCoreApplication::instance();
if (app) {
parentApp = app->applicationName();
}
auto filter = [&parentApp](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
const QString pa = md.value(QStringLiteral("X-KDE-ParentApp"));
return (pa.isEmpty() || pa == parentApp) && !md.value(QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty();
};
KPluginInfo::List allApplets = KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector());
KPluginInfo::List filtered;
foreach (const KPluginInfo &info, allApplets) {
QStringList urlPatterns = info.property(QStringLiteral("X-Plasma-DropUrlPatterns")).toStringList();
foreach (const QString &glob, urlPatterns) {
QRegExp rx(glob);
rx.setPatternSyntax(QRegExp::Wildcard);
if (rx.exactMatch(url.toString())) {
#ifndef NDEBUG
// qCDebug(LOG_PLASMA) << info.name() << "matches" << glob << url;
#endif
filtered << info;
}
}
}
return filtered;
}
QStringList PluginLoader::listAppletCategories(const QString &parentApp, bool visibleOnly)
{
KConfigGroup group(KSharedConfig::openConfig(), "General");
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
auto filter = [&parentApp, &excluded, visibleOnly](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
const QString pa = md.value(QStringLiteral("X-KDE-ParentApp"));
return (pa.isEmpty() || pa == parentApp)
&& (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category"))))
&& (!visibleOnly || !md.isHidden());
};
2015-11-27 20:03:48 +00:00
const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter);
QStringList categories;
foreach (auto& plugin, allApplets) {
if (plugin.category().isEmpty()) {
if (!categories.contains(i18nc("misc category", "Miscellaneous"))) {
categories << i18nc("misc category", "Miscellaneous");
}
} else {
categories << plugin.category();
}
}
categories.sort();
return categories;
}
void PluginLoader::setCustomAppletCategories(const QStringList &categories)
{
PluginLoaderPrivate::s_customCategories = QSet<QString>::fromList(categories);
}
QStringList PluginLoader::customAppletCategories() const
{
return PluginLoaderPrivate::s_customCategories.toList();
}
2014-04-26 01:45:47 +02:00
QString PluginLoader::appletCategory(const QString &appletName)
{
if (appletName.isEmpty()) {
return QString();
}
2015-11-27 20:03:48 +00:00
const KPackage::Package p = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), appletName);
if (!p.isValid()) {
return QString();
}
return p.metadata().category();
}
KPluginInfo::List PluginLoader::listContainments(const QString &category,
2014-04-26 01:45:47 +02:00
const QString &parentApp)
{
return listContainmentsOfType(QString(), category, parentApp);
}
KPluginInfo::List PluginLoader::listContainmentsOfType(const QString &type,
2014-04-26 01:45:47 +02:00
const QString &category,
const QString &parentApp)
{
KConfigGroup group(KSharedConfig::openConfig(), "General");
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
auto filter = [&type, &category, &parentApp](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
if (!md.serviceTypes().contains(QStringLiteral("Plasma/Containment"))) {
return false;
}
2015-11-27 20:03:48 +00:00
const QString pa = md.value(QStringLiteral("X-KDE-ParentApp"));
if (!pa.isEmpty() && pa != parentApp) {
return false;
}
2015-11-27 20:03:48 +00:00
if (!type.isEmpty() && md.value(QStringLiteral("X-Plasma-ContainmentType")) != type) {
return false;
}
2015-11-27 20:03:48 +00:00
if (!category.isEmpty() && md.value(QStringLiteral("X-KDE-PluginInfo-Category")) != category) {
return false;
}
return true;
};
2015-11-27 20:03:48 +00:00
return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector());
}
KPluginInfo::List PluginLoader::listContainmentsForMimeType(const QString &mimeType)
{
auto filter = [&mimeType](const KPluginMetaData &md) -> bool
{
2015-11-27 20:03:48 +00:00
return md.value(QStringLiteral("X-KDE-ServiceTypes")).contains(QLatin1String("Plasma/Containment"))
&& md.value(QStringLiteral("X-Plasma-DropMimeTypes")).contains(mimeType);
};
2015-11-27 20:03:48 +00:00
return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector());
}
QStringList PluginLoader::listContainmentTypes()
{
KPluginInfo::List containmentInfos = listContainments();
QSet<QString> types;
foreach (const KPluginInfo &containmentInfo, containmentInfos) {
QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList();
foreach (const QString &type, theseTypes) {
types.insert(type);
}
}
return types.toList();
}
KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp)
{
KPluginInfo::List list;
if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) {
list = internalDataEngineInfo();
}
QString constraint;
if (parentApp.isEmpty()) {
2015-11-27 20:03:48 +00:00
constraint = QStringLiteral("not exist [X-KDE-ParentApp]");
} else {
2015-11-27 20:03:48 +00:00
constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + '\'';
}
2015-11-27 20:03:48 +00:00
list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_dataEnginePluginDir, QStringLiteral("Plasma/DataEngine"), constraint));
return list;
}
2011-07-19 21:39:51 +02:00
KPluginInfo::List PluginLoader::listContainmentActionsInfo(const QString &parentApp)
{
KPluginInfo::List list;
if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) {
2011-07-19 21:39:51 +02:00
list = internalContainmentActionsInfo();
}
QString constraint;
if (parentApp.isEmpty()) {
2015-11-27 20:03:48 +00:00
constraint = QStringLiteral("not exist [X-KDE-ParentApp]");
2011-07-19 21:39:51 +02:00
} else {
2015-11-27 20:03:48 +00:00
constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + '\'';
2011-07-19 21:39:51 +02:00
}
2015-11-27 20:03:48 +00:00
list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint));
QSet<QString> knownPlugins;
foreach (const KPluginInfo &p, list) {
knownPlugins.insert(p.pluginName());
}
//FIXME: this is only for backwards compatibility, but probably will have to stay
//for the time being
2015-11-27 20:03:48 +00:00
KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint);
foreach (KService::Ptr s, offers) {
if (!knownPlugins.contains(s->pluginKeyword())) {
list.append(KPluginInfo(s));
}
}
return list;
2011-07-19 21:39:51 +02:00
}
2014-04-26 01:45:47 +02:00
Applet *PluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args)
{
Q_UNUSED(name)
Q_UNUSED(appletId)
Q_UNUSED(args)
return 0;
}
2011-07-21 14:38:44 +02:00
DataEngine *PluginLoader::internalLoadDataEngine(const QString &name)
{
Q_UNUSED(name)
return 0;
}
2011-07-21 14:38:44 +02:00
ContainmentActions *PluginLoader::internalLoadContainmentActions(Containment *containment, const QString &name, const QVariantList &args)
{
Q_UNUSED(containment)
Q_UNUSED(name)
Q_UNUSED(args)
return 0;
}
Service *PluginLoader::internalLoadService(const QString &name, const QVariantList &args, QObject *parent)
2011-07-13 20:20:36 +02:00
{
Q_UNUSED(name)
Q_UNUSED(args)
Q_UNUSED(parent)
return 0;
}
Package PluginLoader::internalLoadPackage(const QString &name, const QString &specialization)
2011-07-13 20:20:36 +02:00
{
Q_UNUSED(name);
Q_UNUSED(specialization);
2011-07-13 20:20:36 +02:00
return Package();
}
KPluginInfo::List PluginLoader::internalAppletInfo(const QString &category) const
{
Q_UNUSED(category)
return KPluginInfo::List();
}
KPluginInfo::List PluginLoader::internalDataEngineInfo() const
{
return KPluginInfo::List();
}
KPluginInfo::List PluginLoader::internalServiceInfo() const
{
return KPluginInfo::List();
}
2011-07-19 21:39:51 +02:00
KPluginInfo::List PluginLoader::internalContainmentActionsInfo() const
{
return KPluginInfo::List();
}
static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category = QString())
{
QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
2015-11-27 20:03:48 +00:00
QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/") + type + QLatin1String("/*.desktop"),
2014-04-26 01:45:47 +02:00
QStandardPaths::LocateFile);
KPluginInfo::List allInfo = KPluginInfo::fromFiles(files);
if (category.isEmpty() || allInfo.isEmpty()) {
return allInfo;
}
KPluginInfo::List matchingInfo;
foreach (const KPluginInfo &info, allInfo) {
if (info.category().compare(category, Qt::CaseInsensitive) == 0) {
matchingInfo << info;
}
}
return matchingInfo;
}
KPluginInfo::List PluginLoader::standardInternalAppletInfo(const QString &category) const
{
2015-11-27 20:03:48 +00:00
return standardInternalInfo(QStringLiteral("applets"), category);
}
KPluginInfo::List PluginLoader::standardInternalDataEngineInfo() const
{
2015-11-27 20:03:48 +00:00
return standardInternalInfo(QStringLiteral("dataengines"));
}
KPluginInfo::List PluginLoader::standardInternalServiceInfo() const
{
2015-11-27 20:03:48 +00:00
return standardInternalInfo(QStringLiteral("services"));
}
bool PluginLoader::isPluginVersionCompatible(KPluginLoader &loader)
{
const quint32 version = loader.pluginVersion();
if (version == quint32(-1)) {
// unversioned, just let it through
qCWarning(LOG_PLASMA) << loader.fileName() << "unversioned plugin detected, may result in instability";
return true;
}
// we require PLASMA_VERSION_MAJOR and PLASMA_VERSION_MINOR
const quint32 minVersion = PLASMA_MAKE_VERSION(PLASMA_VERSION_MAJOR, 0, 0);
const quint32 maxVersion = PLASMA_MAKE_VERSION(PLASMA_VERSION_MAJOR, PLASMA_VERSION_MINOR, 60);
if (version < minVersion || version > maxVersion) {
#ifndef NDEBUG
qCDebug(LOG_PLASMA) << loader.fileName() << ": this plugin is compiled against incompatible Plasma version" << version
<< "This build is compatible with" << PLASMA_VERSION_MAJOR << ".0.0 (" << minVersion
<< ") to" << PLASMA_VERSION_STRING << "(" << maxVersion << ")";
#endif
return false;
}
return true;
}
} // Plasma Namespace