#include <ktrader.h>
Inherits TQObject.
Public Types | |
typedef TQValueList< KService::Ptr > | OfferList |
typedef TQValueListIterator< KService::Ptr > | OfferListIterator |
Public Member Functions | |
virtual | ~TDETrader () |
virtual OfferList | query (const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const |
OfferList | query (const TQString &servicetype, const TQString &genericServiceType, const TQString &constraint, const TQString &preferences) const |
Static Public Member Functions | |
static TDETrader * | 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 tdehtml... 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:
Now, say that you want to list all KParts component that can handle HTML.
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-TDE-Blah < 4 needs to be written as [X-TDE-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-TDE-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.
Member Typedef Documentation
◆ OfferList
typedef TQValueList<KService::Ptr> TDETrader::OfferList |
Constructor & Destructor Documentation
◆ ~TDETrader()
|
virtual |
Standard destructor.
Definition at line 102 of file ktrader.cpp.
Member Function Documentation
◆ query() [1/2]
|
virtual |
The main function in the TDETrader 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:
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, TQString::null to get all services of the given servicetype
preferences Indicates a particular preference to return, TQString::null to ignore. Uses an expression in the constraint language that must return a number
- Returns
- A list of services that satisfy the query
Definition at line 106 of file ktrader.cpp.
◆ query() [2/2]
TDETrader::OfferList TDETrader::query | ( | const TQString & | servicetype, |
const TQString & | genericServiceType, | ||
const TQString & | constraint, | ||
const TQString & | 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, TQString::null to get all services of the given servicetype
preferences Indicates a particular preference to return, TQString::null to ignore. Uses an expression in the constraint language that must return a number
- Returns
- A list of services that satisfy the query
Definition at line 112 of file ktrader.cpp.
◆ self()
|
static |
This is a static pointer to a TDETrader instance.
You will need to use this to access the TDETrader functionality since the constuctors are protected.
- Returns
- Static TDETrader instance
Definition at line 90 of file ktrader.cpp.
The documentation for this class was generated from the following files: