From 8d2574b6d932a121abb0e683d379af4333859938 Mon Sep 17 00:00:00 2001 From: Ryan James Rix Date: Sun, 25 Jul 2010 20:56:03 +0000 Subject: [PATCH] Moving Plasma::Applet::listAppletInfo into the PluginLoader logic. Also implemented internalAppletNames which, if implemented, will return a QStringList of the available applets' names. PluginLoader::listAppletInfo will then search for .desktop files in $APPDATA/plasma/applets/ which match the applets' names (ie. $APPDATA/plasma/applets/org.skrooge.report.desktop), and add them to the KPluginInfo::List returned by PluginLoader::listAppletInfo and subsequently Plasma::Applet::listAppletInfo. Since the applets are dynamically loaded, the .desktop files don't need an X-KDE-Library entries, but the others will be used, for example X-KDE-PluginInfo-Name (which will be the value given to PluginLoader::internalAppletLoad, so it is really important), Icon, Type, ServiceTypes... svn path=/trunk/KDE/kdelibs/; revision=1154551 --- applet.cpp | 25 +----------------------- pluginloader.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ pluginloader.h | 28 ++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 25 deletions(-) diff --git a/applet.cpp b/applet.cpp index f3e3f7090..198c91053 100644 --- a/applet.cpp +++ b/applet.cpp @@ -2160,30 +2160,7 @@ QString AppletPrivate::parentAppConstraint(const QString &parentApp) KPluginInfo::List Applet::listAppletInfo(const QString &category, const QString &parentApp) { - QString constraint = AppletPrivate::parentAppConstraint(parentApp); - - //note: constraint guaranteed non-empty from here down - if (category.isEmpty()) { //use all but the excluded categories - KConfigGroup group(KGlobal::config(), "General"); - QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); - foreach (const QString &category, excluded) { - constraint.append(" and [X-KDE-PluginInfo-Category] != '").append(category).append("'"); - } - } else { //specific category (this could be an excluded one - is that bad?) - constraint.append(" and ").append("[X-KDE-PluginInfo-Category] == '").append(category).append("'"); - if (category == "Miscellaneous") { - constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')"); - } - } - - KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); - - //now we have to do some manual filtering because the constraint can't handle everything - AppletPrivate::filterOffers(offers); - - //kDebug() << "Applet::listAppletInfo constraint was '" << constraint - // << "' which got us " << offers.count() << " matches"; - return KPluginInfo::fromServices(offers); + return PluginLoader::pluginLoader()->listAppletInfo(category, parentApp); } KPluginInfo::List Applet::listAppletInfoForMimetype(const QString &mimetype) diff --git a/pluginloader.cpp b/pluginloader.cpp index 83acf2f7c..19478f480 100644 --- a/pluginloader.cpp +++ b/pluginloader.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "applet.h" #include "containment.h" @@ -224,6 +225,48 @@ Service *PluginLoader::loadService(const QString &name, const QVariantList &args return service; } +KPluginInfo::List PluginLoader::listAppletInfo( const QString &category, const QString &parentApp ) +{ + KPluginInfo::List list = KPluginInfo::List(); + + if(PluginLoader::pluginLoader()){ + QStringList appletNames = internalAppletNames(category); + foreach ( QString appletName, appletNames ) { + KService::Ptr service = KService::serviceByStorageId( appletName ); + + if ( !service.isNull() ) { + KPluginInfo info( service ); + list.append(info); + } + } + } + + QString constraint = AppletPrivate::parentAppConstraint(parentApp); + + //note: constraint guaranteed non-empty from here down + if (category.isEmpty()) { //use all but the excluded categories + KConfigGroup group(KGlobal::config(), "General"); + QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); + foreach (const QString &category, excluded) { + constraint.append(" and [X-KDE-PluginInfo-Category] != '").append(category).append("'"); + } + } else { //specific category (this could be an excluded one - is that bad?) + constraint.append(" and ").append("[X-KDE-PluginInfo-Category] == '").append(category).append("'"); + if (category == "Miscellaneous") { + constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')"); + } + } + + KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); + + //now we have to do some manual filtering because the constraint can't handle everything + AppletPrivate::filterOffers(offers); + + //kDebug() << "Applet::listAppletInfo constraint was '" << constraint + // << "' which got us " << offers.count() << " matches"; + return KPluginInfo::fromServices(offers); +} + Applet* PluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args) { Q_UNUSED(name) @@ -246,5 +289,12 @@ Service* PluginLoader::internalLoadService(const QString &name, const QVariantLi return 0; } +QStringList PluginLoader::internalAppletNames(const QString &category) +{ + Q_UNUSED(category) + + return QStringList(); +} + } // Plasma Namespace diff --git a/pluginloader.h b/pluginloader.h index da9b6a56f..e6d2cee09 100644 --- a/pluginloader.h +++ b/pluginloader.h @@ -21,6 +21,7 @@ #define PLUGIN_LOADER_H #include +#include namespace Plasma { @@ -77,6 +78,8 @@ public: **/ Service *loadService(const QString &name, const QVariantList &args, QObject *parent = 0); + KPluginInfo::List listAppletInfo( const QString &category, const QString &parentApp ); + /** * Set the plugin loader which will be queried for all loads. * @@ -134,11 +137,34 @@ protected: **/ virtual Service *internalLoadService(const QString &name, const QVariantList &args, QObject *parent = 0); + /** + * A re-implementable method that allows subclasses to provide additional applets + * for listAppletInfo. If the application has no applets to give to the application, + * then the implementation should return QStringList(). + * This method is called by listAppletInfo prior to generating the list of applets installed + * on the system using the standard Plasma plugin mechanisms, and will try to find .desktop + * files for your applets. + * + * @param category Only applets matchin this category will be returned. + * Useful in conjunction with knownCategories. + * If "Misc" is passed in, then applets without a + * Categories= entry are also 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 + **/ + QStringList internalAppletNames(const QString &category); + + private: PluginLoaderPrivate * const d; }; } -Q_DECLARE_METATYPE( Plasma::PluginLoader* ) // so that it can be wrapped in QVariants, etc #endif