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 KTrader::OfferList plugins =
KTrader::self()->query(
"KResources/Plugin", TQString(
"[X-KDE-ResourceFamily] == '%1'" )
62 .arg( resourceFamily ) );
63 KTrader::OfferList::ConstIterator it;
64 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
65 TQVariant type = (*it)->property(
"X-KDE-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 "
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 "
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 +
159 resource->setType( type );