From f6a4e9612d1975b87b5b1052235ca1c935f92f3e Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 17 Jul 2007 21:30:27 +0000 Subject: [PATCH] * X-PlasmoidCategory => X-KDE-PluginInfo-Category * allow filtering applets by category and parent app * allow filtering categories by parent app svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=689200 --- applet.cpp | 56 ++++++++++++++++++++++++------ applet.h | 23 ++++++++++-- servicetypes/plasma_applet.desktop | 2 +- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/applet.cpp b/applet.cpp index 63c28b398..a0e3a0bc3 100644 --- a/applet.cpp +++ b/applet.cpp @@ -188,12 +188,12 @@ QString Applet::name() const QString Applet::category() const { - return d->appletDescription->property("X-PlasmoidCategory").toString(); + return d->appletDescription->property("X-KDE-PluginInfo-Category").toString(); } QString Applet::category(const KPluginInfo* applet) { - return applet->property("X-PlasmoidCategory").toString(); + return applet->property("X-KDE-PluginInfo-Category").toString(); } QString Applet::category(const QString& appletName) @@ -209,7 +209,7 @@ QString Applet::category(const QString& appletName) return QString(); } - return offers.first()->property("X-PlasmoidCategory").toString(); + return offers.first()->property("X-KDE-PluginInfo-Category").toString(); } bool Applet::immutable() const @@ -405,24 +405,58 @@ void Applet::showConfigurationInterface() { } -KPluginInfo::List Applet::knownApplets() +KPluginInfo::List Applet::knownApplets(const QString &category, + const QString &parentApp) { - KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet"); + QString constraint; + + if (parentApp.isEmpty()) { + constraint.append("not exist [X-KDE-ParentApp]"); + } else { + constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'"); + } + + if (!category.isEmpty()) { + if (!constraint.isEmpty()) { + constraint.append(" and "); + } + + if (category == "NONE") { + constraint.append("(not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')"); + } else { + constraint.append("'").append(category).append("' in [X-KDE-PluginInfo-Category]"); + } + } + + KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); return KPluginInfo::fromServices(offers); } -QStringList Applet::knownCategories() +QStringList Applet::knownCategories(const QString &parentApp) { - KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", "exist [X-PlasmoidCategory]"); + QString constraint = "exist [X-KDE-PluginInfo-Category]"; + + if (parentApp.isEmpty()) { + constraint.append(" and not exist [X-KDE-ParentApp]"); + } else { + constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'"); + } + + KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); QStringList categories; foreach (KService::Ptr applet, offers) { - QString appletCategory = applet->property("X-PlasmoidCategory").toString(); - if (!appletCategory.isEmpty()) { - if (!categories.contains(appletCategory)) { - categories << appletCategory; + QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString(); + kDebug() << " and we have " << appletCategory << endl; + if (appletCategory.isEmpty()) { + if (!categories.contains(i18n("Misc"))) { + categories << i18n("Misc"); } + } else if (!categories.contains(appletCategory)) { + categories << appletCategory; } } + + categories.sort(); return categories; } diff --git a/applet.h b/applet.h index fea4227ac..33f1cd66a 100644 --- a/applet.h +++ b/applet.h @@ -157,15 +157,34 @@ class PLASMA_EXPORT Applet : public QObject, public Widget * Returns a list of all known applets in a hash keyed by a unique * identifier for each applet. * + * @param category Only applets matchin this category will be returned. + * Useful in conjunction with knownCategories. + * If NONE is passed in, then applets without a + * Categories= entry are returned. + * If an empty string is passed in, all applets are + * returned. + * @param parentApp the application to filter applets on. Uses the + * X-KDE-ParentApp entry (if any) in the plugin info. + * The default value of QString() will result in a + * list containing only applets not specifically + * registered to an application. * @return list of applets **/ - static KPluginInfo::List knownApplets(); + static KPluginInfo::List knownApplets(const QString &category = QString(), + const QString &parentApp = QString()); /** * Returns a list of all the categories used by * installed applets. + * + * @param parentApp the application to filter applets on. Uses the + * X-KDE-ParentApp entry (if any) in the plugin info. + * The default value of QString() will result in a + * list containing only applets not specifically + * registered to an application. + * @return list of categories */ - static QStringList knownCategories(); + static QStringList knownCategories(const QString &parentApp = QString()); /** * @return true if this plasmoid provides a GUI configuration diff --git a/servicetypes/plasma_applet.desktop b/servicetypes/plasma_applet.desktop index 19f1903cf..56e6e318f 100644 --- a/servicetypes/plasma_applet.desktop +++ b/servicetypes/plasma_applet.desktop @@ -20,7 +20,7 @@ Comment[sv]=Plasma-miniprogram Comment[uk]=Аплет Плазми Comment[zh_TW]=Plasma 小程式 -[PropertyDef::X-PlasmoidCategory] +[PropertyDef::X-KDE-PluginInfo-Category] Type=QString [PropertyDef::X-KDE-ParentApp]