• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • Plasma
  • AbstractRunner
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Properties | List of all members
Plasma::AbstractRunner Class Reference

#include <Plasma/AbstractRunner>

Inheritance diagram for Plasma::AbstractRunner:
Inheritance graph
[legend]

Public Types

typedef QList< AbstractRunner * > List
 
enum  Priority {
  LowestPriority = 0, LowPriority, NormalPriority, HighPriority,
  HighestPriority
}
 
enum  Speed { SlowSpeed, NormalSpeed }
 

Signals

void matchingSuspended (bool suspended)
 
void prepare ()
 
void teardown ()
 

Public Member Functions

virtual ~AbstractRunner ()
 
virtual void createRunOptions (QWidget *widget)
 
RunnerSyntax * defaultSyntax () const
 
QString description () const
 
bool hasRunOptions ()
 
QIcon icon () const
 
QString id () const
 
RunnerContext::Types ignoredTypes () const
 
bool isMatchingSuspended () const
 
virtual void match (Plasma::RunnerContext &context)
 
QString name () const
 
const Package * package () const
 
void performMatch (Plasma::RunnerContext &context)
 
Priority priority () const
 
virtual void reloadConfiguration ()
 
virtual void run (const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
 
void setIgnoredTypes (RunnerContext::Types types)
 
Speed speed () const
 
QList< RunnerSyntax > syntaxes () const
 

Static Public Member Functions

static QMutex * bigLock ()
 

Protected Slots

void init ()
 
QMimeData * mimeDataForMatch (const Plasma::QueryMatch *match)
 

Protected Member Functions

 AbstractRunner (QObject *parent=0, const QString &path=QString())
 
 AbstractRunner (const KService::Ptr service, QObject *parent=0)
 
 AbstractRunner (QObject *parent, const QVariantList &args)
 
QAction * action (const QString &id) const
 
QHash< QString, QAction * > actions () const
 
virtual QList< QAction * > actionsForMatch (const Plasma::QueryMatch &match)
 
QAction * addAction (const QString &id, const QIcon &icon, const QString &text)
 
void addAction (const QString &id, QAction *action)
 
void addSyntax (const RunnerSyntax &syntax)
 
void clearActions ()
 
KConfigGroup config () const
 
Q_INVOKABLE DataEngine * dataEngine (const QString &name) const
 
void removeAction (const QString &id)
 
KService::List serviceQuery (const QString &serviceType, const QString &constraint=QString()) const
 
void setDefaultSyntax (const RunnerSyntax &syntax)
 
void setHasRunOptions (bool hasRunOptions)
 
void setPriority (Priority newPriority)
 
void setSpeed (Speed newSpeed)
 
void setSyntaxes (const QList< RunnerSyntax > &syns)
 
void suspendMatching (bool suspend)
 

Properties

QString description
 
QIcon icon
 
QString id
 
bool matchingSuspended
 
QString name
 

Detailed Description

An abstract base class for Plasma Runner plugins.

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. See match() for details. To let krunner expose a global shortcut for the single runner query mode, the runner must set the "X-Plasma-AdvertiseSingleRunnerMode" key to true in the .desktop file and set a default syntax. See setDefaultSyntax() for details.

Definition at line 63 of file abstractrunner.h.

Member Typedef Documentation

typedef QList<AbstractRunner*> Plasma::AbstractRunner::List

An ordered list of runners.

Definition at line 88 of file abstractrunner.h.

Member Enumeration Documentation

enum Plasma::AbstractRunner::Priority

Specifies a priority for the runner.

Enumerator
LowestPriority 
LowPriority 
NormalPriority 
HighPriority 
HighestPriority 

Definition at line 79 of file abstractrunner.h.

enum Plasma::AbstractRunner::Speed

Specifies a nominal speed for the runner.

Enumerator
SlowSpeed 
NormalSpeed 

Definition at line 73 of file abstractrunner.h.

Constructor & Destructor Documentation

Plasma::AbstractRunner::~AbstractRunner ( )
virtual

Definition at line 74 of file abstractrunner.cpp.

Plasma::AbstractRunner::AbstractRunner ( QObject *  parent = 0,
const QString &  path = QString() 
)
explicitprotected

Definition at line 48 of file abstractrunner.cpp.

Plasma::AbstractRunner::AbstractRunner ( const KService::Ptr  service,
QObject *  parent = 0 
)
explicitprotected

Definition at line 55 of file abstractrunner.cpp.

Plasma::AbstractRunner::AbstractRunner ( QObject *  parent,
const QVariantList &  args 
)
protected

Definition at line 62 of file abstractrunner.cpp.

Member Function Documentation

QAction * Plasma::AbstractRunner::action ( const QString &  id) const
protected

Returns the action associated with the id.

Definition at line 190 of file abstractrunner.cpp.

QHash< QString, QAction * > Plasma::AbstractRunner::actions ( ) const
protected

Returns all registered actions.

Definition at line 195 of file abstractrunner.cpp.

QList< QAction * > Plasma::AbstractRunner::actionsForMatch ( const Plasma::QueryMatch &  match)
protectedvirtual

A given match can have more than action that can be performed on it.

For example, a song match returned by a music player runner can be queued, added to the playlist, or played.

Call this method to add actions that can be performed by the runner. Actions must first be added to the runner's action registry. Note: execution of correct action is left up to the runner.

Definition at line 162 of file abstractrunner.cpp.

QAction * Plasma::AbstractRunner::addAction ( const QString &  id,
const QIcon &  icon,
const QString &  text 
)
protected

Creates and then adds an action to the action registry.

AbstractRunner assumes ownership of the created action.

Parameters
idA unique identifier string
iconThe icon to display
textThe text to display
Returns
the created QAction

Definition at line 172 of file abstractrunner.cpp.

void Plasma::AbstractRunner::addAction ( const QString &  id,
QAction *  action 
)
protected

Adds an action to the runner's action registry.

The QAction must be created within the GUI thread; do not create it within the match method of AbstractRunner.

Parameters
idA unique identifier string
actionThe QAction to be stored

Definition at line 179 of file abstractrunner.cpp.

void Plasma::AbstractRunner::addSyntax ( const RunnerSyntax &  syntax)
protected

Adds a registered syntax that this runner understands.

This is used to display to the user what this runner can understand and how it can be used.

Parameters
syntaxthe syntax to register
Since
4.3

Definition at line 97 of file abstractrunner.cpp.

QMutex * Plasma::AbstractRunner::bigLock ( )
static

Access to a shared lock that all runners (and code that manages/interacts with them) can share to protect access to non-thread-safe shared code or data.

Access of KSycoca records, for instance, is one place this lock should be used.

Common usage:

{ QMutexLocker lock(bigLock()); .. do something that isn't thread safe .. }

Definition at line 275 of file abstractrunner.cpp.

void Plasma::AbstractRunner::clearActions ( )
protected

Clears the action registry.

The action pool deletes the actions.

Definition at line 200 of file abstractrunner.cpp.

KConfigGroup Plasma::AbstractRunner::config ( ) const
protected

Provides access to the runner's configuration object.

Definition at line 79 of file abstractrunner.cpp.

void Plasma::AbstractRunner::createRunOptions ( QWidget *  widget)
virtual

If hasRunOptions() returns true, this method may be called to get a widget displaying the options the user can interact with to modify the behaviour of what happens when a given match is selected.

Parameters
widgetthe parent of the options widgets.

Definition at line 222 of file abstractrunner.cpp.

DataEngine * Plasma::AbstractRunner::dataEngine ( const QString &  name) const
protected

Loads the given DataEngine.

Tries to load the data engine given by name. Each engine is only loaded once, and that instance is re-used on all subsequent requests.

If the data engine was not found, an invalid data engine is returned (see DataEngine::isValid()).

Note that you should not delete the returned engine.

Parameters
nameName of the data engine to load
Returns
pointer to the data engine if it was loaded, or an invalid data engine if the requested engine could not be loaded
Since
4.4

Definition at line 362 of file abstractrunner.cpp.

RunnerSyntax * Plasma::AbstractRunner::defaultSyntax ( ) const
Returns
the default syntax for the runner or 0 if no default syntax has been defined
Since
4.4

Definition at line 118 of file abstractrunner.cpp.

QString Plasma::AbstractRunner::description ( ) const
Returns
the description of this Runner
bool Plasma::AbstractRunner::hasRunOptions ( )

If the runner has options that the user can interact with to modify what happens when run or one of the actions created in match is called, the runner should return true.

Definition at line 212 of file abstractrunner.cpp.

QIcon Plasma::AbstractRunner::icon ( ) const
Returns
the icon for this Runner
QString Plasma::AbstractRunner::id ( ) const
Returns
an id string for the Runner
RunnerContext::Types Plasma::AbstractRunner::ignoredTypes ( ) const

Returns the OR'ed value of all the Information types (as defined in RunnerContext::Type) this runner is not interested in.

Returns
OR'ed value of black listed types

Definition at line 260 of file abstractrunner.cpp.

void Plasma::AbstractRunner::init ( )
protectedslot

Reimplement this slot to run any initialization routines on first load.

By default, it calls reloadConfiguration(); for scripted Runners this method also sets up the ScriptEngine.

Definition at line 352 of file abstractrunner.cpp.

bool Plasma::AbstractRunner::isMatchingSuspended ( ) const
Returns
true if the runner is currently busy with non-interuptable work, signaling that new threads should not be created for it at this time
Since
4.6

Definition at line 367 of file abstractrunner.cpp.

void Plasma::AbstractRunner::match ( Plasma::RunnerContext &  context)
virtual

This is the main query method.

It should trigger creation of QueryMatch instances through RunnerContext::addMatch and RunnerContext::addMatches. It is called internally by performMatch().

If the runner can run precisely the requested term (RunnerContext::query()), it should create an exact match by setting the type to RunnerContext::ExactMatch. The first runner that creates a QueryMatch will be the default runner. Other runner's matches will be suggested in the interface. Non-exact matches should be offered via RunnerContext::PossibleMatch.

The match will be activated via run() if the user selects it.

Each runner is executed in its own thread. Whenever the user input changes this method is called again. Thus, it needs to be thread-safe. Also, all matches need to be reported once this method returns. Asynchronous runners therefore need to make use of a local event loop to wait for all matches.

It is recommended to use local status data in async runners. The simplest way is to have a separate class doing all the work like so:

void MyFancyAsyncRunner::match( RunnerContext& context )
{
QEventLoop loop;
MyAsyncWorker worker( context );
connect( &worker, SIGNAL(finished()),
&loop, SLOT(quit()) );
worker.work();
loop.exec();
}

Here MyAsyncWorker creates all the matches and calls RunnerContext::addMatch in some internal slot. It emits the finished() signal once done which will quit the loop and make the match() method return. The local status is kept entirely in MyAsyncWorker which makes match() trivially thread-safe.

If a particular match supports multiple actions, set up the corresponding actions in the actionsForMatch method. Do not call any of the action methods within this method!

Execution of the correct action should be handled in the run method. This method needs to be thread-safe since KRunner will simply start a new thread for each new term.

Warning
Returning from this method means to end execution of the runner.
See also
run(), RunnerContext::addMatch, RunnerContext::addMatches, QueryMatch

Definition at line 287 of file abstractrunner.cpp.

void Plasma::AbstractRunner::matchingSuspended ( bool  suspended)
signal

Emitted when the runner enters or exits match suspension.

See also
matchingSuspended
Since
4.6
QMimeData * Plasma::AbstractRunner::mimeDataForMatch ( const Plasma::QueryMatch *  match)
protectedslot

Reimplement this slot if you want your runner to support serialization and drag and drop.

Since
4.5

Definition at line 206 of file abstractrunner.cpp.

QString Plasma::AbstractRunner::name ( ) const
Returns
the user visible engine name for the Runner
const Package * Plasma::AbstractRunner::package ( ) const

Accessor for the associated Package object if any.

Note that the returned pointer is only valid for the lifetime of the runner.

Returns
the Package object, or 0 if none

Definition at line 346 of file abstractrunner.cpp.

void Plasma::AbstractRunner::performMatch ( Plasma::RunnerContext &  context)

Triggers a call to match.

This will call match() internally.

Parameters
contextthe search context used in executing this match.

Definition at line 123 of file abstractrunner.cpp.

void Plasma::AbstractRunner::prepare ( )
signal

This signal is emitted when matching is about to commence, giving runners an opportunity to prepare themselves, e.g.

loading data sets or preparing IPC or network connections. This method should be fast so as not to cause slow downs. Things that take longer or which should be loaded once and remain extant for the lifespan of the AbstractRunner should be done in init().

See also
init()
Since
4.4
AbstractRunner::Priority Plasma::AbstractRunner::priority ( ) const

The priority of the runner.

See also
setPriority

Definition at line 250 of file abstractrunner.cpp.

void Plasma::AbstractRunner::reloadConfiguration ( )
virtual

Signal runner to reload its configuration.

Definition at line 90 of file abstractrunner.cpp.

void Plasma::AbstractRunner::removeAction ( const QString &  id)
protected

Removes the action from the action registry.

AbstractRunner deletes the action once removed.

Parameters
idThe id of the action to be removed

Definition at line 184 of file abstractrunner.cpp.

void Plasma::AbstractRunner::run ( const Plasma::RunnerContext &  context,
const Plasma::QueryMatch &  match 
)
virtual

Called whenever an exact or possible match associated with this runner is triggered.

Parameters
contextThe context in which the match is triggered, i.e. for which the match was created.
matchThe actual match to run/execute.

Definition at line 280 of file abstractrunner.cpp.

KService::List Plasma::AbstractRunner::serviceQuery ( const QString &  serviceType,
const QString &  constraint = QString() 
) const
protected
Deprecated:
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.
Parameters
serviceTypea service type like "Plasma/Applet" or "KFilePlugin"
constrainta constraint to limit the choices returned.
See also
KServiceTypeTrader::query(const QString&, const QString&)
Returns
a list of services that satisfy the query.

Definition at line 270 of file abstractrunner.cpp.

void Plasma::AbstractRunner::setDefaultSyntax ( const RunnerSyntax &  syntax)
protected

Set syntax as the default syntax for the runner; the default syntax will be substituted to the empty query in single runner mode.

This is also used to display to the user what this runner can understand and how it can be used. The default syntax is automatically added to the list of registered syntaxes, there is no need to add it using addSyntax. Note that there can be only one default syntax; if called more than once, the last call will determine the default syntax. A default syntax (even trivial) is required to advertise single runner mode

Parameters
syntaxthe syntax to register and to set as default
Since
4.4

Definition at line 102 of file abstractrunner.cpp.

void Plasma::AbstractRunner::setHasRunOptions ( bool  hasRunOptions)
protected

Sets whether or not the runner has options for matches.

Definition at line 217 of file abstractrunner.cpp.

void Plasma::AbstractRunner::setIgnoredTypes ( RunnerContext::Types  types)

Sets the types this runner will ignore.

Parameters
typesOR'ed listed of ignored types

Definition at line 265 of file abstractrunner.cpp.

void Plasma::AbstractRunner::setPriority ( Priority  newPriority)
protected

Sets the priority of the runner.

Lower priority runners are executed only after higher priority runners.

Definition at line 255 of file abstractrunner.cpp.

void Plasma::AbstractRunner::setSpeed ( Speed  newSpeed)
protected

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.

Definition at line 243 of file abstractrunner.cpp.

void Plasma::AbstractRunner::setSyntaxes ( const QList< RunnerSyntax > &  syns)
protected

Sets the list of syntaxes; passing in an empty list effectively clears the syntaxes.

Parameters
thesyntaxes to register for this runner
Since
4.3

Definition at line 108 of file abstractrunner.cpp.

AbstractRunner::Speed Plasma::AbstractRunner::speed ( ) const

The nominal speed of the runner.

See also
setSpeed

Definition at line 229 of file abstractrunner.cpp.

void Plasma::AbstractRunner::suspendMatching ( bool  suspend)
protected

Sets whether or not the runner is available for match requests.

Useful to prevent more thread spawning when the thread is in a busy state.

Definition at line 372 of file abstractrunner.cpp.

QList< RunnerSyntax > Plasma::AbstractRunner::syntaxes ( ) const
Returns
the syntaxes the runner has registered that it accepts and understands
Since
4.3

Definition at line 113 of file abstractrunner.cpp.

void Plasma::AbstractRunner::teardown ( )
signal

This signal is emitted when a session of matches is complete, giving runners the opportunity to tear down anything set up as a result of the prepare() method.

Since
4.4

Property Documentation

QString Plasma::AbstractRunner::description
read

Definition at line 68 of file abstractrunner.h.

QIcon Plasma::AbstractRunner::icon
read

Definition at line 70 of file abstractrunner.h.

QString Plasma::AbstractRunner::id
read

Definition at line 67 of file abstractrunner.h.

bool Plasma::AbstractRunner::matchingSuspended
readwrite

Definition at line 66 of file abstractrunner.h.

QString Plasma::AbstractRunner::name
read

Definition at line 69 of file abstractrunner.h.


The documentation for this class was generated from the following files:
  • abstractrunner.h
  • abstractrunner.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal