Diffstat (limited to 'microkde/kresources/factory.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kresources/factory.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp index f82e94c..7a5c2f6 100644 --- a/microkde/kresources/factory.cpp +++ b/microkde/kresources/factory.cpp | |||
@@ -30,45 +30,45 @@ | |||
30 | #include <klibloader.h> | 30 | #include <klibloader.h> |
31 | //#endif | 31 | //#endif |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | 33 | ||
34 | #include "resource.h" | 34 | #include "resource.h" |
35 | #include "factory.h" | 35 | #include "factory.h" |
36 | 36 | ||
37 | using namespace KRES; | 37 | using namespace KRES; |
38 | 38 | ||
39 | QDict<Factory> *Factory::mSelves = 0; | 39 | QDict<Factory> *Factory::mSelves = 0; |
40 | static KStaticDeleter< QDict<Factory> > staticDeleter; | 40 | static KStaticDeleter< QDict<Factory> > staticDeleter; |
41 | 41 | ||
42 | Factory *Factory::self( const QString& resourceFamily ) | 42 | Factory *Factory::self( const QString& resourceFamily) |
43 | { | 43 | { |
44 | 44 | ||
45 | 45 | ||
46 | Factory *factory = 0; | 46 | Factory *factory = 0; |
47 | if ( !mSelves ) | 47 | if ( !mSelves ) |
48 | { | 48 | { |
49 | mSelves = staticDeleter.setObject( new QDict<Factory> ); | 49 | mSelves = staticDeleter.setObject( new QDict<Factory> ); |
50 | } | 50 | } |
51 | 51 | ||
52 | factory = mSelves->find( resourceFamily ); | 52 | factory = mSelves->find( resourceFamily ); |
53 | 53 | ||
54 | if ( !factory ) { | 54 | if ( !factory ) { |
55 | factory = new Factory( resourceFamily ); | 55 | factory = new Factory( resourceFamily); |
56 | mSelves->insert( resourceFamily, factory ); | 56 | mSelves->insert( resourceFamily, factory ); |
57 | } | 57 | } |
58 | 58 | ||
59 | return factory; | 59 | return factory; |
60 | } | 60 | } |
61 | 61 | ||
62 | Factory::Factory( const QString& resourceFamily ) : | 62 | Factory::Factory( const QString& resourceFamily) : |
63 | mResourceFamily( resourceFamily ) | 63 | mResourceFamily( resourceFamily ) |
64 | { | 64 | { |
65 | //US so far we have three types available for resourceFamily "contact" | 65 | //US so far we have three types available for resourceFamily "contact" |
66 | // and that are "file", "dir", "ldap" | 66 | // and that are "file", "dir", "ldap" |
67 | /*US | 67 | /*US |
68 | 68 | ||
69 | KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" ) | 69 | KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" ) |
70 | .arg( resourceFamily ) ); | 70 | .arg( resourceFamily ) ); |
71 | KTrader::OfferList::ConstIterator it; | 71 | KTrader::OfferList::ConstIterator it; |
72 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { | 72 | for ( it = plugins.begin(); it != plugins.end(); ++it ) { |
73 | QVariant type = (*it)->property( "X-KDE-ResourceType" ); | 73 | QVariant type = (*it)->property( "X-KDE-ResourceType" ); |
74 | if ( !type.toString().isEmpty() ) | 74 | if ( !type.toString().isEmpty() ) |
@@ -178,49 +178,83 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | ConfigWidget *wdg = pluginFactory->configWidget( parent ); | 180 | ConfigWidget *wdg = pluginFactory->configWidget( parent ); |
181 | if ( !wdg ) { | 181 | if ( !wdg ) { |
182 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; | 182 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; |
183 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); | 183 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); |
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | return wdg; | 186 | return wdg; |
187 | 187 | ||
188 | } | 188 | } |
189 | 189 | ||
190 | SyncWidget *Factory::syncWidget( const QString& type, QWidget *parent ) | ||
191 | { | ||
192 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | ||
193 | return 0; | ||
194 | |||
195 | //US KService::Ptr ptr = mTypeMap[ type ]; | ||
196 | //US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); | ||
197 | PluginInfo* pi = mTypeMap[ type ]; | ||
198 | KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); | ||
199 | if ( !factory ) { | ||
200 | qDebug("KRES::Factory::syncWidget(): Factory creation failed for library %s", pi->library.latin1()); | ||
201 | kdDebug() << "KRES::Factory::syncWidget(): Factory creation failed" << endl; | ||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); | ||
206 | |||
207 | if ( !pluginFactory ) { | ||
208 | qDebug("KRES::Factory::syncWidget(): no plugin factory for library %s", pi->library.latin1()); | ||
209 | kdDebug() << "KRES::Factory::syncWidget(): no plugin factory." << endl; | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | SyncWidget *wdg = pluginFactory->syncWidget( parent ); | ||
214 | if ( !wdg ) { | ||
215 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; | ||
216 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); | ||
217 | return 0; | ||
218 | } | ||
219 | return wdg; | ||
220 | |||
221 | } | ||
222 | |||
223 | |||
190 | QString Factory::typeName( const QString &type ) const | 224 | QString Factory::typeName( const QString &type ) const |
191 | { | 225 | { |
192 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 226 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
193 | return QString(); | 227 | return QString(); |
194 | 228 | ||
195 | 229 | ||
196 | //US KService::Ptr ptr = mTypeMap[ type ]; | 230 | //US KService::Ptr ptr = mTypeMap[ type ]; |
197 | //US return ptr->name(); | 231 | //US return ptr->name(); |
198 | PluginInfo* pi = mTypeMap[ type ]; | 232 | PluginInfo* pi = mTypeMap[ type ]; |
199 | return pi->nameLabel; | 233 | return pi->nameLabel; |
200 | 234 | ||
201 | } | 235 | } |
202 | 236 | ||
203 | QString Factory::typeDescription( const QString &type ) const | 237 | QString Factory::typeDescription( const QString &type ) const |
204 | { | 238 | { |
205 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 239 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
206 | return QString(); | 240 | return QString(); |
207 | 241 | ||
208 | //US KService::Ptr ptr = mTypeMap[ type ]; | 242 | //US KService::Ptr ptr = mTypeMap[ type ]; |
209 | //US return ptr->comment(); | 243 | //US return ptr->comment(); |
210 | PluginInfo* pi = mTypeMap[ type ]; | 244 | PluginInfo* pi = mTypeMap[ type ]; |
211 | return pi->descriptionLabel; | 245 | return pi->descriptionLabel; |
212 | } | 246 | } |
213 | 247 | ||
214 | Resource *Factory::resource( const QString& type, const KConfig *config ) | 248 | Resource *Factory::resource( const QString& type, const KConfig *config, bool syncable ) |
215 | { | 249 | { |
216 | 250 | ||
217 | 251 | ||
218 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) | 252 | if ( type.isEmpty() || !mTypeMap.contains( type ) ) |
219 | return 0; | 253 | return 0; |
220 | 254 | ||
221 | /*US load the lib not dynamicly. !! | 255 | /*US load the lib not dynamicly. !! |
222 | KService::Ptr ptr = mTypeMap[ type ]; | 256 | KService::Ptr ptr = mTypeMap[ type ]; |
223 | KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); | 257 | KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); |
224 | if ( !factory ) { | 258 | if ( !factory ) { |
225 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; | 259 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; |
226 | return 0; | 260 | return 0; |
@@ -233,23 +267,23 @@ Resource *Factory::resource( const QString& type, const KConfig *config ) | |||
233 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; | 267 | kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; |
234 | return 0; | 268 | return 0; |
235 | } | 269 | } |
236 | 270 | ||
237 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); | 271 | PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); |
238 | 272 | ||
239 | if ( !pluginFactory ) { | 273 | if ( !pluginFactory ) { |
240 | qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); | 274 | qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); |
241 | kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; | 275 | kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; |
242 | return 0; | 276 | return 0; |
243 | } | 277 | } |
244 | 278 | ||
245 | Resource *resource = pluginFactory->resource( config ); | 279 | Resource *resource = pluginFactory->resource( config, syncable ); |
246 | if ( !resource ) { | 280 | if ( !resource ) { |
247 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; | 281 | //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; |
248 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); | 282 | qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); |
249 | return 0; | 283 | return 0; |
250 | } | 284 | } |
251 | 285 | ||
252 | resource->setType( type ); | 286 | resource->setType( type ); |
253 | 287 | ||
254 | return resource; | 288 | return resource; |
255 | } | 289 | } |