-rw-r--r-- | libopie2/opiecore/opluginloader.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp index 87e24d4..c2dc239 100644 --- a/libopie2/opiecore/opluginloader.cpp +++ b/libopie2/opiecore/opluginloader.cpp | |||
@@ -357,534 +357,534 @@ QString OGenericPluginLoader::name()const { | |||
357 | 357 | ||
358 | /** | 358 | /** |
359 | * \brief See if loading of a plugin segfaulted | 359 | * \brief See if loading of a plugin segfaulted |
360 | * This tells you | 360 | * This tells you |
361 | * if by previous tries to load, loading crashed your application. | 361 | * if by previous tries to load, loading crashed your application. |
362 | * If isInSafeMode you can use the GUI to configure the plugins prior to loading | 362 | * If isInSafeMode you can use the GUI to configure the plugins prior to loading |
363 | * | 363 | * |
364 | * @return true if prior loading failed | 364 | * @return true if prior loading failed |
365 | */ | 365 | */ |
366 | bool OGenericPluginLoader::isInSafeMode()const { | 366 | bool OGenericPluginLoader::isInSafeMode()const { |
367 | return m_isSafeMode; | 367 | return m_isSafeMode; |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | /** | 371 | /** |
372 | * \brief Return all Plugins found in the plugins dirs. | 372 | * \brief Return all Plugins found in the plugins dirs. |
373 | * Return the list of all available plugins. This will go through all plugin | 373 | * Return the list of all available plugins. This will go through all plugin |
374 | * directories and search for your type of plugins ( by subdir ) | 374 | * directories and search for your type of plugins ( by subdir ) |
375 | * | 375 | * |
376 | * @param sorted Tell if you want to have the positions sorted. This only makes sense if you | 376 | * @param sorted Tell if you want to have the positions sorted. This only makes sense if you |
377 | */ | 377 | */ |
378 | OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { | 378 | OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { |
379 | OPluginItem::List lst; | 379 | OPluginItem::List lst; |
380 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) | 380 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) |
381 | lst += plugins( *it, sorted, false ); | 381 | lst += plugins( *it, sorted, false ); |
382 | 382 | ||
383 | if ( sorted ) | 383 | if ( sorted ) |
384 | qHeapSort( lst ); | 384 | qHeapSort( lst ); |
385 | return lst; | 385 | return lst; |
386 | } | 386 | } |
387 | 387 | ||
388 | /** | 388 | /** |
389 | * \brief Return only the enabled plugins | 389 | * \brief Return only the enabled plugins |
390 | * Return only activated plugins. | 390 | * Return only activated plugins. |
391 | * | 391 | * |
392 | * @param sorted If the list should be sorted | 392 | * @param sorted If the list should be sorted |
393 | */ | 393 | */ |
394 | OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { | 394 | OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { |
395 | OPluginItem::List lst; | 395 | OPluginItem::List lst; |
396 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) | 396 | for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) |
397 | lst += plugins( *it, sorted, true ); | 397 | lst += plugins( *it, sorted, true ); |
398 | 398 | ||
399 | if ( sorted ) | 399 | if ( sorted ) |
400 | qHeapSort( lst ); | 400 | qHeapSort( lst ); |
401 | return lst; | 401 | return lst; |
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | /** | 405 | /** |
406 | * \brief Load a OPluginItem for the specified interface | 406 | * \brief Load a OPluginItem for the specified interface |
407 | * This will open the resource of the OPluginItem::path() and then will query | 407 | * This will open the resource of the OPluginItem::path() and then will query |
408 | * if the Interface specified in the uuid is available and then will manage the | 408 | * if the Interface specified in the uuid is available and then will manage the |
409 | * resource and Interface. | 409 | * resource and Interface. |
410 | * | 410 | * |
411 | * @param item The OPluginItem that should be loaded | 411 | * @param item The OPluginItem that should be loaded |
412 | * @param uuid The Interface to query for | 412 | * @param uuid The Interface to query for |
413 | * | 413 | * |
414 | * @return Either 0 in case of failure or the Plugin as QUnknownInterface* | 414 | * @return Either 0 in case of failure or the Plugin as QUnknownInterface* |
415 | */ | 415 | */ |
416 | QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { | 416 | QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { |
417 | /* | 417 | /* |
418 | * Check if there could be a library | 418 | * Check if there could be a library |
419 | */ | 419 | */ |
420 | QString pa = item.path(); | 420 | QString pa = item.path(); |
421 | if ( pa.isEmpty() ) | 421 | if ( pa.isEmpty() ) |
422 | return 0l; | 422 | return 0l; |
423 | 423 | ||
424 | /* | 424 | /* |
425 | * See if we get a library | 425 | * See if we get a library |
426 | * return if we've none | 426 | * return if we've none |
427 | */ | 427 | */ |
428 | setSafeMode( pa, true ); | 428 | setSafeMode( pa, true ); |
429 | QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); | 429 | QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); |
430 | if ( !lib ) { | 430 | if ( !lib ) { |
431 | setSafeMode(); | 431 | setSafeMode(); |
432 | return 0l; | 432 | return 0l; |
433 | } | 433 | } |
434 | 434 | ||
435 | /** | 435 | /** |
436 | * try to load the plugin and just in case initialize the pointer to a pointer again | 436 | * try to load the plugin and just in case initialize the pointer to a pointer again |
437 | */ | 437 | */ |
438 | QUnknownInterface* iface=0; | 438 | QUnknownInterface* iface=0; |
439 | if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { | 439 | if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { |
440 | installTranslators(pa.left( pa.find("."))); | 440 | installTranslators(pa.left( pa.find("."))); |
441 | m_library.insert( iface, lib ); | 441 | m_library.insert( iface, lib ); |
442 | }else | 442 | }else |
443 | iface = 0; | 443 | iface = 0; |
444 | 444 | ||
445 | setSafeMode(); | 445 | setSafeMode(); |
446 | 446 | ||
447 | return iface; | 447 | return iface; |
448 | } | 448 | } |
449 | 449 | ||
450 | /** | 450 | /** |
451 | * @internal and reads in the safe mode | 451 | * @internal and reads in the safe mode |
452 | */ | 452 | */ |
453 | void OGenericPluginLoader::readConfig() { | 453 | void OGenericPluginLoader::readConfig() { |
454 | 454 | ||
455 | 455 | ||
456 | /* read the config for SafeMode */ | 456 | /* read the config for SafeMode */ |
457 | OConfig conf( m_dir + "-odpplugins" ); | 457 | OConfig conf( m_dir + "-odpplugins" ); |
458 | conf.setGroup( "General" ); | 458 | conf.setGroup( "General" ); |
459 | m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); | 459 | m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); |
460 | } | 460 | } |
461 | 461 | ||
462 | /** | 462 | /** |
463 | * @internal Enter or leave SafeMode | 463 | * @internal Enter or leave SafeMode |
464 | */ | 464 | */ |
465 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { | 465 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { |
466 | OConfig conf( m_dir + "-odpplugins" ); | 466 | OConfig conf( m_dir + "-odpplugins" ); |
467 | conf.setGroup( "General" ); | 467 | conf.setGroup( "General" ); |
468 | conf.writeEntry( "SafeMode", b ); | 468 | conf.writeEntry( "SafeMode", b ); |
469 | conf.writeEntry( "CrashedPlugin", str ); | 469 | conf.writeEntry( "CrashedPlugin", str ); |
470 | } | 470 | } |
471 | 471 | ||
472 | /** | 472 | /** |
473 | * @internal | 473 | * @internal |
474 | * | 474 | * |
475 | * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype | 475 | * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype |
476 | * is used as plugin dir | 476 | * is used as plugin dir |
477 | */ | 477 | */ |
478 | void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { | 478 | void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { |
479 | m_plugDirs = lst; | 479 | m_plugDirs = lst; |
480 | } | 480 | } |
481 | 481 | ||
482 | /** | 482 | /** |
483 | * | 483 | * |
484 | * @internal | 484 | * @internal |
485 | * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs | 485 | * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs |
486 | */ | 486 | */ |
487 | void OGenericPluginLoader::setPluginDir( const QString& str) { | 487 | void OGenericPluginLoader::setPluginDir( const QString& str) { |
488 | m_plugDirs.clear(); | 488 | m_plugDirs.clear(); |
489 | m_plugDirs.append( str ); | 489 | m_plugDirs.append( str ); |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | /** | 493 | /** |
494 | * @internal | 494 | * @internal |
495 | */ | 495 | */ |
496 | bool OGenericPluginLoader::isSorted()const{ | 496 | bool OGenericPluginLoader::isSorted()const{ |
497 | return m_isSorted; | 497 | return m_isSorted; |
498 | } | 498 | } |
499 | 499 | ||
500 | /* | 500 | /* |
501 | * make libfoo.so.1.0.0 -> foo on UNIX | 501 | * make libfoo.so.1.0.0 -> foo on UNIX |
502 | * make libfoo.dylib -> foo on MAC OS X Unix | 502 | * make libfoo.dylib -> foo on MAC OS X Unix |
503 | * windows is obviously missing | 503 | * windows is obviously missing |
504 | */ | 504 | */ |
505 | /** | 505 | /** |
506 | * @internal | 506 | * @internal |
507 | */ | 507 | */ |
508 | QString OGenericPluginLoader::unlibify( const QString& str ) { | 508 | QString OGenericPluginLoader::unlibify( const QString& str ) { |
509 | QString st = str.mid( str.find( "lib" )+3 ); | 509 | QString st = str.mid( str.find( "lib" )+3 ); |
510 | #ifdef Q_OS_MACX | 510 | #ifdef Q_OS_MACX |
511 | return st.left( st.findRev( ".dylib" ) ); | 511 | return st.left( st.findRev( ".dylib" ) ); |
512 | #else | 512 | #else |
513 | return st.left( st.findRev( ".so" ) ); | 513 | return st.left( st.findRev( ".so" ) ); |
514 | #endif | 514 | #endif |
515 | } | 515 | } |
516 | 516 | ||
517 | /** | 517 | /** |
518 | * @internal | 518 | * @internal |
519 | * | 519 | * |
520 | * \brief method to return available plugins. Internal and for reeimplementations | 520 | * \brief method to return available plugins. Internal and for reeimplementations |
521 | * | 521 | * |
522 | *Return a List of Plugins for a dir and add positions and remove disabled. | 522 | *Return a List of Plugins for a dir and add positions and remove disabled. |
523 | * If a plugin is on the excluded list assign position -2 | 523 | * If a plugin is on the excluded list assign position -2 |
524 | * | 524 | * |
525 | * @param dir The dir to look in | 525 | * @param dir The dir to look in |
526 | * @param sorted Should positions be read? | 526 | * @param sorted Should positions be read? |
527 | * @param disabled Remove excluded from the list | 527 | * @param disabled Remove excluded from the list |
528 | */ | 528 | */ |
529 | OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { | 529 | OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { |
530 | #ifdef Q_OS_MACX | 530 | #ifdef Q_OS_MACX |
531 | QDir dir( _dir, "lib*.dylib" ); | 531 | QDir dir( _dir, "lib*.dylib" ); |
532 | #else | 532 | #else |
533 | QDir dir( _dir, "lib*.so" ); | 533 | QDir dir( _dir, "lib*.so" ); |
534 | #endif | 534 | #endif |
535 | 535 | ||
536 | OPluginItem::List lst; | 536 | OPluginItem::List lst; |
537 | 537 | ||
538 | /* | 538 | /* |
539 | * get excluded list and then iterate over them | 539 | * get excluded list and then iterate over them |
540 | * Excluded list contains the name | 540 | * Excluded list contains the name |
541 | * Position is a list with 'name.pos.name.pos.name.pos' | 541 | * Position is a list with 'name.pos.name.pos.name.pos' |
542 | * | 542 | * |
543 | * For the look up we will create two QMap<QString,pos> | 543 | * For the look up we will create two QMap<QString,pos> |
544 | */ | 544 | */ |
545 | QMap<QString, int> positionMap; | 545 | QMap<QString, int> positionMap; |
546 | QMap<QString, int> excludedMap; | 546 | QMap<QString, int> excludedMap; |
547 | 547 | ||
548 | 548 | ||
549 | OConfig cfg( m_dir+"odpplugins" ); | 549 | OConfig cfg( m_dir+"-odpplugins" ); |
550 | cfg.setGroup( _dir ); | 550 | cfg.setGroup( _dir ); |
551 | 551 | ||
552 | 552 | ||
553 | QStringList excludes = cfg.readListEntry( "Excluded", ',' ); | 553 | QStringList excludes = cfg.readListEntry( "Excluded", ',' ); |
554 | for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) | 554 | for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) |
555 | excludedMap.insert( *it, -2 ); | 555 | excludedMap.insert( *it, -2 ); |
556 | 556 | ||
557 | if ( m_isSorted ) { | 557 | if ( m_isSorted ) { |
558 | QStringList pos = cfg.readListEntry( "Positions", '.' ); | 558 | QStringList pos = cfg.readListEntry( "Positions", '.' ); |
559 | QStringList::Iterator it = pos.begin(); | 559 | QStringList::Iterator it = pos.begin(); |
560 | while ( it != pos.end() ) | 560 | while ( it != pos.end() ) |
561 | positionMap.insert( *it++, (*it++).toInt() ); | 561 | positionMap.insert( *it++, (*it++).toInt() ); |
562 | } | 562 | } |
563 | 563 | ||
564 | 564 | ||
565 | 565 | ||
566 | 566 | ||
567 | QStringList list = dir.entryList(); | 567 | QStringList list = dir.entryList(); |
568 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 568 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
569 | QString str = unlibify( *it ); | 569 | QString str = unlibify( *it ); |
570 | OPluginItem item( str, _dir + "/" + *it ); | 570 | OPluginItem item( str, _dir + "/" + *it ); |
571 | 571 | ||
572 | bool ex = excludedMap.contains( str ); | 572 | bool ex = excludedMap.contains( str ); |
573 | /* | 573 | /* |
574 | * if disabled but we should show all mark it as disabled | 574 | * if disabled but we should show all mark it as disabled |
575 | * else continue because we don't want to add the item | 575 | * else continue because we don't want to add the item |
576 | * else if sorted we assign the right position | 576 | * else if sorted we assign the right position |
577 | */ | 577 | */ |
578 | if ( ex && !disabled) | 578 | if ( ex && !disabled) |
579 | item.setEnabled( false ); | 579 | item.setEnabled( false ); |
580 | else if ( ex && disabled ) | 580 | else if ( ex && disabled ) |
581 | continue; | 581 | continue; |
582 | else if ( sorted ) | 582 | else if ( sorted ) |
583 | item.setPosition( positionMap[str] ); | 583 | item.setPosition( positionMap[str] ); |
584 | 584 | ||
585 | lst.append( item ); | 585 | lst.append( item ); |
586 | } | 586 | } |
587 | 587 | ||
588 | return lst; | 588 | return lst; |
589 | } | 589 | } |
590 | 590 | ||
591 | /** | 591 | /** |
592 | * @internal generate a list of languages from $LANG | 592 | * @internal generate a list of languages from $LANG |
593 | */ | 593 | */ |
594 | QStringList OGenericPluginLoader::languageList() { | 594 | QStringList OGenericPluginLoader::languageList() { |
595 | if ( m_languages.isEmpty() ) { | 595 | if ( m_languages.isEmpty() ) { |
596 | /* | 596 | /* |
597 | * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be | 597 | * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be |
598 | * to our list of languages. | 598 | * to our list of languages. |
599 | */ | 599 | */ |
600 | QString str = ::getenv( "LANG" ); | 600 | QString str = ::getenv( "LANG" ); |
601 | m_languages += str; | 601 | m_languages += str; |
602 | int pos = str.find( '.' ); | 602 | int pos = str.find( '.' ); |
603 | 603 | ||
604 | if ( pos > 0 ) | 604 | if ( pos > 0 ) |
605 | m_languages += str.left( pos ); | 605 | m_languages += str.left( pos ); |
606 | 606 | ||
607 | int n_pos = str.find( '_' ); | 607 | int n_pos = str.find( '_' ); |
608 | if ( pos > 0 && n_pos >= pos ) | 608 | if ( pos > 0 && n_pos >= pos ) |
609 | m_languages += str.left( n_pos ); | 609 | m_languages += str.left( n_pos ); |
610 | 610 | ||
611 | } | 611 | } |
612 | return m_languages; | 612 | return m_languages; |
613 | } | 613 | } |
614 | 614 | ||
615 | /** | 615 | /** |
616 | * @internal | 616 | * @internal |
617 | * Tries to install languages using the languageList for the type | 617 | * Tries to install languages using the languageList for the type |
618 | */ | 618 | */ |
619 | void OGenericPluginLoader::installTranslators(const QString& type) { | 619 | void OGenericPluginLoader::installTranslators(const QString& type) { |
620 | QStringList lst = languageList(); | 620 | QStringList lst = languageList(); |
621 | 621 | ||
622 | /* | 622 | /* |
623 | * for each language and maybe later for each language dir... | 623 | * for each language and maybe later for each language dir... |
624 | * try to load a Translator | 624 | * try to load a Translator |
625 | */ | 625 | */ |
626 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 626 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
627 | QTranslator* trans = new QTranslator( qApp ); | 627 | QTranslator* trans = new QTranslator( qApp ); |
628 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; | 628 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; |
629 | 629 | ||
630 | /* | 630 | /* |
631 | * If loaded then install else clean up and don't leak | 631 | * If loaded then install else clean up and don't leak |
632 | */ | 632 | */ |
633 | if ( trans->load( tfn ) ) | 633 | if ( trans->load( tfn ) ) |
634 | qApp->installTranslator( trans ); | 634 | qApp->installTranslator( trans ); |
635 | else | 635 | else |
636 | delete trans; | 636 | delete trans; |
637 | } | 637 | } |
638 | } | 638 | } |
639 | 639 | ||
640 | /** | 640 | /** |
641 | * \brief Simple c'tor. | 641 | * \brief Simple c'tor. |
642 | * | 642 | * |
643 | * Simple C'tor same as the one of the base class. Additional this | 643 | * Simple C'tor same as the one of the base class. Additional this |
644 | * class can cast for you if you nee it. | 644 | * class can cast for you if you nee it. |
645 | * | 645 | * |
646 | * | 646 | * |
647 | * @param name The name of your plugin class | 647 | * @param name The name of your plugin class |
648 | * @param sorted If plugins are sorted | 648 | * @param sorted If plugins are sorted |
649 | * | 649 | * |
650 | * @see OGenericPluginLoader | 650 | * @see OGenericPluginLoader |
651 | */ | 651 | */ |
652 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) | 652 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) |
653 | : OGenericPluginLoader( name, sorted ) | 653 | : OGenericPluginLoader( name, sorted ) |
654 | { | 654 | { |
655 | } | 655 | } |
656 | 656 | ||
657 | /** | 657 | /** |
658 | * d'tor | 658 | * d'tor |
659 | * @see OGenericPluginLoader::~OGenericPluginLoader | 659 | * @see OGenericPluginLoader::~OGenericPluginLoader |
660 | */ | 660 | */ |
661 | OPluginLoader::~OPluginLoader() { | 661 | OPluginLoader::~OPluginLoader() { |
662 | } | 662 | } |
663 | 663 | ||
664 | /** | 664 | /** |
665 | * \brief C'Tor using a OGenericPluginLoader | 665 | * \brief C'Tor using a OGenericPluginLoader |
666 | * The C'tor. Pass your OGenericPluginLoader to manage | 666 | * The C'tor. Pass your OGenericPluginLoader to manage |
667 | * OGenericPluginLoader::allAvailable plugins. | 667 | * OGenericPluginLoader::allAvailable plugins. |
668 | * | 668 | * |
669 | * | 669 | * |
670 | * @param loader A Pointer to your OGenericPluginLoader | 670 | * @param loader A Pointer to your OGenericPluginLoader |
671 | * @param name The name | 671 | * @param name The name |
672 | */ | 672 | */ |
673 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) | 673 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) |
674 | : m_loader( loader ), m_isSorted( false ) | 674 | : m_loader( loader ), m_isSorted( false ) |
675 | { | 675 | { |
676 | } | 676 | } |
677 | 677 | ||
678 | /** | 678 | /** |
679 | * \brief Overloaded c'tor using a List of Plugins and a type name | 679 | * \brief Overloaded c'tor using a List of Plugins and a type name |
680 | * Overloaded Constructor to work with a 'Type' of plugins | 680 | * Overloaded Constructor to work with a 'Type' of plugins |
681 | * and a correspending list of those. In this case calling load | 681 | * and a correspending list of those. In this case calling load |
682 | * is a no operation. | 682 | * is a no operation. |
683 | * | 683 | * |
684 | * @param name The name of your plugin ('today','inputmethods','applets') | 684 | * @param name The name of your plugin ('today','inputmethods','applets') |
685 | * @param lst A List with plugins of your type to manage | 685 | * @param lst A List with plugins of your type to manage |
686 | * @param isSorted If the List should be treated sorted | 686 | * @param isSorted If the List should be treated sorted |
687 | */ | 687 | */ |
688 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) | 688 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) |
689 | : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) | 689 | : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) |
690 | { | 690 | { |
691 | } | 691 | } |
692 | 692 | ||
693 | /** | 693 | /** |
694 | * \brief A simple d'tor | 694 | * \brief A simple d'tor |
695 | */ | 695 | */ |
696 | OPluginManager::~OPluginManager() { | 696 | OPluginManager::~OPluginManager() { |
697 | } | 697 | } |
698 | 698 | ||
699 | /** | 699 | /** |
700 | * \brief Return the OPluginItem where loading is likely to have crashed on. | 700 | * \brief Return the OPluginItem where loading is likely to have crashed on. |
701 | 701 | ||
702 | * Return the Item that made the OGenericPluginLoader crash | 702 | * Return the Item that made the OGenericPluginLoader crash |
703 | * the returned OPluginItem could be empty if no crash occured | 703 | * the returned OPluginItem could be empty if no crash occured |
704 | * which should apply most of the time. It could also be empty if the crashed | 704 | * which should apply most of the time. It could also be empty if the crashed |
705 | * plugin is not in the current list of available/managed plugins | 705 | * plugin is not in the current list of available/managed plugins |
706 | * | 706 | * |
707 | * @see OPluginItem::isEmpty | 707 | * @see OPluginItem::isEmpty |
708 | * @return OPluginItem that crashed the loader | 708 | * @return OPluginItem that crashed the loader |
709 | */ | 709 | */ |
710 | OPluginItem OPluginManager::crashedPlugin()const { | 710 | OPluginItem OPluginManager::crashedPlugin()const { |
711 | return m_crashed; | 711 | return m_crashed; |
712 | } | 712 | } |
713 | 713 | ||
714 | /** | 714 | /** |
715 | * \brief Return a list of plugins that are managed by this OPluginManager | 715 | * \brief Return a list of plugins that are managed by this OPluginManager |
716 | * | 716 | * |
717 | * Return the list of managed plugins. This could either result | 717 | * Return the list of managed plugins. This could either result |
718 | * from passing a OGenericPluginLoader and calling load or by | 718 | * from passing a OGenericPluginLoader and calling load or by |
719 | * giving name and a list of plugins. | 719 | * giving name and a list of plugins. |
720 | */ | 720 | */ |
721 | OPluginItem::List OPluginManager::managedPlugins()const { | 721 | OPluginItem::List OPluginManager::managedPlugins()const { |
722 | return m_plugins; | 722 | return m_plugins; |
723 | } | 723 | } |
724 | 724 | ||
725 | /** | 725 | /** |
726 | * \brief Set the position of the items | 726 | * \brief Set the position of the items |
727 | * | 727 | * |
728 | * Replace the OPluginItem with the name and path and this way | 728 | * Replace the OPluginItem with the name and path and this way |
729 | * apply the new position. The search is linear and this way O(n/2) | 729 | * apply the new position. The search is linear and this way O(n/2) |
730 | * You still need to call save() to make your changes effective. After saving | 730 | * You still need to call save() to make your changes effective. After saving |
731 | * a call to OGenericPluginLoader::filtered() returns the newly configured order and items | 731 | * a call to OGenericPluginLoader::filtered() returns the newly configured order and items |
732 | * | 732 | * |
733 | * @param item The OPluginItem to be replaced internall | 733 | * @param item The OPluginItem to be replaced internall |
734 | * | 734 | * |
735 | */ | 735 | */ |
736 | void OPluginManager::setPosition( const OPluginItem& item) { | 736 | void OPluginManager::setPosition( const OPluginItem& item) { |
737 | replace( item ); | 737 | replace( item ); |
738 | } | 738 | } |
739 | 739 | ||
740 | /** | 740 | /** |
741 | * \brief Enable the item specified as argument | 741 | * \brief Enable the item specified as argument |
742 | * | 742 | * |
743 | * This will make sure that OPluginItem::setEnabled is called and then will replace | 743 | * This will make sure that OPluginItem::setEnabled is called and then will replace |
744 | * the item with one that matches name and path internally. | 744 | * the item with one that matches name and path internally. |
745 | * @see setPosition | 745 | * @see setPosition |
746 | * | 746 | * |
747 | * @param the Item to enable | 747 | * @param the Item to enable |
748 | */ | 748 | */ |
749 | void OPluginManager::enable( const OPluginItem& item ) { | 749 | void OPluginManager::enable( const OPluginItem& item ) { |
750 | setEnabled( item, true ); | 750 | setEnabled( item, true ); |
751 | } | 751 | } |
752 | 752 | ||
753 | /** | 753 | /** |
754 | * \brief disable the Item. | 754 | * \brief disable the Item. |
755 | * | 755 | * |
756 | * Disable the OPluginItem. Same applies as in | 756 | * Disable the OPluginItem. Same applies as in |
757 | * @see setPosition and @see enable | 757 | * @see setPosition and @see enable |
758 | * | 758 | * |
759 | * @param item Item to disable | 759 | * @param item Item to disable |
760 | */ | 760 | */ |
761 | void OPluginManager::disable( const OPluginItem& item) { | 761 | void OPluginManager::disable( const OPluginItem& item) { |
762 | setEnabled( item, false ); | 762 | setEnabled( item, false ); |
763 | } | 763 | } |
764 | 764 | ||
765 | /** | 765 | /** |
766 | * \brief Enable or disable the OPluginItem. | 766 | * \brief Enable or disable the OPluginItem. |
767 | * Depending on the value of the parameter this will either disable | 767 | * Depending on the value of the parameter this will either disable |
768 | * or enable the pluginitem. | 768 | * or enable the pluginitem. |
769 | * Beside that same as in @see disable, @see enable, @see setPosition | 769 | * Beside that same as in @see disable, @see enable, @see setPosition |
770 | * applies. | 770 | * applies. |
771 | * | 771 | * |
772 | * @param _item The OPluginItem to enable or to disable. | 772 | * @param _item The OPluginItem to enable or to disable. |
773 | * @param b Enable or disable the plugin. | 773 | * @param b Enable or disable the plugin. |
774 | * | 774 | * |
775 | */ | 775 | */ |
776 | void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { | 776 | void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { |
777 | OPluginItem item = _item; | 777 | OPluginItem item = _item; |
778 | item.setEnabled( b ); | 778 | item.setEnabled( b ); |
779 | replace( item ); | 779 | replace( item ); |
780 | } | 780 | } |
781 | 781 | ||
782 | /** | 782 | /** |
783 | * \brief Load necessary information after constructing the object | 783 | * \brief Load necessary information after constructing the object |
784 | * If you speified a OGenericPluginLoader you need to call this method | 784 | * If you speified a OGenericPluginLoader you need to call this method |
785 | * so that this manager knows what to manage and have a right value for \sa crashedPlugin | 785 | * so that this manager knows what to manage and have a right value for \sa crashedPlugin |
786 | * For the name and the list of plugins this does only try to find out the crashed plugin | 786 | * For the name and the list of plugins this does only try to find out the crashed plugin |
787 | */ | 787 | */ |
788 | void OPluginManager::load() { | 788 | void OPluginManager::load() { |
789 | OConfig cfg( configName() ); | 789 | OConfig cfg( configName() ); |
790 | cfg.setGroup( "General" ); | 790 | cfg.setGroup( "General" ); |
791 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); | 791 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); |
792 | 792 | ||
793 | /* if we've a loader this applies if we were called from the first part */ | 793 | /* if we've a loader this applies if we were called from the first part */ |
794 | if ( m_loader ) | 794 | if ( m_loader ) |
795 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); | 795 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); |
796 | 796 | ||
797 | /* fast and normal route if we did not crash... */ | 797 | /* fast and normal route if we did not crash... */ |
798 | if ( crashedPath.isEmpty() ) | 798 | if ( crashedPath.isEmpty() ) |
799 | return; | 799 | return; |
800 | 800 | ||
801 | /* lets try to find the plugin path and this way the associated item */ | 801 | /* lets try to find the plugin path and this way the associated item */ |
802 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) | 802 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) |
803 | if ( (*it).path() == crashedPath ) { | 803 | if ( (*it).path() == crashedPath ) { |
804 | m_crashed = *it; | 804 | m_crashed = *it; |
805 | break; | 805 | break; |
806 | } | 806 | } |
807 | } | 807 | } |
808 | 808 | ||
809 | 809 | ||
810 | /** | 810 | /** |
811 | * \brief Save the values and this way make it available. | 811 | * \brief Save the values and this way make it available. |
812 | * | 812 | * |
813 | * Save the current set of data. A call to @see OGenericPluginLoader::filtered | 813 | * Save the current set of data. A call to @see OGenericPluginLoader::filtered |
814 | * now would return your saved changes. | 814 | * now would return your saved changes. |
815 | */ | 815 | */ |
816 | void OPluginManager::save() { | 816 | void OPluginManager::save() { |
817 | QMap<QString, QStringList> excluded; // map for path to excluded name | 817 | QMap<QString, QStringList> excluded; // map for path to excluded name |
818 | QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs | 818 | QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs |
819 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; | 819 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; |
820 | 820 | ||
821 | /* | 821 | /* |
822 | * We will create some maps for the groups to include positions a | 822 | * We will create some maps for the groups to include positions a |
823 | */ | 823 | */ |
824 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { | 824 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { |
825 | OPluginItem item = *it; | 825 | OPluginItem item = *it; |
826 | QString path = QFileInfo( item.path() ).filePath(); | 826 | QString path = QFileInfo( item.path() ).filePath(); |
827 | if ( sorted ) { | 827 | if ( sorted ) { |
828 | positions[path].append( item.name() ); | 828 | positions[path].append( item.name() ); |
829 | positions[path].append( QString::number( item.position() ) ); | 829 | positions[path].append( QString::number( item.position() ) ); |
830 | } | 830 | } |
831 | 831 | ||
832 | if ( !item.isEnabled() ) | 832 | if ( !item.isEnabled() ) |
833 | excluded[path].append( item.name() ); | 833 | excluded[path].append( item.name() ); |
834 | } | 834 | } |
835 | 835 | ||
836 | /* | 836 | /* |
837 | * The code below wouldn't work because we can't delete groups/keys from the config | 837 | * The code below wouldn't work because we can't delete groups/keys from the config |
838 | * ### for ODP make Config right! | 838 | * ### for ODP make Config right! |
839 | */ | 839 | */ |
840 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; | 840 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; |
841 | /* | 841 | /* |
842 | * Now safe for each path | 842 | * Now safe for each path |
843 | */ | 843 | */ |
844 | OConfig cfg( configName() ); | 844 | OConfig cfg( configName() ); |
845 | 845 | ||
846 | /* safe excluded items */ | 846 | /* safe excluded items */ |
847 | for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { | 847 | for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { |
848 | OConfigGroupSaver saver( &cfg, it.key() ); | 848 | OConfigGroupSaver saver( &cfg, it.key() ); |
849 | cfg.writeEntry("Excluded", it.data(), ',' ); | 849 | cfg.writeEntry("Excluded", it.data(), ',' ); |
850 | } | 850 | } |
851 | 851 | ||
852 | /* safe positions we could also see if positions.contains(path) and remove/write in the above loop | 852 | /* safe positions we could also see if positions.contains(path) and remove/write in the above loop |
853 | * ### Write a Test Suite that can profile these runs... | 853 | * ### Write a Test Suite that can profile these runs... |
854 | */ | 854 | */ |
855 | for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { | 855 | for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { |
856 | OConfigGroupSaver saver( &cfg, it.key() ); | 856 | OConfigGroupSaver saver( &cfg, it.key() ); |
857 | cfg.writeEntry("Positions", it.data(), '.' ); | 857 | cfg.writeEntry("Positions", it.data(), '.' ); |
858 | } | 858 | } |
859 | } | 859 | } |
860 | 860 | ||
861 | /** | 861 | /** |
862 | * @internal | 862 | * @internal |
863 | */ | 863 | */ |
864 | QString OPluginManager::configName()const { | 864 | QString OPluginManager::configName()const { |
865 | QString str = m_loader ? m_loader->name() : m_cfgName; | 865 | QString str = m_loader ? m_loader->name() : m_cfgName; |
866 | return str + "odpplugins"; | 866 | return str + "-odpplugins"; |
867 | } | 867 | } |
868 | 868 | ||
869 | /** | 869 | /** |
870 | * @internal.. replace in m_plugins by path... this is linear search O(n/2) | 870 | * @internal.. replace in m_plugins by path... this is linear search O(n/2) |
871 | */ | 871 | */ |
872 | void OPluginManager::replace( const OPluginItem& item ) { | 872 | void OPluginManager::replace( const OPluginItem& item ) { |
873 | OPluginItem _item; | 873 | OPluginItem _item; |
874 | 874 | ||
875 | /* for all plugins */ | 875 | /* for all plugins */ |
876 | for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { | 876 | for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { |
877 | _item = *it; | 877 | _item = *it; |
878 | /* if path and name are the same we will remove, readd and return */ | 878 | /* if path and name are the same we will remove, readd and return */ |
879 | if ( _item.path() == item.path() && | 879 | if ( _item.path() == item.path() && |
880 | _item.name() == item.name() ) { | 880 | _item.name() == item.name() ) { |
881 | it = m_plugins.remove( it ); | 881 | it = m_plugins.remove( it ); |
882 | m_plugins.append( item ); | 882 | m_plugins.append( item ); |
883 | return; | 883 | return; |
884 | } | 884 | } |
885 | 885 | ||
886 | } | 886 | } |
887 | } | 887 | } |
888 | 888 | ||
889 | } | 889 | } |
890 | } | 890 | } |