1 #ifndef __tdeparts_componentfactory_h__
2 #define __tdeparts_componentfactory_h__
4 #include <tdeparts/factory.h>
5 #include <tdeparts/part.h>
7 #include <tqmetaobject.h>
17 namespace ComponentFactory
38 ErrServiceProvidesNoLibrary,
63 const TQStringList &args = TQStringList() )
65 TQObject *
object = factory->
create( parent, name,
66 T::staticMetaObject()->className(),
69 T *result =
dynamic_cast<T *
>( object );
96 TQWidget *parentWidget = 0,
97 const char *widgetName = 0,
100 const TQStringList &args = TQStringList() )
104 T::staticMetaObject()->className(),
107 T *result =
dynamic_cast<T *
>( object );
128 const char *name = 0,
129 const TQStringList &args = TQStringList(),
136 *error = ErrNoLibrary;
144 *error = ErrNoFactory;
147 T *res = createInstanceFromFactory<T>( factory, parent, name, args );
152 *error = ErrNoComponent;
158 static T *createPartInstanceFromLibrary(
const char *libraryName,
159 TQWidget *parentWidget = 0,
160 const char *widgetName = 0,
161 TQObject *parent = 0,
162 const char *name = 0,
163 const TQStringList &args = TQStringList(),
170 *error = ErrNoLibrary;
178 *error = ErrNoFactory;
186 *error = ErrNoFactory;
189 T *res = createPartInstanceFromFactory<T>( partFactory, parentWidget,
190 widgetName, parent, name, args );
195 *error = ErrNoComponent;
201 static T *createInstanceFromService(
const KService::Ptr &service,
202 TQObject *parent = 0,
203 const char *name = 0,
204 const TQStringList &args = TQStringList(),
207 TQString library = service->library();
208 if ( library.isEmpty() )
211 *error = ErrServiceProvidesNoLibrary;
215 return createInstanceFromLibrary<T>( library.local8Bit().data(), parent,
220 static T *createPartInstanceFromService(
const KService::Ptr &service,
221 TQWidget *parentWidget = 0,
222 const char *widgetName = 0,
223 TQObject *parent = 0,
224 const char *name = 0,
225 const TQStringList &args = TQStringList(),
228 TQString library = service->library();
229 if ( library.isEmpty() )
232 *error = ErrServiceProvidesNoLibrary;
236 return createPartInstanceFromLibrary<T>( library.local8Bit().data(), parentWidget,
237 widgetName, parent, name, args, error );
240 template <
class T,
class ServiceIterator>
241 static T *createInstanceFromServices( ServiceIterator begin, ServiceIterator end,
242 TQObject *parent = 0,
243 const char *name = 0,
244 const TQStringList &args = TQStringList(),
247 for (; begin !=
end; ++begin )
249 KService::Ptr service = *begin;
254 T *component = createInstanceFromService<T>( service, parent, name,
261 *error = ErrNoServiceFound;
267 template <
class T,
class ServiceIterator>
268 static T *createPartInstanceFromServices( ServiceIterator begin,
270 TQWidget *parentWidget = 0,
271 const char *widgetName = 0,
272 TQObject *parent = 0,
273 const char *name = 0,
274 const TQStringList &args = TQStringList(),
277 for (; begin !=
end; ++begin )
279 KService::Ptr service = *begin;
284 T *component = createPartInstanceFromService<T>( service, parentWidget,
292 *error = ErrNoServiceFound;
322 const TQString &constraint = TQString::null,
323 TQObject *parent = 0,
324 const char *name = 0,
325 const TQStringList &args = TQStringList(),
328 TDETrader::OfferList offers = TDETrader::self()->query( serviceType, constraint );
329 if ( offers.isEmpty() )
332 *error = ErrNoServiceFound;
336 return createInstanceFromServices<T>( offers.begin(),
338 parent, name, args, error );
371 const TQString &constraint,
372 TQWidget *parentWidget = 0,
373 const char *widgetName = 0,
374 TQObject *parent = 0,
375 const char *name = 0,
376 const TQStringList &args = TQStringList(),
379 TDETrader::OfferList offers = TDETrader::self()->query( serviceType, TQString::fromLatin1(
"KParts/ReadOnlyPart"), constraint, TQString::null );
380 if ( offers.isEmpty() )
383 *error = ErrNoServiceFound;
387 return createPartInstanceFromServices<T>( offers.begin(), offers.end(),
388 parentWidget, widgetName,
389 parent, name, args, error );
TQObject * create(TQObject *parent=0, const char *name=0, const char *classname="TQObject", const TQStringList &args=TQStringList())
static KLibLoader * self()
virtual KLibrary * library(const char *libname)
A generic factory object to create a Part.
Part * createPart(TQWidget *parentWidget=0, const char *widgetName=0, TQObject *parent=0, const char *name=0, const char *classname="KParts::Part", const TQStringList &args=TQStringList())
Creates a part.
static T * createInstanceFromQuery(const TQString &serviceType, const TQString &constraint=TQString::null, TQObject *parent=0, const char *name=0, const TQStringList &args=TQStringList(), int *error=0)
This method creates and returns a plugin, from the trader query for a given serviceType.
ComponentLoadingError
This enum type defines the possible error cases that can happen when loading a component.
static T * createInstanceFromLibrary(const char *libraryName, TQObject *parent=0, const char *name=0, const TQStringList &args=TQStringList(), int *error=0)
This template allows to load the specified library and ask the factory to create an instance of the g...
static T * createInstanceFromFactory(KLibFactory *factory, TQObject *parent=0, const char *name=0, const TQStringList &args=TQStringList())
This template function allows to ask the given factory to create an instance of the given template ty...
static T * createPartInstanceFromFactory(KParts::Factory *factory, TQWidget *parentWidget=0, const char *widgetName=0, TQObject *parent=0, const char *name=0, const TQStringList &args=TQStringList())
This template function allows to ask the given tdeparts factory to create an instance of the given te...
static T * createPartInstanceFromQuery(const TQString &serviceType, const TQString &constraint, TQWidget *parentWidget=0, const char *widgetName=0, TQObject *parent=0, const char *name=0, const TQStringList &args=TQStringList(), int *error=0)
This method creates and returns a KParts part from a serviceType (e.g.
const TDEShortcut & end()