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);
|
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)
|
void AbstractRunner::setSyntaxes(const QList<RunnerSyntax> &syntaxes)
|
||||||
{
|
{
|
||||||
d->syntaxes = syntaxes;
|
d->syntaxes = syntaxes;
|
||||||
@ -94,6 +100,11 @@ QList<RunnerSyntax> AbstractRunner::syntaxes() const
|
|||||||
return d->syntaxes;
|
return d->syntaxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RunnerSyntax *AbstractRunner::defaultSyntax() const
|
||||||
|
{
|
||||||
|
return d->defaultSyntax;
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractRunner::performMatch(Plasma::RunnerContext &localContext)
|
void AbstractRunner::performMatch(Plasma::RunnerContext &localContext)
|
||||||
{
|
{
|
||||||
static const int reasonableRunTime = 1500;
|
static const int reasonableRunTime = 1500;
|
||||||
@ -295,6 +306,7 @@ const Package* AbstractRunner::package() const
|
|||||||
return d->package;
|
return d->package;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractRunner::init()
|
void AbstractRunner::init()
|
||||||
{
|
{
|
||||||
if (d->script) {
|
if (d->script) {
|
||||||
@ -317,7 +329,8 @@ AbstractRunnerPrivate::AbstractRunnerPrivate(AbstractRunner *r, KService::Ptr se
|
|||||||
runner(r),
|
runner(r),
|
||||||
fastRuns(0),
|
fastRuns(0),
|
||||||
package(0),
|
package(0),
|
||||||
hasRunOptions(false)
|
hasRunOptions(false),
|
||||||
|
defaultSyntax(0)
|
||||||
{
|
{
|
||||||
if (runnerDescription.isValid()) {
|
if (runnerDescription.isValid()) {
|
||||||
const QString api = runnerDescription.property("X-Plasma-API").toString();
|
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
|
* 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
|
* 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.
|
* 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
|
class PLASMA_EXPORT AbstractRunner : public QObject
|
||||||
{
|
{
|
||||||
@ -245,6 +249,13 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
*/
|
*/
|
||||||
static QMutex *bigLock();
|
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:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* This signal is emitted when matching is about to commence, giving runners
|
* This signal is emitted when matching is about to commence, giving runners
|
||||||
@ -374,7 +385,7 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
void clearActions();
|
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
|
* display to the user what this runner can understand and how it can be
|
||||||
* used.
|
* used.
|
||||||
*
|
*
|
||||||
@ -383,6 +394,22 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
|||||||
*/
|
*/
|
||||||
void addSyntax(const RunnerSyntax &syntax);
|
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
|
* Sets the list of syntaxes; passing in an empty list effectively clears
|
||||||
* the syntaxes.
|
* the syntaxes.
|
||||||
|
@ -48,6 +48,7 @@ public:
|
|||||||
QList<RunnerSyntax> syntaxes;
|
QList<RunnerSyntax> syntaxes;
|
||||||
bool hasRunOptions;
|
bool hasRunOptions;
|
||||||
QReadWriteLock speedLock;
|
QReadWriteLock speedLock;
|
||||||
|
RunnerSyntax *defaultSyntax;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
@ -152,7 +152,8 @@ class RunnerContextPrivate : public QSharedData
|
|||||||
RunnerContextPrivate(RunnerContext *context)
|
RunnerContextPrivate(RunnerContext *context)
|
||||||
: QSharedData(),
|
: QSharedData(),
|
||||||
type(RunnerContext::UnknownType),
|
type(RunnerContext::UnknownType),
|
||||||
q(context)
|
q(context),
|
||||||
|
singleRunnerQueryMode(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +161,8 @@ class RunnerContextPrivate : public QSharedData
|
|||||||
: QSharedData(),
|
: QSharedData(),
|
||||||
launchCounts(p.launchCounts),
|
launchCounts(p.launchCounts),
|
||||||
type(RunnerContext::None),
|
type(RunnerContext::None),
|
||||||
q(p.q)
|
q(p.q),
|
||||||
|
singleRunnerQueryMode(false)
|
||||||
{
|
{
|
||||||
//kDebug() << "¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿boo yeah" << type;
|
//kDebug() << "¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿boo yeah" << type;
|
||||||
}
|
}
|
||||||
@ -231,6 +233,7 @@ class RunnerContextPrivate : public QSharedData
|
|||||||
RunnerContext::Type type;
|
RunnerContext::Type type;
|
||||||
RunnerContext * q;
|
RunnerContext * q;
|
||||||
static RunnerContext s_dummyContext;
|
static RunnerContext s_dummyContext;
|
||||||
|
bool singleRunnerQueryMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
RunnerContext RunnerContextPrivate::s_dummyContext;
|
RunnerContext RunnerContextPrivate::s_dummyContext;
|
||||||
@ -297,6 +300,7 @@ void RunnerContext::reset()
|
|||||||
d->term.clear();
|
d->term.clear();
|
||||||
d->mimeType.clear();
|
d->mimeType.clear();
|
||||||
d->type = UnknownType;
|
d->type = UnknownType;
|
||||||
|
d->singleRunnerQueryMode = false;
|
||||||
//kDebug() << "match count" << d->matches.count();
|
//kDebug() << "match count" << d->matches.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,6 +478,16 @@ QueryMatch RunnerContext::match(const QString &id) const
|
|||||||
return QueryMatch(0);
|
return QueryMatch(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RunnerContext::setSingleRunnerQueryMode(bool enabled)
|
||||||
|
{
|
||||||
|
d->singleRunnerQueryMode = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RunnerContext::singleRunnerQueryMode() const
|
||||||
|
{
|
||||||
|
return d->singleRunnerQueryMode;
|
||||||
|
}
|
||||||
|
|
||||||
void RunnerContext::restore(const KConfigGroup &config)
|
void RunnerContext::restore(const KConfigGroup &config)
|
||||||
{
|
{
|
||||||
const QStringList cfgList = config.readEntry("LaunchCounts", QStringList());
|
const QStringList cfgList = config.readEntry("LaunchCounts", QStringList());
|
||||||
|
@ -79,7 +79,8 @@ class PLASMA_EXPORT RunnerContext : public QObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the search term for this object.
|
* 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();
|
void reset();
|
||||||
|
|
||||||
@ -194,6 +195,21 @@ class PLASMA_EXPORT RunnerContext : public QObject
|
|||||||
*/
|
*/
|
||||||
QueryMatch match(const QString &id) const;
|
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
|
* Sets the launch counts for the associated match ids
|
||||||
*
|
*
|
||||||
|
@ -144,6 +144,8 @@ public:
|
|||||||
const bool selected = loadAll ||
|
const bool selected = loadAll ||
|
||||||
(description.isPluginEnabled() && (noWhiteList || whiteList.contains(runnerName)));
|
(description.isPluginEnabled() && (noWhiteList || whiteList.contains(runnerName)));
|
||||||
|
|
||||||
|
const bool singleQueryModeEnabled = service->property("SingleRunnerQueryMode", QVariant::Bool).toBool();
|
||||||
|
|
||||||
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
|
//kDebug() << loadAll << description.isPluginEnabled() << noWhiteList << whiteList.contains(runnerName);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
@ -176,8 +178,15 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
kDebug() << "failed to load runner:" << service->name()
|
kDebug() << "failed to load runner:" << service->name()
|
||||||
<< ". error reported:" << error;
|
<< ". error reported:" << error;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (singleQueryModeEnabled) {
|
||||||
|
singleQueryModeEnabledRunners.insert(runnerName, runners.value(runnerName));
|
||||||
|
} else {
|
||||||
|
singleQueryModeEnabledRunners.remove(runnerName);
|
||||||
|
}
|
||||||
} else if (loaded) {
|
} else if (loaded) {
|
||||||
//Remove runner
|
//Remove runner
|
||||||
AbstractRunner *runner = runners.take(runnerName);
|
AbstractRunner *runner = runners.take(runnerName);
|
||||||
@ -267,6 +276,7 @@ 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, AbstractRunner*> singleQueryModeEnabledRunners;
|
||||||
QSet<FindMatchesJob*> searchJobs;
|
QSet<FindMatchesJob*> searchJobs;
|
||||||
QSet<FindMatchesJob*> oldSearchJobs;
|
QSet<FindMatchesJob*> oldSearchJobs;
|
||||||
KConfigGroup conf;
|
KConfigGroup conf;
|
||||||
@ -342,6 +352,11 @@ QList<AbstractRunner *> RunnerManager::runners() const
|
|||||||
return d->runners.values();
|
return d->runners.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<AbstractRunner *> RunnerManager::singleQueryModeEnabledRunners() const
|
||||||
|
{
|
||||||
|
return d->singleQueryModeEnabledRunners.values();
|
||||||
|
}
|
||||||
|
|
||||||
RunnerContext* RunnerManager::searchContext() const
|
RunnerContext* RunnerManager::searchContext() const
|
||||||
{
|
{
|
||||||
return &d->context;
|
return &d->context;
|
||||||
@ -426,6 +441,15 @@ 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()) {
|
||||||
|
singleRunner = runner(runnerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (term.isEmpty() && singleRunner && singleRunner->defaultSyntax()) {
|
||||||
|
term = singleRunner->defaultSyntax()->exampleQueries().first().remove(QRegExp(":q:"));
|
||||||
|
}
|
||||||
|
|
||||||
if (term.isEmpty()) {
|
if (term.isEmpty()) {
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
@ -447,11 +471,9 @@ 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 (!runnerName.isEmpty()) {
|
if (singleRunner) {
|
||||||
AbstractRunner *r = runner(runnerName);
|
runable.append(singleRunner);
|
||||||
if (r) {
|
d->context.setSingleRunnerQueryMode(true);
|
||||||
runable.append(r);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
runable = d->runners.values();
|
runable = d->runners.values();
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,12 @@ class PLASMA_EXPORT RunnerManager : public QObject
|
|||||||
*/
|
*/
|
||||||
QList<AbstractRunner *> runners() const;
|
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
|
* Retrieves the current context
|
||||||
* @return pointer to the current context
|
* @return pointer to the current context
|
||||||
|
Loading…
x
Reference in New Issue
Block a user