25 #include <tdelocale.h>
26 #include <ksimpleconfig.h>
27 #include <kstandarddirs.h>
28 #include <kstaticdeleter.h>
37 TQDict<Factory> *Factory::mSelves = 0;
38 static KStaticDeleter< TQDict<Factory> > staticDeleter;
42 kdDebug(5650) <<
"Factory::self()" << endl;
46 staticDeleter.setObject( mSelves,
new TQDict<Factory> );
48 factory = mSelves->find( resourceFamily );
51 factory =
new Factory( resourceFamily );
52 mSelves->insert( resourceFamily, factory );
58 Factory::Factory(
const TQString& resourceFamily ) :
59 mResourceFamily( resourceFamily )
61 TDETrader::OfferList plugins = TDETrader::self()->query(
"TDEResources/Plugin", TQString(
"[X-TDE-ResourceFamily] == '%1'" )
62 .arg( resourceFamily ) );
63 TDETrader::OfferList::ConstIterator it;
64 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
65 TQVariant type = (*it)->property(
"X-TDE-ResourceType" );
66 if ( !type.toString().isEmpty() )
67 mTypeMap.insert( type.toString(), *it );
77 return mTypeMap.keys();
82 if ( type.isEmpty() || !mTypeMap.contains( type ) )
85 KService::Ptr ptr = mTypeMap[ type ];
86 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
88 kdDebug(5650) <<
"KRES::Factory::configWidget(): Factory creation failed "
89 << KLibLoader::self()->lastErrorMessage() << endl;
93 PluginFactoryBase *pluginFactory =
static_cast<PluginFactoryBase *
>( factory );
95 if ( !pluginFactory ) {
96 kdDebug(5650) <<
"KRES::Factory::configWidget(): no plugin factory."
101 ConfigWidget *wdg = pluginFactory->configWidget( parent );
103 kdDebug(5650) <<
"'" << ptr->library() <<
"' doesn't provide a ConfigWidget" << endl;
112 if ( type.isEmpty() || !mTypeMap.contains( type ) )
115 KService::Ptr ptr = mTypeMap[ type ];
121 if ( type.isEmpty() || !mTypeMap.contains( type ) )
124 KService::Ptr ptr = mTypeMap[ type ];
125 return ptr->comment();
130 kdDebug(5650) <<
"Factory::resource( " << type <<
", config )" << endl;
132 if ( type.isEmpty() || !mTypeMap.contains( type ) ) {
133 kdDebug(5650) <<
"Factory::resource() no such type " << type << endl;
137 KService::Ptr ptr = mTypeMap[ type ];
138 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
140 kdDebug(5650) <<
"KRES::Factory::resource(): Factory creation failed "
141 << KLibLoader::self()->lastErrorMessage() << endl;
145 PluginFactoryBase *pluginFactory =
static_cast<PluginFactoryBase *
>( factory );
147 if ( !pluginFactory ) {
148 kdDebug(5650) <<
"KRES::Factory::resource(): no plugin factory." << endl;
154 kdDebug(5650) <<
"'" << ptr->library() <<
"' is not a " + mResourceFamily +
Class for loading resource plugins.
TQStringList typeNames() const
Returns a list of all available resource types.
Resource * resource(const TQString &type, const TDEConfig *config)
Returns a pointer to a resource object or a null pointer if resource type doesn't exist.
static Factory * self(const TQString &resourceFamily)
Returns the global resource factory.
TQString typeDescription(const TQString &type) const
Returns the description for a special type.
TQString typeName(const TQString &type) const
Returns the name for a special type.
ConfigWidget * configWidget(const TQString &type, TQWidget *parent=0)
Returns the config widget for the given resource type, or a null pointer if resource type doesn't exi...
This class provides a resource which is managed in a general way.