diff --git a/CMakeLists.txt b/CMakeLists.txt index 0da76a22e..20348dd79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ set(plasma_LIB_SRCS plasma.cpp applet.cpp interface.cpp + runner.cpp theme.cpp ) @@ -22,5 +23,11 @@ install(TARGETS plasma DESTINATION ${LIB_INSTALL_DIR} ) ########### install files ############### -install( FILES applet.h plasma.h theme.h interface.h DESTINATION ${INCLUDE_INSTALL_DIR}/plasma ) +install( FILES + applet.h + plasma.h + runner.h + theme.h + interface.h + DESTINATION ${INCLUDE_INSTALL_DIR}/plasma ) diff --git a/runner.cpp b/runner.cpp new file mode 100644 index 000000000..9cd2e1562 --- /dev/null +++ b/runner.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2006 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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. + */ + +#include + +#include "runner.h" + +class Runner::Private +{ + public: + Private( Runner* runner ) + { + actions = new KActionCollection( runner ); + } + + KActionCollection* actions; +}; + +Runner::Runner( QObject* parent ) + : QObject( parent ) +{ + d = new Private( this ); +} + +Runner::~Runner() +{ + delete d; +} + +bool Runner::hasOptions() +{ + return false; +} + +QWidget* Runner::options() +{ + return 0; +} + +KActionCollection* Runner::matches( const QString& term, int max, int offset ) +{ + d->actions->clear(); + fillMatches( d->actions, term, max, offset ); + return d->actions; +} + +void Runner::fillMatches( KActionCollection* matches, + const QString& term, + int max, int offset ) +{ + Q_UNUSED( term ); + Q_UNUSED( max ); + Q_UNUSED( offset ); +} + +#include "runner.moc" diff --git a/runner.h b/runner.h new file mode 100644 index 000000000..1590a5ac1 --- /dev/null +++ b/runner.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2006 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 + +#include +#include + +#include + +class KActionCollection; + +class KDE_EXPORT Runner : public QObject +{ + Q_OBJECT + + public: + typedef QList List; + + explicit Runner( QObject* parent = 0 ); + virtual ~Runner(); + + /** + * 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. + */ + virtual QAction* accepts( const QString& term ) = 0; + + /** + * 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. + */ + virtual QWidget* options( ); + + /** + * 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 ... + */ + virtual bool exec( const QString& command ) = 0; + + KActionCollection* matches( const QString& term, int max, int offset ); + + signals: + /** + * 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 + */ + virtual void fillMatches( KActionCollection* matches, + const QString& term, + int max, int offset ); + + private: + class Private; + Private* d; +}; + +#define K_EXPORT_KRUNNER_RUNNER( libname, classname ) \ + K_EXPORT_COMPONENT_FACTORY( \ + krunner_##libname, \ + KGenericFactory("krunner_" #libname) ) + +#endif