KDECore
KServiceTypeTrader Class Reference
#include <kservicetypetrader.h>
Detailed Description
KDE's trader interface (similar to the CORBA Trader), which provides a way to query the KDE infrastructure for specific applications or components.Basically, KServiceTypeTrader provides a way for an application to query all KDE services (that is, applications, components, plugins) that match a specific set of requirements. This allows to find specific services at run-time without having to hard-code their names and/or paths.
For anything relating to mimetypes (type of files), ignore KServiceTypeTrader and use KMimeTypeTrader instead.
- Example
KService::List offers = KServiceTypeTrader::self()->query("KMyApp/Plugin");
You can add a constraint in the "trader query language". For instance:
KServiceTypeTrader::self()->query("KMyApp/Plugin", "[X-KMyApp-InterfaceVersion] > 15");
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-KMyApp-InterfaceVersion > 4 // wrong!
[X-KMyApp-InterfaceVersion] > 4
Instead of the other meaning, make sure that the numeric value of "X-KMyApp-InterfaceVersion" is greater than 4.
- See also:
- KMimeTypeTrader, KService
Definition at line 70 of file kservicetypetrader.h.
Public Member Functions | |
KService::List | defaultOffers (const QString &serviceType, const QString &constraint=QString()) const |
KService::Ptr | preferredService (const QString &serviceType) const |
KService::List | query (const QString &servicetype, const QString &constraint=QString()) const |
~KServiceTypeTrader () | |
Static Public Member Functions | |
static void | applyConstraints (KService::List &lst, const QString &constraint) |
template<class T> | |
static T * | createInstanceFromQuery (const QString &serviceType, const QString &constraint, QObject *parent, const QStringList &args, int *error=0) |
template<class T> | |
static T * | createInstanceFromQuery (const QString &serviceType, QWidget *parentWidget, QObject *parent, const QString &constraint=QString(), const QVariantList &args=QVariantList(), QString *error=0) |
template<class T> | |
static T * | createInstanceFromQuery (const QString &serviceType, const QString &constraint=QString(), QObject *parent=0, const QVariantList &args=QVariantList(), QString *error=0) |
static KServiceTypeTrader * | self () |
Constructor & Destructor Documentation
KServiceTypeTrader::~KServiceTypeTrader | ( | ) |
Member Function Documentation
void KServiceTypeTrader::applyConstraints | ( | KService::List & | lst, | |
const QString & | constraint | |||
) | [static] |
Definition at line 53 of file kservicetypetrader.cpp.
static T* KServiceTypeTrader::createInstanceFromQuery | ( | const QString & | serviceType, | |
const QString & | constraint, | |||
QObject * | parent, | |||
const QStringList & | args, | |||
int * | error = 0 | |||
) | [inline, static] |
Definition at line 192 of file kservicetypetrader.h.
static T* KServiceTypeTrader::createInstanceFromQuery | ( | const QString & | serviceType, | |
QWidget * | parentWidget, | |||
QObject * | parent, | |||
const QString & | constraint = QString() , |
|||
const QVariantList & | args = QVariantList() , |
|||
QString * | error = 0 | |||
) | [inline, static] |
This method works like the previous one, but you can specify an additional parent widget.
This is used for example for parts
- Parameters:
-
serviceType the type of service for which to find a plugin constraint an optional constraint to pass to the trader (see KTrader) parent the parent object for the part itself args A list of arguments passed to the service component error The string passed here will contain an error description.
- Returns:
- A pointer to the newly created object or a null pointer if the factory was unable to create an object of the given type.
Definition at line 173 of file kservicetypetrader.h.
static T* KServiceTypeTrader::createInstanceFromQuery | ( | const QString & | serviceType, | |
const QString & | constraint = QString() , |
|||
QObject * | parent = 0 , |
|||
const QVariantList & | args = QVariantList() , |
|||
QString * | error = 0 | |||
) | [inline, static] |
This method creates and returns a plugin, from the trader query for a given serviceType.
Example:
KMyAppPlugin* plugin = KServiceTypeTrader::createInstanceFromQuery<KMyAppPlugin>( serviceType, QString(), parentObject ); if ( plugin ) { .... }
- Parameters:
-
serviceType the type of service for which to find a plugin constraint an optional constraint to pass to the trader (see KTrader) parent the parent object for the part itself args A list of arguments passed to the service component error The string passed here will contain an error description.
- Returns:
- A pointer to the newly created object or a null pointer if the factory was unable to create an object of the given type.
Definition at line 153 of file kservicetypetrader.h.
KService::List KServiceTypeTrader::defaultOffers | ( | const QString & | serviceType, | |
const QString & | constraint = QString() | |||
) | const |
Returns all offers associated with a given servicetype, IGNORING the user preference.
The sorting will be the one coming from the InitialPreference in the .desktop files, and services disabled by the user will still be listed here. This is used for "Revert to defaults" buttons in GUIs.
Definition at line 113 of file kservicetypetrader.cpp.
KService::Ptr KServiceTypeTrader::preferredService | ( | const QString & | serviceType | ) | const |
Returns the preferred service for serviceType
.
- Parameters:
-
serviceType the service type (e.g. "KMyApp/Plugin")
- Returns:
- the preferred service, or 0 if no service is available
Definition at line 160 of file kservicetypetrader.cpp.
KService::List KServiceTypeTrader::query | ( | const QString & | servicetype, | |
const QString & | constraint = QString() | |||
) | const |
The main function in the KServiceTypeTrader 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 'KMyApp/Plugin' or 'KFilePlugin'. constraint A constraint to limit the choices returned, QString() to get all services of the given servicetype
- Returns:
- A list of services that satisfy the query
Definition at line 134 of file kservicetypetrader.cpp.
KServiceTypeTrader * KServiceTypeTrader::self | ( | ) | [static] |
This is a static pointer to the KServiceTypeTrader singleton.
You will need to use this to access the KServiceTypeTrader functionality since the constructors are protected.
- Returns:
- Static KServiceTypeTrader instance
Definition at line 37 of file kservicetypetrader.cpp.
The documentation for this class was generated from the following files: