offer info listing as a feature of the manager, use PluginLoader a bit here (needs work to be fully disentangled)

svn path=/trunk/KDE/kdelibs/; revision=1156226
This commit is contained in:
Aaron J. Seigo 2010-07-28 18:19:00 +00:00
parent 6a09a6bb63
commit 4a2f04564b
2 changed files with 52 additions and 23 deletions

View File

@ -43,6 +43,7 @@
#include <Weaver/ThreadWeaver.h>
#include "private/runnerjobs_p.h"
#include "pluginloader.h"
#include "querymatch.h"
using ThreadWeaver::Weaver;
@ -173,7 +174,7 @@ public:
void loadRunners()
{
KConfigGroup config = configGroup();
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
KPluginInfo::List offers = RunnerManager::listRunnerInfo();
const bool loadAll = config.readEntry("loadAll", false);
QStringList whiteList = config.readEntry("pluginWhiteList", QStringList());
@ -187,16 +188,17 @@ public:
advertiseSingleRunnerIds.clear();
foreach (const KService::Ptr &service, offers) {
QMutableListIterator<KPluginInfo> it(offers);
while (it.hasNext()) {
KPluginInfo &description = it.next();
//kDebug() << "Loading runner: " << service->name() << service->storageId();
QString tryExec = service->property("TryExec", QVariant::String).toString();
QString tryExec = description.property("TryExec").toString();
//kDebug() << "TryExec is" << tryExec;
if (!tryExec.isEmpty() && KStandardDirs::findExe(tryExec).isEmpty()) {
// we don't actually have this application!
continue;
}
KPluginInfo description(service);
const QString runnerName = description.pluginName();
description.load(pluginConf);
@ -204,7 +206,7 @@ public:
const bool selected = loadAll ||
(description.isPluginEnabled() && (noWhiteList || whiteList.contains(runnerName)));
const bool singleQueryModeEnabled = service->property("X-Plasma-AdvertiseSingleRunnerQueryMode", QVariant::Bool).toBool();
const bool singleQueryModeEnabled = description.property("X-Plasma-AdvertiseSingleRunnerQueryMode").toBool();
if (singleQueryModeEnabled) {
advertiseSingleRunnerIds.insert(runnerName, description.name());
@ -213,7 +215,7 @@ public:
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
if (selected) {
if (!loaded) {
AbstractRunner *runner = loadInstalledRunner(service);
AbstractRunner *runner = loadInstalledRunner(description.service());
if (runner) {
runners.insert(runnerName, runner);
@ -232,22 +234,31 @@ public:
AbstractRunner *loadInstalledRunner(const KService::Ptr service)
{
AbstractRunner *runner = 0;
const QString api = service->property("X-Plasma-API").toString();
if (!service) {
return 0;
}
if (api.isEmpty()) {
QVariantList args;
args << service->storageId();
if (Plasma::isPluginVersionCompatible(KPluginLoader(*service).pluginVersion())) {
QString error;
runner = service->createInstance<AbstractRunner>(q, args, &error);
if (!runner) {
kDebug() << "Failed to load runner:" << service->name() << ". error reported:" << error;
}
}
AbstractRunner *runner = PluginLoader::pluginLoader()->loadRunner(service->property("X-KDE-PluginInfo-Name", QVariant::String).toString());
if (runner) {
runner->setParent(q);
} else {
//kDebug() << "got a script runner known as" << api;
runner = new AbstractRunner(service, q);
const QString api = service->property("X-Plasma-API").toString();
if (api.isEmpty()) {
QVariantList args;
args << service->storageId();
if (Plasma::isPluginVersionCompatible(KPluginLoader(*service).pluginVersion())) {
QString error;
runner = service->createInstance<AbstractRunner>(q, args, &error);
if (!runner) {
kDebug() << "Failed to load runner:" << service->name() << ". error reported:" << error;
}
}
} else {
//kDebug() << "got a script runner known as" << api;
runner = new AbstractRunner(service, q);
}
}
if (runner) {
@ -434,9 +445,7 @@ void RunnerManager::loadRunner(const QString &path)
{
if (!d->runners.contains(path)) {
AbstractRunner *runner = new AbstractRunner(this, path);
if (runner) {
d->runners.insert(path, runner);
}
d->runners.insert(path, runner);
}
}
@ -584,6 +593,11 @@ QMimeData * RunnerManager::mimeDataForMatch(const QueryMatch &match) const
return 0;
}
KPluginInfo::List RunnerManager::listRunnerInfo(const QString &parentApp)
{
return PluginLoader::pluginLoader()->listRunnerInfo(parentApp);
}
void RunnerManager::setupMatchSession()
{
d->teardownRequested = false;

View File

@ -25,6 +25,8 @@
#include <QtCore/QList>
#include <QtCore/QObject>
#include <kplugininfo.h>
#include <plasma/plasma_export.h>
#include "abstractrunner.h"
@ -203,6 +205,19 @@ class PLASMA_EXPORT RunnerManager : public QObject
*/
QMimeData * mimeDataForMatch(const QString &id) const;
/**
* Returns a list of all known Runner implementations
*
* @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 AbstractRunners
* @since 4.6
**/
static KPluginInfo::List listRunnerInfo(const QString &parentApp = QString());
public Q_SLOTS:
/**
* Call this method when the runners should be prepared for a query session.