the API is more complex, but it's a lot less "modal". it preserves state nicely and obeys "principle of least surprise"; now we just need to decide whether or not the "enabled single runners thing" makes sense
svn path=/trunk/KDE/kdelibs/; revision=1054446
This commit is contained in:
parent
7eb365fac2
commit
4d9892e0a3
@ -60,7 +60,11 @@ public:
|
|||||||
deferredRun(0),
|
deferredRun(0),
|
||||||
currentSingleRunner(0),
|
currentSingleRunner(0),
|
||||||
prepped(false),
|
prepped(false),
|
||||||
teardownRequested(false)
|
allRunnersPrepped(false),
|
||||||
|
singleRunnerPrepped(false),
|
||||||
|
teardownRequested(false),
|
||||||
|
singleMode(false),
|
||||||
|
singleRunnerWasLoaded(false)
|
||||||
{
|
{
|
||||||
matchChangeTimer.setSingleShot(true);
|
matchChangeTimer.setSingleShot(true);
|
||||||
delayTimer.setSingleShot(true);
|
delayTimer.setSingleShot(true);
|
||||||
@ -113,50 +117,60 @@ public:
|
|||||||
return conf.isValid() ? conf : KConfigGroup(KGlobal::config(), "PlasmaRunnerManager");
|
return conf.isValid() ? conf : KConfigGroup(KGlobal::config(), "PlasmaRunnerManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractRunner *loadSingleRunner(QString id)
|
void clearSingleRunner()
|
||||||
{
|
{
|
||||||
if (q->runner(id)) {
|
if (singleRunnerWasLoaded) {
|
||||||
return q->runner(id);
|
delete currentSingleRunner;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSingleRunner && currentSingleRunner->id() == id) {
|
|
||||||
return currentSingleRunner;
|
|
||||||
}
|
|
||||||
delete currentSingleRunner;
|
|
||||||
currentSingleRunner = 0;
|
currentSingleRunner = 0;
|
||||||
|
}
|
||||||
|
|
||||||
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner", QString("[X-KDE-PluginInfo-Name] == '%1'").arg(id));
|
void loadSingleRunner()
|
||||||
|
{
|
||||||
if (offers.isEmpty()) {
|
if (!singleMode || singleModeRunnerId.isEmpty() ||
|
||||||
return 0;
|
!enabledSingleRunnerNames.contains(singleModeRunnerId)) {
|
||||||
}
|
clearSingleRunner();
|
||||||
|
return;
|
||||||
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) {
|
if (currentSingleRunner) {
|
||||||
QMetaObject::invokeMethod(currentSingleRunner, "init");
|
if (currentSingleRunner->id() == singleModeRunnerId) {
|
||||||
emit currentSingleRunner->prepare();
|
return;
|
||||||
}
|
}
|
||||||
return currentSingleRunner;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearSingleRunner()
|
clearSingleRunner();
|
||||||
{
|
}
|
||||||
delete currentSingleRunner;
|
|
||||||
currentSingleRunner = 0;
|
AbstractRunner *loadedRunner = q->runner(singleModeRunnerId);
|
||||||
|
if (loadedRunner) {
|
||||||
|
singleRunnerWasLoaded = false;
|
||||||
|
currentSingleRunner = loadedRunner;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner", QString("[X-KDE-PluginInfo-Name] == '%1'").arg(singleModeRunnerId));
|
||||||
|
if (!offers.isEmpty()) {
|
||||||
|
const KService::Ptr &service = offers[0];
|
||||||
|
QString api = service->property("X-Plasma-API").toString();
|
||||||
|
QString error;
|
||||||
|
|
||||||
|
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();
|
||||||
|
singleRunnerWasLoaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadRunners()
|
void loadRunners()
|
||||||
@ -174,7 +188,7 @@ public:
|
|||||||
pluginConf = KConfigGroup(KGlobal::config(), "Plugins");
|
pluginConf = KConfigGroup(KGlobal::config(), "Plugins");
|
||||||
}
|
}
|
||||||
|
|
||||||
singleRunnerEnabledNames.clear();
|
enabledSingleRunnerNames.clear();
|
||||||
|
|
||||||
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();
|
||||||
@ -196,7 +210,7 @@ public:
|
|||||||
const bool singleQueryModeEnabled = service->property("SingleRunnerQueryMode", QVariant::Bool).toBool();
|
const bool singleQueryModeEnabled = service->property("SingleRunnerQueryMode", QVariant::Bool).toBool();
|
||||||
|
|
||||||
if (singleQueryModeEnabled) {
|
if (singleQueryModeEnabled) {
|
||||||
singleRunnerEnabledNames.insert(runnerName, description.name());
|
enabledSingleRunnerNames.insert(runnerName, description.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
|
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
|
||||||
@ -290,11 +304,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (searchJobs.isEmpty() && oldSearchJobs.isEmpty()) {
|
if (searchJobs.isEmpty() && oldSearchJobs.isEmpty()) {
|
||||||
foreach (AbstractRunner *runner, runners) {
|
if (allRunnersPrepped) {
|
||||||
emit runner->teardown();
|
foreach (AbstractRunner *runner, runners) {
|
||||||
|
emit runner->teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
allRunnersPrepped = false;
|
||||||
}
|
}
|
||||||
if (currentSingleRunner) {
|
|
||||||
emit currentSingleRunner->teardown();
|
if (singleRunnerPrepped) {
|
||||||
|
if (currentSingleRunner) {
|
||||||
|
emit currentSingleRunner->teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
singleRunnerPrepped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepped = false;
|
prepped = false;
|
||||||
@ -326,14 +349,19 @@ public:
|
|||||||
QTimer matchChangeTimer;
|
QTimer matchChangeTimer;
|
||||||
QTimer delayTimer; // Timer to control when to run slow runners
|
QTimer delayTimer; // Timer to control when to run slow runners
|
||||||
QHash<QString, AbstractRunner*> runners;
|
QHash<QString, AbstractRunner*> runners;
|
||||||
QHash<QString, QString> singleRunnerEnabledNames;
|
QHash<QString, QString> enabledSingleRunnerNames;
|
||||||
AbstractRunner* currentSingleRunner;
|
AbstractRunner* currentSingleRunner;
|
||||||
QSet<FindMatchesJob*> searchJobs;
|
QSet<FindMatchesJob*> searchJobs;
|
||||||
QSet<FindMatchesJob*> oldSearchJobs;
|
QSet<FindMatchesJob*> oldSearchJobs;
|
||||||
KConfigGroup conf;
|
KConfigGroup conf;
|
||||||
|
QString singleModeRunnerId;
|
||||||
bool loadAll : 1;
|
bool loadAll : 1;
|
||||||
bool prepped : 1;
|
bool prepped : 1;
|
||||||
|
bool allRunnersPrepped : 1;
|
||||||
|
bool singleRunnerPrepped : 1;
|
||||||
bool teardownRequested : 1;
|
bool teardownRequested : 1;
|
||||||
|
bool singleMode : 1;
|
||||||
|
bool singleRunnerWasLoaded : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
@ -398,13 +426,44 @@ AbstractRunner* RunnerManager::runner(const QString &name) const
|
|||||||
return d->runners.value(name, 0);
|
return d->runners.value(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractRunner * RunnerManager::retrieveSingleRunner(const QString &name)
|
AbstractRunner *RunnerManager::singleModeRunner() const
|
||||||
{
|
{
|
||||||
if (!singleRunnerEnabledIds().contains(name)) {
|
return d->currentSingleRunner;
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
void RunnerManager::setSingleModeRunnerId(const QString &id)
|
||||||
|
{
|
||||||
|
d->singleModeRunnerId = id;
|
||||||
|
d->loadSingleRunner();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RunnerManager::singleModeRunnerId() const
|
||||||
|
{
|
||||||
|
return d->singleModeRunnerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RunnerManager::singleMode() const
|
||||||
|
{
|
||||||
|
return d->singleMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunnerManager::setSingleMode(bool singleMode)
|
||||||
|
{
|
||||||
|
if (d->singleMode == singleMode) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d->loadSingleRunner(name);
|
Plasma::AbstractRunner *prevSingleRunner = d->currentSingleRunner;
|
||||||
|
d->singleMode = singleMode;
|
||||||
|
d->loadSingleRunner();
|
||||||
|
d->singleMode = d->currentSingleRunner;
|
||||||
|
|
||||||
|
if (prevSingleRunner != d->currentSingleRunner) {
|
||||||
|
if (d->prepped) {
|
||||||
|
matchSessionComplete();
|
||||||
|
setupMatchSession();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<AbstractRunner *> RunnerManager::runners() const
|
QList<AbstractRunner *> RunnerManager::runners() const
|
||||||
@ -412,9 +471,9 @@ QList<AbstractRunner *> RunnerManager::runners() const
|
|||||||
return d->runners.values();
|
return d->runners.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList RunnerManager::singleRunnerEnabledIds() const
|
QStringList RunnerManager::enabledSingleModeRunnerIds() const
|
||||||
{
|
{
|
||||||
return d->singleRunnerEnabledNames.keys();
|
return d->enabledSingleRunnerNames.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RunnerManager::runnerName(const QString &id) const
|
QString RunnerManager::runnerName(const QString &id) const
|
||||||
@ -422,7 +481,7 @@ QString RunnerManager::runnerName(const QString &id) const
|
|||||||
if (runner(id)) {
|
if (runner(id)) {
|
||||||
return runner(id)->name();
|
return runner(id)->name();
|
||||||
} else {
|
} else {
|
||||||
return d->singleRunnerEnabledNames.value(id, QString());
|
return d->enabledSingleRunnerNames.value(id, QString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,11 +544,17 @@ void RunnerManager::setupMatchSession()
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->prepped = true;
|
d->prepped = true;
|
||||||
foreach (AbstractRunner *runner, d->runners) {
|
if (d->singleMode) {
|
||||||
emit runner->prepare();
|
if (d->currentSingleRunner) {
|
||||||
}
|
emit d->currentSingleRunner->prepare();
|
||||||
if (d->currentSingleRunner) {
|
d->singleRunnerPrepped = true;
|
||||||
emit d->currentSingleRunner->prepare();
|
}
|
||||||
|
} else {
|
||||||
|
foreach (AbstractRunner *runner, d->runners) {
|
||||||
|
emit runner->prepare();
|
||||||
|
}
|
||||||
|
|
||||||
|
d->allRunnersPrepped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,18 +578,26 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
|
|||||||
setupMatchSession();
|
setupMatchSession();
|
||||||
QString term = untrimmedTerm.trimmed();
|
QString term = untrimmedTerm.trimmed();
|
||||||
|
|
||||||
AbstractRunner *singleRunner = 0;
|
if (!runnerName.isEmpty()) {
|
||||||
if (!runnerName.isEmpty() && singleRunnerEnabledIds().contains(runnerName)) {
|
setSingleModeRunnerId(runnerName);
|
||||||
singleRunner = d->loadSingleRunner(runnerName);
|
setSingleMode(true);
|
||||||
} else {
|
|
||||||
d->clearSingleRunner();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (term.isEmpty() && singleRunner && singleRunner->defaultSyntax()) {
|
|
||||||
term = singleRunner->defaultSyntax()->exampleQueries().first().remove(QRegExp(":q:"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term.isEmpty()) {
|
if (term.isEmpty()) {
|
||||||
|
if (d->singleMode && d->currentSingleRunner && d->currentSingleRunner->defaultSyntax()) {
|
||||||
|
term = d->currentSingleRunner->defaultSyntax()->exampleQueries().first().remove(QRegExp(":q:"));
|
||||||
|
} else {
|
||||||
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->context.query() == term) {
|
||||||
|
// we already are searching for this!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->singleMode && !d->currentSingleRunner) {
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -533,11 +606,6 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
|
|||||||
d->loadRunners();
|
d->loadRunners();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->context.query() == term) {
|
|
||||||
// we already are searching for this!
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
// kDebug() << "runners searching for" << term << "on" << runnerName;
|
// kDebug() << "runners searching for" << term << "on" << runnerName;
|
||||||
d->context.setQuery(term);
|
d->context.setQuery(term);
|
||||||
@ -545,8 +613,8 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
|
|||||||
AbstractRunner::List runable;
|
AbstractRunner::List runable;
|
||||||
|
|
||||||
//if the name is not empty we will launch only the specified runner
|
//if the name is not empty we will launch only the specified runner
|
||||||
if (singleRunner) {
|
if (d->singleMode && d->currentSingleRunner) {
|
||||||
runable.append(singleRunner);
|
runable.append(d->currentSingleRunner);
|
||||||
d->context.setSingleRunnerQueryMode(true);
|
d->context.setSingleRunnerQueryMode(true);
|
||||||
} else {
|
} else {
|
||||||
runable = d->runners.values();
|
runable = d->runners.values();
|
||||||
@ -564,6 +632,7 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
|
|||||||
d->searchJobs.insert(job);
|
d->searchJobs.insert(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start timer to unblock slow runners
|
// Start timer to unblock slow runners
|
||||||
d->delayTimer.start(RunnerManagerPrivate::slowRunDelay);
|
d->delayTimer.start(RunnerManagerPrivate::slowRunDelay);
|
||||||
}
|
}
|
||||||
|
@ -60,21 +60,48 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
*/
|
*/
|
||||||
AbstractRunner *runner(const QString &name) const;
|
AbstractRunner *runner(const QString &name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the single runner enabled runner given by
|
* @return the currently active "single mode" runner, or null if none
|
||||||
* the argument or NULL if not valid; the runner will be loaded
|
* @since 4.4
|
||||||
* if necessary
|
*/
|
||||||
* @arg name the name of the runner
|
AbstractRunner *singleModeRunner() const;
|
||||||
* @return Pointer to the runner
|
|
||||||
*/
|
/**
|
||||||
AbstractRunner *retrieveSingleRunner(const QString &name);
|
* Puts the manager into "single runner" mode using the given
|
||||||
|
* runner; if the runner does not exist or can not be loaded then
|
||||||
/**
|
* the single runner mode will not be started and singleModeRunner()
|
||||||
|
* will return NULL
|
||||||
|
* @arg id the id of the runner to use
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
void setSingleModeRunnerId(const QString &id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id of the runner to use in single mode
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
QString singleModeRunnerId() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the manager is set to run in single runner mode
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
bool singleMode() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not the manager is in single mode.
|
||||||
|
*
|
||||||
|
* @arg singleMode true if the manager should be in single mode, false otherwise
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
void setSingleMode(bool singleMode);
|
||||||
|
|
||||||
|
/**
|
||||||
* Returns the translated name of a runner
|
* Returns the translated name of a runner
|
||||||
* @arg id the id of the runner
|
* @arg id the id of the runner
|
||||||
*
|
*
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
QString runnerName(const QString &id) const;
|
QString runnerName(const QString &id) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,11 +109,11 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
*/
|
*/
|
||||||
QList<AbstractRunner *> runners() const;
|
QList<AbstractRunner *> runners() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the names of all single query mode enabled runners
|
* @return the names of all single query mode enabled runners
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
QStringList singleRunnerEnabledIds() const;
|
QStringList enabledSingleModeRunnerIds() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the current context
|
* Retrieves the current context
|
||||||
@ -165,9 +192,10 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
* matchesChanged signal.
|
* matchesChanged signal.
|
||||||
*
|
*
|
||||||
* @arg term the term we want to find matches for
|
* @arg term the term we want to find matches for
|
||||||
* @arg runner optional, if only one specific runner is to be used
|
* @arg runnerId optional, if only one specific runner is to be used;
|
||||||
|
* providing an id will put the manager into single runner mode
|
||||||
*/
|
*/
|
||||||
void launchQuery(const QString &term, const QString &runnerName);
|
void launchQuery(const QString &term, const QString &runnerId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience version of above
|
* Convenience version of above
|
||||||
|
Loading…
Reference in New Issue
Block a user