Load single runners on the fly

svn path=/trunk/KDE/kdelibs/; revision=1054351
This commit is contained in:
Jacopo De Simoi 2009-11-25 22:31:56 +00:00
parent 08ae083579
commit 7eb365fac2
2 changed files with 104 additions and 13 deletions

View File

@ -58,6 +58,7 @@ public:
RunnerManagerPrivate(RunnerManager *parent)
: q(parent),
deferredRun(0),
currentSingleRunner(0),
prepped(false),
teardownRequested(false)
{
@ -112,6 +113,52 @@ public:
return conf.isValid() ? conf : KConfigGroup(KGlobal::config(), "PlasmaRunnerManager");
}
AbstractRunner *loadSingleRunner(QString id)
{
if (q->runner(id)) {
return q->runner(id);
}
if (currentSingleRunner && currentSingleRunner->id() == id) {
return currentSingleRunner;
}
delete currentSingleRunner;
currentSingleRunner = 0;
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner", QString("[X-KDE-PluginInfo-Name] == '%1'").arg(id));
if (offers.isEmpty()) {
return 0;
}
const KService::Ptr &service = offers[0];
QString api = service->property("X-Plasma-API").toString();
QString error;
AbstractRunner *runner = 0;
if (api.isEmpty()) {
QVariantList args;
args << service->storageId();
if (Plasma::isPluginVersionCompatible(KPluginLoader(*service).pluginVersion())) {
currentSingleRunner = service->createInstance<AbstractRunner>(q, args, &error);
}
} else {
currentSingleRunner = new AbstractRunner(q, service->storageId());
}
if (currentSingleRunner) {
QMetaObject::invokeMethod(currentSingleRunner, "init");
emit currentSingleRunner->prepare();
}
return currentSingleRunner;
}
void clearSingleRunner()
{
delete currentSingleRunner;
currentSingleRunner = 0;
}
void loadRunners()
{
KConfigGroup config = configGroup();
@ -127,6 +174,8 @@ public:
pluginConf = KConfigGroup(KGlobal::config(), "Plugins");
}
singleRunnerEnabledNames.clear();
foreach (const KService::Ptr &service, offers) {
//kDebug() << "Loading runner: " << service->name() << service->storageId();
QString tryExec = service->property("TryExec", QVariant::String).toString();
@ -146,6 +195,10 @@ public:
const bool singleQueryModeEnabled = service->property("SingleRunnerQueryMode", QVariant::Bool).toBool();
if (singleQueryModeEnabled) {
singleRunnerEnabledNames.insert(runnerName, description.name());
}
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
if (selected) {
if (!loaded) {
@ -181,12 +234,6 @@ public:
continue;
}
}
if (singleQueryModeEnabled) {
singleQueryModeEnabledRunners.insert(runnerName, runners.value(runnerName));
} else {
singleQueryModeEnabledRunners.remove(runnerName);
}
} else if (loaded) {
//Remove runner
AbstractRunner *runner = runners.take(runnerName);
@ -246,6 +293,9 @@ public:
foreach (AbstractRunner *runner, runners) {
emit runner->teardown();
}
if (currentSingleRunner) {
emit currentSingleRunner->teardown();
}
prepped = false;
teardownRequested = false;
@ -276,7 +326,8 @@ public:
QTimer matchChangeTimer;
QTimer delayTimer; // Timer to control when to run slow runners
QHash<QString, AbstractRunner*> runners;
QHash<QString, AbstractRunner*> singleQueryModeEnabledRunners;
QHash<QString, QString> singleRunnerEnabledNames;
AbstractRunner* currentSingleRunner;
QSet<FindMatchesJob*> searchJobs;
QSet<FindMatchesJob*> oldSearchJobs;
KConfigGroup conf;
@ -347,14 +398,32 @@ AbstractRunner* RunnerManager::runner(const QString &name) const
return d->runners.value(name, 0);
}
AbstractRunner * RunnerManager::retrieveSingleRunner(const QString &name)
{
if (!singleRunnerEnabledIds().contains(name)) {
return 0;
}
return d->loadSingleRunner(name);
}
QList<AbstractRunner *> RunnerManager::runners() const
{
return d->runners.values();
}
QList<AbstractRunner *> RunnerManager::singleQueryModeEnabledRunners() const
QStringList RunnerManager::singleRunnerEnabledIds() const
{
return d->singleQueryModeEnabledRunners.values();
return d->singleRunnerEnabledNames.keys();
}
QString RunnerManager::runnerName(const QString &id) const
{
if (runner(id)) {
return runner(id)->name();
} else {
return d->singleRunnerEnabledNames.value(id, QString());
}
}
RunnerContext* RunnerManager::searchContext() const
@ -419,6 +488,9 @@ void RunnerManager::setupMatchSession()
foreach (AbstractRunner *runner, d->runners) {
emit runner->prepare();
}
if (d->currentSingleRunner) {
emit d->currentSingleRunner->prepare();
}
}
void RunnerManager::matchSessionComplete()
@ -442,8 +514,10 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
QString term = untrimmedTerm.trimmed();
AbstractRunner *singleRunner = 0;
if (!runnerName.isEmpty()) {
singleRunner = runner(runnerName);
if (!runnerName.isEmpty() && singleRunnerEnabledIds().contains(runnerName)) {
singleRunner = d->loadSingleRunner(runnerName);
} else {
d->clearSingleRunner();
}
if (term.isEmpty() && singleRunner && singleRunner->defaultSyntax()) {

View File

@ -60,16 +60,33 @@ class PLASMA_EXPORT RunnerManager : public QObject
*/
AbstractRunner *runner(const QString &name) const;
/**
* Returns the single runner enabled runner given by
* the argument or NULL if not valid; the runner will be loaded
* if necessary
* @arg name the name of the runner
* @return Pointer to the runner
*/
AbstractRunner *retrieveSingleRunner(const QString &name);
/**
* Returns the translated name of a runner
* @arg id the id of the runner
*
* @since 4.4
*/
QString runnerName(const QString &id) const;
/**
* @return the list of all currently loaded runners
*/
QList<AbstractRunner *> runners() const;
/**
* @return the list of all single query mode enabled runners
* @return the names of all single query mode enabled runners
* @since 4.4
*/
QList<AbstractRunner *> singleQueryModeEnabledRunners() const;
QStringList singleRunnerEnabledIds() const;
/**
* Retrieves the current context