summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-12 23:18:37 (UTC)
committer zecke <zecke>2004-09-12 23:18:37 (UTC)
commitf05a19bd1e248ea8cea29d361a1a8085ca145c6a (patch) (unidiff)
treeae7204968f4e8841232a976eb9cc341db65dca50
parent8123b75c55cb5140ae5b0c5aeddb4644a0a8ffbb (diff)
downloadopie-f05a19bd1e248ea8cea29d361a1a8085ca145c6a.zip
opie-f05a19bd1e248ea8cea29d361a1a8085ca145c6a.tar.gz
opie-f05a19bd1e248ea8cea29d361a1a8085ca145c6a.tar.bz2
If there is no 'excluded' plugin the excluded-list wasn't made
empty and the old/prior setting still was used. This fix makes sure that an empty string is written if no plugin is excluded
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opluginloader.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp
index 1edf3a1..b8b6b79 100644
--- a/libopie2/opiecore/opluginloader.cpp
+++ b/libopie2/opiecore/opluginloader.cpp
@@ -498,154 +498,158 @@ 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 */
509QString OGenericPluginLoader::unlibify( const QString& str ) { 509QString 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 */
530OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { 530OPluginItem::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 while ( it != pos.end() ) 562 QString tmp; int i;
563 positionMap.insert( *it++, (*it++).toInt() ); 563 while ( it != pos.end() ) {
564 tmp = *it++; i = (*it++).toInt();
565 positionMap.insert( tmp, i );
566 }
564 567
565 } 568 }
566 569
567 570
568 571
569 572
570 QStringList list = dir.entryList(); 573 QStringList list = dir.entryList();
571 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 574 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
572 QString str = unlibify( *it ); 575 QString str = unlibify( *it );
573 OPluginItem item( str, _dir + "/" + *it ); 576 OPluginItem item( str, _dir + "/" + *it );
574 577
575 bool ex = excludedMap.contains( str ); 578 bool ex = excludedMap.contains( str );
576 /* 579 /*
577 * if disabled but we should show all mark it as disabled 580 * if disabled but we should show all mark it as disabled
578 * else continue because we don't want to add the item 581 * else continue because we don't want to add the item
579 * else if sorted we assign the right position 582 * else if sorted we assign the right position
580 */ 583 */
581 if ( ex && !disabled) 584 if ( ex && !disabled)
582 item.setEnabled( false ); 585 item.setEnabled( false );
583 else if ( ex && disabled ) 586 else if ( ex && disabled )
584 continue; 587 continue;
585 else if ( sorted ) 588 else if ( sorted )
586 item.setPosition( positionMap[str] ); 589 item.setPosition( positionMap[str] );
587 590
591
588 lst.append( item ); 592 lst.append( item );
589 } 593 }
590 594
591 return lst; 595 return lst;
592} 596}
593 597
594/** 598/**
595 * @internal generate a list of languages from $LANG 599 * @internal generate a list of languages from $LANG
596 */ 600 */
597QStringList OGenericPluginLoader::languageList() { 601QStringList OGenericPluginLoader::languageList() {
598 if ( m_languages.isEmpty() ) { 602 if ( m_languages.isEmpty() ) {
599 /* 603 /*
600 * 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
601 * to our list of languages. 605 * to our list of languages.
602 */ 606 */
603 QString str = ::getenv( "LANG" ); 607 QString str = ::getenv( "LANG" );
604 m_languages += str; 608 m_languages += str;
605 int pos = str.find( '.' ); 609 int pos = str.find( '.' );
606 610
607 if ( pos > 0 ) 611 if ( pos > 0 )
608 m_languages += str.left( pos ); 612 m_languages += str.left( pos );
609 613
610 int n_pos = str.find( '_' ); 614 int n_pos = str.find( '_' );
611 if ( pos > 0 && n_pos >= pos ) 615 if ( pos > 0 && n_pos >= pos )
612 m_languages += str.left( n_pos ); 616 m_languages += str.left( n_pos );
613 617
614 } 618 }
615 return m_languages; 619 return m_languages;
616} 620}
617 621
618/** 622/**
619 * @internal 623 * @internal
620 * Tries to install languages using the languageList for the type 624 * Tries to install languages using the languageList for the type
621 */ 625 */
622void OGenericPluginLoader::installTranslators(const QString& type) { 626void OGenericPluginLoader::installTranslators(const QString& type) {
623 QStringList lst = languageList(); 627 QStringList lst = languageList();
624 628
625 /* 629 /*
626 * for each language and maybe later for each language dir... 630 * for each language and maybe later for each language dir...
627 * try to load a Translator 631 * try to load a Translator
628 */ 632 */
629 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { 633 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
630 QTranslator* trans = new QTranslator( qApp ); 634 QTranslator* trans = new QTranslator( qApp );
631 QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; 635 QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ;
632 636
633 /* 637 /*
634 * If loaded then install else clean up and don't leak 638 * If loaded then install else clean up and don't leak
635 */ 639 */
636 if ( trans->load( tfn ) ) 640 if ( trans->load( tfn ) )
637 qApp->installTranslator( trans ); 641 qApp->installTranslator( trans );
638 else 642 else
639 delete trans; 643 delete trans;
640 } 644 }
641} 645}
642 646
643/** 647/**
644 * \brief Simple c'tor. 648 * \brief Simple c'tor.
645 * 649 *
646 * Simple C'tor same as the one of the base class. Additional this 650 * Simple C'tor same as the one of the base class. Additional this
647 * class can cast for you if you nee it. 651 * class can cast for you if you nee it.
648 * 652 *
649 * 653 *
650 * @param name The name of your plugin class 654 * @param name The name of your plugin class
651 * @param sorted If plugins are sorted 655 * @param sorted If plugins are sorted
@@ -773,121 +777,124 @@ void OPluginManager::disable( const OPluginItem& item) {
773 * applies. 777 * applies.
774 * 778 *
775 * @param _item The OPluginItem to enable or to disable. 779 * @param _item The OPluginItem to enable or to disable.
776 * @param b Enable or disable the plugin. 780 * @param b Enable or disable the plugin.
777 * 781 *
778 */ 782 */
779void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { 783void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) {
780 OPluginItem item = _item; 784 OPluginItem item = _item;
781 item.setEnabled( b ); 785 item.setEnabled( b );
782 replace( item ); 786 replace( item );
783} 787}
784 788
785/** 789/**
786 * \brief Load necessary information after constructing the object 790 * \brief Load necessary information after constructing the object
787 * If you speified a OGenericPluginLoader you need to call this method 791 * If you speified a OGenericPluginLoader you need to call this method
788 * so that this manager knows what to manage and have a right value for \sa crashedPlugin 792 * so that this manager knows what to manage and have a right value for \sa crashedPlugin
789 * For the name and the list of plugins this does only try to find out the crashed plugin 793 * For the name and the list of plugins this does only try to find out the crashed plugin
790 */ 794 */
791void OPluginManager::load() { 795void OPluginManager::load() {
792 OConfig cfg( configName() ); 796 OConfig cfg( configName() );
793 cfg.setGroup( "General" ); 797 cfg.setGroup( "General" );
794 QString crashedPath = cfg.readEntry( "CrashedPlugin" ); 798 QString crashedPath = cfg.readEntry( "CrashedPlugin" );
795 799
796 /* if we've a loader this applies if we were called from the first part */ 800 /* if we've a loader this applies if we were called from the first part */
797 if ( m_loader ) 801 if ( m_loader )
798 m_plugins = m_loader->allAvailable( m_loader->isSorted() ); 802 m_plugins = m_loader->allAvailable( m_loader->isSorted() );
799 803
800 /* fast and normal route if we did not crash... */ 804 /* fast and normal route if we did not crash... */
801 if ( crashedPath.isEmpty() ) 805 if ( crashedPath.isEmpty() )
802 return; 806 return;
803 807
804 /* lets try to find the plugin path and this way the associated item */ 808 /* lets try to find the plugin path and this way the associated item */
805 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) 809 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it )
806 if ( (*it).path() == crashedPath ) { 810 if ( (*it).path() == crashedPath ) {
807 m_crashed = *it; 811 m_crashed = *it;
808 break; 812 break;
809 } 813 }
810} 814}
811 815
812 816
813/** 817/**
814 * \brief Save the values and this way make it available. 818 * \brief Save the values and this way make it available.
815 * 819 *
816 * Save the current set of data. A call to @see OGenericPluginLoader::filtered 820 * Save the current set of data. A call to @see OGenericPluginLoader::filtered
817 * now would return your saved changes. 821 * now would return your saved changes.
818 */ 822 */
819void OPluginManager::save() { 823void OPluginManager::save() {
820 QMap<QString, QStringList> excluded; // map for path to excluded name 824 QMap<QString, QStringList> excluded; // map for path to excluded name
821 QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs 825 QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs
822 bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; 826 bool sorted = m_loader ? m_loader->isSorted() : m_isSorted;
823 827
824 /* 828 /*
825 * We will create some maps for the groups to include positions a 829 * We will create some maps for the groups to include positions a
826 */ 830 */
827 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { 831 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) {
828 OPluginItem item = *it; 832 OPluginItem item = *it;
829 QString path = QFileInfo( item.path() ).dirPath(true); 833 QString path = QFileInfo( item.path() ).dirPath(true);
830 if ( sorted ) { 834 if ( sorted ) {
831 positions[path].append( item.name() ); 835 positions[path].append( item.name() );
832 positions[path].append( QString::number( item.position() ) ); 836 positions[path].append( QString::number( item.position() ) );
833 } 837 }
834 838
835 if ( !item.isEnabled() ) 839 if ( !item.isEnabled() )
836 excluded[path].append( item.name() ); 840 excluded[path].append( item.name() );
841 if ( !excluded.contains( path ) )
842 excluded[path] = QString::null;
843
837 } 844 }
838 845
839/* 846/*
840 * The code below wouldn't work because we can't delete groups/keys from the config 847 * The code below wouldn't work because we can't delete groups/keys from the config
841 * ### for ODP make Config right! 848 * ### for ODP make Config right!
842 */ 849 */
843// if ( excluded.isEmpty() && positions.isEmpty() ) return; 850// if ( excluded.isEmpty() && positions.isEmpty() ) return;
844 /* 851 /*
845 * Now safe for each path 852 * Now safe for each path
846 */ 853 */
847 OConfig cfg( configName() ); 854 OConfig cfg( configName() );
848 855
849 /* safe excluded items */ 856 /* safe excluded items */
850 for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { 857 for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) {
851 OConfigGroupSaver saver( &cfg, it.key() ); 858 OConfigGroupSaver saver( &cfg, it.key() );
852 cfg.writeEntry("Excluded", it.data(), ',' ); 859 cfg.writeEntry("Excluded", it.data(), ',' );
853 } 860 }
854 861
855 /* safe positions we could also see if positions.contains(path) and remove/write in the above loop 862 /* safe positions we could also see if positions.contains(path) and remove/write in the above loop
856 * ### Write a Test Suite that can profile these runs... 863 * ### Write a Test Suite that can profile these runs...
857 */ 864 */
858 for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { 865 for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) {
859 OConfigGroupSaver saver( &cfg, it.key() ); 866 OConfigGroupSaver saver( &cfg, it.key() );
860 cfg.writeEntry("Positions", it.data(), '.' ); 867 cfg.writeEntry("Positions", it.data(), '.' );
861 } 868 }
862} 869}
863 870
864/** 871/**
865 * @internal 872 * @internal
866 */ 873 */
867QString OPluginManager::configName()const { 874QString OPluginManager::configName()const {
868 QString str = m_loader ? m_loader->name() : m_cfgName; 875 QString str = m_loader ? m_loader->name() : m_cfgName;
869 return str + "-odpplugins"; 876 return str + "-odpplugins";
870} 877}
871 878
872/** 879/**
873 * @internal.. replace in m_plugins by path... this is linear search O(n/2) 880 * @internal.. replace in m_plugins by path... this is linear search O(n/2)
874 */ 881 */
875void OPluginManager::replace( const OPluginItem& item ) { 882void OPluginManager::replace( const OPluginItem& item ) {
876 OPluginItem _item; 883 OPluginItem _item;
877 884
878 /* for all plugins */ 885 /* for all plugins */
879 for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { 886 for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) {
880 _item = *it; 887 _item = *it;
881 /* if path and name are the same we will remove, readd and return */ 888 /* if path and name are the same we will remove, readd and return */
882 if ( _item.path() == item.path() && 889 if ( _item.path() == item.path() &&
883 _item.name() == item.name() ) { 890 _item.name() == item.name() ) {
884 it = m_plugins.remove( it ); 891 it = m_plugins.remove( it );
885 m_plugins.append( item ); 892 m_plugins.append( item );
886 return; 893 return;
887 } 894 }
888 895
889 } 896 }
890} 897}
891 898
892} 899}
893} 900}