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"
43 class PluginLoaderPrivate
63 kDebug() <<
"Cannot set pluginLoader, already set!" <<
s_pluginLoader;
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;
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()) {
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);
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);
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);
350 return KPluginInfo::List();
355 return KPluginInfo::List();
360 return KPluginInfo::List();
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;