KApplicationTrader

KApplicationTrader Namespace Reference

Typedefs

using FilterFunc = std::function< bool(const KService::Ptr &)>
 

Functions

KSERVICE_EXPORT bool isSubsequence (const QString &pattern, const QString &text, Qt::CaseSensitivity cs=Qt::CaseSensitive)
 
KSERVICE_EXPORT KService::Ptr preferredService (const QString &mimeType)
 
KSERVICE_EXPORT KService::List query (FilterFunc filterFunc)
 
KSERVICE_EXPORT KService::List queryByMimeType (const QString &mimeType, FilterFunc filterFunc={})
 
KSERVICE_EXPORT void setPreferredService (const QString &mimeType, const KService::Ptr service)
 

Detailed Description

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

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

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

See also
KService

Typedef Documentation

◆ FilterFunc

using KApplicationTrader::FilterFunc = typedef std::function<bool(const KService::Ptr &)>

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

Definition at line 39 of file kapplicationtrader.h.

Function Documentation

◆ isSubsequence()

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().

Since
5.68

Definition at line 143 of file kapplicationtrader.cpp.

◆ preferredService()

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.

Parameters
mimeTypethe MIME type (see query())
Returns
the preferred service, or nullptr if no service is available
Since
5.68

Definition at line 109 of file kapplicationtrader.cpp.

◆ query()

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

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

Parameters
filtera 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
5.68

Definition at line 79 of file kapplicationtrader.cpp.

◆ queryByMimeType()

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

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

Parameters
mimeTypea MIME type like 'text/plain' or 'text/html'
filtera 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)
Since
5.68

Definition at line 97 of file kapplicationtrader.cpp.

◆ setPreferredService()

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

Parameters
mimeTypethe MIME type
servicethe service to set as the preferred one
Since
5.101

Definition at line 118 of file kapplicationtrader.cpp.

KSERVICE_EXPORT KService::List queryByMimeType(const QString &mimeType, FilterFunc filterFunc={})
This method returns a list of services (applications) which are associated with a given MIME type.
KSERVICE_EXPORT KService::Ptr preferredService(const QString &mimeType)
Returns the preferred service for mimeType.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Dec 8 2023 03:50:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.