-rw-r--r-- | libopie2/opiecore/opluginloader.cpp | 18 | ||||
-rw-r--r-- | libopie2/opiecore/opluginloader.h | 1 |
2 files changed, 16 insertions, 3 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp index 2aca382..87e24d4 100644 --- a/libopie2/opiecore/opluginloader.cpp +++ b/libopie2/opiecore/opluginloader.cpp | |||
@@ -472,300 +472,299 @@ void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { | |||
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 | QStringList::Iterator it; | ||
569 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 568 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
570 | QString str = unlibify( *it ); | 569 | QString str = unlibify( *it ); |
571 | OPluginItem item( str, _dir + "/" + *it ); | 570 | OPluginItem item( str, _dir + "/" + *it ); |
572 | 571 | ||
573 | bool ex = excludedMap.contains( str ); | 572 | bool ex = excludedMap.contains( str ); |
574 | /* | 573 | /* |
575 | * if disabled but we should show all mark it as disabled | 574 | * if disabled but we should show all mark it as disabled |
576 | * else continue because we don't want to add the item | 575 | * else continue because we don't want to add the item |
577 | * else if sorted we assign the right position | 576 | * else if sorted we assign the right position |
578 | */ | 577 | */ |
579 | if ( ex && !disabled) | 578 | if ( ex && !disabled) |
580 | item.setEnabled( false ); | 579 | item.setEnabled( false ); |
581 | else if ( ex && disabled ) | 580 | else if ( ex && disabled ) |
582 | continue; | 581 | continue; |
583 | else if ( sorted ) | 582 | else if ( sorted ) |
584 | item.setPosition( positionMap[str] ); | 583 | item.setPosition( positionMap[str] ); |
585 | 584 | ||
586 | lst.append( item ); | 585 | lst.append( item ); |
587 | } | 586 | } |
588 | 587 | ||
589 | return lst; | 588 | return lst; |
590 | } | 589 | } |
591 | 590 | ||
592 | /** | 591 | /** |
593 | * @internal generate a list of languages from $LANG | 592 | * @internal generate a list of languages from $LANG |
594 | */ | 593 | */ |
595 | QStringList OGenericPluginLoader::languageList() { | 594 | QStringList OGenericPluginLoader::languageList() { |
596 | if ( m_languages.isEmpty() ) { | 595 | if ( m_languages.isEmpty() ) { |
597 | /* | 596 | /* |
598 | * 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 |
599 | * to our list of languages. | 598 | * to our list of languages. |
600 | */ | 599 | */ |
601 | QString str = ::getenv( "LANG" ); | 600 | QString str = ::getenv( "LANG" ); |
602 | m_languages += str; | 601 | m_languages += str; |
603 | int pos = str.find( '.' ); | 602 | int pos = str.find( '.' ); |
604 | 603 | ||
605 | if ( pos > 0 ) | 604 | if ( pos > 0 ) |
606 | m_languages += str.left( pos ); | 605 | m_languages += str.left( pos ); |
607 | 606 | ||
608 | int n_pos = str.find( '_' ); | 607 | int n_pos = str.find( '_' ); |
609 | if ( pos > 0 && n_pos >= pos ) | 608 | if ( pos > 0 && n_pos >= pos ) |
610 | m_languages += str.left( n_pos ); | 609 | m_languages += str.left( n_pos ); |
611 | 610 | ||
612 | } | 611 | } |
613 | return m_languages; | 612 | return m_languages; |
614 | } | 613 | } |
615 | 614 | ||
616 | /** | 615 | /** |
617 | * @internal | 616 | * @internal |
618 | * Tries to install languages using the languageList for the type | 617 | * Tries to install languages using the languageList for the type |
619 | */ | 618 | */ |
620 | void OGenericPluginLoader::installTranslators(const QString& type) { | 619 | void OGenericPluginLoader::installTranslators(const QString& type) { |
621 | QStringList lst = languageList(); | 620 | QStringList lst = languageList(); |
622 | 621 | ||
623 | /* | 622 | /* |
624 | * for each language and maybe later for each language dir... | 623 | * for each language and maybe later for each language dir... |
625 | * try to load a Translator | 624 | * try to load a Translator |
626 | */ | 625 | */ |
627 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { | 626 | for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { |
628 | QTranslator* trans = new QTranslator( qApp ); | 627 | QTranslator* trans = new QTranslator( qApp ); |
629 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; | 628 | QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; |
630 | 629 | ||
631 | /* | 630 | /* |
632 | * If loaded then install else clean up and don't leak | 631 | * If loaded then install else clean up and don't leak |
633 | */ | 632 | */ |
634 | if ( trans->load( tfn ) ) | 633 | if ( trans->load( tfn ) ) |
635 | qApp->installTranslator( trans ); | 634 | qApp->installTranslator( trans ); |
636 | else | 635 | else |
637 | delete trans; | 636 | delete trans; |
638 | } | 637 | } |
639 | } | 638 | } |
640 | 639 | ||
641 | /** | 640 | /** |
642 | * \brief Simple c'tor. | 641 | * \brief Simple c'tor. |
643 | * | 642 | * |
644 | * 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 |
645 | * class can cast for you if you nee it. | 644 | * class can cast for you if you nee it. |
646 | * | 645 | * |
647 | * | 646 | * |
648 | * @param name The name of your plugin class | 647 | * @param name The name of your plugin class |
649 | * @param sorted If plugins are sorted | 648 | * @param sorted If plugins are sorted |
650 | * | 649 | * |
651 | * @see OGenericPluginLoader | 650 | * @see OGenericPluginLoader |
652 | */ | 651 | */ |
653 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) | 652 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) |
654 | : OGenericPluginLoader( name, sorted ) | 653 | : OGenericPluginLoader( name, sorted ) |
655 | { | 654 | { |
656 | } | 655 | } |
657 | 656 | ||
658 | /** | 657 | /** |
659 | * d'tor | 658 | * d'tor |
660 | * @see OGenericPluginLoader::~OGenericPluginLoader | 659 | * @see OGenericPluginLoader::~OGenericPluginLoader |
661 | */ | 660 | */ |
662 | OPluginLoader::~OPluginLoader() { | 661 | OPluginLoader::~OPluginLoader() { |
663 | } | 662 | } |
664 | 663 | ||
665 | /** | 664 | /** |
666 | * \brief C'Tor using a OGenericPluginLoader | 665 | * \brief C'Tor using a OGenericPluginLoader |
667 | * The C'tor. Pass your OGenericPluginLoader to manage | 666 | * The C'tor. Pass your OGenericPluginLoader to manage |
668 | * OGenericPluginLoader::allAvailable plugins. | 667 | * OGenericPluginLoader::allAvailable plugins. |
669 | * | 668 | * |
670 | * | 669 | * |
671 | * @param loader A Pointer to your OGenericPluginLoader | 670 | * @param loader A Pointer to your OGenericPluginLoader |
672 | * @param name The name | 671 | * @param name The name |
673 | */ | 672 | */ |
674 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) | 673 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) |
675 | : m_loader( loader ) | 674 | : m_loader( loader ), m_isSorted( false ) |
676 | { | 675 | { |
677 | } | 676 | } |
678 | 677 | ||
679 | /** | 678 | /** |
680 | * \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 |
681 | * Overloaded Constructor to work with a 'Type' of plugins | 680 | * Overloaded Constructor to work with a 'Type' of plugins |
682 | * and a correspending list of those. In this case calling load | 681 | * and a correspending list of those. In this case calling load |
683 | * is a no operation. | 682 | * is a no operation. |
684 | * | 683 | * |
685 | * @param name The name of your plugin ('today','inputmethods','applets') | 684 | * @param name The name of your plugin ('today','inputmethods','applets') |
686 | * @param lst A List with plugins of your type to manage | 685 | * @param lst A List with plugins of your type to manage |
687 | * @param isSorted If the List should be treated sorted | 686 | * @param isSorted If the List should be treated sorted |
688 | */ | 687 | */ |
689 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) | 688 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) |
690 | : 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 ) |
691 | { | 690 | { |
692 | } | 691 | } |
693 | 692 | ||
694 | /** | 693 | /** |
695 | * \brief A simple d'tor | 694 | * \brief A simple d'tor |
696 | */ | 695 | */ |
697 | OPluginManager::~OPluginManager() { | 696 | OPluginManager::~OPluginManager() { |
698 | } | 697 | } |
699 | 698 | ||
700 | /** | 699 | /** |
701 | * \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. |
702 | 701 | ||
703 | * Return the Item that made the OGenericPluginLoader crash | 702 | * Return the Item that made the OGenericPluginLoader crash |
704 | * the returned OPluginItem could be empty if no crash occured | 703 | * the returned OPluginItem could be empty if no crash occured |
705 | * 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 |
706 | * plugin is not in the current list of available/managed plugins | 705 | * plugin is not in the current list of available/managed plugins |
707 | * | 706 | * |
708 | * @see OPluginItem::isEmpty | 707 | * @see OPluginItem::isEmpty |
709 | * @return OPluginItem that crashed the loader | 708 | * @return OPluginItem that crashed the loader |
710 | */ | 709 | */ |
711 | OPluginItem OPluginManager::crashedPlugin()const { | 710 | OPluginItem OPluginManager::crashedPlugin()const { |
712 | return m_crashed; | 711 | return m_crashed; |
713 | } | 712 | } |
714 | 713 | ||
715 | /** | 714 | /** |
716 | * \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 |
717 | * | 716 | * |
718 | * Return the list of managed plugins. This could either result | 717 | * Return the list of managed plugins. This could either result |
719 | * from passing a OGenericPluginLoader and calling load or by | 718 | * from passing a OGenericPluginLoader and calling load or by |
720 | * giving name and a list of plugins. | 719 | * giving name and a list of plugins. |
721 | */ | 720 | */ |
722 | OPluginItem::List OPluginManager::managedPlugins()const { | 721 | OPluginItem::List OPluginManager::managedPlugins()const { |
723 | return m_plugins; | 722 | return m_plugins; |
724 | } | 723 | } |
725 | 724 | ||
726 | /** | 725 | /** |
727 | * \brief Set the position of the items | 726 | * \brief Set the position of the items |
728 | * | 727 | * |
729 | * Replace the OPluginItem with the name and path and this way | 728 | * Replace the OPluginItem with the name and path and this way |
730 | * 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) |
731 | * 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 |
732 | * 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 |
733 | * | 732 | * |
734 | * @param item The OPluginItem to be replaced internall | 733 | * @param item The OPluginItem to be replaced internall |
735 | * | 734 | * |
736 | */ | 735 | */ |
737 | void OPluginManager::setPosition( const OPluginItem& item) { | 736 | void OPluginManager::setPosition( const OPluginItem& item) { |
738 | replace( item ); | 737 | replace( item ); |
739 | } | 738 | } |
740 | 739 | ||
741 | /** | 740 | /** |
742 | * \brief Enable the item specified as argument | 741 | * \brief Enable the item specified as argument |
743 | * | 742 | * |
744 | * 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 |
745 | * the item with one that matches name and path internally. | 744 | * the item with one that matches name and path internally. |
746 | * @see setPosition | 745 | * @see setPosition |
747 | * | 746 | * |
748 | * @param the Item to enable | 747 | * @param the Item to enable |
749 | */ | 748 | */ |
750 | void OPluginManager::enable( const OPluginItem& item ) { | 749 | void OPluginManager::enable( const OPluginItem& item ) { |
751 | setEnabled( item, true ); | 750 | setEnabled( item, true ); |
752 | } | 751 | } |
753 | 752 | ||
754 | /** | 753 | /** |
755 | * \brief disable the Item. | 754 | * \brief disable the Item. |
756 | * | 755 | * |
757 | * Disable the OPluginItem. Same applies as in | 756 | * Disable the OPluginItem. Same applies as in |
758 | * @see setPosition and @see enable | 757 | * @see setPosition and @see enable |
759 | * | 758 | * |
760 | * @param item Item to disable | 759 | * @param item Item to disable |
761 | */ | 760 | */ |
762 | void OPluginManager::disable( const OPluginItem& item) { | 761 | void OPluginManager::disable( const OPluginItem& item) { |
763 | setEnabled( item, false ); | 762 | setEnabled( item, false ); |
764 | } | 763 | } |
765 | 764 | ||
766 | /** | 765 | /** |
767 | * \brief Enable or disable the OPluginItem. | 766 | * \brief Enable or disable the OPluginItem. |
768 | * Depending on the value of the parameter this will either disable | 767 | * Depending on the value of the parameter this will either disable |
769 | * or enable the pluginitem. | 768 | * or enable the pluginitem. |
770 | * Beside that same as in @see disable, @see enable, @see setPosition | 769 | * Beside that same as in @see disable, @see enable, @see setPosition |
771 | * applies. | 770 | * applies. |
@@ -778,101 +777,114 @@ void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { | |||
778 | OPluginItem item = _item; | 777 | OPluginItem item = _item; |
779 | item.setEnabled( b ); | 778 | item.setEnabled( b ); |
780 | replace( item ); | 779 | replace( item ); |
781 | } | 780 | } |
782 | 781 | ||
783 | /** | 782 | /** |
784 | * \brief Load necessary information after constructing the object | 783 | * \brief Load necessary information after constructing the object |
785 | * If you speified a OGenericPluginLoader you need to call this method | 784 | * If you speified a OGenericPluginLoader you need to call this method |
786 | * 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 |
787 | * 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 |
788 | */ | 787 | */ |
789 | void OPluginManager::load() { | 788 | void OPluginManager::load() { |
790 | OConfig cfg( configName() ); | 789 | OConfig cfg( configName() ); |
791 | cfg.setGroup( "General" ); | 790 | cfg.setGroup( "General" ); |
792 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); | 791 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); |
793 | 792 | ||
794 | /* 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 */ |
795 | if ( m_loader ) | 794 | if ( m_loader ) |
796 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); | 795 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); |
797 | 796 | ||
798 | /* fast and normal route if we did not crash... */ | 797 | /* fast and normal route if we did not crash... */ |
799 | if ( crashedPath.isEmpty() ) | 798 | if ( crashedPath.isEmpty() ) |
800 | return; | 799 | return; |
801 | 800 | ||
802 | /* 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 */ |
803 | 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 ) |
804 | if ( (*it).path() == crashedPath ) { | 803 | if ( (*it).path() == crashedPath ) { |
805 | m_crashed = *it; | 804 | m_crashed = *it; |
806 | break; | 805 | break; |
807 | } | 806 | } |
808 | } | 807 | } |
809 | 808 | ||
810 | 809 | ||
811 | /** | 810 | /** |
812 | * \brief Save the values and this way make it available. | 811 | * \brief Save the values and this way make it available. |
813 | * | 812 | * |
814 | * 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 |
815 | * now would return your saved changes. | 814 | * now would return your saved changes. |
816 | */ | 815 | */ |
817 | void OPluginManager::save() { | 816 | void OPluginManager::save() { |
818 | QMap<QString, QStringList> excluded; // map for path to excluded name | 817 | QMap<QString, QStringList> excluded; // map for path to excluded name |
819 | 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 |
820 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; | 819 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; |
821 | 820 | ||
822 | /* | 821 | /* |
823 | * 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 |
824 | */ | 823 | */ |
825 | 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 ) { |
826 | OPluginItem item = *it; | 825 | OPluginItem item = *it; |
827 | QString path = QFileInfo( item.path() ).filePath(); | 826 | QString path = QFileInfo( item.path() ).filePath(); |
828 | if ( sorted ) { | 827 | if ( sorted ) { |
829 | positions[path].append( item.name() ); | 828 | positions[path].append( item.name() ); |
830 | positions[path].append( QString::number( item.position() ) ); | 829 | positions[path].append( QString::number( item.position() ) ); |
831 | } | 830 | } |
832 | 831 | ||
833 | if ( !item.isEnabled() ) | 832 | if ( !item.isEnabled() ) |
834 | excluded[path].append( item.name() ); | 833 | excluded[path].append( item.name() ); |
835 | } | 834 | } |
836 | 835 | ||
837 | /* | 836 | /* |
838 | * 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 |
839 | * ### for ODP make Config right! | 838 | * ### for ODP make Config right! |
840 | */ | 839 | */ |
841 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; | 840 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; |
842 | /* | 841 | /* |
843 | * Now safe for each path | 842 | * Now safe for each path |
844 | */ | 843 | */ |
845 | OConfig cfg( configName() ); | 844 | OConfig cfg( configName() ); |
846 | 845 | ||
847 | /* safe excluded items */ | 846 | /* safe excluded items */ |
848 | 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 ) { |
849 | OConfigGroupSaver saver( &cfg, it.key() ); | 848 | OConfigGroupSaver saver( &cfg, it.key() ); |
850 | cfg.writeEntry("Excluded", it.data(), ',' ); | 849 | cfg.writeEntry("Excluded", it.data(), ',' ); |
851 | } | 850 | } |
852 | 851 | ||
853 | /* 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 |
854 | * ### Write a Test Suite that can profile these runs... | 853 | * ### Write a Test Suite that can profile these runs... |
855 | */ | 854 | */ |
856 | 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 ) { |
857 | OConfigGroupSaver saver( &cfg, it.key() ); | 856 | OConfigGroupSaver saver( &cfg, it.key() ); |
858 | cfg.writeEntry("Positions", it.data(), '.' ); | 857 | cfg.writeEntry("Positions", it.data(), '.' ); |
859 | } | 858 | } |
860 | } | 859 | } |
861 | 860 | ||
862 | /** | 861 | /** |
863 | * @internal | 862 | * @internal |
864 | */ | 863 | */ |
865 | QString OPluginManager::configName()const { | 864 | QString OPluginManager::configName()const { |
866 | QString str = m_loader ? m_loader->name() : m_cfgName; | 865 | QString str = m_loader ? m_loader->name() : m_cfgName; |
867 | return str + "odpplugins"; | 866 | return str + "odpplugins"; |
868 | } | 867 | } |
869 | 868 | ||
870 | /** | 869 | /** |
871 | * @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) |
872 | */ | 871 | */ |
873 | void OPluginManager::replace( const OPluginItem& item ) { | 872 | void OPluginManager::replace( const OPluginItem& item ) { |
874 | // ### fixme | 873 | OPluginItem _item; |
874 | |||
875 | /* for all plugins */ | ||
876 | for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { | ||
877 | _item = *it; | ||
878 | /* if path and name are the same we will remove, readd and return */ | ||
879 | if ( _item.path() == item.path() && | ||
880 | _item.name() == item.name() ) { | ||
881 | it = m_plugins.remove( it ); | ||
882 | m_plugins.append( item ); | ||
883 | return; | ||
884 | } | ||
885 | |||
886 | } | ||
875 | } | 887 | } |
876 | 888 | ||
877 | } | 889 | } |
878 | } | 890 | } |
diff --git a/libopie2/opiecore/opluginloader.h b/libopie2/opiecore/opluginloader.h index 2f9ec2a..740551c 100644 --- a/libopie2/opiecore/opluginloader.h +++ b/libopie2/opiecore/opluginloader.h | |||
@@ -64,143 +64,144 @@ private: | |||
64 | * \brief A generic class to easily load and manage plugins | 64 | * \brief A generic class to easily load and manage plugins |
65 | * | 65 | * |
66 | * This is the generic non sepcialised loader for plugins. Normally | 66 | * This is the generic non sepcialised loader for plugins. Normally |
67 | * you would prefer using the OPluginLoader directly. This class | 67 | * you would prefer using the OPluginLoader directly. This class |
68 | * exists to minimize the application binary size due the usage | 68 | * exists to minimize the application binary size due the usage |
69 | * of templates in the specialized API | 69 | * of templates in the specialized API |
70 | * | 70 | * |
71 | * @since 1.2 | 71 | * @since 1.2 |
72 | * @see OPluginLoader | 72 | * @see OPluginLoader |
73 | */ | 73 | */ |
74 | class OGenericPluginLoader { | 74 | class OGenericPluginLoader { |
75 | public: | 75 | public: |
76 | typedef OPluginItem::List List; | 76 | typedef OPluginItem::List List; |
77 | OGenericPluginLoader( const QString &name, bool isSorted = false ); | 77 | OGenericPluginLoader( const QString &name, bool isSorted = false ); |
78 | virtual ~OGenericPluginLoader(); | 78 | virtual ~OGenericPluginLoader(); |
79 | 79 | ||
80 | void setAutoDelete( bool ); | 80 | void setAutoDelete( bool ); |
81 | bool autoDelete()const; | 81 | bool autoDelete()const; |
82 | void clear(); | 82 | void clear(); |
83 | 83 | ||
84 | QString name()const; | 84 | QString name()const; |
85 | bool isSorted()const; | 85 | bool isSorted()const; |
86 | bool isInSafeMode()const; | 86 | bool isInSafeMode()const; |
87 | 87 | ||
88 | 88 | ||
89 | List allAvailable(bool sorted = false )const; | 89 | List allAvailable(bool sorted = false )const; |
90 | List filtered(bool sorted = false )const; | 90 | List filtered(bool sorted = false )const; |
91 | 91 | ||
92 | 92 | ||
93 | virtual QUnknownInterface* load( const OPluginItem& item, const QUuid& ); | 93 | virtual QUnknownInterface* load( const OPluginItem& item, const QUuid& ); |
94 | virtual void unload( QUnknownInterface* ); | 94 | virtual void unload( QUnknownInterface* ); |
95 | 95 | ||
96 | protected: | 96 | protected: |
97 | friend class OPluginManager; // we need the static unlibify | 97 | friend class OPluginManager; // we need the static unlibify |
98 | void readConfig(); | 98 | void readConfig(); |
99 | virtual List plugins( const QString& dir, bool sorted, bool disabled )const; | 99 | virtual List plugins( const QString& dir, bool sorted, bool disabled )const; |
100 | void setPluginDirs( const QStringList& ); | 100 | void setPluginDirs( const QStringList& ); |
101 | void setPluginDir( const QString& ); | 101 | void setPluginDir( const QString& ); |
102 | void setSafeMode(const QString& app = QString::null, bool b = false); | 102 | void setSafeMode(const QString& app = QString::null, bool b = false); |
103 | static QString unlibify( const QString& str ); | 103 | static QString unlibify( const QString& str ); |
104 | private: | 104 | private: |
105 | QStringList languageList(); | 105 | QStringList languageList(); |
106 | void installTranslators(const QString& type); | 106 | void installTranslators(const QString& type); |
107 | QString m_dir; | 107 | QString m_dir; |
108 | QStringList m_plugDirs; | 108 | QStringList m_plugDirs; |
109 | QStringList m_languages; | 109 | QStringList m_languages; |
110 | bool m_autoDelete : 1; | 110 | bool m_autoDelete : 1; |
111 | bool m_isSafeMode : 1; | 111 | bool m_isSafeMode : 1; |
112 | bool m_isSorted : 1; | 112 | bool m_isSorted : 1; |
113 | QPtrDict<QLibrary> m_library; | 113 | QPtrDict<QLibrary> m_library; |
114 | 114 | ||
115 | struct Private; | 115 | struct Private; |
116 | Private* d; | 116 | Private* d; |
117 | }; | 117 | }; |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * \brief The class to load your QCOM+ plugins | 120 | * \brief The class to load your QCOM+ plugins |
121 | * | 121 | * |
122 | * This class takes care of activation and even the order | 122 | * This class takes care of activation and even the order |
123 | * if you need it. It is normally good to place a .directory file | 123 | * if you need it. It is normally good to place a .directory file |
124 | * into your plugin directory if you need order of activation. | 124 | * into your plugin directory if you need order of activation. |
125 | * | 125 | * |
126 | * You'll create the OPluginLoader and then use it to load the filtered | 126 | * You'll create the OPluginLoader and then use it to load the filtered |
127 | * plugins. | 127 | * plugins. |
128 | * | 128 | * |
129 | * There is also a GUI for the configuration and a Manager to write the | 129 | * There is also a GUI for the configuration and a Manager to write the |
130 | * mentioned .directory file | 130 | * mentioned .directory file |
131 | * | 131 | * |
132 | * On crash the safe mode is activated for the next run. You can then decide | 132 | * On crash the safe mode is activated for the next run. You can then decide |
133 | * if you want to load plugins or come up with the Configuration on | 133 | * if you want to load plugins or come up with the Configuration on |
134 | * next start yourself then. | 134 | * next start yourself then. |
135 | * | 135 | * |
136 | * @since 1.2 | 136 | * @since 1.2 |
137 | */ | 137 | */ |
138 | class OPluginLoader : public OGenericPluginLoader { | 138 | class OPluginLoader : public OGenericPluginLoader { |
139 | public: | 139 | public: |
140 | OPluginLoader( const QString& name, bool sorted = false ); | 140 | OPluginLoader( const QString& name, bool sorted = false ); |
141 | virtual ~OPluginLoader(); | 141 | virtual ~OPluginLoader(); |
142 | 142 | ||
143 | template<class IFace> | 143 | template<class IFace> |
144 | IFace* load( const OPluginItem& item, const QUuid& ); | 144 | IFace* load( const OPluginItem& item, const QUuid& ); |
145 | }; | 145 | }; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * \brief A class to manage order and activation of plugins | 148 | * \brief A class to manage order and activation of plugins |
149 | * | 149 | * |
150 | * Manage order and activation. This is used by the Opie::Ui::OPluginConfig | 150 | * Manage order and activation. This is used by the Opie::Ui::OPluginConfig |
151 | * This class controls the activation and order of plugins depending | 151 | * This class controls the activation and order of plugins depending |
152 | * on the OPluginLoader you supply. | 152 | * on the OPluginLoader you supply. |
153 | * You must call load() and save after construnction an instance | 153 | * You must call load() and save after construnction an instance |
154 | * | 154 | * |
155 | * @see Opie::Ui::OPluginConfig | 155 | * @see Opie::Ui::OPluginConfig |
156 | * | 156 | * |
157 | */ | 157 | */ |
158 | class OPluginManager { | 158 | class OPluginManager { |
159 | public: | 159 | public: |
160 | typedef QValueList<OPluginManager*> List; | ||
160 | OPluginManager( OGenericPluginLoader* ); | 161 | OPluginManager( OGenericPluginLoader* ); |
161 | OPluginManager( const QString& name, const OPluginItem::List&, bool isSorted = false ); | 162 | OPluginManager( const QString& name, const OPluginItem::List&, bool isSorted = false ); |
162 | virtual ~OPluginManager(); | 163 | virtual ~OPluginManager(); |
163 | 164 | ||
164 | OPluginItem crashedPlugin()const; | 165 | OPluginItem crashedPlugin()const; |
165 | 166 | ||
166 | OPluginItem::List managedPlugins()const; | 167 | OPluginItem::List managedPlugins()const; |
167 | 168 | ||
168 | void setPosition( const OPluginItem& ); | 169 | void setPosition( const OPluginItem& ); |
169 | void enable( const OPluginItem& ); | 170 | void enable( const OPluginItem& ); |
170 | void disable( const OPluginItem& ); | 171 | void disable( const OPluginItem& ); |
171 | void setEnabled( const OPluginItem&, bool = true); | 172 | void setEnabled( const OPluginItem&, bool = true); |
172 | 173 | ||
173 | virtual void load(); | 174 | virtual void load(); |
174 | virtual void save(); | 175 | virtual void save(); |
175 | 176 | ||
176 | protected: | 177 | protected: |
177 | QString configName()const; | 178 | QString configName()const; |
178 | void replace( const OPluginItem& ); | 179 | void replace( const OPluginItem& ); |
179 | private: | 180 | private: |
180 | OGenericPluginLoader *m_loader; | 181 | OGenericPluginLoader *m_loader; |
181 | QString m_cfgName; | 182 | QString m_cfgName; |
182 | OPluginItem::List m_plugins; | 183 | OPluginItem::List m_plugins; |
183 | OPluginItem m_crashed; | 184 | OPluginItem m_crashed; |
184 | bool m_isSorted : 1; | 185 | bool m_isSorted : 1; |
185 | }; | 186 | }; |
186 | 187 | ||
187 | 188 | ||
188 | /** | 189 | /** |
189 | * This is a template method allowing you to safely cast | 190 | * This is a template method allowing you to safely cast |
190 | * your load function | 191 | * your load function |
191 | * | 192 | * |
192 | * \code | 193 | * \code |
193 | * MyTypePlugin *plug = load->load<MyTypePlugin>( item, IID_MyPlugin ); | 194 | * MyTypePlugin *plug = load->load<MyTypePlugin>( item, IID_MyPlugin ); |
194 | * \endcode | 195 | * \endcode |
195 | * | 196 | * |
196 | */ | 197 | */ |
197 | template<class IFace> | 198 | template<class IFace> |
198 | IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) { | 199 | IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) { |
199 | return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) ); | 200 | return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) ); |
200 | } | 201 | } |
201 | 202 | ||
202 | } | 203 | } |
203 | } | 204 | } |
204 | 205 | ||
205 | 206 | ||
206 | #endif | 207 | #endif |