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>
|
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
|
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,
|
|
|
|
SlowSpeed };
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* If the runner can run precisely this term, return a QAction, else
|
|
|
|
* return 0. The first runner that returns a QAction will be the
|
|
|
|
* default runner. Other runner's actions will be suggested in the
|
|
|
|
* interface. Non-exact matches should be offered via findMatches.
|
2007-02-28 04:55:22 +01:00
|
|
|
* The action will be activated if the user selects it.
|
2007-03-02 08:44:42 +01:00
|
|
|
* If the action is informational only and should not be executed,
|
|
|
|
* disable the action with setEnabled( false ).
|
2007-07-18 21:09:41 +02:00
|
|
|
*
|
|
|
|
* If this runner's exact match is selected, the action will not
|
|
|
|
* be triggered, but it will be passed into the exec method.
|
|
|
|
* @see exec
|
|
|
|
*
|
|
|
|
* Ownership of the action passes to the AbstractRunner class.
|
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
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
Speed speed() const;
|
|
|
|
|
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);
|
|
|
|
|
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
|