Applet::listCategories in PluginLoader

Applet::listCategories -> PluginLoader::listAppletCategories
This commit is contained in:
Marco Martin 2013-02-12 21:40:59 +01:00
parent 42bc0a2208
commit dfaaea7c1c
4 changed files with 60 additions and 60 deletions

View File

@ -931,50 +931,6 @@ bool Applet::hasValidAssociatedApplication() const
return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this); return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
} }
QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
{
QString constraint = AppletPrivate::parentAppConstraint(parentApp);
constraint.append(" and exist [X-KDE-PluginInfo-Category]");
KConfigGroup group(KSharedConfig::openConfig(), "General");
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
foreach (const QString &category, excluded) {
constraint.append(" and [X-KDE-PluginInfo-Category] != '").append(category).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
QStringList categories;
QSet<QString> known = AppletPrivate::knownCategories();
foreach (const KService::Ptr &applet, offers) {
QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
if (visibleOnly && applet->noDisplay()) {
// we don't want to show the hidden category
continue;
}
//kDebug() << " and we have " << appletCategory;
if (!appletCategory.isEmpty() && !known.contains(appletCategory.toLower())) {
#ifndef NDEBUG
kDebug() << "Unknown category: " << applet->name() << "says it is in the"
<< appletCategory << "category which is unknown to us";
#endif
appletCategory.clear();
}
if (appletCategory.isEmpty()) {
if (!categories.contains(i18nc("misc category", "Miscellaneous"))) {
categories << i18nc("misc category", "Miscellaneous");
}
} else if (!categories.contains(appletCategory)) {
categories << appletCategory;
}
}
categories.sort();
return categories;
}
void Applet::setCustomCategories(const QStringList &categories) void Applet::setCustomCategories(const QStringList &categories)
{ {
AppletPrivate::s_customCategories = QSet<QString>::fromList(categories); AppletPrivate::s_customCategories = QSet<QString>::fromList(categories);

View File

@ -267,20 +267,6 @@ class PLASMA_EXPORT Applet : public QObject
*/ */
void setTitle(const QString &title) const; void setTitle(const QString &title) const;
/**
* 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
* @param visibleOnly true if it should only return applets that are marked as visible
*/
static QStringList listCategories(const QString &parentApp = QString(),
bool visibleOnly = true);
/** /**
* Sets the list of custom categories that are used in addition to the default * Sets the list of custom categories that are used in addition to the default
* set of categories known to libplasma for Applets. * set of categories known to libplasma for Applets.

View File

@ -455,6 +455,50 @@ KPluginInfo::List PluginLoader::listAppletInfoForUrl(const QUrl &url)
return filtered; return filtered;
} }
QStringList PluginLoader::listAppletCategories(const QString &parentApp, bool visibleOnly)
{
QString constraint = AppletPrivate::parentAppConstraint(parentApp);
constraint.append(" and exist [X-KDE-PluginInfo-Category]");
KConfigGroup group(KSharedConfig::openConfig(), "General");
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
foreach (const QString &category, excluded) {
constraint.append(" and [X-KDE-PluginInfo-Category] != '").append(category).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
QStringList categories;
QSet<QString> known = AppletPrivate::knownCategories();
foreach (const KService::Ptr &applet, offers) {
QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
if (visibleOnly && applet->noDisplay()) {
// we don't want to show the hidden category
continue;
}
//kDebug() << " and we have " << appletCategory;
if (!appletCategory.isEmpty() && !known.contains(appletCategory.toLower())) {
#ifndef NDEBUG
kDebug() << "Unknown category: " << applet->name() << "says it is in the"
<< appletCategory << "category which is unknown to us";
#endif
appletCategory.clear();
}
if (appletCategory.isEmpty()) {
if (!categories.contains(i18nc("misc category", "Miscellaneous"))) {
categories << i18nc("misc category", "Miscellaneous");
}
} else if (!categories.contains(appletCategory)) {
categories << appletCategory;
}
}
categories.sort();
return categories;
}
KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp) KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp)
{ {

View File

@ -141,14 +141,28 @@ public:
* *
* @return list of applets * @return list of applets
**/ **/
static KPluginInfo::List listAppletInfoForMimeType(const QString &mimetype); KPluginInfo::List listAppletInfoForMimeType(const QString &mimetype);
/** /**
* Returns a list of all known applets associated with a certain URL. * Returns a list of all known applets associated with a certain URL.
* *
* @return list of applets * @return list of applets
**/ **/
static KPluginInfo::List listAppletInfoForUrl(const QUrl &url); KPluginInfo::List listAppletInfoForUrl(const QUrl &url);
/**
* 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
* @param visibleOnly true if it should only return applets that are marked as visible
*/
QStringList listAppletCategories(const QString &parentApp = QString(),
bool visibleOnly = true);
/** /**
* Returns a list of all known DataEngines. * Returns a list of all known DataEngines.