Diffstat (limited to 'libopie2/opiecore/opluginloader.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiecore/opluginloader.cpp | 359 |
1 files changed, 348 insertions, 11 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp index b473cd7..2aca382 100644 --- a/libopie2/opiecore/opluginloader.cpp +++ b/libopie2/opiecore/opluginloader.cpp | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <qdir.h> | 11 | #include <qdir.h> |
12 | #include <qdict.h> | 12 | #include <qdict.h> |
13 | #include <qtl.h> | 13 | #include <qtl.h> |
14 | #include <qfile.h> | ||
14 | 15 | ||
15 | #include <stdlib.h> | 16 | #include <stdlib.h> |
16 | 17 | ||
@@ -110,18 +111,22 @@ OPluginItem::OPluginItem() | |||
110 | } | 111 | } |
111 | 112 | ||
112 | /** | 113 | /** |
114 | * @todo Create Internal name so we can have the plugin names translated. Or only for the gui? I'm not yet sure | ||
113 | * \brief Create an OPluginItem | 115 | * \brief Create an OPluginItem |
114 | * | 116 | * |
115 | * Create a Plugin Item with all information. | 117 | * Create a Plugin Item with all information. If you for some reasons |
118 | * need to create your own OPluginItems make sure that 'name' is always the same | ||
119 | * as it if used for positions and exclude list. | ||
116 | * | 120 | * |
117 | * @param name The if available translated Name | 121 | * @param name The if available translated Name |
118 | * @param path The path to the plugin | 122 | * @param path The path to the plugin must be absolute. |
123 | * @param b If the OPluginItem is enabled or not | ||
119 | * @param pos The position of the plugin if used for sorting | 124 | * @param pos The position of the plugin if used for sorting |
120 | * | 125 | * |
121 | */ | 126 | */ |
122 | OPluginItem::OPluginItem( const QString& name, const QString& path, int pos ) | 127 | OPluginItem::OPluginItem( const QString& name, const QString& path, bool b, int pos ) |
123 | : m_name( name ), m_path( path ), m_pos( pos ) { | 128 | : m_name( name ), m_path( path ), m_enabled( b ), m_pos( pos ) |
124 | } | 129 | {} |
125 | 130 | ||
126 | /** | 131 | /** |
127 | * \brief simple d'tor | 132 | * \brief simple d'tor |
@@ -130,20 +135,44 @@ OPluginItem::~OPluginItem() { | |||
130 | } | 135 | } |
131 | 136 | ||
132 | /** | 137 | /** |
138 | * \brief Test if this Item is Empty and does not represent a loadable plugin | ||
139 | * Test if a OPluginItem is empty. A OPluginItem is empty if name and path are empty | ||
140 | * ,pos equals -1 and the item is disabled | ||
141 | * | ||
142 | * @see QString::isEmpty() | ||
143 | * | ||
144 | */ | ||
145 | bool OPluginItem::isEmpty()const { | ||
146 | if ( m_pos != -1 ) return false; | ||
147 | if ( m_enabled ) return false; | ||
148 | if ( !m_name.isEmpty() ) return false; | ||
149 | if ( !m_path.isEmpty() ) return false; | ||
150 | |||
151 | return true; | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * \brief test equality | ||
133 | * operator to test equalness of two OPluginItem | 156 | * operator to test equalness of two OPluginItem |
134 | */ | 157 | */ |
135 | bool OPluginItem::operator==( const OPluginItem& r )const{ | 158 | bool OPluginItem::operator==( const OPluginItem& r )const{ |
136 | if ( m_pos != r.m_pos ) return false; | 159 | if ( m_pos != r.m_pos ) return false; |
160 | if ( m_enabled != r.m_enabled) return false; | ||
137 | if ( m_name != r.m_name ) return false; | 161 | if ( m_name != r.m_name ) return false; |
138 | if ( m_path != r.m_path ) return false; | 162 | if ( m_path != r.m_path ) return false; |
139 | return true; | 163 | return true; |
140 | } | 164 | } |
141 | 165 | ||
166 | /** | ||
167 | * \brief test non equality | ||
168 | * operator to test non-equalness of two OPluginItem | ||
169 | */ | ||
142 | bool OPluginItem::operator!=( const OPluginItem& r )const{ | 170 | bool OPluginItem::operator!=( const OPluginItem& r )const{ |
143 | return !( *this == r ); | 171 | return !( *this == r ); |
144 | } | 172 | } |
145 | 173 | ||
146 | /** | 174 | /** |
175 | * \brief returns the name of the plugin | ||
147 | * return the name of this Plugin | 176 | * return the name of this Plugin |
148 | */ | 177 | */ |
149 | QString OPluginItem::name()const { | 178 | QString OPluginItem::name()const { |
@@ -151,17 +180,35 @@ QString OPluginItem::name()const { | |||
151 | } | 180 | } |
152 | 181 | ||
153 | /** | 182 | /** |
154 | * return the path of the plugin | 183 | * \brief return the path of the plugin |
155 | */ | 184 | */ |
156 | QString OPluginItem::path()const { | 185 | QString OPluginItem::path()const { |
157 | return m_path; | 186 | return m_path; |
158 | } | 187 | } |
159 | 188 | ||
189 | /** | ||
190 | * \brief Return if this item is enabled. | ||
191 | */ | ||
192 | bool OPluginItem::isEnabled()const { | ||
193 | return m_enabled; | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * \brief return the position of a plugin. | ||
198 | * return the position of the item | ||
199 | * -1 is the default value and means normally that the whole items are unsorted. | ||
200 | * Higher numbers belong to an upper position. With plugins with the postions 20,19,5,3 | ||
201 | * the item with pos 20 would be the first in the list returned by the OGenericPluginLoader | ||
202 | * | ||
203 | * @see OGenericPluginLoader::allAvailable | ||
204 | * @see OGenericPluginLoader::filtered | ||
205 | */ | ||
160 | int OPluginItem::position()const{ | 206 | int OPluginItem::position()const{ |
161 | return m_pos; | 207 | return m_pos; |
162 | } | 208 | } |
163 | 209 | ||
164 | /** | 210 | /** |
211 | * \brief set the name of a plugin | ||
165 | * Set the name of the Plugin Item | 212 | * Set the name of the Plugin Item |
166 | * @param name | 213 | * @param name |
167 | */ | 214 | */ |
@@ -170,7 +217,8 @@ void OPluginItem::setName( const QString& name ) { | |||
170 | } | 217 | } |
171 | 218 | ||
172 | /** | 219 | /** |
173 | * Set the path of Plugin Item | 220 | * \brief set the path of a plugin |
221 | * Set the path of Plugin Item. The path must be absolute. | ||
174 | * @param name The path of the plugin | 222 | * @param name The path of the plugin |
175 | */ | 223 | */ |
176 | void OPluginItem::setPath( const QString& name ) { | 224 | void OPluginItem::setPath( const QString& name ) { |
@@ -178,8 +226,23 @@ void OPluginItem::setPath( const QString& name ) { | |||
178 | } | 226 | } |
179 | 227 | ||
180 | /** | 228 | /** |
229 | * \brief enable or disable the to load attribute | ||
230 | * Set the Enabled attribute. Such changes won't be saved. If you want to save it | ||
231 | * use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig | ||
232 | * for a graphical frontend. | ||
233 | * | ||
234 | * @param enabled Enable or Disable the Enabled Attribute | ||
235 | */ | ||
236 | void OPluginItem::setEnabled( bool enabled ) { | ||
237 | m_enabled = enabled; | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * \brief Set the position. | ||
181 | * Set the position | 242 | * Set the position |
182 | * @param pos The position | 243 | * @param pos The position |
244 | * | ||
245 | * @see position() | ||
183 | */ | 246 | */ |
184 | void OPluginItem::setPosition( int pos ) { | 247 | void OPluginItem::setPosition( int pos ) { |
185 | m_pos = pos; | 248 | m_pos = pos; |
@@ -224,6 +287,8 @@ OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted) | |||
224 | 287 | ||
225 | 288 | ||
226 | /** | 289 | /** |
290 | * \brief simple d'tor that cleans up depending on autoDelete | ||
291 | * | ||
227 | * calls clear if autoDelete is true. This will release all interfaces | 292 | * calls clear if autoDelete is true. This will release all interfaces |
228 | * and remove the library from this process if the refcount falls to zero | 293 | * and remove the library from this process if the refcount falls to zero |
229 | */ | 294 | */ |
@@ -233,6 +298,8 @@ OGenericPluginLoader::~OGenericPluginLoader() { | |||
233 | } | 298 | } |
234 | 299 | ||
235 | /** | 300 | /** |
301 | * \brief Enable or disable autoDelete on destruction | ||
302 | * | ||
236 | * enable autoDelete. This will call clear on the d'tor | 303 | * enable autoDelete. This will call clear on the d'tor |
237 | * | 304 | * |
238 | * @see ~OGenericPluginLoader | 305 | * @see ~OGenericPluginLoader |
@@ -243,13 +310,15 @@ void OGenericPluginLoader::setAutoDelete( bool t ) { | |||
243 | } | 310 | } |
244 | 311 | ||
245 | /** | 312 | /** |
246 | * see if autoDelet is enabled | 313 | * \brief See if autoDelete is enabled. |
247 | */ | 314 | */ |
248 | bool OGenericPluginLoader::autoDelete()const{ | 315 | bool OGenericPluginLoader::autoDelete()const{ |
249 | return m_autoDelete; | 316 | return m_autoDelete; |
250 | } | 317 | } |
251 | 318 | ||
252 | /** | 319 | /** |
320 | * \brief unload all loaded Plugins | ||
321 | * | ||
253 | * This will unload all returned QUnknownInterfaces by load. Unload | 322 | * This will unload all returned QUnknownInterfaces by load. Unload |
254 | * will be called. | 323 | * will be called. |
255 | */ | 324 | */ |
@@ -260,6 +329,8 @@ void OGenericPluginLoader::clear() { | |||
260 | } | 329 | } |
261 | 330 | ||
262 | /** | 331 | /** |
332 | * \brief unload the Plugin and the accompanied Resources. | ||
333 | * | ||
263 | * This will take the iface from the internal QPtrDict, Release it, | 334 | * This will take the iface from the internal QPtrDict, Release it, |
264 | * and deref the libray used. | 335 | * and deref the libray used. |
265 | * The visibility depends on the QPtrDict. | 336 | * The visibility depends on the QPtrDict. |
@@ -274,6 +345,18 @@ void OGenericPluginLoader::unload( QUnknownInterface* iface ) { | |||
274 | } | 345 | } |
275 | 346 | ||
276 | /** | 347 | /** |
348 | * \brief The name of the plugins. | ||
349 | * | ||
350 | * Return the name/type you specified in the constructor. | ||
351 | * This is at least used by the OPluginManager to find the right config | ||
352 | */ | ||
353 | QString OGenericPluginLoader::name()const { | ||
354 | return m_dir; | ||
355 | } | ||
356 | |||
357 | |||
358 | /** | ||
359 | * \brief See if loading of a plugin segfaulted | ||
277 | * This tells you | 360 | * This tells you |
278 | * if by previous tries to load, loading crashed your application. | 361 | * if by previous tries to load, loading crashed your application. |
279 | * 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 |
@@ -286,6 +369,7 @@ bool OGenericPluginLoader::isInSafeMode()const { | |||
286 | 369 | ||
287 | 370 | ||
288 | /** | 371 | /** |
372 | * \brief Return all Plugins found in the plugins dirs. | ||
289 | * 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 |
290 | * directories and search for your type of plugins ( by subdir ) | 374 | * directories and search for your type of plugins ( by subdir ) |
291 | * | 375 | * |
@@ -302,6 +386,7 @@ OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { | |||
302 | } | 386 | } |
303 | 387 | ||
304 | /** | 388 | /** |
389 | * \brief Return only the enabled plugins | ||
305 | * Return only activated plugins. | 390 | * Return only activated plugins. |
306 | * | 391 | * |
307 | * @param sorted If the list should be sorted | 392 | * @param sorted If the list should be sorted |
@@ -318,7 +403,15 @@ OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { | |||
318 | 403 | ||
319 | 404 | ||
320 | /** | 405 | /** |
406 | * \brief Load a OPluginItem for the specified interface | ||
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 | ||
409 | * resource and Interface. | ||
321 | * | 410 | * |
411 | * @param item The OPluginItem that should be loaded | ||
412 | * @param uuid The Interface to query for | ||
413 | * | ||
414 | * @return Either 0 in case of failure or the Plugin as QUnknownInterface* | ||
322 | */ | 415 | */ |
323 | QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { | 416 | QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { |
324 | /* | 417 | /* |
@@ -358,6 +451,8 @@ QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QU | |||
358 | * @internal and reads in the safe mode | 451 | * @internal and reads in the safe mode |
359 | */ | 452 | */ |
360 | void OGenericPluginLoader::readConfig() { | 453 | void OGenericPluginLoader::readConfig() { |
454 | |||
455 | |||
361 | /* read the config for SafeMode */ | 456 | /* read the config for SafeMode */ |
362 | OConfig conf( m_dir + "-odpplugins" ); | 457 | OConfig conf( m_dir + "-odpplugins" ); |
363 | conf.setGroup( "General" ); | 458 | conf.setGroup( "General" ); |
@@ -365,7 +460,7 @@ void OGenericPluginLoader::readConfig() { | |||
365 | } | 460 | } |
366 | 461 | ||
367 | /** | 462 | /** |
368 | * Enter or leave SafeMode | 463 | * @internal Enter or leave SafeMode |
369 | */ | 464 | */ |
370 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { | 465 | void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { |
371 | OConfig conf( m_dir + "-odpplugins" ); | 466 | OConfig conf( m_dir + "-odpplugins" ); |
@@ -420,6 +515,10 @@ QString OGenericPluginLoader::unlibify( const QString& str ) { | |||
420 | } | 515 | } |
421 | 516 | ||
422 | /** | 517 | /** |
518 | * @internal | ||
519 | * | ||
520 | * \brief method to return available plugins. Internal and for reeimplementations | ||
521 | * | ||
423 | * 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. |
424 | * If a plugin is on the excluded list assign position -2 | 523 | * If a plugin is on the excluded list assign position -2 |
425 | * | 524 | * |
@@ -473,12 +572,12 @@ OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorte | |||
473 | 572 | ||
474 | bool ex = excludedMap.contains( str ); | 573 | bool ex = excludedMap.contains( str ); |
475 | /* | 574 | /* |
476 | * if disabled but we should show all assign a -2 | 575 | * if disabled but we should show all mark it as disabled |
477 | * else continue because we don't want to add the item | 576 | * else continue because we don't want to add the item |
478 | * else if sorted we assign the right position | 577 | * else if sorted we assign the right position |
479 | */ | 578 | */ |
480 | if ( ex && !disabled) | 579 | if ( ex && !disabled) |
481 | item.setPosition( -2 ); | 580 | item.setEnabled( false ); |
482 | else if ( ex && disabled ) | 581 | else if ( ex && disabled ) |
483 | continue; | 582 | continue; |
484 | else if ( sorted ) | 583 | else if ( sorted ) |
@@ -514,6 +613,10 @@ QStringList OGenericPluginLoader::languageList() { | |||
514 | return m_languages; | 613 | return m_languages; |
515 | } | 614 | } |
516 | 615 | ||
616 | /** | ||
617 | * @internal | ||
618 | * Tries to install languages using the languageList for the type | ||
619 | */ | ||
517 | void OGenericPluginLoader::installTranslators(const QString& type) { | 620 | void OGenericPluginLoader::installTranslators(const QString& type) { |
518 | QStringList lst = languageList(); | 621 | QStringList lst = languageList(); |
519 | 622 | ||
@@ -535,7 +638,241 @@ void OGenericPluginLoader::installTranslators(const QString& type) { | |||
535 | } | 638 | } |
536 | } | 639 | } |
537 | 640 | ||
641 | /** | ||
642 | * \brief Simple c'tor. | ||
643 | * | ||
644 | * Simple C'tor same as the one of the base class. Additional this | ||
645 | * class can cast for you if you nee it. | ||
646 | * | ||
647 | * | ||
648 | * @param name The name of your plugin class | ||
649 | * @param sorted If plugins are sorted | ||
650 | * | ||
651 | * @see OGenericPluginLoader | ||
652 | */ | ||
653 | OPluginLoader::OPluginLoader( const QString& name, bool sorted ) | ||
654 | : OGenericPluginLoader( name, sorted ) | ||
655 | { | ||
656 | } | ||
657 | |||
658 | /** | ||
659 | * d'tor | ||
660 | * @see OGenericPluginLoader::~OGenericPluginLoader | ||
661 | */ | ||
662 | OPluginLoader::~OPluginLoader() { | ||
663 | } | ||
664 | |||
665 | /** | ||
666 | * \brief C'Tor using a OGenericPluginLoader | ||
667 | * The C'tor. Pass your OGenericPluginLoader to manage | ||
668 | * OGenericPluginLoader::allAvailable plugins. | ||
669 | * | ||
670 | * | ||
671 | * @param loader A Pointer to your OGenericPluginLoader | ||
672 | * @param name The name | ||
673 | */ | ||
674 | OPluginManager::OPluginManager( OGenericPluginLoader* loader) | ||
675 | : m_loader( loader ) | ||
676 | { | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * \brief Overloaded c'tor using a List of Plugins and a type name | ||
681 | * Overloaded Constructor to work with a 'Type' of plugins | ||
682 | * and a correspending list of those. In this case calling load | ||
683 | * is a no operation. | ||
684 | * | ||
685 | * @param name The name of your plugin ('today','inputmethods','applets') | ||
686 | * @param lst A List with plugins of your type to manage | ||
687 | * @param isSorted If the List should be treated sorted | ||
688 | */ | ||
689 | OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) | ||
690 | : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) | ||
691 | { | ||
692 | } | ||
693 | |||
694 | /** | ||
695 | * \brief A simple d'tor | ||
696 | */ | ||
697 | OPluginManager::~OPluginManager() { | ||
698 | } | ||
699 | |||
700 | /** | ||
701 | * \brief Return the OPluginItem where loading is likely to have crashed on. | ||
702 | |||
703 | * Return the Item that made the OGenericPluginLoader crash | ||
704 | * 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 | ||
706 | * plugin is not in the current list of available/managed plugins | ||
707 | * | ||
708 | * @see OPluginItem::isEmpty | ||
709 | * @return OPluginItem that crashed the loader | ||
710 | */ | ||
711 | OPluginItem OPluginManager::crashedPlugin()const { | ||
712 | return m_crashed; | ||
713 | } | ||
714 | |||
715 | /** | ||
716 | * \brief Return a list of plugins that are managed by this OPluginManager | ||
717 | * | ||
718 | * Return the list of managed plugins. This could either result | ||
719 | * from passing a OGenericPluginLoader and calling load or by | ||
720 | * giving name and a list of plugins. | ||
721 | */ | ||
722 | OPluginItem::List OPluginManager::managedPlugins()const { | ||
723 | return m_plugins; | ||
724 | } | ||
725 | |||
726 | /** | ||
727 | * \brief Set the position of the items | ||
728 | * | ||
729 | * 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) | ||
731 | * 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 | ||
733 | * | ||
734 | * @param item The OPluginItem to be replaced internall | ||
735 | * | ||
736 | */ | ||
737 | void OPluginManager::setPosition( const OPluginItem& item) { | ||
738 | replace( item ); | ||
739 | } | ||
740 | |||
741 | /** | ||
742 | * \brief Enable the item specified as argument | ||
743 | * | ||
744 | * This will make sure that OPluginItem::setEnabled is called and then will replace | ||
745 | * the item with one that matches name and path internally. | ||
746 | * @see setPosition | ||
747 | * | ||
748 | * @param the Item to enable | ||
749 | */ | ||
750 | void OPluginManager::enable( const OPluginItem& item ) { | ||
751 | setEnabled( item, true ); | ||
752 | } | ||
753 | |||
754 | /** | ||
755 | * \brief disable the Item. | ||
756 | * | ||
757 | * Disable the OPluginItem. Same applies as in | ||
758 | * @see setPosition and @see enable | ||
759 | * | ||
760 | * @param item Item to disable | ||
761 | */ | ||
762 | void OPluginManager::disable( const OPluginItem& item) { | ||
763 | setEnabled( item, false ); | ||
764 | } | ||
765 | |||
766 | /** | ||
767 | * \brief Enable or disable the OPluginItem. | ||
768 | * Depending on the value of the parameter this will either disable | ||
769 | * or enable the pluginitem. | ||
770 | * Beside that same as in @see disable, @see enable, @see setPosition | ||
771 | * applies. | ||
772 | * | ||
773 | * @param _item The OPluginItem to enable or to disable. | ||
774 | * @param b Enable or disable the plugin. | ||
775 | * | ||
776 | */ | ||
777 | void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { | ||
778 | OPluginItem item = _item; | ||
779 | item.setEnabled( b ); | ||
780 | replace( item ); | ||
781 | } | ||
782 | |||
783 | /** | ||
784 | * \brief Load necessary information after constructing the object | ||
785 | * 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 | ||
787 | * For the name and the list of plugins this does only try to find out the crashed plugin | ||
788 | */ | ||
789 | void OPluginManager::load() { | ||
790 | OConfig cfg( configName() ); | ||
791 | cfg.setGroup( "General" ); | ||
792 | QString crashedPath = cfg.readEntry( "CrashedPlugin" ); | ||
793 | |||
794 | /* if we've a loader this applies if we were called from the first part */ | ||
795 | if ( m_loader ) | ||
796 | m_plugins = m_loader->allAvailable( m_loader->isSorted() ); | ||
797 | |||
798 | /* fast and normal route if we did not crash... */ | ||
799 | if ( crashedPath.isEmpty() ) | ||
800 | return; | ||
801 | |||
802 | /* 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 ) | ||
804 | if ( (*it).path() == crashedPath ) { | ||
805 | m_crashed = *it; | ||
806 | break; | ||
807 | } | ||
808 | } | ||
809 | |||
810 | |||
811 | /** | ||
812 | * \brief Save the values and this way make it available. | ||
813 | * | ||
814 | * Save the current set of data. A call to @see OGenericPluginLoader::filtered | ||
815 | * now would return your saved changes. | ||
816 | */ | ||
817 | void OPluginManager::save() { | ||
818 | QMap<QString, QStringList> excluded; // map for path to excluded name | ||
819 | QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs | ||
820 | bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; | ||
821 | |||
822 | /* | ||
823 | * We will create some maps for the groups to include positions a | ||
824 | */ | ||
825 | for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { | ||
826 | OPluginItem item = *it; | ||
827 | QString path = QFileInfo( item.path() ).filePath(); | ||
828 | if ( sorted ) { | ||
829 | positions[path].append( item.name() ); | ||
830 | positions[path].append( QString::number( item.position() ) ); | ||
831 | } | ||
832 | |||
833 | if ( !item.isEnabled() ) | ||
834 | excluded[path].append( item.name() ); | ||
835 | } | ||
836 | |||
837 | /* | ||
838 | * The code below wouldn't work because we can't delete groups/keys from the config | ||
839 | * ### for ODP make Config right! | ||
840 | */ | ||
841 | // if ( excluded.isEmpty() && positions.isEmpty() ) return; | ||
842 | /* | ||
843 | * Now safe for each path | ||
844 | */ | ||
845 | OConfig cfg( configName() ); | ||
846 | |||
847 | /* safe excluded items */ | ||
848 | for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { | ||
849 | OConfigGroupSaver saver( &cfg, it.key() ); | ||
850 | cfg.writeEntry("Excluded", it.data(), ',' ); | ||
851 | } | ||
852 | |||
853 | /* 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... | ||
855 | */ | ||
856 | for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { | ||
857 | OConfigGroupSaver saver( &cfg, it.key() ); | ||
858 | cfg.writeEntry("Positions", it.data(), '.' ); | ||
859 | } | ||
860 | } | ||
861 | |||
862 | /** | ||
863 | * @internal | ||
864 | */ | ||
865 | QString OPluginManager::configName()const { | ||
866 | QString str = m_loader ? m_loader->name() : m_cfgName; | ||
867 | return str + "odpplugins"; | ||
868 | } | ||
538 | 869 | ||
870 | /** | ||
871 | * @internal.. replace in m_plugins by path... this is linear search O(n/2) | ||
872 | */ | ||
873 | void OPluginManager::replace( const OPluginItem& item ) { | ||
874 | // ### fixme | ||
875 | } | ||
539 | 876 | ||
540 | } | 877 | } |
541 | } | 878 | } |