kparts Library API Documentation

KParts::ComponentFactory Namespace Reference


Enumerations

enum  ComponentLoadingError {
  ErrNoServiceFound = 1, ErrServiceProvidesNoLibrary, ErrNoLibrary, ErrNoFactory,
  ErrNoComponent
}

Functions

template<class T>
static T * createInstanceFromFactory (KLibFactory *factory, QObject *parent=0, const char *name=0, const QStringList &args=QStringList())
template<class T>
static T * createPartInstanceFromFactory (KParts::Factory *factory, QWidget *parentWidget=0, const char *widgetName=0, QObject *parent=0, const char *name=0, const QStringList &args=QStringList())
template<class T>
static T * createInstanceFromLibrary (const char *libraryName, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T>
static T * createPartInstanceFromLibrary (const char *libraryName, QWidget *parentWidget=0, const char *widgetName=0, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T>
static T * createInstanceFromService (const KService::Ptr &service, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T>
static T * createPartInstanceFromService (const KService::Ptr &service, QWidget *parentWidget=0, const char *widgetName=0, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T, class ServiceIterator>
static T * createInstanceFromServices (ServiceIterator begin, ServiceIterator end, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T, class ServiceIterator>
static T * createPartInstanceFromServices (ServiceIterator begin, ServiceIterator end, QWidget *parentWidget=0, const char *widgetName=0, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T>
static T * createInstanceFromQuery (const QString &serviceType, const QString &constraint=QString::null, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)
template<class T>
static T * createPartInstanceFromQuery (const QString &serviceType, const QString &constraint, QWidget *parentWidget=0, const char *widgetName=0, QObject *parent=0, const char *name=0, const QStringList &args=QStringList(), int *error=0)


Enumeration Type Documentation

enum KParts::ComponentFactory::ComponentLoadingError
 

This enum type defines the possible error cases that can happen when loading a component.

  • ErrNoServiceFound - no service implementing the given mimetype and fullfilling the given constraint expression can be found.
  • ErrServiceProvidesNoLibrary - the specified service provides no shared library
  • ErrNoLibrary - the specified library could not be loaded. Use KLibLoader::lastErrorMessage for details.
  • ErrNoFactory - the library does not export a factory for creating components
  • ErrNoComponent - the factory does not support creating components of the specified type

Definition at line 34 of file componentfactory.h.


Function Documentation

template<class T>
static T* KParts::ComponentFactory::createInstanceFromFactory KLibFactory factory,
QObject parent = 0,
const char *  name = 0,
const QStringList args = QStringList()
[static]
 

This template function allows to ask the given factory to create an instance of the given template type.

Example of usage:

     MyPlugin *plugin = KParts::ComponentFactory::createInstanceFromFactory&lt;MyPlugin&gt;( factory, parent );

Parameters:
factory The factory to ask for the creation of the component
parent The parent object (see QObject constructor)
name The name of the object to create (see QObject constructor)
args A list of string arguments, passed to the factory and possibly to the component (see KLibFactory)
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 58 of file componentfactory.h.

References KLibFactory::create().

template<class T>
static T* KParts::ComponentFactory::createPartInstanceFromFactory KParts::Factory factory,
QWidget parentWidget = 0,
const char *  widgetName = 0,
QObject parent = 0,
const char *  name = 0,
const QStringList args = QStringList()
[static]
 

This template function allows to ask the given kparts factory to create an instance of the given template type.

Example of usage:

     KViewPart *doc = KParts::ComponentFactory::createPartInstanceFromFactory&lt;KViewPart&gt;( factory, parent );

Parameters:
factory The factory to ask for the creation of the component
parentWidget the parent widget for the part
widgetName the name of the part's widget
parent The parent object (see QObject constructor)
name The name of the object to create (see QObject constructor)
args A list of string arguments, passed to the factory and possibly to the component (see KLibFactory)
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 92 of file componentfactory.h.

References KParts::Factory::createPart().

template<class T>
static T* KParts::ComponentFactory::createInstanceFromLibrary const char *  libraryName,
QObject parent = 0,
const char *  name = 0,
const QStringList args = QStringList(),
int *  error = 0
[static]
 

This template allows to load the specified library and ask the factory to create an instance of the given template type.

Parameters:
libraryName The library to open
parent The parent object (see QObject constructor)
name The name of the object to create (see QObject constructor)
args A list of string arguments, passed to the factory and possibly to the component (see KLibFactory)
error 
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 124 of file componentfactory.h.

References KLibrary::factory(), KLibLoader::library(), KLibLoader::self(), and KLibrary::unload().

template<class T>
static T* KParts::ComponentFactory::createInstanceFromQuery const QString serviceType,
const QString constraint = QString::null,
QObject parent = 0,
const char *  name = 0,
const QStringList args = QStringList(),
int *  error = 0
[static]
 

This method creates and returns a plugin, from the trader query for a given serviceType.

Example:

 KMyAppPlugin* plugin = KParts::ComponentFactory::createInstanceFromQuery<KMyAppPlugin>( serviceType, QString::null, parentObject );
 if ( plugin ) {
     ....
 }

Parameters:
serviceType the type of service for which to find a plugin
constraint an optionnal constraint to pass to the trader (see KTrader)
parent the parent object for the part itself
name the name that will be given to the part
args A list of string arguments, passed to the factory and possibly to the component (see KLibFactory)
error The int passed here will receive an error code in case of errors. (See enum ComponentLoadingError)
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 318 of file componentfactory.h.

References QValueList::begin(), QValueList::end(), QValueList::isEmpty(), KTrader::query(), and KTrader::self().

template<class T>
static T* KParts::ComponentFactory::createPartInstanceFromQuery const QString serviceType,
const QString constraint,
QWidget parentWidget = 0,
const char *  widgetName = 0,
QObject parent = 0,
const char *  name = 0,
const QStringList args = QStringList(),
int *  error = 0
[static]
 

This method creates and returns a KParts part from a serviceType (e.g.

a mimetype).

You can use this method to create a generic viewer - that can display any kind of file, provided that there is a ReadOnlyPart installed for it - in 5 lines:

 // Given the following: KURL url, QWidget* parentWidget and QObject* parentObject.
 QString mimetype = KMimeType::findByURL( url )->name();
 KParts::ReadOnlyPart* part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, QString::null, parentWidget, 0, parentObject, 0 );
 if ( part ) {
     part->openURL( url );
     part->widget()->show();  // also insert the widget into a layout, or simply use a QVBox as parentWidget
 }

Parameters:
serviceType the type of service for which to find a part, e.g. a mimetype
constraint an optionnal constraint to pass to the trader (see KTrader)
parentWidget the parent widget, will be set as the parent of the part's widget
widgetName the name that will be given to the part's widget
parent the parent object for the part itself
name the name that will be given to the part
args A list of string arguments, passed to the factory and possibly to the component (see KLibFactory)
error The int passed here will receive an error code in case of errors. (See enum ComponentLoadingError)
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 367 of file componentfactory.h.

References QValueList::begin(), QValueList::end(), QString::fromLatin1(), QValueList::isEmpty(), KTrader::query(), and KTrader::self().

KDE Logo
This file is part of the documentation for kparts Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Nov 1 10:33:59 2005 by doxygen 1.4.3 written by Dimitri van Heesch, © 1997-2003