* 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
This commit is contained in:
Aaron J. Seigo 2007-07-17 21:30:27 +00:00
parent 9f555db9a1
commit f6a4e9612d
3 changed files with 67 additions and 14 deletions

View File

@ -188,12 +188,12 @@ QString Applet::name() const
QString Applet::category() 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) 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) QString Applet::category(const QString& appletName)
@ -209,7 +209,7 @@ QString Applet::category(const QString& appletName)
return QString(); return QString();
} }
return offers.first()->property("X-PlasmoidCategory").toString(); return offers.first()->property("X-KDE-PluginInfo-Category").toString();
} }
bool Applet::immutable() const 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); 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; QStringList categories;
foreach (KService::Ptr applet, offers) { foreach (KService::Ptr applet, offers) {
QString appletCategory = applet->property("X-PlasmoidCategory").toString(); QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
if (!appletCategory.isEmpty()) { kDebug() << " and we have " << appletCategory << endl;
if (!categories.contains(appletCategory)) { if (appletCategory.isEmpty()) {
if (!categories.contains(i18n("Misc"))) {
categories << i18n("Misc");
}
} else if (!categories.contains(appletCategory)) {
categories << appletCategory; categories << appletCategory;
} }
} }
}
categories.sort();
return categories; return categories;
} }

View File

@ -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 * Returns a list of all known applets in a hash keyed by a unique
* identifier for each applet. * 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 * @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 * Returns a list of all the categories used by
* installed applets. * 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 * @return true if this plasmoid provides a GUI configuration

View File

@ -20,7 +20,7 @@ Comment[sv]=Plasma-miniprogram
Comment[uk]=Аплет Плазми Comment[uk]=Аплет Плазми
Comment[zh_TW]=Plasma Comment[zh_TW]=Plasma
[PropertyDef::X-PlasmoidCategory] [PropertyDef::X-KDE-PluginInfo-Category]
Type=QString Type=QString
[PropertyDef::X-KDE-ParentApp] [PropertyDef::X-KDE-ParentApp]