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>
|
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>
|
2007-12-03 18:18:28 +01:00
|
|
|
#include <plasma/searchmatch.h>
|
2007-11-02 03:34:46 +01:00
|
|
|
#include <plasma/searchcontext.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
|
|
|
|
{
|
|
|
|
|
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:
|
2007-12-10 17:20:46 +01:00
|
|
|
enum Speed { NormalSpeed,
|
2008-01-08 01:21:10 +01:00
|
|
|
SlowSpeed
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Priority { LowestPriority = 0,
|
|
|
|
LowPriority,
|
|
|
|
NormalPriority,
|
|
|
|
HighPriority,
|
|
|
|
HighestPriority
|
|
|
|
};
|
2007-12-10 17:20:46 +01:00
|
|
|
|
2007-03-20 18:37:44 +01:00
|
|
|
typedef QList<AbstractRunner*> List;
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-10-31 05:44:09 +01:00
|
|
|
/**
|
|
|
|
* Static method is called to load and get a list available of Runners.
|
2007-12-10 17:20:46 +01:00
|
|
|
*
|
|
|
|
* @param whitelist An optional whitelist of runners to load
|
2007-10-31 05:44:09 +01:00
|
|
|
*/
|
2007-11-22 10:08:58 +01:00
|
|
|
static List loadRunners(QObject* parent, const QStringList& whitelist = QStringList() );
|
2007-10-31 05:44:09 +01:00
|
|
|
|
2007-03-20 18:37:44 +01:00
|
|
|
/**
|
2007-11-22 10:08:58 +01:00
|
|
|
* Constructs a Runner object. Since AbstractRunner has pure virtuals,
|
2007-03-20 18:37:44 +01:00
|
|
|
* this constructor can not be called directly. Rather a subclass must
|
|
|
|
* be created
|
|
|
|
*/
|
2007-10-31 05:44:09 +01:00
|
|
|
explicit AbstractRunner(QObject* parent = 0);
|
2007-03-20 18:37:44 +01:00
|
|
|
virtual ~AbstractRunner();
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-12-11 17:53:40 +01:00
|
|
|
/**
|
|
|
|
* Provides access to the runner's configuration object.
|
|
|
|
*/
|
|
|
|
KConfigGroup config() const;
|
|
|
|
|
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
|
|
|
|
* SearchMatch instances through SearchContext::addInformationalMatch,
|
|
|
|
* SearchContext::addExactMatch, and SearchContext::addPossibleMatch.
|
|
|
|
*
|
|
|
|
* If the runner can run precisely the requested term (SearchContext::searchTerm),
|
|
|
|
* it should create an exact match (SearchContext::addExactMatch).
|
|
|
|
* The first runner that creates a SearchMatch will be the
|
|
|
|
* default runner. Other runner's matches will be suggested in the
|
|
|
|
* interface. Non-exact matches should be offered via SearchContext::addPossibleMatch.
|
|
|
|
*
|
|
|
|
* The match will be activated if the user selects it.
|
2007-07-18 21:09:41 +02:00
|
|
|
*
|
2008-01-08 16:33:26 +01:00
|
|
|
* If this runner's exact match is selected, it will be passed into
|
|
|
|
* the exec method.
|
2007-07-18 21:09:41 +02:00
|
|
|
* @see exec
|
|
|
|
*
|
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
|
|
|
*/
|
2007-10-31 05:44:09 +01:00
|
|
|
virtual void match(Plasma::SearchContext *search) = 0;
|
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.
|
|
|
|
*/
|
2007-12-02 08:11:50 +01:00
|
|
|
void performMatch(Plasma::SearchContext &globalContext);
|
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
/**
|
|
|
|
* If the runner has options that the user can interact with to modify
|
|
|
|
* what happens when exec or one of the actions created in fillMatches
|
|
|
|
* is called, the runner should return true
|
|
|
|
*/
|
2007-10-31 05:44:09 +01:00
|
|
|
bool hasMatchOptions();
|
2007-02-28 01:41:09 +01:00
|
|
|
|
|
|
|
/**
|
2007-10-31 06:25:07 +01:00
|
|
|
* If hasMatchOptions() returns true, this method may be called to get
|
|
|
|
* 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
|
|
|
*/
|
2007-10-31 06:25:07 +01:00
|
|
|
virtual void createMatchOptions(QWidget *widget);
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-03-02 08:44:42 +01:00
|
|
|
/**
|
2007-10-31 05:44:09 +01:00
|
|
|
* If the runner itself has configuration options, this method returns true
|
2007-03-02 08:44:42 +01:00
|
|
|
*/
|
2007-11-22 10:08:58 +01:00
|
|
|
bool isConfigurable();
|
2007-03-02 01:06:52 +01:00
|
|
|
|
2007-10-31 06:25:07 +01:00
|
|
|
/**
|
2007-11-22 10:08:58 +01:00
|
|
|
* If isConfigurable() returns true, this method may to get
|
2007-10-31 06:25:07 +01:00
|
|
|
* a widget displaying the options the user can interact with to modify
|
|
|
|
* the behaviour of what happens when a given match is selected.
|
|
|
|
*
|
|
|
|
* @param widget the parent of the options widgets.
|
|
|
|
*/
|
|
|
|
virtual void createConfigurationInterface(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
|
|
|
*/
|
2007-12-03 18:18:28 +01:00
|
|
|
virtual void exec(Plasma::SearchMatch *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;
|
|
|
|
|
|
|
|
// For 4.1
|
|
|
|
// /**
|
|
|
|
// * The tier of the runner.
|
|
|
|
// * @see setTier
|
|
|
|
// */
|
|
|
|
// int tier() 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
|
|
|
|
2007-02-28 01:41:09 +01:00
|
|
|
protected:
|
|
|
|
/**
|
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
|
|
|
*/
|
2007-10-31 05:44:09 +01:00
|
|
|
void setHasMatchOptions(bool hasMatchOptions);
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-02-28 04:55:22 +01:00
|
|
|
/**
|
2007-10-31 05:44:09 +01:00
|
|
|
* Sets whether or not the runner has configuration options itself
|
2007-02-28 04:55:22 +01:00
|
|
|
*/
|
2007-11-22 10:08:58 +01:00
|
|
|
void setIsConfigurable(bool canBeConfigured);
|
2007-02-28 04:55:22 +01:00
|
|
|
|
2007-12-10 17:20:46 +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
|
|
|
|
* this within their constructors.
|
|
|
|
*/
|
|
|
|
void setSpeed(Speed newSpeed);
|
|
|
|
|
2008-01-08 01:21:10 +01:00
|
|
|
//For 4.1
|
|
|
|
// /**
|
|
|
|
// * Sets the run tier of the runner. Higher tier runners execute only
|
|
|
|
// * after all lower-level runners execute. Call this method if your runner
|
|
|
|
// * depends on the output of previous runners.
|
|
|
|
// */
|
|
|
|
// void setTier(int tier);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
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
|
|
|
|
|
|
|
#endif
|