• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

Public Member Functions | Static Public Member Functions

KMimeTypeTrader Class Reference

KDE's trader for services associated to a given mimetype. More...

#include <kmimetypetrader.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

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

Detailed Description

KDE's trader for services associated to a given mimetype.

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

 KService::List lst = KMimeTypeTrader::self()->query("text/html",
                                                        "KParts/ReadOnlyPart");

If you want to get the preferred KParts component for text/html you could use preferredService("text/html", "KParts/ReadOnlyPart"), although if this is about loading that component you would use createPartInstanceFromQuery directly.

See also:
KServiceTypeTrader, KService

Definition at line 42 of file kmimetypetrader.h.


Constructor & Destructor Documentation

KMimeTypeTrader::~KMimeTypeTrader ( )

Standard destructor.

Definition at line 49 of file kmimetypetrader.cpp.


Member Function Documentation

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

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.

Definition at line 154 of file kmimetypetrader.h.

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

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

Example:

 KParts::ReadOnlyPart* part = KMimeTypeTrader::createInstanceFromQuery<KParts::ReadOnlyPart>("text/plain", parentWidget, parentObject);
 if (part) {
     part->openUrl(url);
     part->widget()->show();  // also insert the widget into a layout, or simply use a KVBox as parentWidget
 }
Parameters:
mimeTypethe mimetype 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.

Definition at line 121 of file kmimetypetrader.h.

KService::Ptr KMimeTypeTrader::preferredService ( const QString &  mimeType,
const QString &  genericServiceType = QString::fromLatin1("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 0 if no service is available

Definition at line 157 of file kmimetypetrader.cpp.

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

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

Example usage: To get list of applications that can handle a given mimetype, set genericServiceType to "Application" (which is the default). To get list of embeddable components that can handle a given mimetype, 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

Definition at line 142 of file kmimetypetrader.cpp.

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 38 of file kmimetypetrader.cpp.


The documentation for this class was generated from the following files:
  • kmimetypetrader.h
  • kmimetypetrader.cpp

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal