KMimeTypeTrader

Search for usage in LXR

#include <KMimeTypeTrader>

Public Member Functions

 ~KMimeTypeTrader ()
 
KService::Ptr preferredService (const QString &mimeType, const QString &genericServiceType=QStringLiteral("Application"))
 
KService::List query (const QString &mimeType, const QString &genericServiceType=QStringLiteral("Application"), const QString &constraint=QString()) const
 

Static Public Member Functions

template<class T >
static T * createInstanceFromQuery (const QString &mimeType, const QString &serviceType, QObject *parent=nullptr, const QString &constraint=QString(), const QVariantList &args=QVariantList(), QString *error=nullptr)
 
template<class T >
static T * createPartInstanceFromQuery (const QString &mimeType, QWidget *parentWidget=nullptr, QObject *parent=nullptr, const QString &constraint=QString(), const QVariantList &args=QVariantList(), QString *error=nullptr)
 
static KMimeTypeTraderself ()
 

Detailed Description

KDE's trader for services associated to a given MIME type.

Example: say that you want to the list of all KParts components that can handle HTML. Our code would look like:

"KParts/ReadOnlyPart");

If you want to get the preferred KParts component for text/html you would use:

"KParts/ReadOnlyPart");

Although if this is about loading that component you would use createPartInstanceFromQuery() directly.

See also
KServiceTypeTrader, KService
Deprecated:
since 5.82. For querying applications use KApplicationTrader. For querying KParts use KParts::PartLoader. For querying plugins use KPluginLoader.

Definition at line 43 of file kmimetypetrader.h.

Constructor & Destructor Documentation

◆ ~KMimeTypeTrader()

KMimeTypeTrader::~KMimeTypeTrader ( )

Standard destructor.

Definition at line 49 of file kmimetypetrader.cpp.

Member Function Documentation

◆ createInstanceFromQuery()

template<class T >
static T* KMimeTypeTrader::createInstanceFromQuery ( const QString mimeType,
const QString serviceType,
QObject parent = nullptr,
const QString constraint = QString(),
const QVariantList &  args = QVariantList(),
QString error = nullptr 
)
inlinestatic

This can be used to create a service instance from a MIME type query.

Parameters
mimeTypea MIME type like 'text/plain' or 'text/html'
serviceTypea basic service type
parentthe parent object for the plugin itself
constraintA constraint to limit the choices returned, QString() to get all services that can handle the given mimeType
argsA list of arguments passed to the service component
errorThe string passed here will contain an error description.
Returns
A pointer to the newly created object or a null pointer if the factory was unable to create an object of the given type.
Deprecated:
since 5.82. For KParts use KParts::PartLoader::createPartInstanceForMimeType(). Otherwise use KPluginLoader.

Definition at line 169 of file kmimetypetrader.h.

◆ createPartInstanceFromQuery()

template<class T >
static T* KMimeTypeTrader::createPartInstanceFromQuery ( const QString mimeType,
QWidget parentWidget = nullptr,
QObject parent = nullptr,
const QString constraint = QString(),
const QVariantList &  args = QVariantList(),
QString error = nullptr 
)
inlinestatic

This method creates and returns a part object from the trader query for a given mimeType.

Example:

KParts::ReadOnlyPart* part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>("text/plain", parentWidget, parentObject);
if (part) {
part->openUrl(url);
part->widget()->show(); // also insert the widget into a layout
}
Parameters
mimeTypethe MIME type which this part is associated with
parentWidgetthe parent widget, will be set as the parent of the part's widget
parentthe parent object for the part itself
constraintan optional constraint to pass to the trader
argsA list of arguments passed to the service component
errorThe string passed here will contain an error description.
Returns
A pointer to the newly created object or a null pointer if the factory was unable to create an object of the given type.
Deprecated:
since 5.82. For KParts use KParts::PartLoader::createPartInstanceForMimeType(). Otherwise use KPluginLoader.

Definition at line 129 of file kmimetypetrader.h.

◆ preferredService()

KService::Ptr KMimeTypeTrader::preferredService ( const QString mimeType,
const QString genericServiceType = QStringLiteral("Application") 
)

Returns the preferred service for mimeType and genericServiceType.

This is almost like query().first(), except that it also checks if the service is allowed as a preferred service (see KService::allowAsDefault).

Parameters
mimeTypethe MIME type (see query())
genericServiceTypethe service type (see query())
Returns
the preferred service, or nullptr if no service is available.
Deprecated:
since 5.82. For querying applications use KApplicationTrader::preferredService(). For querying KParts use KParts::PartLoader::partsForMimeType().first().

Definition at line 176 of file kmimetypetrader.cpp.

◆ query()

KService::List KMimeTypeTrader::query ( const QString mimeType,
const QString genericServiceType = QStringLiteral("Application"),
const QString constraint = QString() 
) const

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

Example usage: To get list of applications that can handle a given MIME type, set genericServiceType to "Application" (which is the default). To get list of embeddable components that can handle a given MIME type, set genericServiceType to "KParts/ReadOnlyPart".

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:

(Type == 'Service') and (('Browser/View' in ServiceTypes) and (exist Library))

The keys used in the query (Type, ServiceTypes, Library) are all fields found in the .desktop files.

Parameters
mimeTypea MIME type like 'text/plain' or 'text/html'
genericServiceTypea basic service type, like 'KParts/ReadOnlyPart' or 'Application'
constraintA constraint to limit the choices returned, QString() to get all services that can handle the given mimetype
Returns
A list of services that satisfy the query, sorted by preference (preferred service first)
See also
http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language
Deprecated:
since 5.82. For querying applications use KApplicationTrader::query(). For querying KParts use KParts::PartLoader::partsForMimeType(). For querying plugins use KPluginLoader.

Definition at line 163 of file kmimetypetrader.cpp.

◆ self()

KMimeTypeTrader * KMimeTypeTrader::self ( )
static

This is a static pointer to the KMimeTypeTrader singleton.

You will need to use this to access the KMimeTypeTrader functionality since the constructors are protected.

Returns
Static KMimeTypeTrader instance

Definition at line 39 of file kmimetypetrader.cpp.


The documentation for this class was generated from the following files:
KService::Ptr preferredService(const QString &mimeType, const QString &genericServiceType=QStringLiteral("Application"))
Returns the preferred service for mimeType and genericServiceType.
KService::List query(const QString &mimeType, const QString &genericServiceType=QStringLiteral("Application"), const QString &constraint=QString()) const
This method returns a list of services which are associated with a given MIME type.
virtual bool openUrl(const QUrl &url)
void show()
virtual QWidget * widget()
static KMimeTypeTrader * self()
This is a static pointer to the KMimeTypeTrader singleton.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:54:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.