KServiceTypeTrader Class Reference
from PyKDE4.kdecore import *
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");
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!needs to be written as
[X-KMyApp-InterfaceVersion] > 4otherwise 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.\n Instead of the other meaning, make sure that the numeric value of "X-KMyApp-InterfaceVersion" is greater than 4.
- See also:
- KMimeTypeTrader, KService
Methods | |
__init__ (self) | |
__init__ (self, KServiceTypeTrader other) | |
[KSharedPtr | defaultOffers (self, QString serviceType, QString constraint=QString()) |
KSharedPtr | preferredService (self, QString serviceType) |
[KSharedPtr | query (self, QString servicetype, QString constraint=QString()) |
Static Methods | |
applyConstraints ([KSharedPtr | |
KServiceTypeTrader | self () |
Method Documentation
__init__ | ( | self ) |
- Internal:
__init__ | ( | self, | ||
KServiceTypeTrader | other | |||
) |
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.
KSharedPtr |
( | self, | ||
QString | serviceType | |||
) |
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
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
- See also:
- http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language
Static Method Documentation
applyConstraints | ( | [KSharedPtr |
lst, | |
QString | constraint | |||
) |
- Internal:
- (public for KMimeTypeTrader)
KServiceTypeTrader self | ( | ) |
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