25#include <kservicetypetrader.h>
26#include <kstandarddirs.h>
27#include <kplugininfo.h>
34#include "private/applet_p.h"
35#include "private/extenderapplet_p.h"
36#include "private/service_p.h"
37#include "private/storage_p.h"
43class PluginLoaderPrivate
48PluginLoader::PluginLoader()
53PluginLoader::~PluginLoader()
63 kDebug() <<
"Cannot set pluginLoader, already set!" <<
s_pluginLoader;
79Applet *PluginLoader::loadApplet(
const QString &name, uint appletId,
const QVariantList &args)
91 const QString constraint = QString(
"[X-KDE-PluginInfo-Name] == '%1'").arg(name);
92 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/Applet", constraint);
94 bool isContainment =
false;
95 if (offers.isEmpty()) {
98 offers = KServiceTypeTrader::self()->query(
"Plasma/Containment", constraint);
99 if (offers.count() > 0) {
100 isContainment =
true;
108 AppletPrivate::filterOffers(offers);
109 if (offers.isEmpty()) {
110 kDebug() <<
"offers is empty for " << name;
114 KService::Ptr offer = offers.first();
117 appletId = ++AppletPrivate::s_maxAppletId;
120 QVariantList allArgs;
121 allArgs << offer->storageId() << appletId << args;
123 if (!offer->property(
"X-Plasma-API").toString().isEmpty()) {
124 kDebug() <<
"we have a script using the"
125 << offer->property(
"X-Plasma-API").toString() <<
"API";
129 if (offer->serviceTypes().contains(
"Plasma/Containment")) {
131 }
else if (offer->serviceTypes().contains(
"Plasma/PopupApplet")) {
134 return new Applet(0, allArgs);
139 KPluginLoader plugin(*offer);
142 (name !=
"internal:extender")) {
148 if (name ==
"internal:extender") {
149 applet =
new ExtenderApplet(0, allArgs);
151 applet = offer->createInstance<
Plasma::Applet>(0, allArgs, &error);
155 kWarning() <<
"Could not load applet" << name <<
"! reason given:" << error;
169 QString constraint = QString(
"[X-KDE-PluginInfo-Name] == '%1'").arg(name);
170 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/DataEngine",
174 if (offers.isEmpty()) {
175 kDebug() <<
"offers are empty for " << name <<
" with constraint " << constraint;
177 QVariantList allArgs;
178 allArgs << offers.first()->storageId();
179 QString api = offers.first()->property(
"X-Plasma-API").toString();
181 if (offers.first()) {
182 KPluginLoader plugin(*offers.first());
193 kDebug() <<
"Couldn't load engine \"" << name <<
"\". Error given: " << error;
206Service *PluginLoader::loadService(
const QString &name,
const QVariantList &args,
QObject *parent)
214 if (name.isEmpty()) {
215 return new NullService(QString(), parent);
216 }
else if (name ==
"org.kde.servicestorage") {
217 return new Storage(parent);
220 QString constraint = QString(
"[X-KDE-PluginInfo-Name] == '%1'").arg(name);
221 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/Service", constraint);
223 if (offers.isEmpty()) {
224 kDebug() <<
"offers is empty for " << name;
225 return new NullService(name, parent);
228 KService::Ptr offer = offers.first();
232 service = offer->createInstance<
Plasma::Service>(parent, args, &error);
236 kDebug() <<
"Couldn't load Service \"" << name <<
"\"! reason given: " << error;
237 return new NullService(name, parent);
240 if (service->
name().isEmpty()) {
247KPluginInfo::List PluginLoader::listAppletInfo(
const QString &category,
const QString &parentApp)
249 KPluginInfo::List list;
251 if (parentApp.isEmpty() || parentApp == KGlobal::mainComponent().componentName()) {
255 QString constraint = AppletPrivate::parentAppConstraint(parentApp);
258 if (category.isEmpty()) {
259 KConfigGroup group(KGlobal::config(),
"General");
260 QStringList excluded = group.readEntry(
"ExcludeCategories", QStringList());
261 foreach (
const QString &category, excluded) {
262 constraint.append(
" and [X-KDE-PluginInfo-Category] != '").append(category).append(
"'");
265 constraint.append(
" and ").append(
"[X-KDE-PluginInfo-Category] == '").append(category).append(
"'");
266 if (category ==
"Miscellaneous") {
267 constraint.append(
" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
271 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/Applet", constraint);
274 AppletPrivate::filterOffers(offers);
278 return KPluginInfo::fromServices(offers);
281KPluginInfo::List PluginLoader::listDataEngineInfo(
const QString &parentApp)
283 KPluginInfo::List list;
285 if (parentApp.isEmpty() || parentApp == KGlobal::mainComponent().componentName()) {
290 if (parentApp.isEmpty()) {
291 constraint.append(
"not exist [X-KDE-ParentApp]");
293 constraint.append(
"[X-KDE-ParentApp] == '").append(parentApp).append(
"'");
296 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/DataEngine", constraint);
297 return list + KPluginInfo::fromServices(offers);
300KPluginInfo::List PluginLoader::listRunnerInfo(
const QString &parentApp)
302 KPluginInfo::List list;
304 if (parentApp.isEmpty() || parentApp == KGlobal::mainComponent().componentName()) {
309 if (parentApp.isEmpty()) {
310 constraint.append(
"not exist [X-KDE-ParentApp]");
312 constraint.append(
"[X-KDE-ParentApp] == '").append(parentApp).append(
"'");
315 KService::List offers = KServiceTypeTrader::self()->query(
"Plasma/Runner", constraint);
316 return list + KPluginInfo::fromServices(offers);
319Applet* PluginLoader::internalLoadApplet(
const QString &name, uint appletId,
const QVariantList &args)
327DataEngine* PluginLoader::internalLoadDataEngine(
const QString &name)
339Service* PluginLoader::internalLoadService(
const QString &name,
const QVariantList &args,
QObject *parent)
347KPluginInfo::List PluginLoader::internalAppletInfo(
const QString &category)
const
350 return KPluginInfo::List();
353KPluginInfo::List PluginLoader::internalDataEngineInfo()
const
355 return KPluginInfo::List();
358KPluginInfo::List PluginLoader::internalRunnerInfo()
const
360 return KPluginInfo::List();
363KPluginInfo::List PluginLoader::internalServiceInfo()
const
365 return KPluginInfo::List();
370 QStringList files = KGlobal::dirs()->findAllResources(
"appdata",
371 "plasma/internal/" + type +
"/*.desktop",
372 KStandardDirs::NoDuplicates);
374 KPluginInfo::List allInfo = KPluginInfo::fromFiles(files);
376 if (category.isEmpty() || allInfo.isEmpty()) {
380 KPluginInfo::List matchingInfo;
381 foreach (
const KPluginInfo &info, allInfo) {
382 if (info.category().compare(category, Qt::CaseInsensitive) == 0) {
383 matchingInfo << info;
390KPluginInfo::List PluginLoader::standardInternalAppletInfo(
const QString &category)
const
395KPluginInfo::List PluginLoader::standardInternalDataEngineInfo()
const
400KPluginInfo::List PluginLoader::standardInternalRunnerInfo()
const
405KPluginInfo::List PluginLoader::standardInternalServiceInfo()
const
An abstract base class for Plasma Runner plugins.
The base class for plugins that provide backgrounds and applet grouping containers.
Data provider for plasmoids (Plasma plugins)
This is an abstract base class which defines an interface to which Plasma's Applet Loading logic can ...
virtual DataEngine * internalLoadDataEngine(const QString &name)
A re-implementable method that allows subclasses to override the default behaviour of loadDataEngine.
virtual KPluginInfo::List internalDataEngineInfo() const
A re-implementable method that allows subclasses to provide additional DataEngines for DataEngineMana...
virtual KPluginInfo::List internalRunnerInfo() const
Returns a list of all known Runner implementations.
virtual KPluginInfo::List internalAppletInfo(const QString &category) const
A re-implementable method that allows subclasses to provide additional applets for listAppletInfo.
virtual Service * internalLoadService(const QString &name, const QVariantList &args, QObject *parent=0)
A re-implementable method that allows subclasses to override the default behaviour of loadService.
virtual Applet * internalLoadApplet(const QString &name, uint appletId=0, const QVariantList &args=QVariantList())
A re-implementable method that allows subclasses to override the default behaviour of loadApplet.
virtual AbstractRunner * internalLoadRunner(const QString &name)
A re-implementable method that allows subclasses to override the default behaviour of loadRunner.
This class provides a generic API for write access to settings or services.
void setName(const QString &name)
Sets the name of the Service; useful for Services not loaded from plugins, which use the plugin name ...
Namespace for everything in libplasma.
bool isPluginVersionCompatible(unsigned int version)
Verifies that a plugin is compatible with plasma.
static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category=QString())
static PluginLoader * s_pluginLoader