get run of m_currentRunner, we just always launch the first thing in the list now

if needed, we can go back to holding on to the default action, but for
    right now it is always shown first in the list
allow launching of any item that shows in the matches. coooool.

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=637896
This commit is contained in:
Aaron J. Seigo 2007-02-28 03:55:22 +00:00
parent 23bcf68924
commit 13920a4cc1
2 changed files with 52 additions and 11 deletions

View File

@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QAction>
#include <KActionCollection>
#include "runner.h"
@ -23,12 +24,16 @@
class Runner::Private
{
public:
Private( Runner* runner )
Private( Runner* runner ) :
exactMatch( 0 ),
actions( new KActionCollection( runner ) )
{
actions = new KActionCollection( runner );
}
QAction* exactMatch;
KActionCollection* actions;
// FIXME: it's a bit lame to keep a copy of the term in each runner
QString term;
};
Runner::Runner( QObject* parent )
@ -52,6 +57,21 @@ QWidget* Runner::options()
return 0;
}
QAction* Runner::exactMatch( const QString& term )
{
delete d->exactMatch;
d->term.clear();
d->exactMatch = accepts( term );
if ( d->exactMatch ) {
d->term = term;
connect( d->exactMatch, SIGNAL( triggered() ),
this, SLOT( runExactMatch() ) );
}
return d->exactMatch;
}
KActionCollection* Runner::matches( const QString& term, int max, int offset )
{
d->actions->clear();
@ -63,9 +83,15 @@ void Runner::fillMatches( KActionCollection* matches,
const QString& term,
int max, int offset )
{
Q_UNUSED( matches );
Q_UNUSED( term );
Q_UNUSED( max );
Q_UNUSED( offset );
}
void Runner::runExactMatch()
{
exec( d->term );
}
#include "runner.moc"

View File

@ -41,8 +41,9 @@ class KDE_EXPORT Runner : public QObject
* 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.
*/
virtual QAction* accepts( const QString& term ) = 0;
QAction* exactMatch( const QString& command );
/**
* If the runner has options that the user can interact with to modify
@ -57,14 +58,6 @@ class KDE_EXPORT Runner : public QObject
*/
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:
@ -86,9 +79,31 @@ class KDE_EXPORT Runner : public QObject
const QString& term,
int max, int offset );
/**
* 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.
*/
virtual QAction* accepts( const QString& term ) = 0;
/**
* 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 ...
* This will be called automatically when the exact match
* QAction is triggered
*/
virtual bool exec( const QString& command ) = 0;
private:
class Private;
Private* d;
private Q_SLOTS:
void runExactMatch();
};
#define K_EXPORT_KRUNNER_RUNNER( libname, classname ) \