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-04-22 11:35:04 +02:00
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtCore/QList>
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma_export.h>
|
2007-02-28 01:41:09 +01:00
|
|
|
|
|
|
|
class KActionCollection;
|
2007-03-20 18:37:44 +01:00
|
|
|
class QAction;
|
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
|
|
|
/**
|
|
|
|
* A abstract super-class for Plasma Runners
|
|
|
|
*/
|
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-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
|
|
|
/**
|
|
|
|
* Constrcuts an 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 );
|
|
|
|
virtual ~AbstractRunner();
|
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-07-18 21:09:41 +02:00
|
|
|
QAction* exactMatch(const QString& command);
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-03-05 01:07:21 +01:00
|
|
|
/**
|
|
|
|
* @return the last action generated by exactMatch( const QString& )
|
|
|
|
*/
|
2007-07-18 21:09:41 +02:00
|
|
|
QAction* exactMatch();
|
2007-03-05 01:07:21 +01:00
|
|
|
|
2007-03-20 18:37:44 +01:00
|
|
|
/**
|
|
|
|
* Requests the runner to find possible matches for the search term.
|
|
|
|
* Includes basic results paging controls via max and offset.
|
|
|
|
*
|
|
|
|
* @param term the search string to use
|
|
|
|
* @param max maximum number of matches to return
|
|
|
|
* @param offset the offset into the matched set to start at
|
|
|
|
*
|
|
|
|
* @return the collection of actions representing the potential matches
|
|
|
|
**/
|
|
|
|
KActionCollection* matches( const QString& term, int max, int offset );
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
virtual bool hasOptions( );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the hasOptions() returns true, this method will be called to get
|
|
|
|
* the widget displaying the options the user can interact with.
|
|
|
|
*/
|
2007-07-18 21:09:41 +02:00
|
|
|
virtual QWidget* options();
|
2007-02-28 01:41:09 +01:00
|
|
|
|
2007-03-02 08:44:42 +01:00
|
|
|
/**
|
|
|
|
* Static method is called to load and get a list available of Runners.
|
|
|
|
*/
|
|
|
|
static List loadRunners( QWidget* parent );
|
2007-03-02 01:06:52 +01:00
|
|
|
|
2007-04-22 11:35:04 +02:00
|
|
|
Q_SIGNALS:
|
2007-02-28 01:41:09 +01:00
|
|
|
/**
|
|
|
|
* When emitted, the interface will update itself to show the new
|
|
|
|
* matches. This is meant to be used by asynchronous runners that will
|
|
|
|
* only be able to start a query on fillMatches being called with
|
|
|
|
* response (and therefore matches) coming later
|
|
|
|
*/
|
|
|
|
void matchesUpdated( KActionCollection* matches );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* This method is called when there is text input to match. The runner
|
|
|
|
* should fill the matches action collection with one action per match
|
|
|
|
* to a maximium of max matches starting at offset in the data set
|
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
|
|
|
*
|
|
|
|
* @param matches the action collection to add matches to
|
|
|
|
* @param term the current search term
|
|
|
|
* @param max the maximum number of results to return
|
|
|
|
* @param offset the number of initial results to skip,
|
|
|
|
* used in conjunction with max
|
2007-02-28 01:41:09 +01:00
|
|
|
*/
|
|
|
|
virtual void fillMatches( KActionCollection* matches,
|
|
|
|
const QString& term,
|
|
|
|
int max, int offset );
|
|
|
|
|
2007-02-28 04:55:22 +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.
|
|
|
|
* The action will be activated if the user selects it.
|
2007-07-18 21:09:41 +02:00
|
|
|
*
|
|
|
|
* @param term the current search term
|
2007-02-28 04:55:22 +01:00
|
|
|
*/
|
2007-07-18 21:09:41 +02:00
|
|
|
virtual QAction* accepts(const QString& term) = 0;
|
2007-02-28 04:55:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Take action on the command. What this means is dependant on the
|
|
|
|
* particular runner implementation, e.g. some runners may treat
|
|
|
|
* command as a shell command, while others may treat it as an
|
|
|
|
* equation or a user name or ...
|
2007-07-18 21:09:41 +02:00
|
|
|
*
|
|
|
|
* This will be called automatically when the exact match is
|
|
|
|
* selected.
|
|
|
|
*
|
|
|
|
* @param action the QAction provided via exactMatch
|
|
|
|
* @param command the full command string
|
2007-02-28 04:55:22 +01:00
|
|
|
*/
|
2007-07-18 21:09:41 +02:00
|
|
|
virtual bool exec(QAction* action, const QString& command) = 0;
|
2007-02-28 04:55:22 +01:00
|
|
|
|
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 04:55:22 +01:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void runExactMatch();
|
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
|