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
This commit is contained in:
Ryan James Rix 2010-07-25 20:56:03 +00:00
parent 7e23828338
commit 8d2574b6d9
3 changed files with 78 additions and 25 deletions

View File

@ -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)

View File

@ -23,6 +23,7 @@
#include <kglobal.h>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <kplugininfo.h>
#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

View File

@ -21,6 +21,7 @@
#define PLUGIN_LOADER_H
#include <plasma/plasma.h>
#include <kplugininfo.h>
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