KTrader Class Reference

`#include <ktrader.h>`

Inherits QObject.

## Public Types

typedef QValueList< KService::Ptr > | OfferList
typedef QValueListIterator < KService::Ptr > | OfferListIterator

## Public Member Functions

virtual | ~KTrader ()
virtual OfferList | query (const QString &servicetype, const QString &constraint=QString::null, const QString &preferences=QString::null) const
OfferList | query (const QString &servicetype, const QString &genericServiceType, const QString &constraint, const QString &preferences) const

## Static Public Member Functions

static KTrader * | self ()

## Protected Member Functions

virtual void | virtual_hook (int id, void *data)

## Detailed Description

A Trader interface, similar to the CORBA Trader.

Basically, it provides a way for an application to query all KDE services (that is, applications and components) that match a specific set of requirements. This allows you to find an application in real-time without you having to hard-code the name and/or path of the application.

Examples

A few examples will make this a lot more clear.

Say you have an application that will display HTML. In this example, you don't want to link to khtml... and furthermore, you really don't care if the HTML browser is ours or not, as long as it works. The way that you formulate your query as well as the way that you execute the browser depends on whether or not you want the browser to run stand-alone or embedded.

If you want the browser to run standalone, then you will limit the query to search for all services that handle 'text/html' and, furthermore, they must be applications (Type=Application). You then will use KRun::run() to invoke the application. In "trader-speak", this looks like this:

KTrader::OfferList offers = KTrader::self()->query("text/html", "Type == 'Application'");
KService::Ptr ptr = offers.first();
KURL::List lst;
lst.append("http://www.kde.org/index.html");
KRun::run(*ptr, lst);

Now, say that you want to list all KParts component that can handle HTML.

KTrader::OfferList offers = KTrader::self()->query("text/html", "KParts/ReadOnlyPart");

If you want to get the preferred KParts component for text/html you could use KServiceTypeProfile::preferredService("text/html", "KParts/ReadOnlyPart"), although if this is about loading that component you would rather use KParts::ComponentFactory directly.

Please note that when including property names containing arithmetic operators like - or +, then you have to put brackets around the property name, in order to correctly separate arithmetic operations from the name. So for example a constraint expression like X-KDE-Blah < 4 needs to be written as [X-KDE-Blah] < 4 otherwise it could also be interpreted as Substract the numeric value of the property "KDE" and "Blah" from the property "X" and make sure it is less than 4. Instead of the other meaning, make sure that the numeric value of "X-KDE-Blah" is less than 4.

See also the formal syntax defined in Trader Syntax .

Provides a way to query the KDE infrastructure for specific applications or components.

Author
  Torben Weis weis@.nosp@m.kde..nosp@m.org

Definition at line 85 of file ktrader.h.

## Member Typedef Documentation

typedef QValueList<KService::Ptr> KTrader::OfferList

A list of services.

Definition at line 92 of file ktrader.h.

## Constructor & Destructor Documentation

KTrader::~KTrader | ( |  | ) |

virtual

Standard destructor.

Definition at line 102 of file ktrader.cpp.

## Member Function Documentation

KTrader::OfferList KTrader::query | ( | const QString & | servicetype,
|  | const QString & | constraint = `QString::null`,
|  | const QString & | preferences = `QString::null`
| ) |  | const

virtual

The main function in the KTrader class.

It will return a list of services that match your specifications. The only required parameter is the service type. This is something like 'text/plain' or 'text/html'. The constraint parameter is used to limit the possible choices returned based on the constraints you give it.

The `constraint` language is rather full. The most common keywords are AND, OR, NOT, IN, and EXIST, all used in an almost spoken-word form. An example is:

(Type == 'Service') and (('KParts/ReadOnlyPart' in ServiceTypes) or (exist Exec))

The keys used in the query (Type, ServiceType, Exec) are all fields found in the .desktop files.

Parameters

  servicetype | A service type like 'text/plain', 'text/html', or 'KOfficePlugin'.
  constraint | A constraint to limit the choices returned, QString::null to get all services of the given `servicetype`
  preferences | Indicates a particular preference to return, QString::null to ignore. Uses an expression in the constraint language that must return a number

Returns
  A list of services that satisfy the query

See also
  http://developer.kde.org/documentation/library/3.5-api/kdelibs-apidocs/kio/kio/html/tradersyntax.html

Definition at line 106 of file ktrader.cpp.

KTrader::OfferList KTrader::query | ( | const QString & | servicetype,
|  | const QString & | genericServiceType,
|  | const QString & | constraint,
|  | const QString & | preferences
| ) |  | const

A variant of query(), that takes two service types as an input.

It is not exactly the same as adding the second service type in the constraints of the other query call, because this one takes into account user preferences for this combination of service types.

Example usage: To get list of applications that can handle a given mimetype, set `servicetype` to the mimetype and `genericServiceType` is "Application". To get list of embeddable components that can handle a given mimetype, set `servicetype` to the mimetype and `genericServiceType` is "KParts/ReadOnlyPart".

Parameters

  servicetype | A service type like 'text/plain', 'text/html', or 'KOfficePlugin'.
  genericServiceType | a basic service type, like 'KParts/ReadOnlyPart' or 'Application'
  constraint | A constraint to limit the choices returned, QString::null to get all services of the given `servicetype`
  preferences | Indicates a particular preference to return, QString::null to ignore. Uses an expression in the constraint language that must return a number

Returns
  A list of services that satisfy the query

See also
  http://developer.kde.org/documentation/library/kdeqt/tradersyntax.html

Definition at line 112 of file ktrader.cpp.

KTrader * KTrader::self | ( |  | ) |

static

This is a static pointer to a KTrader instance.

You will need to use this to access the KTrader functionality since the constuctors are protected.

Returns
  Static KTrader instance

Definition at line 90 of file ktrader.cpp.

The documentation for this class was generated from the following files:

- ktrader.h
- ktrader.cpp

KDE Home | KDE Accessibility Home | Description of Access Keys