2007-02-28 01:41:09 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2007-02-28 01:41:09 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-08-06 13:20:02 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2007-02-28 01:41:09 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RUNNER_H
|
|
|
|
#define RUNNER_H
|
|
|
|
|
2007-11-01 09:22:28 +01:00
|
|
|
#include <QtCore/QObject>
|
2008-02-04 21:28:09 +01:00
|
|
|
#include <QtCore/QMutex>
|
2007-12-10 19:04:45 +01:00
|
|
|
#include <QtCore/QStringList>
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-12-11 17:56:06 +01:00
|
|
|
#include <KDE/KConfigGroup>
|
2008-01-30 04:41:36 +01:00
|
|
|
#include <KDE/KService>
|
2007-12-11 17:53:40 +01:00
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2008-05-01 20:40:10 +02:00
|
|
|
#include <plasma/runnercontext.h>
|
2008-05-02 20:46:05 +02:00
|
|
|
#include <plasma/querymatch.h>
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-11-02 03:34:46 +01:00
|
|
|
class KCompletion;
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-04-13 16:37:10 +02:00
|
|
|
class Package;
|
2008-02-04 05:41:40 +01:00
|
|
|
class RunnerScript;
|
2008-05-02 20:46:05 +02:00
|
|
|
class QueryMatch;
|
2008-02-04 05:41:40 +01:00
|
|
|
|
2007-05-20 18:25:07 +02:00
|
|
|
/**
|
2007-11-02 03:34:46 +01:00
|
|
|
* An abstract base class for Plasma Runner plugins
|
2008-01-08 16:33:26 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2007-05-20 18:25:07 +02:00
|
|
|
*/
|
2007-05-20 22:13:46 +02:00
|
|
|
class PLASMA_EXPORT AbstractRunner : public QObject
|
2007-02-28 01:41:09 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2008-04-26 13:49:59 +02:00
|
|
|
enum Speed { SlowSpeed,
|
|
|
|
NormalSpeed
|
2008-01-08 01:21:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Priority { LowestPriority = 0,
|
|
|
|
LowPriority,
|
|
|
|
NormalPriority,
|
|
|
|
HighPriority,
|
|
|
|
HighestPriority
|
|
|
|
};
|
2008-05-19 19:02:15 +02:00
|
|
|
|
2007-03-20 18:37:44 +01:00
|
|
|
typedef QList<AbstractRunner*> List;
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-03-20 18:37:44 +01:00
|
|
|
virtual ~AbstractRunner();
|
2007-02-28 01:41:09 +01:00
|
|
|
|
|
|
|
/**
|
2008-01-08 16:33:26 +01:00
|
|
|
* This is the main query method. It should trigger creation of
|
2008-05-02 20:46:05 +02:00
|
|
|
* QueryMatch instances through RunnerContext::addInformationalMatch,
|
2008-05-01 20:40:10 +02:00
|
|
|
* RunnerContext::addExactMatch, and RunnerContext::addPossibleMatch.
|
2008-01-08 16:33:26 +01:00
|
|
|
*
|
2008-05-02 20:17:09 +02:00
|
|
|
* If the runner can run precisely the requested term (RunnerContext::query()),
|
2008-05-01 20:40:10 +02:00
|
|
|
* it should create an exact match (RunnerContext::addExactMatch).
|
2008-05-02 20:46:05 +02:00
|
|
|
* The first runner that creates a QueryMatch will be the
|
2008-01-08 16:33:26 +01:00
|
|
|
* default runner. Other runner's matches will be suggested in the
|
2008-05-01 20:40:10 +02:00
|
|
|
* interface. Non-exact matches should be offered via RunnerContext::addPossibleMatch.
|
2008-01-08 16:33:26 +01:00
|
|
|
*
|
|
|
|
* The match will be activated if the user selects it.
|
2007-07-18 21:09:41 +02:00
|
|
|
*
|
2008-02-04 05:41:40 +01:00
|
|
|
* If this runner's exact match is selected, it will be passed into
|
2008-04-28 19:11:12 +02:00
|
|
|
* the run method.
|
|
|
|
* @see run
|
2007-07-18 21:09:41 +02:00
|
|
|
*
|
2008-01-08 16:33:26 +01:00
|
|
|
* Since each runner is executed in its own thread there is no need
|
|
|
|
* to return from this method right away, nor to create all matches
|
|
|
|
* here.
|
2007-02-28 01:41:09 +01:00
|
|
|
*/
|
2008-05-09 05:49:11 +02:00
|
|
|
virtual void match(Plasma::RunnerContext &context);
|
2007-03-20 18:37:44 +01:00
|
|
|
|
2008-01-31 04:25:19 +01:00
|
|
|
/**
|
|
|
|
* Triggers a call to match.
|
|
|
|
*
|
|
|
|
* @arg globalContext the search context used in executing this match.
|
|
|
|
*/
|
2008-05-09 05:49:11 +02:00
|
|
|
void performMatch(Plasma::RunnerContext &context);
|
2007-12-02 08:11:50 +01:00
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
/**
|
|
|
|
* If the runner has options that the user can interact with to modify
|
2008-04-28 19:11:12 +02:00
|
|
|
* what happens when run or one of the actions created in fillMatches
|
2007-02-28 01:41:09 +01:00
|
|
|
* is called, the runner should return true
|
|
|
|
*/
|
2008-04-26 14:41:16 +02:00
|
|
|
bool hasRunOptions();
|
2007-02-28 01:41:09 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-26 14:54:25 +02:00
|
|
|
* If hasRunOptions() returns true, this method may be called to get
|
2007-10-31 06:25:07 +01:00
|
|
|
* a widget displaying the options the user can interact with to modify
|
2007-10-31 05:44:09 +01:00
|
|
|
* the behaviour of what happens when a given match is selected.
|
|
|
|
*
|
|
|
|
* @param widget the parent of the options widgets.
|
2007-02-28 01:41:09 +01:00
|
|
|
*/
|
2008-04-26 14:54:25 +02:00
|
|
|
virtual void createRunOptions(QWidget *widget);
|
2007-02-28 01:41:09 +01:00
|
|
|
|
|
|
|
/**
|
2007-10-31 05:44:09 +01:00
|
|
|
* Called whenever an exact or possible match associated with this
|
|
|
|
* runner is triggered.
|
2007-02-28 01:41:09 +01:00
|
|
|
*/
|
2008-05-09 05:49:11 +02:00
|
|
|
virtual void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action);
|
2007-10-31 05:44:09 +01:00
|
|
|
|
2007-12-10 17:20:46 +01:00
|
|
|
/**
|
|
|
|
* The nominal speed of the runner.
|
2008-01-08 01:21:10 +01:00
|
|
|
* @see setSpeed
|
|
|
|
*/
|
|
|
|
Speed speed() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The priority of the runner.
|
|
|
|
* @see setPriority
|
2007-12-10 17:20:46 +01:00
|
|
|
*/
|
2008-01-08 01:21:10 +01:00
|
|
|
Priority priority() const;
|
2007-12-10 17:20:46 +01:00
|
|
|
|
2008-05-01 09:51:59 +02:00
|
|
|
/**
|
2008-05-01 20:40:10 +02:00
|
|
|
* Returns the OR'ed value of all the Information types (as defined in RunnerContext::Type)
|
2008-05-01 09:51:59 +02:00
|
|
|
* this runner is not interested in.
|
|
|
|
* @return OR'ed value of black listed types
|
|
|
|
*/
|
2008-05-01 20:40:10 +02:00
|
|
|
RunnerContext::Types ignoredTypes() const;
|
2008-05-01 09:51:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the types this runner will ignore
|
|
|
|
* @param types OR'ed listed of ignored types
|
|
|
|
*/
|
2008-05-01 20:40:10 +02:00
|
|
|
void setIgnoredTypes(RunnerContext::Types types);
|
2008-05-01 09:51:59 +02:00
|
|
|
|
2008-02-04 05:41:40 +01:00
|
|
|
/**
|
2008-05-06 20:43:55 +02:00
|
|
|
* Returns the user visible engine name for the Runner
|
2008-02-04 05:41:40 +01:00
|
|
|
*/
|
2008-04-26 14:20:29 +02:00
|
|
|
QString name() const;
|
2008-02-04 05:41:40 +01:00
|
|
|
|
2008-05-06 20:43:55 +02:00
|
|
|
/**
|
|
|
|
* Returns an id string for the Runner
|
|
|
|
*/
|
|
|
|
QString id() const;
|
|
|
|
|
2008-05-01 09:51:59 +02:00
|
|
|
/**
|
|
|
|
* Returns the description of this Runner
|
|
|
|
*/
|
|
|
|
QString description() const;
|
|
|
|
|
2008-04-13 16:37:10 +02:00
|
|
|
/**
|
|
|
|
* Accessor for the associated Package object if any.
|
|
|
|
*
|
|
|
|
* @return the Package object, or 0 if none
|
|
|
|
**/
|
|
|
|
const Package* package() const;
|
|
|
|
|
2008-05-19 19:02:15 +02:00
|
|
|
/**
|
|
|
|
* Signal runner to reload its configuration.
|
|
|
|
*/
|
|
|
|
virtual void reloadConfiguration();
|
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
protected:
|
2008-05-06 22:48:44 +02:00
|
|
|
friend class RunnerManager;
|
|
|
|
|
2008-04-26 13:55:02 +02:00
|
|
|
/**
|
|
|
|
* Constructs a Runner object. Since AbstractRunner has pure virtuals,
|
|
|
|
* this constructor can not be called directly. Rather a subclass must
|
|
|
|
* be created
|
|
|
|
*/
|
|
|
|
explicit AbstractRunner(QObject* parent = 0, const QString& serviceId = QString());
|
|
|
|
AbstractRunner(QObject* parent, const QVariantList& args);
|
|
|
|
|
2008-04-26 13:59:23 +02:00
|
|
|
/**
|
|
|
|
* Provides access to the runner's configuration object.
|
|
|
|
*/
|
|
|
|
KConfigGroup config() const;
|
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
/**
|
2007-10-31 05:44:09 +01:00
|
|
|
* Sets whether or not the the runner has options for matches
|
2007-02-28 01:41:09 +01:00
|
|
|
*/
|
2008-04-26 14:41:16 +02:00
|
|
|
void setHasRunOptions(bool hasRunOptions);
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-12-10 17:20:46 +01:00
|
|
|
/**
|
2008-02-04 05:41:40 +01:00
|
|
|
* Sets the nominal speed of the runner. Only slow runners need
|
|
|
|
* to call this within their constructor because the default
|
|
|
|
* speed is NormalSpeed. Runners that use DBUS should call
|
2007-12-10 17:20:46 +01:00
|
|
|
* this within their constructors.
|
|
|
|
*/
|
|
|
|
void setSpeed(Speed newSpeed);
|
|
|
|
|
2008-01-08 01:21:10 +01:00
|
|
|
/**
|
|
|
|
* Sets the priority of the runner. Lower priority runners are executed
|
|
|
|
* only after higher priority runners.
|
|
|
|
*/
|
|
|
|
void setPriority(Priority newPriority);
|
|
|
|
|
2008-01-30 04:41:36 +01:00
|
|
|
/**
|
2008-01-30 07:17:13 +01:00
|
|
|
* A blocking method to do queries of installed Services which can provide
|
|
|
|
* a measure of safety for runners running their own threads. This should
|
|
|
|
* be used instead of calling KServiceTypeTrader::query(..) directly.
|
2008-01-30 04:41:36 +01:00
|
|
|
*
|
|
|
|
* @arg serviceType a service type like "Plasma/Applet" or "KFilePlugin"
|
2008-01-30 07:17:13 +01:00
|
|
|
* @arg constraint a constraint to limit the the choices returned.
|
2008-01-30 04:41:36 +01:00
|
|
|
* @see KServiceTypeTrader::query(const QString&, const QString&)
|
|
|
|
*
|
|
|
|
* @return a list of services that satisfy the query.
|
|
|
|
*/
|
|
|
|
KService::List serviceQuery(const QString &serviceType,
|
|
|
|
const QString &constraint = QString()) const;
|
|
|
|
|
2008-02-19 07:27:31 +01:00
|
|
|
QMutex* bigLock() const;
|
2008-02-04 21:28:09 +01:00
|
|
|
|
2008-03-02 12:05:54 +01:00
|
|
|
protected Q_SLOTS:
|
2008-02-04 05:41:40 +01:00
|
|
|
void init();
|
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
private:
|
|
|
|
class Private;
|
2007-05-21 16:28:03 +02:00
|
|
|
Private* const d;
|
2007-02-28 01:41:09 +01:00
|
|
|
};
|
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-10-09 05:41:24 +02:00
|
|
|
#define K_EXPORT_PLASMA_RUNNER( libname, classname ) \
|
2007-08-29 04:17:39 +02:00
|
|
|
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
2007-10-09 05:41:24 +02:00
|
|
|
K_EXPORT_PLUGIN(factory("plasma_runner_" #libname))
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2008-05-19 19:02:15 +02:00
|
|
|
|
|
|
|
#define K_EXPORT_RUNNER_CONFIG( name, classname ) \
|
|
|
|
K_PLUGIN_FACTORY(ConfigFactory, registerPlugin<classname>();) \
|
|
|
|
K_EXPORT_PLUGIN(ConfigFactory("kcm_krunner_" #name))
|
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
#endif
|