-rw-r--r-- | libopie2/opiecore/opluginloader.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp index b8b6b79..ec19fa0 100644 --- a/libopie2/opiecore/opluginloader.cpp +++ b/libopie2/opiecore/opluginloader.cpp | |||
@@ -185,713 +185,719 @@ QString OPluginItem::name()const { | |||
185 | */ | 185 | */ |
186 | QString OPluginItem::path()const { | 186 | QString OPluginItem::path()const { |
187 | return m_path; | 187 | return m_path; |
188 | } | 188 | } |
189 | 189 | ||
190 | /** | 190 | /** |
191 | * \brief Return if this item is enabled. | 191 | * \brief Return if this item is enabled. |
192 | */ | 192 | */ |
193 | bool OPluginItem::isEnabled()const { | 193 | bool OPluginItem::isEnabled()const { |
194 | return m_enabled; | 194 | return m_enabled; |
195 | } | 195 | } |
196 | 196 | ||
197 | /** | 197 | /** |
198 | * \brief return the position of a plugin. | 198 | * \brief return the position of a plugin. |
199 | * return the position of the item | 199 | * return the position of the item |
200 | * -1 is the default value and means normally that the whole items are unsorted. | 200 | * -1 is the default value and means normally that the whole items are unsorted. |
201 | * Higher numbers belong to an upper position. With plugins with the postions 20,19,5,3 | 201 | * Higher numbers belong to an upper position. With plugins with the postions 20,19,5,3 |
202 | * the item with pos 20 would be the first in the list returned by the OGenericPluginLoader | 202 | * the item with pos 20 would be the first in the list returned by the OGenericPluginLoader |
203 | * | 203 | * |
204 | * @see OGenericPluginLoader::allAvailable | 204 | * @see OGenericPluginLoader::allAvailable |
205 | * @see OGenericPluginLoader::filtered | 205 | * @see OGenericPluginLoader::filtered |
206 | */ | 206 | */ |
207 | int OPluginItem::position()const{ | 207 | int OPluginItem::position()const{ |
208 | return m_pos; | 208 | return m_pos; |
209 | } | 209 | } |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * \brief set the name of a plugin | 212 | * \brief set the name of a plugin |
213 | * Set the name of the Plugin Item | 213 | * Set the name of the Plugin Item |
214 | * @param name | 214 | * @param name |
215 | */ | 215 | */ |
216 | void OPluginItem::setName( const QString& name ) { | 216 | void OPluginItem::setName( const QString& name ) { |
217 | m_name = name; | 217 | m_name = name; |
218 | } | 218 | } |
219 | 219 | ||
220 | /** | 220 | /** |
221 | * \brief set the path of a plugin | 221 | * \brief set the path of a plugin |
222 | * Set the path of Plugin Item. The path must be absolute. | 222 | * Set the path of Plugin Item. The path must be absolute. |
223 | * @param name The path of the plugin | 223 | * @param name The path of the plugin |
224 | */ | 224 | */ |
225 | void OPluginItem::setPath( const QString& name ) { | 225 | void OPluginItem::setPath( const QString& name ) { |
226 | m_path = name; | 226 | m_path = name; |
227 | } | 227 | } |
228 | 228 | ||
229 | /** | 229 | /** |
230 | * \brief enable or disable the to load attribute | 230 | * \brief enable or disable the to load attribute |
231 | * Set the Enabled attribute. Such changes won't be saved. If you want to save it | 231 | * Set the Enabled attribute. Such changes won't be saved. If you want to save it |
232 | * use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig | 232 | * use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig |
233 | * for a graphical frontend. | 233 | * for a graphical frontend. |
234 | * | 234 | * |
235 | * @param enabled Enable or Disable the Enabled Attribute | 235 | * @param enabled Enable or Disable the Enabled Attribute |
236 | */ | 236 | */ |
237 | void OPluginItem::setEnabled( bool enabled ) { | 237 | void OPluginItem::setEnabled( bool enabled ) { |
238 | m_enabled = enabled; | 238 | m_enabled = enabled; |
239 | } | 239 | } |
240 | 240 | ||
241 | /** | 241 | /** |
242 | * \brief Set the position. | 242 | * \brief Set the position. |
243 | * Set the position | 243 | * Set the position |
244 | * @param pos The position | 244 | * @param pos The position |
245 | * | 245 | * |
246 | * @see position() | 246 | * @see position() |
247 | */ | 247 | */ |
248 | void OPluginItem::setPosition( int pos ) { | 248 | void OPluginItem::setPosition( int pos ) { |
249 | m_pos = pos; | 249 | m_pos = pos; |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | 253 | ||
254 | /** | 254 | /** |
255 | * \brief create a PluginLoader | 255 | * \brief create a PluginLoader |
256 | * | 256 | * |
257 | * Create a PluginLoader autoDelete is set to false | 257 | * Create a PluginLoader autoDelete is set to false |
258 | * | 258 | * |
259 | * \code | 259 | * \code |
260 | * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); | 260 | * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); |
261 | * Opie::Core::OPluginItem::List lst = loader.filtered(); | 261 | * Opie::Core::OPluginItem::List lst = loader.filtered(); |
262 | * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ | 262 | * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ |
263 | * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); | 263 | * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); |
264 | * } | 264 | * } |
265 | * \endcode | 265 | * \endcode |
266 | * | 266 | * |
267 | * \code | 267 | * \code |
268 | * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); | 268 | * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); |
269 | * Opie::Core::OPluginItem::List lst = loader.filtered(); | 269 | * Opie::Core::OPluginItem::List lst = loader.filtered(); |
270 | * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ | 270 | * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ |
271 | * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); | 271 | * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); |
272 | * } | 272 | * } |
273 | * ... | 273 | * ... |
274 | * loader.clear(); | 274 | * loader.clear(); |
275 | * | 275 | * |
276 | * \endcode | 276 | * \endcode |
277 | * | 277 | * |
278 | * @param name The name of the plugin directory. | 278 | * @param name The name of the plugin directory. |
279 | * @param isSorted Tell the PluginLoader if your Plugins are sorted | 279 | * @param isSorted Tell the PluginLoader if your Plugins are sorted |
280 | */ | 280 | */ |
281 | OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted) | 281 | OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted) |
282 | : m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ), | 282 | : m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ), |
283 | m_isSorted( isSorted ) | 283 | m_isSorted( isSorted ) |
284 | { | 284 | { |
285 | setPluginDir( QPEApplication::qpeDir() + "plugins/"+name ); | 285 | setPluginDir( QPEApplication::qpeDir() + "plugins/"+name ); |
286 | readConfig(); | 286 | readConfig(); |
287 | } | 287 | } |
288 | 288 | ||
289 | 289 | ||
290 | /** | 290 | /** |
291 | * \brief simple d'tor that cleans up depending on autoDelete | 291 | * \brief simple d'tor that cleans up depending on autoDelete |
292 | * | 292 | * |
293 | * calls clear if autoDelete is true. This will release all interfaces | 293 | * calls clear if autoDelete is true. This will release all interfaces |
294 | * and remove the library from this process if the refcount falls to zero | 294 | * and remove the library from this process if the refcount falls to zero |
295 | */ | 295 | */ |
296 | OGenericPluginLoader::~OGenericPluginLoader() { | 296 | OGenericPluginLoader::~OGenericPluginLoader() { |
297 | if ( m_autoDelete ) | 297 | if ( m_autoDelete ) |
298 | clear(); | 298 | clear(); |
299 | } | 299 | } |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * \brief Enable or disable autoDelete on destruction | 302 | * \brief Enable or disable autoDelete on destruction |
303 | * | 303 | * |
304 | * enable autoDelete. This will call clear on the d'tor | 304 | * enable autoDelete. This will call clear on the d'tor |
305 | * | 305 | * |
306 | * @see ~OGenericPluginLoader | 306 | * @see ~OGenericPluginLoader |
307 | * @see clear() | 307 | * @see clear() |
308 | */ | 308 | */ |
309 | void OGenericPluginLoader::setAutoDelete( bool t ) { | 309 | void OGenericPluginLoader::setAutoDelete( bool t ) { |
310 | m_autoDelete = t; | 310 | m_autoDelete = t; |
311 | } | 311 | } |
312 | 312 | ||
313 | /** | 313 | /** |
314 | * \brief See if autoDelete is enabled. | 314 | * \brief See if autoDelete is enabled. |
315 | */ | 315 | */ |
316 | bool OGenericPluginLoader::autoDelete()const{ | 316 | bool OGenericPluginLoader::autoDelete()const{ |
317 | return m_autoDelete; | 317 | return m_autoDelete; |
318 | } | 318 | } |
319 | 319 | ||
320 | /** | 320 | /** |
321 | * \brief unload all loaded Plugins | 321 | * \brief unload all loaded Plugins |
322 | * | 322 | * |
323 | * This will unload all returned QUnknownInterfaces by load. Unload | 323 | * This will unload all returned QUnknownInterfaces by load. Unload |
324 | * will be called. | 324 | * will be called. |
325 | */ | 325 | */ |
326 | void OGenericPluginLoader::clear() { | 326 | void OGenericPluginLoader::clear() { |
327 | QPtrDictIterator<QLibrary> it( m_library ); | 327 | QPtrDictIterator<QLibrary> it( m_library ); |
328 | for ( ;it.current(); ) | 328 | for ( ;it.current(); ) |
329 | unload( static_cast<QUnknownInterface*>( it.currentKey() ) ); | 329 | unload( static_cast<QUnknownInterface*>( it.currentKey() ) ); |
330 | } | 330 | } |
331 | 331 | ||
332 | /** | 332 | /** |
333 | * \brief unload the Plugin and the accompanied Resources. | 333 | * \brief unload the Plugin and the accompanied Resources. |
334 | * | 334 | * |
335 | * This will take the iface from the internal QPtrDict, Release it, | 335 | * This will take the iface from the internal QPtrDict, Release it, |
336 | * and deref the libray used. | 336 | * and deref the libray used. |
337 | * The visibility depends on the QPtrDict. | 337 | * The visibility depends on the QPtrDict. |
338 | * @see QPtrDict::insert | 338 | * @see QPtrDict::insert |
339 | */ | 339 | */ |
340 | void OGenericPluginLoader::unload( QUnknownInterface* iface ) { | 340 | void OGenericPluginLoader::unload( QUnknownInterface* iface ) { |
341 | if ( !iface ) | 341 | if ( !iface ) |
342 | return; | 342 | return; |
343 | 343 | ||
344 | iface->release(); | 344 | iface->release(); |
345 | Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) ); | 345 | Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) ); |
346 | } | 346 | } |
347 | 347 | ||
348 | /** | 348 | /** |
349 | * \brief The name of the plugins. | 349 | * \brief The name of the plugins. |
350 | * | 350 | * |
351 | * Return the name/type you specified in the constructor. | 351 | * Return the name/type you specified in the constructor. |
352 | * This is at least used by the OPluginManager to find the right config | 352 | * This is at least used by the OPluginManager to find the right config |
353 | */ | 353 | */ |
354 | QString OGenericPluginLoader::name()const { | 354 | QString OGenericPluginLoader::name()const { |
355 | return m_dir; | 355 | return m_dir; |
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||
359 | /** | 359 | /** |
360 | * \brief See if loading of a plugin segfaulted | 360 | * \brief See if loading of a plugin segfaulted |
361 | * This tells you | 361 | * This tells you |
362 | * if by previous tries to load, loading crashed your application. | 362 | * if by previous tries to load, loading crashed your application. |
363 | * If isInSafeMode you can use the GUI to configure the plugins prior to loading | 363 | * If isInSafeMode you can use the GUI to configure the plugins prior to loading |
364 | * | 364 | * |
365 | * @return true if prior loading failed | 365 | * @return true if prior loading failed |
366 | */ | 366 | */ |
367 | bool OGenericPluginLoader::isInSafeMode()const { | 367 | bool OGenericPluginLoader::isInSafeMode()const { |
368 | return m_isSafeMode; | 368 | return m_isSafeMode; |
369 | } | 369 | } |
370 | 370 | ||
371 | 371 | ||
372 | /** | 372 | /** |
373 | * \brief Return all Plugins found in the plugins dirs. | 373 | * \brief Return all Plugins found in the plugins dirs. |
374 | * Return the list of all available plugins. This will go through all plugin | 374 | * Return the list of all available plugins. This will go through all plugin |
375 | * directories and search for your type of plugins ( by subdir ) | 375 | * directories and search for your type of plugins ( by subdir ) |
376 | * | 376 | * |
377 | * @param sorted Tell if you want to have the positions sorted. This only makes sense if you | 377 | * @param sorted Tell if you want to have the positions sorted. This only makes sense if you |
378 | */ | 378 | */ |
379 | OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { | 379 | OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { |
380 | OPluginItem::List lst; | 380 | OPluginItem::List lst; |
381 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) | 381 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) |
382 | lst += plugins( *it, sorted, false ); | 382 | lst += plugins( *it, sorted, false ); |
383 | 383 | ||
384 | if ( sorted ) | 384 | if ( sorted ) |
385 | qHeapSort( lst ); | 385 | qHeapSort( lst ); |
386 | return lst; | 386 | return lst; |
387 | } | 387 | } |
388 | 388 | ||
389 | /** | 389 | /** |
390 | * \brief Return only the enabled plugins | 390 | * \brief Return only the enabled plugins |
391 | * Return only activated plugins. | 391 | * Return only activated plugins. |
392 | * | 392 | * |
393 | * @param sorted If the list should be sorted | 393 | * @param sorted If the list should be sorted |
394 | */ | 394 | */ |
395 | OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { | 395 | OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { |
396 | OPluginItem::List lst; | 396 | OPluginItem::List lst; |
397 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) | 397 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) |
398 | lst += plugins( *it, sorted, true ); | 398 | lst += plugins( *it, sorted, true ); |
399 | 399 | ||
400 | if ( sorted ) | 400 | if ( sorted ) |
401 | qHeapSort( lst ); | 401 | qHeapSort( lst ); |
402 | return lst; | 402 | return lst; |
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | /** | 406 | /** |
407 | * \brief Load a OPluginItem for the specified interface | 407 | * \brief Load a OPluginItem for the specified interface |
408 | * This will open the resource of the OPluginItem::path() and then will query | 408 | * This will open the resource of the OPluginItem::path() and then will query |
409 | * if the Interface specified in the uuid is available and then will manage the | 409 | * if the Interface specified in the uuid is available and then will manage the |
410 | * resource and Interface. | 410 | * resource and Interface. |
411 | * | 411 | * |
412 | * @param item The OPluginItem that should be loaded | 412 | * @param item The OPluginItem that should be loaded |
413 | * @param uuid The Interface to query for | 413 | * @param uuid The Interface to query for |
414 | * | 414 | * |
415 | * @return Either 0 in case of failure or the Plugin as QUnknownInterface* | 415 | * @return Either 0 in case of failure or the Plugin as QUnknownInterface* |
416 | */ | 416 | */ |
417 | QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { | 417 | QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { |
418 | /* | 418 | /* |
419 | * Check if there could be a library | 419 | * Check if there could be a library |
420 | */ | 420 | */ |
421 | QString pa = item.path(); | 421 | QString pa = item.path(); |
422 | if ( pa.isEmpty() ) | 422 | if ( pa.isEmpty() ) |
423 | return 0l; | 423 | return 0l; |
424 | 424 | ||
425 | /* | 425 | /* |
426 | * See if we get a library | 426 | * See if we get a library |
427 | * return if we've none | 427 | * return if we've none |
428 | */ | 428 | */ |
429 | setSafeMode( pa, true ); | 429 | setSafeMode( pa, true ); |
430 | QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); | 430 | QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); |
431 | if ( !lib ) { | 431 | if ( !lib ) { |
432 | setSafeMode(); | 432 | setSafeMode(); |
433 | return 0l; | 433 | return 0l; |
434 | } | 434 | } |
435 | 435 | ||
436 | /** | 436 | /** |
437 | * try to load the plugin and just in case initialize the pointer to a pointer again | 437 | * try to load the plugin and just in case initialize the pointer to a pointer again |
438 | */ | 438 | */ |
439 | QUnknownInterface* iface=0; | 439 | QUnknownInterface* iface=0; |
440 | if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { | 440 | if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { |
441 | installTranslators(pa.left( pa.find("."))); | 441 | installTranslators( item.name() ); |
442 | m_library.insert( iface, lib ); | 442 | m_library.insert( iface, lib ); |
443 | }else | 443 | }else |
444 | iface = 0; | 444 | iface = 0; |
445 | 445 | ||
446 | setSafeMode(); | 446 | setSafeMode(); |
447 | 447 | ||
448 | return iface; | 448 | return iface; |
449 | } | 449 | } |
450 | 450 | ||
451 | /** | 451 | /** |
452 | * @internal and reads in the safe mode | 452 | * @internal and reads in the safe mode |
453 | */ | 453 | */ |
454 | void OGenericPluginLoader::readConfig() { | 454 | void OGenericPluginLoader::readConfig() { |
455 | 455 | ||
456 | 456 | ||
457 | /* read the config for SafeMode */ | 457 | /* read the config for SafeMode */ |
458 | OConfig conf( m_dir + "-odpplugins" ); | 458 | OConfig conf( m_dir + "-odpplugins" ); |
459 | conf.setGroup( "General" ); | 459 | conf.setGroup( "General" ); |
460 | m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); | 460 | m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); |
461 | } | 461 | } |
462 | 462 | ||
463 | /** | 463 | /** |
464 | * @internal Enter or leave SafeMode | 464 | * @internal Enter or leave SafeMode |
465 | */ | 465 | */ |
466 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { | 466 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { |
467 | OConfig conf( m_dir + "-odpplugins" ); | 467 | OConfig conf( m_dir + "-odpplugins" ); |
468 | conf.setGroup( "General" ); | 468 | conf.setGroup( "General" ); |
469 | conf.writeEntry( "SafeMode", b ); | 469 | conf.writeEntry( "SafeMode", b ); |
470 | conf.writeEntry( "CrashedPlugin", str ); | 470 | conf.writeEntry( "CrashedPlugin", str ); |
471 | } | 471 | } |
472 | 472 | ||
473 | /** | 473 | /** |
474 | * @internal | 474 | * @internal |
475 | * | 475 | * |
476 | * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype | 476 | * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype |
477 | * is used as plugin dir | 477 | * is used as plugin dir |
478 | */ | 478 | */ |
479 | void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { | 479 | void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { |
480 | m_plugDirs = lst; | 480 | m_plugDirs = lst; |
481 | } | 481 | } |
482 | 482 | ||
483 | /** | 483 | /** |
484 | * | 484 | * |
485 | * @internal | 485 | * @internal |
486 | * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs | 486 | * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs |
487 | */ | 487 | */ |
488 | void OGenericPluginLoader::setPluginDir( const QString& str) { | 488 | void OGenericPluginLoader::setPluginDir( const QString& str) { |
489 | m_plugDirs.clear(); | 489 | m_plugDirs.clear(); |
490 | m_plugDirs.append( str ); | 490 | m_plugDirs.append( str ); |
491 | } | 491 | } |
492 | 492 | ||
493 | 493 | ||
494 | /** | 494 | /** |
495 | * @internal | 495 | * @internal |
496 | */ | 496 | */ |
497 | bool OGenericPluginLoader::isSorted()const{ | 497 | bool OGenericPluginLoader::isSorted()const{ |
498 | return m_isSorted; | 498 | return m_isSorted; |
499 | } | 499 | } |
500 | 500 | ||
501 | /* | 501 | /* |
502 | * make libfoo.so.1.0.0 -> foo on UNIX | 502 | * make libfoo.so.1.0.0 -> foo on UNIX |
503 | * make libfoo.dylib -> foo on MAC OS X Unix | 503 | * make libfoo.dylib -> foo on MAC OS X Unix |
504 | * windows is obviously missing | 504 | * windows is obviously missing |
505 | */ | 505 | */ |
506 | /** | 506 | /** |
507 | * @internal | 507 | * @internal |
508 | */ | 508 | */ |
509 | QString OGenericPluginLoader::unlibify( const QString& str ) { | 509 | QString OGenericPluginLoader::unlibify( const QString& str ) { |
510 | QString st = str.mid( str.find( "lib" )+3 ); | 510 | QString st = str.mid( str.find( "lib" )+3 ); |
511 | #ifdef Q_OS_MACX | 511 | #ifdef Q_OS_MACX |
512 | return st.left( st.findRev( ".dylib" ) ); | 512 | return st.left( st.findRev( ".dylib" ) ); |
513 | #else | 513 | #else |
514 | return st.left( st.findRev( ".so" ) ); | 514 | return st.left( st.findRev( ".so" ) ); |
515 | #endif | 515 | #endif |
516 | } | 516 | } |
517 | 517 | ||
518 | /** | 518 | /** |
519 | * @internal | 519 | * @internal |
520 | * | 520 | * |
521 | * \brief method to return available plugins. Internal and for reeimplementations | 521 | * \brief method to return available plugins. Internal and for reeimplementations |
522 | * | 522 | * |
523 | *Return a List of Plugins for a dir and add positions and remove disabled. | 523 | *Return a List of Plugins for a dir and add positions and remove disabled. |
524 | * If a plugin is on the excluded list assign position -2 | 524 | * If a plugin is on the excluded list assign position -2 |
525 | * | 525 | * |
526 | * @param dir The dir to look in | 526 | * @param dir The dir to look in |
527 | * @param sorted Should positions be read? | 527 | * @param sorted Should positions be read? |
528 | * @param disabled Remove excluded from the list | 528 | * @param disabled Remove excluded from the list |
529 | */ | 529 | */ |
530 | OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { | 530 | OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { |
531 | #ifdef Q_OS_MACX | 531 | #ifdef Q_OS_MACX |
532 | QDir dir( _dir, "lib*.dylib" ); | 532 | QDir dir( _dir, "lib*.dylib" ); |
533 | #else | 533 | #else |
534 | QDir dir( _dir, "lib*.so" ); | 534 | QDir dir( _dir, "lib*.so" ); |
535 | #endif | 535 | #endif |
536 | 536 | ||
537 | 537 | ||
538 | OPluginItem::List lst; | 538 | OPluginItem::List lst; |
539 | 539 | ||
540 | /* | 540 | /* |
541 | * get excluded list and then iterate over them | 541 | * get excluded list and then iterate over them |
542 | * Excluded list contains the name | 542 | * Excluded list contains the name |
543 | * Position is a list with 'name.pos.name.pos.name.pos' | 543 | * Position is a list with 'name.pos.name.pos.name.pos' |
544 | * | 544 | * |
545 | * For the look up we will create two QMap<QString,pos> | 545 | * For the look up we will create two QMap<QString,pos> |
546 | */ | 546 | */ |
547 | QMap<QString, int> positionMap; | 547 | QMap<QString, int> positionMap; |
548 | QMap<QString, int> excludedMap; | 548 | QMap<QString, int> excludedMap; |
549 | 549 | ||
550 | 550 | ||
551 | OConfig cfg( m_dir+"-odpplugins" ); | 551 | OConfig cfg( m_dir+"-odpplugins" ); |
552 | cfg.setGroup( _dir ); | 552 | cfg.setGroup( _dir ); |
553 | 553 | ||
554 | 554 | ||
555 | QStringList excludes = cfg.readListEntry( "Excluded", ',' ); | 555 | QStringList excludes = cfg.readListEntry( "Excluded", ',' ); |
556 | for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) | 556 | for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) |
557 | excludedMap.insert( *it, -2 ); | 557 | excludedMap.insert( *it, -2 ); |
558 | 558 | ||
559 | if ( sorted ) { | 559 | if ( sorted ) { |
560 | QStringList pos = cfg.readListEntry( "Positions", '.' ); | 560 | QStringList pos = cfg.readListEntry( "Positions", '.' ); |
561 | QStringList::Iterator it = pos.begin(); | 561 | QStringList::Iterator it = pos.begin(); |
562 | QString tmp; int i; | 562 | QString tmp; int i; |
563 | while ( it != pos.end() ) { | 563 | while ( it != pos.end() ) { |
564 | tmp = *it++; i = (*it++).toInt(); | 564 | tmp = *it++; i = (*it++).toInt(); |
565 | positionMap.insert( tmp, i ); | 565 | positionMap.insert( tmp, i ); |
566 | } | 566 | } |
567 | 567 | ||
568 | } | 568 | } |
569 | 569 | ||
570 | 570 | ||
571 | 571 | ||
572 | 572 | ||
573 | QStringList list = dir.entryList(); | 573 | QStringList list = dir.entryList(); |
574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 574 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
575 | QString str = unlibify( *it ); | 575 | QString str = unlibify( *it ); |
576 | OPluginItem item( str, _dir + "/" + *it ); | 576 | OPluginItem item( str, _dir + "/" + *it ); |
577 | 577 | ||
578 | bool ex = excludedMap.contains( str ); | 578 | bool ex = excludedMap.contains( str ); |
579 | /* | 579 | /* |
580 | * if disabled but we should show all mark it as disabled | 580 | * if disabled but we should show all mark it as disabled |
581 | * else continue because we don't want to add the item | 581 | * else continue because we don't want to add the item |
582 | * else if sorted we assign the right position | 582 | * else if sorted we assign the right position |
583 | */ | 583 | */ |
584 | if ( ex && !disabled) | 584 | if ( ex && !disabled) |
585 | item.setEnabled( false ); | 585 | item.setEnabled( false ); |
586 | else if ( ex && disabled ) | 586 | else if ( ex && disabled ) |
587 | continue; | 587 | continue; |
588 | else if ( sorted ) | 588 | else if ( sorted ) |
589 | item.setPosition( positionMap[str] ); | 589 | item.setPosition( positionMap[str] ); |
590 | 590 | ||
591 | 591 | ||
592 | lst.append( item ); | 592 | lst.append( item ); |
593 | } | 593 | } |
594 | 594 | ||
595 | return lst; | 595 | return lst; |
596 | } | 596 | } |
597 | 597 | ||
598 | /** | 598 | /** |
599 | * @internal generate a list of languages from $LANG | 599 | * @internal generate a list of languages from $LANG |
600 | */ | 600 | */ |
601 | QStringList OGenericPluginLoader::languageList() { | 601 | QStringList OGenericPluginLoader::languageList() { |
602 | if ( m_languages.isEmpty() ) { | 602 | if ( m_languages.isEmpty() ) { |
603 | /* | 603 | /* |
604 | * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be | 604 | * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be |
605 | * to our list of languages. | 605 | * to our list of languages. |
606 | * Also for de_DE@euro we will add de_DE@eurp, de_DE, de | ||
607 | * to our list of languages | ||
606 | */ | 608 | */ |
607 | QString str = ::getenv( "LANG" ); | 609 | QString str = ::getenv( "LANG" ); |
608 | m_languages += str; | 610 | m_languages += str; |
609 | int pos = str.find( '.' ); | 611 | int pos = str.find( '@' ); |
610 | 612 | if( pos > 0 ) | |
613 | m_languages += str.left( pos ); | ||
614 | |||
615 | |||
616 | pos = str.find( '.' ); | ||
611 | if ( pos > 0 ) | 617 | if ( pos > 0 ) |
612 | m_languages += str.left( pos ); | 618 | m_languages += str.left( pos ); |
613 | 619 | ||
614 | int n_pos = str.find( '_' ); | 620 | int n_pos = str.find( '_' ); |
615 | if ( pos > 0 && n_pos >= pos ) | 621 | if ( n_pos > 0 ) |
616 | m_languages += str.left( n_pos ); | 622 | m_languages += str.left( n_pos ); |
617 | 623 | ||
618 | } | 624 | } |
619 | return m_languages; | 625 | return m_languages; |
620 | } | 626 | } |
621 | 627 | ||
622 | /** | 628 | /** |
623 | * @internal | 629 | * @internal |
624 | * Tries to install languages using the languageList for the type | 630 | * Tries to install languages using the languageList for the type |
625 | */ | 631 | */ |
626 | void OGenericPluginLoader::installTranslators(const QString& type) { | 632 | void OGenericPluginLoader::installTranslators(const QString& type) { |
627 | QStringList lst = languageList(); | 633 | QStringList lst = languageList(); |
628 | 634 | ||
629 | /* | 635 | /* |
630 | * for each language and maybe later for each language dir... | 636 | * for each language and maybe later for each language dir... |
631 | * try to load a Translator | 637 | * try to load a Translator |
632 | */ | 638 | */ |
633 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 639 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
634 | QTranslator* trans = new QTranslator( qApp ); | 640 | QTranslator* trans = new QTranslator( qApp ); |
635 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; | 641 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/lib" + type + ".qm" ; |
636 | 642 | ||
637 | /* | 643 | /* |
638 | * If loaded then install else clean up and don't leak | 644 | * If loaded then install else clean up and don't leak |
639 | */ | 645 | */ |
640 | if ( trans->load( tfn ) ) | 646 | if ( trans->load( tfn ) ) |
641 | qApp->installTranslator( trans ); | 647 | qApp->installTranslator( trans ); |
642 | else | 648 | else |
643 | delete trans; | 649 | delete trans; |
644 | } | 650 | } |
645 | } | 651 | } |
646 | 652 | ||
647 | /** | 653 | /** |
648 | * \brief Simple c'tor. | 654 | * \brief Simple c'tor. |
649 | * | 655 | * |
650 | * Simple C'tor same as the one of the base class. Additional this | 656 | * Simple C'tor same as the one of the base class. Additional this |
651 | * class can cast for you if you nee it. | 657 | * class can cast for you if you nee it. |
652 | * | 658 | * |
653 | * | 659 | * |
654 | * @param name The name of your plugin class | 660 | * @param name The name of your plugin class |
655 | * @param sorted If plugins are sorted | 661 | * @param sorted If plugins are sorted |
656 | * | 662 | * |
657 | * @see OGenericPluginLoader | 663 | * @see OGenericPluginLoader |
658 | */ | 664 | */ |
659 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) | 665 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) |
660 | : OGenericPluginLoader( name, sorted ) | 666 | : OGenericPluginLoader( name, sorted ) |
661 | { | 667 | { |
662 | } | 668 | } |
663 | 669 | ||
664 | /** | 670 | /** |
665 | * d'tor | 671 | * d'tor |
666 | * @see OGenericPluginLoader::~OGenericPluginLoader | 672 | * @see OGenericPluginLoader::~OGenericPluginLoader |
667 | */ | 673 | */ |
668 | OPluginLoader::~OPluginLoader() { | 674 | OPluginLoader::~OPluginLoader() { |
669 | } | 675 | } |
670 | 676 | ||
671 | /** | 677 | /** |
672 | * \brief C'Tor using a OGenericPluginLoader | 678 | * \brief C'Tor using a OGenericPluginLoader |
673 | * The C'tor. Pass your OGenericPluginLoader to manage | 679 | * The C'tor. Pass your OGenericPluginLoader to manage |
674 | * OGenericPluginLoader::allAvailable plugins. | 680 | * OGenericPluginLoader::allAvailable plugins. |
675 | * | 681 | * |
676 | * | 682 | * |
677 | * @param loader A Pointer to your OGenericPluginLoader | 683 | * @param loader A Pointer to your OGenericPluginLoader |
678 | * @param name The name | 684 | * @param name The name |
679 | */ | 685 | */ |
680 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) | 686 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) |
681 | : m_loader( loader ), m_isSorted( false ) | 687 | : m_loader( loader ), m_isSorted( false ) |
682 | { | 688 | { |
683 | } | 689 | } |
684 | 690 | ||
685 | /** | 691 | /** |
686 | * \brief Overloaded c'tor using a List of Plugins and a type name | 692 | * \brief Overloaded c'tor using a List of Plugins and a type name |
687 | * Overloaded Constructor to work with a 'Type' of plugins | 693 | * Overloaded Constructor to work with a 'Type' of plugins |
688 | * and a correspending list of those. In this case calling load | 694 | * and a correspending list of those. In this case calling load |
689 | * is a no operation. | 695 | * is a no operation. |
690 | * | 696 | * |
691 | * @param name The name of your plugin ('today','inputmethods','applets') | 697 | * @param name The name of your plugin ('today','inputmethods','applets') |
692 | * @param lst A List with plugins of your type to manage | 698 | * @param lst A List with plugins of your type to manage |
693 | * @param isSorted If the List should be treated sorted | 699 | * @param isSorted If the List should be treated sorted |
694 | */ | 700 | */ |
695 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) | 701 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) |
696 | : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) | 702 | : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) |
697 | { | 703 | { |
698 | } | 704 | } |
699 | 705 | ||
700 | /** | 706 | /** |
701 | * \brief A simple d'tor | 707 | * \brief A simple d'tor |
702 | */ | 708 | */ |
703 | OPluginManager::~OPluginManager() { | 709 | OPluginManager::~OPluginManager() { |
704 | } | 710 | } |
705 | 711 | ||
706 | /** | 712 | /** |
707 | * \brief Return the OPluginItem where loading is likely to have crashed on. | 713 | * \brief Return the OPluginItem where loading is likely to have crashed on. |
708 | 714 | ||
709 | * Return the Item that made the OGenericPluginLoader crash | 715 | * Return the Item that made the OGenericPluginLoader crash |
710 | * the returned OPluginItem could be empty if no crash occured | 716 | * the returned OPluginItem could be empty if no crash occured |
711 | * which should apply most of the time. It could also be empty if the crashed | 717 | * which should apply most of the time. It could also be empty if the crashed |
712 | * plugin is not in the current list of available/managed plugins | 718 | * plugin is not in the current list of available/managed plugins |
713 | * | 719 | * |
714 | * @see OPluginItem::isEmpty | 720 | * @see OPluginItem::isEmpty |
715 | * @return OPluginItem that crashed the loader | 721 | * @return OPluginItem that crashed the loader |
716 | */ | 722 | */ |
717 | OPluginItem OPluginManager::crashedPlugin()const { | 723 | OPluginItem OPluginManager::crashedPlugin()const { |
718 | return m_crashed; | 724 | return m_crashed; |
719 | } | 725 | } |
720 | 726 | ||
721 | /** | 727 | /** |
722 | * \brief Return a list of plugins that are managed by this OPluginManager | 728 | * \brief Return a list of plugins that are managed by this OPluginManager |
723 | * | 729 | * |
724 | * Return the list of managed plugins. This could either result | 730 | * Return the list of managed plugins. This could either result |
725 | * from passing a OGenericPluginLoader and calling load or by | 731 | * from passing a OGenericPluginLoader and calling load or by |
726 | * giving name and a list of plugins. | 732 | * giving name and a list of plugins. |
727 | */ | 733 | */ |
728 | OPluginItem::List OPluginManager::managedPlugins()const { | 734 | OPluginItem::List OPluginManager::managedPlugins()const { |
729 | return m_plugins; | 735 | return m_plugins; |
730 | } | 736 | } |
731 | 737 | ||
732 | /** | 738 | /** |
733 | * \brief Set the position of the items | 739 | * \brief Set the position of the items |
734 | * | 740 | * |
735 | * Replace the OPluginItem with the name and path and this way | 741 | * Replace the OPluginItem with the name and path and this way |
736 | * apply the new position. The search is linear and this way O(n/2) | 742 | * apply the new position. The search is linear and this way O(n/2) |
737 | * You still need to call save() to make your changes effective. After saving | 743 | * You still need to call save() to make your changes effective. After saving |
738 | * a call to OGenericPluginLoader::filtered() returns the newly configured order and items | 744 | * a call to OGenericPluginLoader::filtered() returns the newly configured order and items |
739 | * | 745 | * |
740 | * @param item The OPluginItem to be replaced internall | 746 | * @param item The OPluginItem to be replaced internall |
741 | * | 747 | * |
742 | */ | 748 | */ |
743 | void OPluginManager::setPosition( const OPluginItem& item) { | 749 | void OPluginManager::setPosition( const OPluginItem& item) { |
744 | replace( item ); | 750 | replace( item ); |
745 | } | 751 | } |
746 | 752 | ||
747 | /** | 753 | /** |
748 | * \brief Enable the item specified as argument | 754 | * \brief Enable the item specified as argument |
749 | * | 755 | * |
750 | * This will make sure that OPluginItem::setEnabled is called and then will replace | 756 | * This will make sure that OPluginItem::setEnabled is called and then will replace |
751 | * the item with one that matches name and path internally. | 757 | * the item with one that matches name and path internally. |
752 | * @see setPosition | 758 | * @see setPosition |
753 | * | 759 | * |
754 | * @param the Item to enable | 760 | * @param the Item to enable |
755 | */ | 761 | */ |
756 | void OPluginManager::enable( const OPluginItem& item ) { | 762 | void OPluginManager::enable( const OPluginItem& item ) { |
757 | setEnabled( item, true ); | 763 | setEnabled( item, true ); |
758 | } | 764 | } |
759 | 765 | ||
760 | /** | 766 | /** |
761 | * \brief disable the Item. | 767 | * \brief disable the Item. |
762 | * | 768 | * |
763 | * Disable the OPluginItem. Same applies as in | 769 | * Disable the OPluginItem. Same applies as in |
764 | * @see setPosition and @see enable | 770 | * @see setPosition and @see enable |
765 | * | 771 | * |
766 | * @param item Item to disable | 772 | * @param item Item to disable |
767 | */ | 773 | */ |
768 | void OPluginManager::disable( const OPluginItem& item) { | 774 | void OPluginManager::disable( const OPluginItem& item) { |
769 | setEnabled( item, false ); | 775 | setEnabled( item, false ); |
770 | } | 776 | } |
771 | 777 | ||
772 | /** | 778 | /** |
773 | * \brief Enable or disable the OPluginItem. | 779 | * \brief Enable or disable the OPluginItem. |
774 | * Depending on the value of the parameter this will either disable | 780 | * Depending on the value of the parameter this will either disable |
775 | * or enable the pluginitem. | 781 | * or enable the pluginitem. |
776 | * Beside that same as in @see disable, @see enable, @see setPosition | 782 | * Beside that same as in @see disable, @see enable, @see setPosition |
777 | * applies. | 783 | * applies. |
778 | * | 784 | * |
779 | * @param _item The OPluginItem to enable or to disable. | 785 | * @param _item The OPluginItem to enable or to disable. |
780 | * @param b Enable or disable the plugin. | 786 | * @param b Enable or disable the plugin. |
781 | * | 787 | * |
782 | */ | 788 | */ |
783 | void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { | 789 | void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { |
784 | OPluginItem item = _item; | 790 | OPluginItem item = _item; |
785 | item.setEnabled( b ); | 791 | item.setEnabled( b ); |
786 | replace( item ); | 792 | replace( item ); |
787 | } | 793 | } |
788 | 794 | ||
789 | /** | 795 | /** |
790 | * \brief Load necessary information after constructing the object | 796 | * \brief Load necessary information after constructing the object |
791 | * If you speified a OGenericPluginLoader you need to call this method | 797 | * If you speified a OGenericPluginLoader you need to call this method |
792 | * so that this manager knows what to manage and have a right value for \sa crashedPlugin | 798 | * so that this manager knows what to manage and have a right value for \sa crashedPlugin |
793 | * For the name and the list of plugins this does only try to find out the crashed plugin | 799 | * For the name and the list of plugins this does only try to find out the crashed plugin |
794 | */ | 800 | */ |
795 | void OPluginManager::load() { | 801 | void OPluginManager::load() { |
796 | OConfig cfg( configName() ); | 802 | OConfig cfg( configName() ); |
797 | cfg.setGroup( "General" ); | 803 | cfg.setGroup( "General" ); |
798 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); | 804 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); |
799 | 805 | ||
800 | /* if we've a loader this applies if we were called from the first part */ | 806 | /* if we've a loader this applies if we were called from the first part */ |
801 | if ( m_loader ) | 807 | if ( m_loader ) |
802 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); | 808 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); |
803 | 809 | ||
804 | /* fast and normal route if we did not crash... */ | 810 | /* fast and normal route if we did not crash... */ |
805 | if ( crashedPath.isEmpty() ) | 811 | if ( crashedPath.isEmpty() ) |
806 | return; | 812 | return; |
807 | 813 | ||
808 | /* lets try to find the plugin path and this way the associated item */ | 814 | /* lets try to find the plugin path and this way the associated item */ |
809 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) | 815 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) |
810 | if ( (*it).path() == crashedPath ) { | 816 | if ( (*it).path() == crashedPath ) { |
811 | m_crashed = *it; | 817 | m_crashed = *it; |
812 | break; | 818 | break; |
813 | } | 819 | } |
814 | } | 820 | } |
815 | 821 | ||
816 | 822 | ||
817 | /** | 823 | /** |
818 | * \brief Save the values and this way make it available. | 824 | * \brief Save the values and this way make it available. |
819 | * | 825 | * |
820 | * Save the current set of data. A call to @see OGenericPluginLoader::filtered | 826 | * Save the current set of data. A call to @see OGenericPluginLoader::filtered |
821 | * now would return your saved changes. | 827 | * now would return your saved changes. |
822 | */ | 828 | */ |
823 | void OPluginManager::save() { | 829 | void OPluginManager::save() { |
824 | QMap<QString, QStringList> excluded; // map for path to excluded name | 830 | QMap<QString, QStringList> excluded; // map for path to excluded name |
825 | QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs | 831 | QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs |
826 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; | 832 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; |
827 | 833 | ||
828 | /* | 834 | /* |
829 | * We will create some maps for the groups to include positions a | 835 | * We will create some maps for the groups to include positions a |
830 | */ | 836 | */ |
831 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { | 837 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { |
832 | OPluginItem item = *it; | 838 | OPluginItem item = *it; |
833 | QString path = QFileInfo( item.path() ).dirPath(true); | 839 | QString path = QFileInfo( item.path() ).dirPath(true); |
834 | if ( sorted ) { | 840 | if ( sorted ) { |
835 | positions[path].append( item.name() ); | 841 | positions[path].append( item.name() ); |
836 | positions[path].append( QString::number( item.position() ) ); | 842 | positions[path].append( QString::number( item.position() ) ); |
837 | } | 843 | } |
838 | 844 | ||
839 | if ( !item.isEnabled() ) | 845 | if ( !item.isEnabled() ) |
840 | excluded[path].append( item.name() ); | 846 | excluded[path].append( item.name() ); |
841 | if ( !excluded.contains( path ) ) | 847 | if ( !excluded.contains( path ) ) |
842 | excluded[path] = QString::null; | 848 | excluded[path] = QString::null; |
843 | 849 | ||
844 | } | 850 | } |
845 | 851 | ||
846 | /* | 852 | /* |
847 | * The code below wouldn't work because we can't delete groups/keys from the config | 853 | * The code below wouldn't work because we can't delete groups/keys from the config |
848 | * ### for ODP make Config right! | 854 | * ### for ODP make Config right! |
849 | */ | 855 | */ |
850 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; | 856 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; |
851 | /* | 857 | /* |
852 | * Now safe for each path | 858 | * Now safe for each path |
853 | */ | 859 | */ |
854 | OConfig cfg( configName() ); | 860 | OConfig cfg( configName() ); |
855 | 861 | ||
856 | /* safe excluded items */ | 862 | /* safe excluded items */ |
857 | for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { | 863 | for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { |
858 | OConfigGroupSaver saver( &cfg, it.key() ); | 864 | OConfigGroupSaver saver( &cfg, it.key() ); |
859 | cfg.writeEntry("Excluded", it.data(), ',' ); | 865 | cfg.writeEntry("Excluded", it.data(), ',' ); |
860 | } | 866 | } |
861 | 867 | ||
862 | /* safe positions we could also see if positions.contains(path) and remove/write in the above loop | 868 | /* safe positions we could also see if positions.contains(path) and remove/write in the above loop |
863 | * ### Write a Test Suite that can profile these runs... | 869 | * ### Write a Test Suite that can profile these runs... |
864 | */ | 870 | */ |
865 | for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { | 871 | for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { |
866 | OConfigGroupSaver saver( &cfg, it.key() ); | 872 | OConfigGroupSaver saver( &cfg, it.key() ); |
867 | cfg.writeEntry("Positions", it.data(), '.' ); | 873 | cfg.writeEntry("Positions", it.data(), '.' ); |
868 | } | 874 | } |
869 | } | 875 | } |
870 | 876 | ||
871 | /** | 877 | /** |
872 | * @internal | 878 | * @internal |
873 | */ | 879 | */ |
874 | QString OPluginManager::configName()const { | 880 | QString OPluginManager::configName()const { |
875 | QString str = m_loader ? m_loader->name() : m_cfgName; | 881 | QString str = m_loader ? m_loader->name() : m_cfgName; |
876 | return str + "-odpplugins"; | 882 | return str + "-odpplugins"; |
877 | } | 883 | } |
878 | 884 | ||
879 | /** | 885 | /** |
880 | * @internal.. replace in m_plugins by path... this is linear search O(n/2) | 886 | * @internal.. replace in m_plugins by path... this is linear search O(n/2) |
881 | */ | 887 | */ |
882 | void OPluginManager::replace( const OPluginItem& item ) { | 888 | void OPluginManager::replace( const OPluginItem& item ) { |
883 | OPluginItem _item; | 889 | OPluginItem _item; |
884 | 890 | ||
885 | /* for all plugins */ | 891 | /* for all plugins */ |
886 | for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { | 892 | for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { |
887 | _item = *it; | 893 | _item = *it; |
888 | /* if path and name are the same we will remove, readd and return */ | 894 | /* if path and name are the same we will remove, readd and return */ |
889 | if ( _item.path() == item.path() && | 895 | if ( _item.path() == item.path() && |
890 | _item.name() == item.name() ) { | 896 | _item.name() == item.name() ) { |
891 | it = m_plugins.remove( it ); | 897 | it = m_plugins.remove( it ); |
892 | m_plugins.append( item ); | 898 | m_plugins.append( item ); |
893 | return; | 899 | return; |
894 | } | 900 | } |
895 | 901 | ||
896 | } | 902 | } |
897 | } | 903 | } |