2010-07-15 21:06:21 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2010-07-15 21:38:56 +00:00
|
|
|
|
2013-07-10 03:27:19 +02:00
|
|
|
#include <QStandardPaths>
|
|
|
|
|
2013-07-29 19:05:59 +02:00
|
|
|
#include <QDebug>
|
2010-07-15 21:38:56 +00:00
|
|
|
#include <kservice.h>
|
|
|
|
#include <kservicetypetrader.h>
|
2013-09-12 01:31:37 +02:00
|
|
|
#include <kplugintrader.h>
|
2015-04-08 04:21:09 +02:00
|
|
|
#include <KPluginLoader>
|
2014-11-11 16:44:48 +01:00
|
|
|
#include <kpackage/packageloader.h>
|
2010-07-15 21:38:56 +00:00
|
|
|
|
2011-09-02 10:50:04 +02:00
|
|
|
#include "config-plasma.h"
|
|
|
|
|
2012-08-24 03:16:04 +02:00
|
|
|
#if !PLASMA_NO_KIO
|
2011-07-15 13:34:10 +02:00
|
|
|
#include <kio/job.h>
|
|
|
|
#endif
|
|
|
|
|
2010-07-15 21:38:56 +00:00
|
|
|
#include "applet.h"
|
|
|
|
#include "containment.h"
|
2011-07-19 21:39:51 +02:00
|
|
|
#include "containmentactions.h"
|
2012-09-24 15:51:14 +02:00
|
|
|
#include "dataengine.h"
|
2011-07-15 13:34:10 +02:00
|
|
|
#include "package.h"
|
2010-07-15 21:38:56 +00:00
|
|
|
#include "private/applet_p.h"
|
2011-07-15 13:34:10 +02:00
|
|
|
#include "private/packages_p.h"
|
2010-07-15 21:38:56 +00:00
|
|
|
#include "private/service_p.h" // for NullService
|
2010-10-23 17:02:49 +00:00
|
|
|
#include "private/storage_p.h"
|
2014-11-11 16:44:48 +01:00
|
|
|
#include "private/package_p.h"
|
|
|
|
#include "private/packagestructure_p.h"
|
2010-07-15 21:06:21 +00:00
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2010-07-15 21:06:21 +00:00
|
|
|
|
2011-07-13 20:25:47 +02:00
|
|
|
static PluginLoader *s_pluginLoader = 0;
|
2010-07-15 21:06:21 +00:00
|
|
|
|
2011-04-21 16:25:10 +02:00
|
|
|
class PluginLoaderPrivate
|
|
|
|
{
|
2011-07-19 21:40:12 +02:00
|
|
|
public:
|
2013-09-12 15:15:59 +02:00
|
|
|
PluginLoaderPrivate()
|
2014-08-29 11:49:24 +02:00
|
|
|
: isDefaultLoader(false),
|
|
|
|
packageRE("[^a-zA-Z0-9\\-_]")
|
2013-09-12 15:15:59 +02:00
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/Applet", new PlasmoidPackage());
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/DataEngine", new DataEnginePackage());
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/Theme", new ThemePackage());
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/ContainmentActions", new ContainmentActionsPackage());
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/Generic", new GenericPackage());
|
2013-09-12 15:15:59 +02:00
|
|
|
}
|
|
|
|
|
2013-02-12 22:05:14 +01:00
|
|
|
static QSet<QString> knownCategories();
|
|
|
|
static QString parentAppConstraint(const QString &parentApp = QString());
|
|
|
|
|
|
|
|
static QSet<QString> s_customCategories;
|
2011-07-19 21:40:12 +02:00
|
|
|
QHash<QString, QWeakPointer<PackageStructure> > structures;
|
|
|
|
bool isDefaultLoader;
|
2015-05-07 16:26:37 +02:00
|
|
|
|
|
|
|
static QString s_dataEnginePluginDir;
|
|
|
|
static QString s_packageStructurePluginDir;
|
|
|
|
static QString s_plasmoidsPluginDir;
|
|
|
|
static QString s_servicesPluginDir;
|
|
|
|
static QString s_containmentActionsPluginDir;
|
2013-09-12 15:15:59 +02:00
|
|
|
QRegExp packageRE;
|
2011-04-21 16:25:10 +02:00
|
|
|
};
|
|
|
|
|
2013-02-12 22:05:14 +01:00
|
|
|
QSet<QString> PluginLoaderPrivate::s_customCategories;
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
QString PluginLoaderPrivate::s_dataEnginePluginDir("plasma/dataengine");
|
|
|
|
QString PluginLoaderPrivate::s_packageStructurePluginDir("plasma/packagestructure");
|
|
|
|
QString PluginLoaderPrivate::s_plasmoidsPluginDir("plasma/applets");
|
|
|
|
QString PluginLoaderPrivate::s_servicesPluginDir("plasma/services");
|
|
|
|
QString PluginLoaderPrivate::s_containmentActionsPluginDir("plasma/containmentactions");
|
|
|
|
|
2013-02-12 22:05:14 +01:00
|
|
|
QSet<QString> PluginLoaderPrivate::knownCategories()
|
|
|
|
{
|
|
|
|
// this is to trick the tranlsation tools into making the correct
|
|
|
|
// strings for translation
|
|
|
|
QSet<QString> categories = s_customCategories;
|
|
|
|
categories << QString(I18N_NOOP("Accessibility")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Application Launchers")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Astronomy")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Date and Time")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Development Tools")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Education")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Environment and Weather")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Examples")).toLower()
|
|
|
|
<< QString(I18N_NOOP("File System")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Fun and Games")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Graphics")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Language")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Mapping")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Miscellaneous")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Multimedia")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Online Services")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Productivity")).toLower()
|
|
|
|
<< QString(I18N_NOOP("System Information")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Utilities")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Windows and Tasks")).toLower();
|
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PluginLoaderPrivate::parentAppConstraint(const QString &parentApp)
|
|
|
|
{
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
QCoreApplication *app = QCoreApplication::instance();
|
|
|
|
if (!app) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString("((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());
|
2013-02-12 22:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString("[X-KDE-ParentApp] == '%1'").arg(parentApp);
|
|
|
|
}
|
|
|
|
|
2010-07-15 21:11:20 +00:00
|
|
|
PluginLoader::PluginLoader()
|
2011-07-19 21:40:12 +02:00
|
|
|
: d(new PluginLoaderPrivate)
|
2010-07-15 21:11:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-15 21:06:21 +00:00
|
|
|
PluginLoader::~PluginLoader()
|
|
|
|
{
|
2011-07-19 21:40:12 +02:00
|
|
|
typedef QWeakPointer<PackageStructure> pswp;
|
|
|
|
foreach (pswp wp, d->structures) {
|
|
|
|
delete wp.data();
|
|
|
|
}
|
2011-04-20 18:37:07 +02:00
|
|
|
delete d;
|
2010-07-15 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
void PluginLoader::setPluginLoader(PluginLoader *loader)
|
2010-07-15 21:06:21 +00:00
|
|
|
{
|
2010-07-15 21:38:56 +00:00
|
|
|
if (!s_pluginLoader) {
|
2010-07-15 21:06:21 +00:00
|
|
|
s_pluginLoader = loader;
|
|
|
|
} else {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2013-07-29 19:05:59 +02:00
|
|
|
// qDebug() << "Cannot set pluginLoader, already set!" << s_pluginLoader;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2010-07-15 21:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-19 21:40:12 +02:00
|
|
|
PluginLoader *PluginLoader::self()
|
2010-07-15 21:06:21 +00:00
|
|
|
{
|
2010-07-15 21:38:56 +00:00
|
|
|
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;
|
2011-07-19 21:40:12 +02:00
|
|
|
s_pluginLoader->d->isDefaultLoader = true;
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-15 21:06:21 +00:00
|
|
|
return s_pluginLoader;
|
|
|
|
}
|
|
|
|
|
2010-07-15 21:38:56 +00:00
|
|
|
Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVariantList &args)
|
2011-07-19 21:40:12 +02:00
|
|
|
{
|
2010-07-15 21:38:56 +00:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-19 21:40:12 +02:00
|
|
|
Applet *applet = d->isDefaultLoader ? 0 : internalLoadApplet(name, appletId, args);
|
2010-07-15 21:38:56 +00:00
|
|
|
if (applet) {
|
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = ++AppletPrivate::s_maxAppletId;
|
|
|
|
}
|
2010-07-15 21:38:56 +00:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Look for C++ plugins first
|
|
|
|
auto filter = [&name](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.pluginId() == name;
|
|
|
|
};
|
|
|
|
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_plasmoidsPluginDir, filter);
|
|
|
|
|
|
|
|
if (plugins.count()) {
|
|
|
|
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
|
|
|
|
KPluginLoader loader(lst.first().libraryPath());
|
|
|
|
if (!Plasma::isPluginVersionCompatible(loader.pluginVersion())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
KPluginFactory *factory = loader.factory();
|
|
|
|
if (factory) {
|
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << loader.metaData().toVariantMap() << appletId << args;
|
|
|
|
applet = factory->create<Plasma::Applet>(0, allArgs);
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-07 16:26:37 +02:00
|
|
|
if (applet) {
|
|
|
|
return applet;
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
2013-02-05 15:50:37 +01:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
KPackage::Package p = KPackage::PackageLoader::self()->loadPackage("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);
|
2011-07-15 13:34:10 +02:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
KPluginMetaData md(p.filePath("metadata"));
|
|
|
|
const KPackage::Package fp = KPackage::PackageLoader::self()->loadPackage("Plasma/Applet", md.value("X-Plasma-RootPath"));
|
|
|
|
p.setFallbackPackage(fp);
|
2010-07-15 21:38:56 +00:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!fp.isValid()) {
|
|
|
|
return 0;
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
// backwards compatibility: search in the root plugins directory
|
|
|
|
// TODO: remove when Plasma 5.4 is released
|
|
|
|
{
|
|
|
|
KPluginInfo info = KPluginInfo::fromMetaData(p.metadata());
|
|
|
|
KPluginLoader loader(info.libraryPath());
|
|
|
|
if (!Plasma::isPluginVersionCompatible(loader.pluginVersion())) {
|
|
|
|
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;
|
|
|
|
}
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!applet) {
|
2015-05-11 17:48:01 +02:00
|
|
|
//qDebug() << name << "not a C++ applet: Falling back to an empty one";
|
2015-05-07 16:26:37 +02:00
|
|
|
|
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << p.metadata().fileName() << appletId << args;
|
2015-02-20 13:35:30 +01:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (p.metadata().serviceTypes().contains("Plasma/Containment")) {
|
2015-02-20 13:35:30 +01:00
|
|
|
return new Containment(0, allArgs);
|
|
|
|
} else {
|
2015-05-07 16:26:37 +02:00
|
|
|
return new Applet(0, allArgs);
|
2015-02-20 13:35:30 +01:00
|
|
|
}
|
2015-05-07 16:26:37 +02:00
|
|
|
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return applet;
|
2010-07-15 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-15 21:38:56 +00:00
|
|
|
DataEngine *PluginLoader::loadDataEngine(const QString &name)
|
2011-10-04 16:50:44 +02:00
|
|
|
{
|
2011-07-19 21:40:12 +02:00
|
|
|
DataEngine *engine = d->isDefaultLoader ? 0 : internalLoadDataEngine(name);
|
2010-07-15 21:38:56 +00:00
|
|
|
if (engine) {
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
2015-04-08 04:21:09 +02:00
|
|
|
// Look for C++ plugins first
|
|
|
|
auto filter = [&name](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.pluginId() == name;
|
|
|
|
};
|
2015-05-07 16:26:37 +02:00
|
|
|
QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter);
|
2015-04-08 04:21:09 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
const KPackage::Package p = KPackage::PackageLoader::self()->loadPackage("Plasma/DataEngine", name);
|
|
|
|
if (!p.isValid()) {
|
|
|
|
return 0;
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
return new DataEngine(KPluginInfo(p.metadata().fileName()), 0);
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 17:33:55 +02:00
|
|
|
QStringList PluginLoader::listAllEngines(const QString &parentApp)
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!KPackage::PackageLoader::self()->loadPackageStructure("Plasma/DataEngine")) {
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/DataEngine", new DataEnginePackage());
|
|
|
|
}
|
2013-04-04 17:33:55 +02:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
QStringList engines;
|
|
|
|
// Look for C++ plugins first
|
|
|
|
auto filter = [&parentApp](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.value("X-KDE-ParentApp") == parentApp;
|
|
|
|
};
|
|
|
|
QVector<KPluginMetaData> plugins;
|
2013-04-04 17:33:55 +02:00
|
|
|
if (parentApp.isEmpty()) {
|
2015-05-07 16:26:37 +02:00
|
|
|
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir);
|
2013-04-04 17:33:55 +02:00
|
|
|
} else {
|
2015-05-07 16:26:37 +02:00
|
|
|
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter);
|
2013-04-04 17:33:55 +02:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
for (auto plugin : plugins) {
|
|
|
|
engines << plugin.pluginId();
|
|
|
|
}
|
2013-04-04 17:33:55 +02:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages("Plasma/DataEngine");
|
|
|
|
for (auto plugin : packagePlugins) {
|
|
|
|
engines << plugin.pluginId();
|
2013-04-04 17:33:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return engines;
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List PluginLoader::listEngineInfo(const QString &parentApp)
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!KPackage::PackageLoader::self()->loadPackageStructure("Plasma/DataEngine")) {
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/DataEngine", new DataEnginePackage());
|
|
|
|
}
|
2013-04-04 17:33:55 +02:00
|
|
|
return PluginLoader::self()->listDataEngineInfo(parentApp);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List PluginLoader::listEngineInfoByCategory(const QString &category, const QString &parentApp)
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!KPackage::PackageLoader::self()->loadPackageStructure("Plasma/DataEngine")) {
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/DataEngine", new DataEnginePackage());
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List list;
|
2013-04-04 17:33:55 +02:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
// Look for C++ plugins first
|
|
|
|
auto filterNormal = [&category](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.value("X-KDE-PluginInfo-Category") == category;
|
|
|
|
};
|
|
|
|
auto filterParentApp = [&category, &parentApp](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.value("X-KDE-ParentApp") == parentApp && md.value("X-KDE-PluginInfo-Category") == category;
|
|
|
|
};
|
|
|
|
QVector<KPluginMetaData> plugins;
|
2013-04-04 17:33:55 +02:00
|
|
|
if (parentApp.isEmpty()) {
|
2015-05-07 16:26:37 +02:00
|
|
|
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filterNormal);
|
2013-04-04 17:33:55 +02:00
|
|
|
} else {
|
2015-05-07 16:26:37 +02:00
|
|
|
plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filterParentApp);
|
2013-04-04 17:33:55 +02:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
list = KPluginInfo::fromMetaData(plugins);
|
|
|
|
|
|
|
|
|
|
|
|
//TODO FIXME: PackageLoader needs to have a function to inject packageStructures
|
|
|
|
const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages("Plasma/DataEngine");
|
|
|
|
list << KPluginInfo::fromMetaData(packagePlugins.toVector());
|
|
|
|
|
|
|
|
return list;
|
2013-04-04 17:33:55 +02:00
|
|
|
}
|
|
|
|
|
2010-07-15 21:38:56 +00:00
|
|
|
Service *PluginLoader::loadService(const QString &name, const QVariantList &args, QObject *parent)
|
2011-07-13 20:20:36 +02:00
|
|
|
{
|
2011-07-19 21:40:12 +02:00
|
|
|
Service *service = d->isDefaultLoader ? 0 : internalLoadService(name, args, parent);
|
2010-07-15 21:38:56 +00:00
|
|
|
if (service) {
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: scripting API support
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
return new NullService(QString(), parent);
|
2010-10-23 17:02:49 +00:00
|
|
|
} else if (name == "org.kde.servicestorage") {
|
|
|
|
return new Storage(parent);
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
// 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);
|
2010-07-15 21:38:56 +00:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (plugins.count()) {
|
|
|
|
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
|
|
|
|
KPluginLoader loader(lst.first().libraryPath());
|
|
|
|
if (!Plasma::isPluginVersionCompatible(loader.pluginVersion())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
KPluginFactory *factory = loader.factory();
|
|
|
|
if (factory) {
|
|
|
|
service = factory->create<Plasma::Service>(0, args);
|
|
|
|
}
|
2010-07-15 21:38:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (service) {
|
|
|
|
if (service->name().isEmpty()) {
|
|
|
|
service->setName(name);
|
|
|
|
}
|
|
|
|
return service;
|
|
|
|
} else {
|
2010-07-15 21:38:56 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
|
|
|
|
// 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.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) {
|
|
|
|
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
|
2011-07-19 21:39:51 +02:00
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ContainmentActions", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2014-04-26 01:45:47 +02:00
|
|
|
qDebug() << "offers is empty for " << name;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-19 21:39:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::Ptr offer = offers.first();
|
|
|
|
KPluginLoader plugin(*offer);
|
|
|
|
|
|
|
|
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << offer->storageId() << args;
|
|
|
|
QString error;
|
|
|
|
actions = offer->createInstance<Plasma::ContainmentActions>(parent, allArgs, &error);
|
|
|
|
|
|
|
|
if (!actions) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2013-07-29 19:05:59 +02:00
|
|
|
// qDebug() << "Couldn't load containmentActions \"" << name << "\"! reason given: " << error;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-19 21:39:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
2011-07-15 13:34:10 +02:00
|
|
|
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) {
|
2011-07-15 13:34:10 +02:00
|
|
|
Package p = internalLoadPackage(packageFormat, specialization);
|
2014-08-08 14:11:50 +02:00
|
|
|
if (p.hasValidStructure()) {
|
2011-07-13 20:25:47 +02:00
|
|
|
return p;
|
|
|
|
}
|
2011-07-13 20:20:36 +02:00
|
|
|
}
|
|
|
|
|
2011-07-15 13:34:10 +02:00
|
|
|
if (packageFormat.isEmpty()) {
|
|
|
|
return Package();
|
|
|
|
}
|
|
|
|
|
2011-07-19 21:40:12 +02:00
|
|
|
const QString hashkey = packageFormat + '%' + specialization;
|
|
|
|
PackageStructure *structure = d->structures.value(hashkey).data();
|
2014-11-11 16:44:48 +01:00
|
|
|
|
|
|
|
KPackage::PackageStructure *internalStructure = 0;
|
2011-07-19 21:40:12 +02:00
|
|
|
if (structure) {
|
|
|
|
return Package(structure);
|
|
|
|
}
|
|
|
|
|
2011-07-15 13:34:10 +02:00
|
|
|
if (packageFormat.startsWith("Plasma")) {
|
|
|
|
if (packageFormat.endsWith("/Applet")) {
|
2014-11-11 16:44:48 +01:00
|
|
|
internalStructure = new PlasmoidPackage();
|
2011-07-15 13:34:10 +02:00
|
|
|
} else if (packageFormat.endsWith("/DataEngine")) {
|
2014-11-11 16:44:48 +01:00
|
|
|
internalStructure = new DataEnginePackage();
|
2011-07-15 13:34:10 +02:00
|
|
|
} else if (packageFormat.endsWith("/Theme")) {
|
2014-11-11 16:44:48 +01:00
|
|
|
internalStructure = new ThemePackage();
|
2011-07-15 13:34:10 +02:00
|
|
|
} else if (packageFormat.endsWith("/ContainmentActions")) {
|
2014-11-11 16:44:48 +01:00
|
|
|
internalStructure = new ContainmentActionsPackage();
|
2011-07-15 13:34:10 +02:00
|
|
|
} else if (packageFormat.endsWith("/Generic")) {
|
2014-11-11 16:44:48 +01:00
|
|
|
internalStructure = new GenericPackage();
|
2011-07-19 21:40:12 +02:00
|
|
|
}
|
|
|
|
|
2014-11-11 16:44:48 +01:00
|
|
|
if (internalStructure) {
|
|
|
|
structure = new PackageStructure();
|
|
|
|
structure->d->internalStructure = internalStructure;
|
2011-07-19 21:40:12 +02:00
|
|
|
d->structures.insert(hashkey, structure);
|
|
|
|
return Package(structure);
|
2011-07-15 13:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 16:44:48 +01:00
|
|
|
internalStructure = KPackage::PackageLoader::self()->loadPackageStructure(packageFormat);
|
|
|
|
|
|
|
|
if (internalStructure) {
|
|
|
|
structure = new PackageStructure();
|
|
|
|
structure->d->internalStructure = internalStructure;
|
|
|
|
//fallback to old structures
|
|
|
|
} else {
|
|
|
|
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(packageFormat);
|
2015-05-07 16:26:37 +02:00
|
|
|
structure = KPluginTrader::createInstanceFromQuery<Plasma::PackageStructure>(PluginLoaderPrivate::s_packageStructurePluginDir, "Plasma/PackageStructure", constraint, 0);
|
2014-11-11 16:44:48 +01:00
|
|
|
if (structure) {
|
|
|
|
structure->d->internalStructure = new PackageStructureWrapper(structure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-29 12:19:08 +02:00
|
|
|
if (structure) {
|
|
|
|
d->structures.insert(hashkey, structure);
|
|
|
|
return Package(structure);
|
|
|
|
}
|
2011-07-15 13:34:10 +02:00
|
|
|
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2013-07-29 19:05:59 +02:00
|
|
|
// qDebug() << "Couldn't load Package for" << packageFormat << "! reason given: " << error;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2011-07-15 13:34:10 +02:00
|
|
|
|
2011-07-19 21:40:12 +02:00
|
|
|
return Package();
|
2011-07-13 20:20:36 +02:00
|
|
|
}
|
|
|
|
|
2010-07-27 22:07:53 +00:00
|
|
|
KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp)
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
{
|
2010-07-27 22:07:53 +00:00
|
|
|
KPluginInfo::List list;
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
|
2012-06-18 13:11:26 +05:30
|
|
|
if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) {
|
2010-07-27 22:07:53 +00:00
|
|
|
list = internalAppletInfo(category);
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
//FIXME: this assumes we are always use packages.. no pure c++
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
if (category.isEmpty()) { //use all but the excluded categories
|
2012-03-24 19:33:54 +01:00
|
|
|
KConfigGroup group(KSharedConfig::openConfig(), "General");
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
|
2015-05-07 16:26:37 +02:00
|
|
|
|
|
|
|
auto filter = [&excluded, &parentApp](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
const QString pa = md.value("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
|
|
|
|
for (auto md : KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter)) {
|
2015-06-10 09:35:21 -07:00
|
|
|
auto pi = KPluginInfo(KService::serviceByStorageId(md.metaDataFileName()));
|
|
|
|
if (!pi.isValid()) {
|
|
|
|
qWarning() << "Could not load plugin info:" << md.metaDataFileName() << "skipping plugin";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list << pi;
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
}
|
2015-05-07 16:26:37 +02:00
|
|
|
return list;
|
|
|
|
|
|
|
|
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
} else { //specific category (this could be an excluded one - is that bad?)
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
auto filter = [&category, &parentApp](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
const QString pa = md.value("X-KDE-ParentApp");
|
|
|
|
if (category == "Miscellaneous") {
|
|
|
|
return (pa.isEmpty() || pa == parentApp) && (md.category() == category || md.category().isEmpty());
|
|
|
|
} else {
|
|
|
|
return (pa.isEmpty() || pa == parentApp) && md.category() == category;
|
|
|
|
}
|
|
|
|
};
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
|
2015-06-10 09:35:21 -07:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
//NOTE: it still produces kplugininfos from KServices because some user code expects
|
|
|
|
//info.sevice() to be valid and would crash ohtherwise
|
|
|
|
for (auto md : KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter)) {
|
2015-06-10 09:35:21 -07:00
|
|
|
auto pi = KPluginInfo(KService::serviceByStorageId(md.metaDataFileName()));
|
|
|
|
if (!pi.isValid()) {
|
|
|
|
qWarning() << "Could not load plugin info:" << md.metaDataFileName() << "skipping plugin";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list << pi;
|
2015-05-07 16:26:37 +02:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 21:34:24 +01:00
|
|
|
KPluginInfo::List PluginLoader::listAppletInfoForMimeType(const QString &mimeType)
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
auto filter = [&mimeType](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.value("X-Plasma-DropMimeTypes").contains(mimeType);
|
|
|
|
};
|
|
|
|
return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter).toVector());
|
2013-02-12 21:34:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List PluginLoader::listAppletInfoForUrl(const QUrl &url)
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
QString parentApp;
|
|
|
|
QCoreApplication *app = QCoreApplication::instance();
|
|
|
|
if (app) {
|
|
|
|
parentApp = app->applicationName();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto filter = [&parentApp](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
const QString pa = md.value("X-KDE-ParentApp");
|
|
|
|
return (pa.isEmpty() || pa == parentApp) && !md.value("X-Plasma-DropUrlPatterns").isEmpty();
|
|
|
|
};
|
|
|
|
KPluginInfo::List allApplets = KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter).toVector());
|
2013-02-12 21:34:24 +01:00
|
|
|
|
|
|
|
KPluginInfo::List filtered;
|
|
|
|
foreach (const KPluginInfo &info, allApplets) {
|
|
|
|
QStringList urlPatterns = info.property("X-Plasma-DropUrlPatterns").toStringList();
|
|
|
|
foreach (const QString &glob, urlPatterns) {
|
|
|
|
QRegExp rx(glob);
|
|
|
|
rx.setPatternSyntax(QRegExp::Wildcard);
|
|
|
|
if (rx.exactMatch(url.toString())) {
|
|
|
|
#ifndef NDEBUG
|
2013-07-29 19:05:59 +02:00
|
|
|
// qDebug() << info.name() << "matches" << glob << url;
|
2013-02-12 21:34:24 +01:00
|
|
|
#endif
|
|
|
|
filtered << info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered;
|
|
|
|
}
|
|
|
|
|
2013-02-12 21:40:59 +01:00
|
|
|
QStringList PluginLoader::listAppletCategories(const QString &parentApp, bool visibleOnly)
|
|
|
|
{
|
|
|
|
KConfigGroup group(KSharedConfig::openConfig(), "General");
|
|
|
|
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
|
2015-05-07 16:26:37 +02:00
|
|
|
auto filter = [&parentApp, &excluded, visibleOnly](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
const QString pa = md.value("X-KDE-ParentApp");
|
|
|
|
return (pa.isEmpty() || pa == parentApp) && (excluded.isEmpty() || excluded.contains(md.value("X-KDE-PluginInfo-Category"))) && (!visibleOnly || !md.isHidden());
|
|
|
|
};
|
|
|
|
QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter);
|
2013-02-12 21:40:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
QStringList categories;
|
2015-05-07 16:26:37 +02:00
|
|
|
for (auto plugin : allApplets) {
|
|
|
|
if (plugin.category().isEmpty()) {
|
2013-02-12 21:40:59 +01:00
|
|
|
if (!categories.contains(i18nc("misc category", "Miscellaneous"))) {
|
|
|
|
categories << i18nc("misc category", "Miscellaneous");
|
|
|
|
}
|
2015-05-07 16:26:37 +02:00
|
|
|
} else {
|
|
|
|
categories << plugin.category();
|
2013-02-12 21:40:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
categories.sort();
|
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
2013-02-12 21:45:18 +01:00
|
|
|
void PluginLoader::setCustomAppletCategories(const QStringList &categories)
|
|
|
|
{
|
2013-02-12 22:05:14 +01:00
|
|
|
PluginLoaderPrivate::s_customCategories = QSet<QString>::fromList(categories);
|
2013-02-12 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList PluginLoader::customAppletCategories() const
|
|
|
|
{
|
2013-02-12 22:05:14 +01:00
|
|
|
return PluginLoaderPrivate::s_customCategories.toList();
|
2013-02-12 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QString PluginLoader::appletCategory(const QString &appletName)
|
2013-02-12 21:54:08 +01:00
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
const KPackage::Package p = KPackage::PackageLoader::self()->loadPackage("Plasma/Applet", appletName);
|
|
|
|
if (!p.isValid()) {
|
2013-02-12 21:54:08 +01:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
return p.metadata().category();
|
2013-02-12 21:54:08 +01:00
|
|
|
}
|
|
|
|
|
2013-02-19 13:09:33 +01:00
|
|
|
KPluginInfo::List PluginLoader::listContainments(const QString &category,
|
2014-04-26 01:45:47 +02:00
|
|
|
const QString &parentApp)
|
2013-02-19 13:09:33 +01:00
|
|
|
{
|
|
|
|
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)
|
2013-02-19 13:09:33 +01:00
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!KPackage::PackageLoader::self()->loadPackageStructure("Plasma/Applet")) {
|
2015-05-08 19:24:38 +02:00
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/Applet", new PlasmoidPackage());
|
2013-02-19 13:09:33 +01:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
KConfigGroup group(KSharedConfig::openConfig(), "General");
|
|
|
|
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
|
|
|
|
auto filter = [&type, &category, &parentApp](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
if (!md.serviceTypes().contains("Plasma/Containment")) {
|
|
|
|
return false;
|
2013-02-19 13:09:33 +01:00
|
|
|
}
|
2015-05-07 16:26:37 +02:00
|
|
|
const QString pa = md.value("X-KDE-ParentApp");
|
|
|
|
if (!pa.isEmpty() && pa != parentApp) {
|
|
|
|
return false;
|
2013-03-07 19:55:45 +01:00
|
|
|
}
|
2013-02-19 13:09:33 +01:00
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!type.isEmpty() && md.value("X-Plasma-ContainmentType") != type) {
|
|
|
|
return false;
|
2013-02-19 13:09:33 +01:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!category.isEmpty() && md.value("X-KDE-PluginInfo-Category") != category) {
|
|
|
|
return false;
|
2013-02-19 13:09:33 +01:00
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter).toVector());
|
2013-02-19 13:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List PluginLoader::listContainmentsForMimeType(const QString &mimeType)
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!KPackage::PackageLoader::self()->loadPackageStructure("Plasma/Applet")) {
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/Applet", new DataEnginePackage());
|
|
|
|
}
|
|
|
|
auto filter = [&mimeType](const KPluginMetaData &md) -> bool
|
|
|
|
{
|
|
|
|
return md.value("X-KDE-ServiceTypes").contains("Plasma/Containment") && md.value("X-Plasma-DropMimeTypes").contains(mimeType);
|
|
|
|
};
|
|
|
|
|
|
|
|
return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages("Plasma/Applet", QString(), filter).toVector());
|
2013-02-19 13:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList PluginLoader::listContainmentTypes()
|
|
|
|
{
|
2015-05-07 16:26:37 +02:00
|
|
|
if (!KPackage::PackageLoader::self()->loadPackageStructure("Plasma/Applet")) {
|
|
|
|
KPackage::PackageLoader::self()->addKnownPackageStructure("Plasma/Applet", new DataEnginePackage());
|
|
|
|
}
|
2013-02-19 13:09:33 +01:00
|
|
|
KPluginInfo::List containmentInfos = listContainments();
|
|
|
|
QSet<QString> types;
|
|
|
|
|
|
|
|
foreach (const KPluginInfo &containmentInfo, containmentInfos) {
|
2013-03-07 19:28:06 +01:00
|
|
|
QStringList theseTypes = containmentInfo.service()->property("X-Plasma-ContainmentType").toStringList();
|
2013-02-19 13:09:33 +01:00
|
|
|
foreach (const QString &type, theseTypes) {
|
|
|
|
types.insert(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.toList();
|
|
|
|
}
|
|
|
|
|
2010-07-27 22:07:53 +00:00
|
|
|
KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp)
|
|
|
|
{
|
|
|
|
KPluginInfo::List list;
|
|
|
|
|
2012-06-18 13:11:26 +05:30
|
|
|
if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) {
|
2010-07-27 22:07:53 +00:00
|
|
|
list = internalDataEngineInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint;
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_dataEnginePluginDir, "Plasma/DataEngine", constraint));
|
2013-09-12 02:03:52 +02:00
|
|
|
return list;
|
2010-07-27 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-19 21:39:51 +02:00
|
|
|
KPluginInfo::List PluginLoader::listContainmentActionsInfo(const QString &parentApp)
|
|
|
|
{
|
|
|
|
KPluginInfo::List list;
|
|
|
|
|
2012-06-18 13:11:26 +05:30
|
|
|
if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) {
|
2011-07-19 21:39:51 +02:00
|
|
|
list = internalContainmentActionsInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint;
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:26:37 +02:00
|
|
|
list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, "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
|
2011-07-19 21:39:51 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ContainmentActions", constraint);
|
2015-05-07 16:26:37 +02:00
|
|
|
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)
|
2011-10-04 16:50:44 +02:00
|
|
|
{
|
2010-07-15 21:38:56 +00:00
|
|
|
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)
|
2010-07-15 21:38:56 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(name)
|
|
|
|
return 0;
|
2010-07-15 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-07-15 21:38:56 +00:00
|
|
|
Q_UNUSED(name)
|
|
|
|
Q_UNUSED(args)
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
return 0;
|
2010-07-15 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 13:34:10 +02:00
|
|
|
Package PluginLoader::internalLoadPackage(const QString &name, const QString &specialization)
|
2011-07-13 20:20:36 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(name);
|
2011-07-15 13:34:10 +02:00
|
|
|
Q_UNUSED(specialization);
|
2011-07-13 20:20:36 +02:00
|
|
|
return Package();
|
|
|
|
}
|
|
|
|
|
2010-07-27 22:07:53 +00:00
|
|
|
KPluginInfo::List PluginLoader::internalAppletInfo(const QString &category) const
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(category)
|
2010-07-27 22:07:53 +00:00
|
|
|
return KPluginInfo::List();
|
|
|
|
}
|
Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo.
Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes...
svn path=/trunk/KDE/kdelibs/; revision=1154551
2010-07-25 20:56:03 +00:00
|
|
|
|
2010-07-27 22:07:53 +00:00
|
|
|
KPluginInfo::List PluginLoader::internalDataEngineInfo() const
|
|
|
|
{
|
|
|
|
return KPluginInfo::List();
|
|
|
|
}
|
|
|
|
|
2010-07-28 18:17:58 +00:00
|
|
|
KPluginInfo::List PluginLoader::internalServiceInfo() const
|
|
|
|
{
|
|
|
|
return KPluginInfo::List();
|
|
|
|
}
|
|
|
|
|
2011-07-19 21:39:51 +02:00
|
|
|
KPluginInfo::List PluginLoader::internalContainmentActionsInfo() const
|
|
|
|
{
|
|
|
|
return KPluginInfo::List();
|
|
|
|
}
|
|
|
|
|
2010-10-13 21:21:30 +00:00
|
|
|
static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category = QString())
|
2010-07-27 22:07:53 +00:00
|
|
|
{
|
2013-07-10 03:27:19 +02:00
|
|
|
QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
2014-04-27 23:04:18 +02:00
|
|
|
PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/" + type + "/*.desktop",
|
2014-04-26 01:45:47 +02:00
|
|
|
QStandardPaths::LocateFile);
|
2010-07-27 22:07:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return standardInternalInfo("applets", category);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List PluginLoader::standardInternalDataEngineInfo() const
|
|
|
|
{
|
|
|
|
return standardInternalInfo("dataengines");
|
|
|
|
}
|
|
|
|
|
2010-07-28 18:17:58 +00:00
|
|
|
KPluginInfo::List PluginLoader::standardInternalServiceInfo() const
|
|
|
|
{
|
|
|
|
return standardInternalInfo("services");
|
|
|
|
}
|
|
|
|
|
2010-07-15 21:06:21 +00:00
|
|
|
} // Plasma Namespace
|
|
|
|
|