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

KDECore

Public Member Functions | Static Public Member Functions | List of all members
KServiceTypeTrader Class Reference

#include <kservicetypetrader.h>

Public Member Functions

 ~KServiceTypeTrader ()
 
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
 

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, const QString &constraint=QString(), QObject *parent=0, const QVariantList &args=QVariantList(), QString *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)
 
static KServiceTypeTrader * self ()
 

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

If you want to find all plugins for your application, you would define a KMyApp/Plugin servicetype, and then you can query the trader for it:

KService::List offers =
KServiceTypeTrader::self()->query("KMyApp/Plugin");
KServiceTypeTrader::self
static KServiceTypeTrader * self()
This is a static pointer to the KServiceTypeTrader singleton.
Definition: kservicetypetrader.cpp:37
KServiceTypeTrader::query
KService::List query(const QString &servicetype, const QString &constraint=QString()) const
The main function in the KServiceTypeTrader class.
Definition: kservicetypetrader.cpp:134
QList< Ptr >

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
#define X

needs to be written as

[X-KMyApp-InterfaceVersion] > 4

otherwise it could also be interpreted as Subtract the numeric value of the property "KMyApp" and "InterfaceVersion" from the property "X" and make sure it is greater than 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.

Constructor & Destructor Documentation

◆ ~KServiceTypeTrader()

KServiceTypeTrader::~KServiceTypeTrader ( )

Standard destructor.

Definition at line 48 of file kservicetypetrader.cpp.

Member Function Documentation

◆ applyConstraints()

void KServiceTypeTrader::applyConstraints ( KService::List &  lst,
const QString &  constraint 
)
static

(public for KMimeTypeTrader)

Definition at line 53 of file kservicetypetrader.cpp.

◆ createInstanceFromQuery() [1/3]

template<class T >
static T * KServiceTypeTrader::createInstanceFromQuery ( const QString &  serviceType,
const QString &  constraint,
QObject *  parent,
const QStringList &  args,
int *  error = 0 
)
inlinestatic
Deprecated:
Use createInstanceFromQuery(const QString&, const QString&, QObject*, const QVariantList&, QString*) instead

Definition at line 203 of file kservicetypetrader.h.

◆ createInstanceFromQuery() [2/3]

template<class T >
static T * KServiceTypeTrader::createInstanceFromQuery ( const QString &  serviceType,
const QString &  constraint = QString(),
QObject *  parent = 0,
const QVariantList &  args = QVariantList(),
QString *  error = 0 
)
inlinestatic

Get a plugin from a trader query.

Example:

KMyAppPlugin* plugin = KServiceTypeTrader::createInstanceFromQuery<KMyAppPlugin>( serviceType, QString(), parentObject );
if ( plugin ) {
....
}
QString
Parameters
serviceTypethe type of service for which to find a plugin
constraintan optional constraint to pass to the trader (see KTrader)
parentthe parent object for the part itself
argsA list of arguments passed to the service component
errorThe 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.

◆ createInstanceFromQuery() [3/3]

template<class T >
static T * KServiceTypeTrader::createInstanceFromQuery ( const QString &  serviceType,
QWidget *  parentWidget,
QObject *  parent,
const QString &  constraint = QString(),
const QVariantList &  args = QVariantList(),
QString *  error = 0 
)
inlinestatic

Get a plugin from a trader query.

This method works like createInstanceFromQuery(const QString&, const QString&, QObject*, const QVariantList&, QString*), but you can specify an additional parent widget. This is important for a KPart, for example.

Parameters
serviceTypethe type of service for which to find a plugin
parentWidgetthe parent widget for the plugin
parentthe parent object for the part itself
constraintan optional constraint to pass to the trader (see KTrader)
argsA list of arguments passed to the service component
errorThe 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 178 of file kservicetypetrader.h.

◆ defaultOffers()

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.

◆ preferredService()

KService::Ptr KServiceTypeTrader::preferredService ( const QString &  serviceType) const

Returns the preferred service for serviceType.

Parameters
serviceTypethe 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.

◆ query()

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
servicetypeA service type like 'KMyApp/Plugin' or 'KFilePlugin'.
constraintA constraint to limit the choices returned, QString() to get all services of the given servicetype
Returns
A list of services that satisfy the query
See also
http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language

Definition at line 134 of file kservicetypetrader.cpp.

◆ self()

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:
  • kservicetypetrader.h
  • kservicetypetrader.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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