KApplicationTrader Namespace

The application trader is a convenient way to find installed applications based on specific criteria (association with a MIME type, name contains Foo, etc.). More...

Header: #include <KApplicationTrader>
CMake: find_package(KF6 REQUIRED COMPONENTS Service)
target_link_libraries(mytarget PRIVATE KF6::Service)

Types

Functions

bool isSubsequence(const QString &pattern, const QString &text, Qt::CaseSensitivity cs = Qt::CaseSensitive)
KService::Ptr preferredService(const QString &mimeType)
(since 6.33) KService::Ptr preferredServiceForIntent(const QString &intent, const QString &scope = {})
KService::List query(KApplicationTrader::FilterFunc filterFunc)
(since 6.33) KService::List queryByIntent(const QString &intent, const QString &scope = {})
KService::List queryByMimeType(const QString &mimeType, KApplicationTrader::FilterFunc filterFunc = {})
void setPreferredService(const QString &mimeType, const KService::Ptr service)
(since 6.33) void setPreferredServiceForIntent(const QString &intent, const KService::Ptr &service, const QString &scope = {})
(since 6.33) void setPreferredServiceForIntentOnCurrentPlatform(const QString &intent, const KService::Ptr &service, const QString &scope = {})

Detailed Description

Example: say that you want to get the list of all applications that can handle PNG images. The code would look like:


 KService::List lst = KApplicationTrader::queryByMimeType("image/png");

If you want to get the preferred application for image/png you would use:


 KService::Ptr service = KApplicationTrader::preferredService("image/png");

See also KService.

Type Documentation

[alias] KApplicationTrader::FilterFunc

Filter function, used for filtering results of query and queryByMimeType.

Function Documentation

bool KApplicationTrader::isSubsequence(const QString &pattern, const QString &text, Qt::CaseSensitivity cs = Qt::CaseSensitive)

Returns true if pattern matches a subsequence of the string text. For instance the pattern "libremath" matches the text "LibreOffice Math", assuming cs is Qt::CaseInsensitive.

This can be useful from your filter function, e.g. with text being service->name().

KService::Ptr KApplicationTrader::preferredService(const QString &mimeType)

Returns the preferred service for mimeType

This a convenience method for queryByMimeType(mimeType).at(0), with a check for empty.

mimeType the MIME type (see query())

Returns the preferred service, or nullptr if no service is available

See also setPreferredService().

[since 6.33] KService::Ptr KApplicationTrader::preferredServiceForIntent(const QString &intent, const QString &scope = {})

Returns the preferred/default service for the given XDG Intent.

If no suitable service is found, nullptr is returned.

intent Name of the XDG Intent.

scope Optional scope of the intent, if used/supported by the specific intent.

This function was introduced in 6.33.

See also setPreferredServiceForIntent().

KService::List KApplicationTrader::query(KApplicationTrader::FilterFunc filterFunc)

This method returns a list of services (applications) that match a given filter.

filterFunc a callback function that returns true if the application should be selected and false if it should be skipped.

Returns a list of services that satisfy the query

[since 6.33] KService::List KApplicationTrader::queryByIntent(const QString &intent, const QString &scope = {})

Returns a list of services implementing the given XDG Intent.

intent Name of the XDG Intent.

scope Optional scope of the intent, if used/supported by the specific intent.

This function was introduced in 6.33.

See also https://specifications.freedesktop.org/intent-apps/.

KService::List KApplicationTrader::queryByMimeType(const QString &mimeType, KApplicationTrader::FilterFunc filterFunc = {})

This method returns a list of services (applications) which are associated with a given MIME type.

mimeType a MIME type like 'text/plain' or 'text/html'

filterFunc a callback function that returns true if the application should be selected and false if it should be skipped. Do not return true for all services, this would return the complete list of all installed applications (slow).

Returns a list of services that satisfy the query, sorted by preference (preferred service first)

void KApplicationTrader::setPreferredService(const QString &mimeType, const KService::Ptr service)

Changes the preferred service for mimeType to service

You may need to rebuild KSyCoca for the change to be reflected

mimeType the MIME type

service the service to set as the preferred one

See also preferredService().

[since 6.33] void KApplicationTrader::setPreferredServiceForIntent(const QString &intent, const KService::Ptr &service, const QString &scope = {})

Sets the preferred service for a given XDG Intent.

intent Name of the XDG Intent.

service The service that should be preferred to handle this intent.

scope Optional scope of the intent, if used/supported by the specific intent.

This function was introduced in 6.33.

See also preferredServiceForIntent().

[since 6.33] void KApplicationTrader::setPreferredServiceForIntentOnCurrentPlatform(const QString &intent, const KService::Ptr &service, const QString &scope = {})

Sets the preferred service for a given XDG Intent on the current platform only.

The current platform is determined based on the first entry in the $XDG_CURRENT_DESKTOP environment variable.

intent Name of the XDG Intent.

service The service that should be preferred to handle this intent.

scope Optional scope of the intent, if used/supported by the specific intent.

This function was introduced in 6.33.