Single runner mode in libplasma
svn path=/trunk/KDE/kdelibs/; revision=1053993
This commit is contained in:
parent
c43ef1bcb8
commit
132b963dbe
@ -84,6 +84,12 @@ void AbstractRunner::addSyntax(const RunnerSyntax &syntax)
|
||||
d->syntaxes.append(syntax);
|
||||
}
|
||||
|
||||
void AbstractRunner::setDefaultSyntax(const RunnerSyntax &syntax)
|
||||
{
|
||||
d->syntaxes.append(syntax);
|
||||
d->defaultSyntax = &(d->syntaxes.last());
|
||||
}
|
||||
|
||||
void AbstractRunner::setSyntaxes(const QList<RunnerSyntax> &syntaxes)
|
||||
{
|
||||
d->syntaxes = syntaxes;
|
||||
@ -94,6 +100,11 @@ QList<RunnerSyntax> AbstractRunner::syntaxes() const
|
||||
return d->syntaxes;
|
||||
}
|
||||
|
||||
RunnerSyntax *AbstractRunner::defaultSyntax() const
|
||||
{
|
||||
return d->defaultSyntax;
|
||||
}
|
||||
|
||||
void AbstractRunner::performMatch(Plasma::RunnerContext &localContext)
|
||||
{
|
||||
static const int reasonableRunTime = 1500;
|
||||
@ -295,6 +306,7 @@ const Package* AbstractRunner::package() const
|
||||
return d->package;
|
||||
}
|
||||
|
||||
|
||||
void AbstractRunner::init()
|
||||
{
|
||||
if (d->script) {
|
||||
@ -317,7 +329,8 @@ AbstractRunnerPrivate::AbstractRunnerPrivate(AbstractRunner *r, KService::Ptr se
|
||||
runner(r),
|
||||
fastRuns(0),
|
||||
package(0),
|
||||
hasRunOptions(false)
|
||||
hasRunOptions(false),
|
||||
defaultSyntax(0)
|
||||
{
|
||||
if (runnerDescription.isValid()) {
|
||||
const QString api = runnerDescription.property("X-Plasma-API").toString();
|
||||
|
@ -54,6 +54,10 @@ class AbstractRunnerPrivate;
|
||||
* Be aware that runners have to be thread-safe. This is due to the fact that
|
||||
* each runner is executed in its own thread for each new term. Thus, a runner
|
||||
* may be executed more than once at the same time. See match() for details.
|
||||
* To let krunner expose the runner for single runner query mode, the runner
|
||||
* must set the "SingleRunnerQueryMode" key to true in the .desktop file
|
||||
* and set a default syntax. See setDefaultSyntax() for details.
|
||||
*
|
||||
*/
|
||||
class PLASMA_EXPORT AbstractRunner : public QObject
|
||||
{
|
||||
@ -245,6 +249,13 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
||||
*/
|
||||
static QMutex *bigLock();
|
||||
|
||||
/**
|
||||
* @return the default syntax for the runner or 0 if no default syntax has been defined
|
||||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
RunnerSyntax *defaultSyntax() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* This signal is emitted when matching is about to commence, giving runners
|
||||
@ -374,7 +385,7 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
||||
void clearActions();
|
||||
|
||||
/**
|
||||
* Adds a registed syntax that this runner understands. This is used to
|
||||
* Adds a registered syntax that this runner understands. This is used to
|
||||
* display to the user what this runner can understand and how it can be
|
||||
* used.
|
||||
*
|
||||
@ -383,6 +394,22 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
||||
*/
|
||||
void addSyntax(const RunnerSyntax &syntax);
|
||||
|
||||
/**
|
||||
* Set @p syntax as the default syntax for the runner; the default syntax will be
|
||||
* substituted to the empty query in single runner mode. This is also used to
|
||||
* display to the user what this runner can understand and how it can be
|
||||
* used.
|
||||
* The default syntax is automatically added to the list of registered syntaxes, there
|
||||
* is no need to add it using addSyntax.
|
||||
* Note that there can be only one default syntax; if called more than once, the last
|
||||
* call will determine the default syntax.
|
||||
* A default syntax (even trivial) is required to enable single runner mode
|
||||
*
|
||||
* @param syntax the syntax to register and to set as default
|
||||
* @since 4.4
|
||||
**/
|
||||
void setDefaultSyntax(const RunnerSyntax &syntax);
|
||||
|
||||
/**
|
||||
* Sets the list of syntaxes; passing in an empty list effectively clears
|
||||
* the syntaxes.
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
QList<RunnerSyntax> syntaxes;
|
||||
bool hasRunOptions;
|
||||
QReadWriteLock speedLock;
|
||||
RunnerSyntax *defaultSyntax;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
@ -152,7 +152,8 @@ class RunnerContextPrivate : public QSharedData
|
||||
RunnerContextPrivate(RunnerContext *context)
|
||||
: QSharedData(),
|
||||
type(RunnerContext::UnknownType),
|
||||
q(context)
|
||||
q(context),
|
||||
singleRunnerQueryMode(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -160,7 +161,8 @@ class RunnerContextPrivate : public QSharedData
|
||||
: QSharedData(),
|
||||
launchCounts(p.launchCounts),
|
||||
type(RunnerContext::None),
|
||||
q(p.q)
|
||||
q(p.q),
|
||||
singleRunnerQueryMode(false)
|
||||
{
|
||||
//kDebug() << "¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿boo yeah" << type;
|
||||
}
|
||||
@ -231,6 +233,7 @@ class RunnerContextPrivate : public QSharedData
|
||||
RunnerContext::Type type;
|
||||
RunnerContext * q;
|
||||
static RunnerContext s_dummyContext;
|
||||
bool singleRunnerQueryMode;
|
||||
};
|
||||
|
||||
RunnerContext RunnerContextPrivate::s_dummyContext;
|
||||
@ -297,6 +300,7 @@ void RunnerContext::reset()
|
||||
d->term.clear();
|
||||
d->mimeType.clear();
|
||||
d->type = UnknownType;
|
||||
d->singleRunnerQueryMode = false;
|
||||
//kDebug() << "match count" << d->matches.count();
|
||||
}
|
||||
|
||||
@ -474,6 +478,16 @@ QueryMatch RunnerContext::match(const QString &id) const
|
||||
return QueryMatch(0);
|
||||
}
|
||||
|
||||
void RunnerContext::setSingleRunnerQueryMode(bool enabled)
|
||||
{
|
||||
d->singleRunnerQueryMode = enabled;
|
||||
}
|
||||
|
||||
bool RunnerContext::singleRunnerQueryMode() const
|
||||
{
|
||||
return d->singleRunnerQueryMode;
|
||||
}
|
||||
|
||||
void RunnerContext::restore(const KConfigGroup &config)
|
||||
{
|
||||
const QStringList cfgList = config.readEntry("LaunchCounts", QStringList());
|
||||
|
@ -79,7 +79,8 @@ class PLASMA_EXPORT RunnerContext : public QObject
|
||||
|
||||
/**
|
||||
* Resets the search term for this object.
|
||||
* This removes all current matches in the process.
|
||||
* This removes all current matches in the process and
|
||||
* turns off single runner query mode.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
@ -194,6 +195,21 @@ class PLASMA_EXPORT RunnerContext : public QObject
|
||||
*/
|
||||
QueryMatch match(const QString &id) const;
|
||||
|
||||
/**
|
||||
* Sets single runner query mode. Note that a call to reset() will
|
||||
* turn off single runner query mode.
|
||||
*
|
||||
* @see reset()
|
||||
* @since 4.4
|
||||
*/
|
||||
void setSingleRunnerQueryMode(bool enabled);
|
||||
|
||||
/**
|
||||
* @return true if the current query is a single runner query
|
||||
* @since 4.4
|
||||
*/
|
||||
bool singleRunnerQueryMode() const;
|
||||
|
||||
/**
|
||||
* Sets the launch counts for the associated match ids
|
||||
*
|
||||
|
@ -144,6 +144,8 @@ public:
|
||||
const bool selected = loadAll ||
|
||||
(description.isPluginEnabled() && (noWhiteList || whiteList.contains(runnerName)));
|
||||
|
||||
const bool singleQueryModeEnabled = service->property("SingleRunnerQueryMode", QVariant::Bool).toBool();
|
||||
|
||||
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
|
||||
if (selected) {
|
||||
if (!loaded) {
|
||||
@ -176,8 +178,15 @@ public:
|
||||
} else {
|
||||
kDebug() << "failed to load runner:" << service->name()
|
||||
<< ". error reported:" << error;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (singleQueryModeEnabled) {
|
||||
singleQueryModeEnabledRunners.insert(runnerName, runners.value(runnerName));
|
||||
} else {
|
||||
singleQueryModeEnabledRunners.remove(runnerName);
|
||||
}
|
||||
} else if (loaded) {
|
||||
//Remove runner
|
||||
AbstractRunner *runner = runners.take(runnerName);
|
||||
@ -267,6 +276,7 @@ public:
|
||||
QTimer matchChangeTimer;
|
||||
QTimer delayTimer; // Timer to control when to run slow runners
|
||||
QHash<QString, AbstractRunner*> runners;
|
||||
QHash<QString, AbstractRunner*> singleQueryModeEnabledRunners;
|
||||
QSet<FindMatchesJob*> searchJobs;
|
||||
QSet<FindMatchesJob*> oldSearchJobs;
|
||||
KConfigGroup conf;
|
||||
@ -342,6 +352,11 @@ QList<AbstractRunner *> RunnerManager::runners() const
|
||||
return d->runners.values();
|
||||
}
|
||||
|
||||
QList<AbstractRunner *> RunnerManager::singleQueryModeEnabledRunners() const
|
||||
{
|
||||
return d->singleQueryModeEnabledRunners.values();
|
||||
}
|
||||
|
||||
RunnerContext* RunnerManager::searchContext() const
|
||||
{
|
||||
return &d->context;
|
||||
@ -426,6 +441,15 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
|
||||
setupMatchSession();
|
||||
QString term = untrimmedTerm.trimmed();
|
||||
|
||||
AbstractRunner *singleRunner = 0;
|
||||
if (!runnerName.isEmpty()) {
|
||||
singleRunner = runner(runnerName);
|
||||
}
|
||||
|
||||
if (term.isEmpty() && singleRunner && singleRunner->defaultSyntax()) {
|
||||
term = singleRunner->defaultSyntax()->exampleQueries().first().remove(QRegExp(":q:"));
|
||||
}
|
||||
|
||||
if (term.isEmpty()) {
|
||||
reset();
|
||||
return;
|
||||
@ -447,11 +471,9 @@ void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &run
|
||||
AbstractRunner::List runable;
|
||||
|
||||
//if the name is not empty we will launch only the specified runner
|
||||
if (!runnerName.isEmpty()) {
|
||||
AbstractRunner *r = runner(runnerName);
|
||||
if (r) {
|
||||
runable.append(r);
|
||||
}
|
||||
if (singleRunner) {
|
||||
runable.append(singleRunner);
|
||||
d->context.setSingleRunnerQueryMode(true);
|
||||
} else {
|
||||
runable = d->runners.values();
|
||||
}
|
||||
|
@ -65,6 +65,12 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
||||
*/
|
||||
QList<AbstractRunner *> runners() const;
|
||||
|
||||
/**
|
||||
* @return the list of all single query mode enabled runners
|
||||
* @since 4.4
|
||||
*/
|
||||
QList<AbstractRunner *> singleQueryModeEnabledRunners() const;
|
||||
|
||||
/**
|
||||
* Retrieves the current context
|
||||
* @return pointer to the current context
|
||||
|
Loading…
x
Reference in New Issue
Block a user