changes to allow integration with kpluginselector; based on patch by Ryan Bitanga
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=809860
This commit is contained in:
parent
8b20aab3fb
commit
fb80125034
@ -118,6 +118,10 @@ KConfigGroup AbstractRunner::config() const
|
|||||||
return KConfigGroup(&runners, group);
|
return KConfigGroup(&runners, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractRunner::reloadConfiguration()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractRunner::performMatch(Plasma::RunnerContext &globalContext)
|
void AbstractRunner::performMatch(Plasma::RunnerContext &globalContext)
|
||||||
{
|
{
|
||||||
static const int reasonableRunTime = 1500;
|
static const int reasonableRunTime = 1500;
|
||||||
@ -167,21 +171,6 @@ void AbstractRunner::createRunOptions(QWidget *parent)
|
|||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractRunner::isConfigurable()
|
|
||||||
{
|
|
||||||
return d->hasConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AbstractRunner::setIsConfigurable(bool hasConfig)
|
|
||||||
{
|
|
||||||
d->hasConfig = hasConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AbstractRunner::createConfigurationInterface(QWidget *widget)
|
|
||||||
{
|
|
||||||
Q_UNUSED(widget)
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractRunner::Speed AbstractRunner::speed() const
|
AbstractRunner::Speed AbstractRunner::speed() const
|
||||||
{
|
{
|
||||||
return d->speed;
|
return d->speed;
|
||||||
|
@ -63,7 +63,7 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
HighPriority,
|
HighPriority,
|
||||||
HighestPriority
|
HighestPriority
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QList<AbstractRunner*> List;
|
typedef QList<AbstractRunner*> List;
|
||||||
|
|
||||||
virtual ~AbstractRunner();
|
virtual ~AbstractRunner();
|
||||||
@ -114,20 +114,6 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
*/
|
*/
|
||||||
virtual void createRunOptions(QWidget *widget);
|
virtual void createRunOptions(QWidget *widget);
|
||||||
|
|
||||||
/**
|
|
||||||
* If the runner itself has configuration options, this method returns true
|
|
||||||
*/
|
|
||||||
bool isConfigurable();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If isConfigurable() returns true, this method may to get
|
|
||||||
* a widget displaying the options the user can interact with to modify
|
|
||||||
* the behaviour of what happens when a given match is selected.
|
|
||||||
*
|
|
||||||
* @param widget the parent of the options widgets.
|
|
||||||
*/
|
|
||||||
virtual void createConfigurationInterface(QWidget *widget);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever an exact or possible match associated with this
|
* Called whenever an exact or possible match associated with this
|
||||||
* runner is triggered.
|
* runner is triggered.
|
||||||
@ -181,6 +167,11 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
**/
|
**/
|
||||||
const Package* package() const;
|
const Package* package() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal runner to reload its configuration.
|
||||||
|
*/
|
||||||
|
virtual void reloadConfiguration();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class RunnerManager;
|
friend class RunnerManager;
|
||||||
|
|
||||||
@ -202,11 +193,6 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
*/
|
*/
|
||||||
void setHasRunOptions(bool hasRunOptions);
|
void setHasRunOptions(bool hasRunOptions);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether or not the runner has configuration options itself
|
|
||||||
*/
|
|
||||||
void setIsConfigurable(bool canBeConfigured);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the nominal speed of the runner. Only slow runners need
|
* Sets the nominal speed of the runner. Only slow runners need
|
||||||
* to call this within their constructor because the default
|
* to call this within their constructor because the default
|
||||||
@ -251,4 +237,9 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
||||||
K_EXPORT_PLUGIN(factory("plasma_runner_" #libname))
|
K_EXPORT_PLUGIN(factory("plasma_runner_" #libname))
|
||||||
|
|
||||||
|
|
||||||
|
#define K_EXPORT_RUNNER_CONFIG( name, classname ) \
|
||||||
|
K_PLUGIN_FACTORY(ConfigFactory, registerPlugin<classname>();) \
|
||||||
|
K_EXPORT_PLUGIN(ConfigFactory("kcm_krunner_" #name))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2006-2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
* Copyright (C) 2007 Ryan P. Bitanga <ryan.bitanga@gmail.com>
|
||||||
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
* Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
|
||||||
* Copyright 2008 Jordi Polo <mumismo@gmail.com>
|
* Copyright 2008 Jordi Polo <mumismo@gmail.com>
|
||||||
*
|
*
|
||||||
@ -31,10 +31,8 @@
|
|||||||
#include <threadweaver/DebuggingAids.h>
|
#include <threadweaver/DebuggingAids.h>
|
||||||
#include <ThreadWeaver/Thread>
|
#include <ThreadWeaver/Thread>
|
||||||
#include <ThreadWeaver/Job>
|
#include <ThreadWeaver/Job>
|
||||||
#include <ThreadWeaver/State>
|
|
||||||
#include <ThreadWeaver/QueuePolicy>
|
#include <ThreadWeaver/QueuePolicy>
|
||||||
#include <ThreadWeaver/Weaver>
|
#include <ThreadWeaver/Weaver>
|
||||||
#include <ThreadWeaver/WeaverObserver>
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@ -218,62 +216,62 @@ public:
|
|||||||
//This entry allows to define a hard upper limit independent of the number of processors.
|
//This entry allows to define a hard upper limit independent of the number of processors.
|
||||||
const int maxThreads = config.readEntry("maxThreads",16);
|
const int maxThreads = config.readEntry("maxThreads",16);
|
||||||
const int numThreads = qMin(maxThreads, 2 + ((numProcs - 1) * 2));
|
const int numThreads = qMin(maxThreads, 2 + ((numProcs - 1) * 2));
|
||||||
// kDebug() << "setting up" << numThreads << "threads for" << numProcs << "processors";
|
//kDebug() << "setting up" << numThreads << "threads for" << numProcs << "processors";
|
||||||
Weaver::instance()->setMaximumNumberOfThreads(numThreads);
|
Weaver::instance()->setMaximumNumberOfThreads(numThreads);
|
||||||
|
|
||||||
//Preferred order of execution of runners
|
//Preferred order of execution of runners
|
||||||
//prioritylist = config.readEntry("priority", QStringList());
|
//prioritylist = config.readEntry("priority", QStringList());
|
||||||
|
|
||||||
//If set, this list defines which runners won't be used at runtime
|
//If set, this list defines which runners won't be used at runtime
|
||||||
blacklist = config.readEntry("blacklist", QStringList());
|
//blacklist = config.readEntry("blacklist", QStringList());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadAll()
|
void loadRunners()
|
||||||
{
|
{
|
||||||
AbstractRunner::List firstRunners;
|
|
||||||
AbstractRunner::List normalRunners;
|
|
||||||
AbstractRunner::List lastRunners;
|
|
||||||
|
|
||||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
|
||||||
QString error;
|
|
||||||
|
bool loadAll = config.readEntry("loadAll", false);
|
||||||
|
KConfigGroup conf(&config, "Plugins");
|
||||||
|
|
||||||
foreach (const KService::Ptr &service, offers) {
|
foreach (const KService::Ptr &service, offers) {
|
||||||
//kDebug() << "Loading runner: " << service->name() << service->storageId();
|
//kDebug() << "Loading runner: " << service->name() << service->storageId();
|
||||||
KPluginInfo description(service);
|
KPluginInfo description(service);
|
||||||
QString runnerName = description.pluginName();
|
QString runnerName = description.pluginName();
|
||||||
if (blacklist.contains(runnerName)) {
|
description.load(conf);
|
||||||
kDebug() << "The plugin" << service->name() << "was blackListed and will not load";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QString api = service->property("X-Plasma-API").toString();
|
|
||||||
AbstractRunner* runner = 0;
|
|
||||||
|
|
||||||
if (api.isEmpty()) {
|
bool loaded = runners.contains(runnerName);
|
||||||
QVariantList args;
|
bool selected = loadAll || description.isPluginEnabled();
|
||||||
args << service->storageId();
|
|
||||||
runner = service->createInstance<AbstractRunner>(q, args, &error);
|
|
||||||
} else {
|
|
||||||
//kDebug() << "got a script runner known as" << api;
|
|
||||||
runner = new AbstractRunner(q, service->storageId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (runner) {
|
if (selected) {
|
||||||
//kDebug() << "loading runner: " << service->name();
|
if (!loaded) {
|
||||||
QString phase = service->property("X-Plasma-RunnerPhase").toString();
|
QString api = service->property("X-Plasma-API").toString();
|
||||||
if (phase == "last") {
|
QString error;
|
||||||
lastRunners.append(runner);
|
AbstractRunner* runner = 0;
|
||||||
} else if (phase == "first") {
|
|
||||||
firstRunners.append(runner);
|
if (api.isEmpty()) {
|
||||||
} else {
|
QVariantList args;
|
||||||
normalRunners.append(runner);
|
args << service->storageId();
|
||||||
|
runner = service->createInstance<AbstractRunner>(q, args, &error);
|
||||||
|
} else {
|
||||||
|
//kDebug() << "got a script runner known as" << api;
|
||||||
|
runner = new AbstractRunner(q, service->storageId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runner) {
|
||||||
|
kDebug() << "loading runner:" << service->name();
|
||||||
|
runners.insert(runnerName, runner);
|
||||||
|
} else {
|
||||||
|
kDebug() << "failed to load runner:" << service->name() << ". error reported:" << error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (loaded) {
|
||||||
kDebug() << "failed to load runner : " << service->name() << ". error reported: " << error;
|
//Remove runner
|
||||||
|
AbstractRunner* runner = runners.take(runnerName);
|
||||||
|
kDebug() << "Removing runner: " << runnerName;
|
||||||
|
delete runner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
firstRunners << normalRunners << lastRunners;
|
|
||||||
runners.clear();
|
|
||||||
runners = firstRunners;
|
|
||||||
//kDebug() << "All runners loaded, total:" << runners.count();
|
//kDebug() << "All runners loaded, total:" << runners.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,10 +291,10 @@ public:
|
|||||||
QueryMatch deferredRun;
|
QueryMatch deferredRun;
|
||||||
RunnerContext context;
|
RunnerContext context;
|
||||||
QTimer matchChangeTimer;
|
QTimer matchChangeTimer;
|
||||||
AbstractRunner::List runners;
|
QHash<QString, AbstractRunner*> runners;
|
||||||
QList<FindMatchesJob*> searchJobs;
|
QList<FindMatchesJob*> searchJobs;
|
||||||
QStringList prioritylist;
|
// QStringList prioritylist;
|
||||||
QStringList blacklist;
|
bool loadAll;
|
||||||
KConfigGroup config;
|
KConfigGroup config;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -329,23 +327,21 @@ RunnerManager::~RunnerManager()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RunnerManager::reloadConfiguration()
|
||||||
|
{
|
||||||
|
d->loadConfiguration(d->config);
|
||||||
|
d->loadRunners();
|
||||||
|
}
|
||||||
|
|
||||||
AbstractRunner* RunnerManager::runner(const QString &name) const
|
AbstractRunner* RunnerManager::runner(const QString &name) const
|
||||||
{
|
{
|
||||||
if (d->runners.isEmpty()) {
|
if (d->runners.isEmpty()) {
|
||||||
d->loadAll();
|
d->loadRunners();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: using a list of runners, if this gets slow, switch to hash
|
return d->runners.value(name);
|
||||||
foreach (Plasma::AbstractRunner* runner, d->runners) {
|
|
||||||
//kDebug() << "comparing" << name << "with" << runner->id() << runner->name();
|
|
||||||
if (name == runner->id()) {
|
|
||||||
return runner;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RunnerContext* RunnerManager::searchContext() const
|
RunnerContext* RunnerManager::searchContext() const
|
||||||
{
|
{
|
||||||
return &d->context;
|
return &d->context;
|
||||||
@ -394,7 +390,7 @@ void RunnerManager::launchQuery(const QString &term)
|
|||||||
void RunnerManager::launchQuery(const QString &term, const QString &runnerName)
|
void RunnerManager::launchQuery(const QString &term, const QString &runnerName)
|
||||||
{
|
{
|
||||||
if (d->runners.isEmpty()) {
|
if (d->runners.isEmpty()) {
|
||||||
d->loadAll();
|
d->loadRunners();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term.isEmpty()) {
|
if (term.isEmpty()) {
|
||||||
@ -417,7 +413,7 @@ void RunnerManager::launchQuery(const QString &term, const QString &runnerName)
|
|||||||
if (!runnerName.isEmpty()) {
|
if (!runnerName.isEmpty()) {
|
||||||
runable.append(runner(runnerName));
|
runable.append(runner(runnerName));
|
||||||
} else {
|
} else {
|
||||||
runable = d->runners;
|
runable = d->runners.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Plasma::AbstractRunner* r, runable) {
|
foreach (Plasma::AbstractRunner* r, runable) {
|
||||||
@ -439,7 +435,7 @@ bool RunnerManager::execQuery(const QString &term)
|
|||||||
bool RunnerManager::execQuery(const QString &term, const QString &runnerName)
|
bool RunnerManager::execQuery(const QString &term, const QString &runnerName)
|
||||||
{
|
{
|
||||||
if (d->runners.isEmpty()) {
|
if (d->runners.isEmpty()) {
|
||||||
d->loadAll();
|
d->loadRunners();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term.isEmpty()) {
|
if (term.isEmpty()) {
|
||||||
@ -496,11 +492,6 @@ void RunnerManager::reset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->context.reset();
|
d->context.reset();
|
||||||
|
|
||||||
//FIXME: if the weaver is not idle we have a number of jobs that
|
|
||||||
// will eventually return their matches
|
|
||||||
// we need a way to stop them (Weaver::requestAbort() Job::requestAbort )
|
|
||||||
// or discard results
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include <plasma/plasma_export.h>
|
#include <plasma/plasma_export.h>
|
||||||
#include "abstractrunner.h"
|
#include "abstractrunner.h"
|
||||||
|
|
||||||
|
class KConfigGroup;
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
class QueryMatch;
|
class QueryMatch;
|
||||||
@ -84,6 +86,11 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
*/
|
*/
|
||||||
QString query() const;
|
QString query() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes a reload of the current configuration
|
||||||
|
*/
|
||||||
|
void reloadConfiguration();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
* Launch a query, this will create threads and return inmediately.
|
* Launch a query, this will create threads and return inmediately.
|
||||||
|
Loading…
Reference in New Issue
Block a user