Trader Syntax

# Literals

As elementary atoms of the constraint language, KTrader supports booleans, integers, floats and strings. Boolean literals are TRUE and FALSE . Integers can be positive or negative, i.e. 42 and -10 are legal values. Floating point numbers are 3.141592535 or -999.999 . Scientific notation like 1.5e-2 is not supported. Character literals are delimited by single quotation marks, e.g. 'Bernd' .

# Symbols

Identifiers in query string are interpreted as property names, which are listed in the service's `.desktop` file. For example, `Name` is the name of the service, `ServiceTypes` is a list of the service types it supports. Note that only properties can be written as-is which start with an alphabetical character and contain only alphanumerical characters. Other properties have to be enclosed in brackets, e.g. `[X-KDE-Init]`. Properties must not contain any special characters other than `-`.

Special property names:

- DesktopEntryName stands for the filename of the service desktop entry without any extension. This can be useful to exclude some specific services.
- DesktopEntryPath stands for the relative or full path to the .desktop file, see KService::desktopEntryPath. Mentionned here for completeness, better not use it (things can be moved around).
- Library is the property whose value is set by `X-KDE-Library` in the .desktop file. This renaming happened to conform to the desktop file standard, but the property name didn't change.

# Comparison

Supported comparison operators are:

- `==`
- `!=`
- `<`
- `<=`
- `>`
- `>=`

# Arithmetic and boolean expressions

- `+`
- `-`
- `*`
- `/`
- `and`
- `or`
- `not`

Note that the arithmetic operators are possible for integers and floating point numbers. `-` is both a unary and binary operator, `not` is a unary operator.

# Other operators

- `~`
- `in`
- `exist`
- `()`

The tilde operator stands for a substring match. For example, `KParts ~ 'KParts/ReadOnlyPart'` is TRUE. The membership operator `in` tests whether a value is in a list. A list is a string with semi-colon- or comma-separated entries, depending on the type. An example for the membership operator is `'text/plain' in ServiceTypes`. The `exist` tests whether a certain property is defined in the `.desktop` file. Subexpressions are written in parentheses.

Warning, testing the contents of a property only works if the property is specified. There is not support for default values. If the property might be missing, and you still want such services to be included, you have to check for existence before testing it. For instance, to say that MyProp is a boolean that defaults to true, and that you want the services that have it set to true, use: `not exist MyProp or MyProp` Simply testing for `MyProp` would exclude the services without the property at all.

# Examples

The following examples show filters for .desktop files. `Type`, `ServiceTypes` and `MimeType` are properties in .desktop files. Be aware that within KTrader MimeType properties are understood as ServiceTypes ones.

- `Type == 'Application'`
  All services that are applications.
- `'KParts/ReadOnlyPart' in ServiceTypes`
  All read-only KParts.
- `('KParts/ReadOnlyPart' in ServiceTypes) and ('text/plain' in ServiceTypes)`
  All read-only KParts that handle the mime type 'text/plain'.

Author
  Bernd Gehrmann bernd@kdevelop.org

KDE Home | KDE Accessibility Home | Description of Access Keys