summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-28 22:49:15 (UTC)
committer zecke <zecke>2004-05-28 22:49:15 (UTC)
commit08998f34ec77062224dc0783be78d9e6e3bf7910 (patch) (unidiff)
treeef7855f9ead12b408e9b4b3ca7f6f8f58466016f
parente15f3bb9f0a652076050ddcfb0c31a16ae845373 (diff)
downloadopie-08998f34ec77062224dc0783be78d9e6e3bf7910.zip
opie-08998f34ec77062224dc0783be78d9e6e3bf7910.tar.gz
opie-08998f34ec77062224dc0783be78d9e6e3bf7910.tar.bz2
Make harlekin happy. AkA uncomitted code
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opluginloader.cpp18
-rw-r--r--libopie2/opiecore/opluginloader.h1
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
@@ -520,97 +520,96 @@ QString OGenericPluginLoader::unlibify( const QString& str ) {
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 */
529OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { 529OPluginItem::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 */
595QStringList OGenericPluginLoader::languageList() { 594QStringList 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/**
@@ -627,97 +626,97 @@ void OGenericPluginLoader::installTranslators(const QString& type) {
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 */
653OPluginLoader::OPluginLoader( const QString& name, bool sorted ) 652OPluginLoader::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 */
662OPluginLoader::~OPluginLoader() { 661OPluginLoader::~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 */
674OPluginManager::OPluginManager( OGenericPluginLoader* loader) 673OPluginManager::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 */
689OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) 688OPluginManager::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 */
697OPluginManager::~OPluginManager() { 696OPluginManager::~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 */
711OPluginItem OPluginManager::crashedPlugin()const { 710OPluginItem 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 */
722OPluginItem::List OPluginManager::managedPlugins()const { 721OPluginItem::List OPluginManager::managedPlugins()const {
723 return m_plugins; 722 return m_plugins;
@@ -826,53 +825,66 @@ void OPluginManager::save() {
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 */
865QString OPluginManager::configName()const { 864QString 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 */
873void OPluginManager::replace( const OPluginItem& item ) { 872void 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
@@ -112,95 +112,96 @@ private:
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 */
138class OPluginLoader : public OGenericPluginLoader { 138class OPluginLoader : public OGenericPluginLoader {
139public: 139public:
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 */
158class OPluginManager { 158class OPluginManager {
159public: 159public:
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
176protected: 177protected:
177 QString configName()const; 178 QString configName()const;
178 void replace( const OPluginItem& ); 179 void replace( const OPluginItem& );
179private: 180private:
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 */
197template<class IFace> 198template<class IFace>
198IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) { 199IFace* 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