org.kde.koala
public class KTrader extends QObject
ArrayList 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);It should be noted that in the above example, using KServiceTypeProfile would be the better choice since you would probably want the preferred service and the trader doesn't take this into account. The trader does allow you to do more complex things, though. Say, for instance, you want to only choose Netscape. You can do it with the constraint: "(Type == 'Application') and (Name == 'Netscape')" More the likely, though, you will only use the trader for such things as finding components. In our continuing example, we say that we want to load any KParts component that can handle HTML. We will need to use the KLibFactory and KLibLoader to actually do something with our query, then. Our code would look like so:
ArrayList offers = KTrader.self().query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes"); KService.Ptr ptr = offers.first(); KLibFactory factory = KLibLoader.self().factory( ptr.library() ); if (factory) part = static_castPlease 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 KTrader .(factory.create(this, ptr.name(), "KParts.ReadOnlyPart"));
UNKNOWN: Provides a way to query the KDE infrastructure for specific applications or components.
Constructor Summary | |
---|---|
protected | KTrader(Class dummy) |
KTrader() |
Method Summary | |
---|---|
String | className() |
void | dispose() Delete the wrapped C++ instance ahead of finalize() |
protected void | finalize() Deletes the wrapped C++ instance |
boolean | isDisposed() Has the wrapped C++ instance been deleted? |
QMetaObject | metaObject() |
ArrayList | query(String servicetype, String constraint, String preferences)
The main function in the KTrader class.
|
ArrayList | query(String servicetype, String constraint) |
ArrayList | query(String servicetype) |
ArrayList | query(String servicetype, String genericServiceType, String constraint, String preferences)
A variant of query(), that takes two service types as an input.
|
static KTrader | self()
This is a static pointer to a KTrader instance.
|
UNKNOWN:
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, null to
get all services of the given servicetype
preferences Indicates a particular preference to return, 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: ://developer#kde#org/documentation/library/kdeqt/tradersyntax#html
UNKNOWN: The main function in the KTrader class.
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, null to
get all services of the given servicetype
preferences Indicates a particular preference to return, 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: ://developer#kde#org/documentation/library/kdeqt/tradersyntax#html
UNKNOWN: A variant of query(), that takes two service types as an input.
Returns: Static KTrader instance
UNKNOWN: This is a static pointer to a KTrader instance.