From dfaaea7c1cad41fe0983264564f5851b5bbecb0a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 12 Feb 2013 21:40:59 +0100 Subject: [PATCH] Applet::listCategories in PluginLoader Applet::listCategories -> PluginLoader::listAppletCategories --- plasma/applet.cpp | 44 ----------------------------------------- plasma/applet.h | 14 ------------- plasma/pluginloader.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ plasma/pluginloader.h | 18 +++++++++++++++-- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/plasma/applet.cpp b/plasma/applet.cpp index c7527938b..52dce9dac 100644 --- a/plasma/applet.cpp +++ b/plasma/applet.cpp @@ -931,50 +931,6 @@ bool Applet::hasValidAssociatedApplication() const 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 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) { AppletPrivate::s_customCategories = QSet::fromList(categories); diff --git a/plasma/applet.h b/plasma/applet.h index f3911084a..f94b05522 100644 --- a/plasma/applet.h +++ b/plasma/applet.h @@ -267,20 +267,6 @@ class PLASMA_EXPORT Applet : public QObject */ 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 * set of categories known to libplasma for Applets. diff --git a/plasma/pluginloader.cpp b/plasma/pluginloader.cpp index 09831cdd7..1493d2a5c 100644 --- a/plasma/pluginloader.cpp +++ b/plasma/pluginloader.cpp @@ -455,6 +455,50 @@ KPluginInfo::List PluginLoader::listAppletInfoForUrl(const QUrl &url) 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 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) { diff --git a/plasma/pluginloader.h b/plasma/pluginloader.h index 09450daac..9b28bf01a 100644 --- a/plasma/pluginloader.h +++ b/plasma/pluginloader.h @@ -141,14 +141,28 @@ public: * * @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. * * @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.