author | zecke <zecke> | 2004-05-17 21:22:51 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-05-17 21:22:51 (UTC) |
commit | f3d15e6f81369f8495811c7c3624e51d032615ba (patch) (unidiff) | |
tree | 8319000a9aa8634a4214306ca19ac49dbcc5bc2b | |
parent | e0d8fdf2bcf61f8b6793ee757de35b985aef1b8d (diff) | |
download | opie-f3d15e6f81369f8495811c7c3624e51d032615ba.zip opie-f3d15e6f81369f8495811c7c3624e51d032615ba.tar.gz opie-f3d15e6f81369f8495811c7c3624e51d032615ba.tar.bz2 |
OPluginManager first bits of saving, enabling and sorting Plugin Config
At least it compiles, test and GUI will come this week
-rw-r--r-- | libopie2/opiecore/opluginloader.cpp | 369 | ||||
-rw-r--r-- | libopie2/opiecore/opluginloader.h | 59 |
2 files changed, 395 insertions, 33 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; |
137 | if ( m_name != r.m_name ) return false; | 160 | if ( m_enabled != r.m_enabled) return false; |
138 | if ( m_path != r.m_path ) return false; | 161 | if ( m_name != r.m_name ) 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. | ||
410 | * | ||
411 | * @param item The OPluginItem that should be loaded | ||
412 | * @param uuid The Interface to query for | ||
321 | * | 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,14 +451,16 @@ 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() { |
361 | /* read the config for SafeMode */ | 454 | |
455 | |||
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" ); |
364 | m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); | 459 | m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); |
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,7 +515,11 @@ QString OGenericPluginLoader::unlibify( const QString& str ) { | |||
420 | } | 515 | } |
421 | 516 | ||
422 | /** | 517 | /** |
423 | * Return a List of Plugins for a dir and add positions and remove disabled. | 518 | * @internal |
519 | * | ||
520 | * \brief method to return available plugins. Internal and for reeimplementations | ||
521 | * | ||
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 | * |
426 | * @param dir The dir to look in | 525 | * @param dir The dir to look in |
@@ -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. | ||
538 | 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 | } | ||
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 | } |
diff --git a/libopie2/opiecore/opluginloader.h b/libopie2/opiecore/opluginloader.h index 6166b75..2f9ec2a 100644 --- a/libopie2/opiecore/opluginloader.h +++ b/libopie2/opiecore/opluginloader.h | |||
@@ -32,24 +32,29 @@ class OPluginItem { | |||
32 | public: | 32 | public: |
33 | typedef QValueList<OPluginItem> List; | 33 | typedef QValueList<OPluginItem> List; |
34 | OPluginItem(); | 34 | OPluginItem(); |
35 | OPluginItem( const QString& name, const QString& path, int pos = -1 ); | 35 | OPluginItem( const QString& name, const QString& path, bool enabled = true, int pos = -1 ); |
36 | ~OPluginItem(); | 36 | ~OPluginItem(); |
37 | 37 | ||
38 | bool isEmpty()const; | ||
39 | |||
38 | bool operator==( const OPluginItem& )const; | 40 | bool operator==( const OPluginItem& )const; |
39 | bool operator!=( const OPluginItem& )const; | 41 | bool operator!=( const OPluginItem& )const; |
40 | 42 | ||
41 | 43 | ||
42 | QString name()const; | 44 | QString name()const; |
43 | QString path()const; | 45 | QString path()const; |
46 | bool isEnabled()const; | ||
44 | int position()const; | 47 | int position()const; |
45 | 48 | ||
46 | void setName( const QString& ); | 49 | void setName( const QString& ); |
47 | void setPath( const QString& ); | 50 | void setPath( const QString& ); |
51 | void setEnabled( bool ); | ||
48 | void setPosition( int ); | 52 | void setPosition( int ); |
49 | 53 | ||
50 | private: | 54 | private: |
51 | QString m_name; | 55 | QString m_name; |
52 | QString m_path; | 56 | QString m_path; |
57 | bool m_enabled : 1; | ||
53 | int m_pos; | 58 | int m_pos; |
54 | struct Private; | 59 | struct Private; |
55 | Private *d; | 60 | Private *d; |
@@ -76,26 +81,26 @@ public: | |||
76 | bool autoDelete()const; | 81 | bool autoDelete()const; |
77 | void clear(); | 82 | void clear(); |
78 | 83 | ||
79 | 84 | QString name()const; | |
85 | bool isSorted()const; | ||
80 | bool isInSafeMode()const; | 86 | bool isInSafeMode()const; |
81 | 87 | ||
82 | 88 | ||
83 | List allAvailable(bool sorted = FALSE)const; | 89 | List allAvailable(bool sorted = false )const; |
84 | List filtered(bool sorted = FALSE)const; | 90 | List filtered(bool sorted = false )const; |
85 | 91 | ||
86 | 92 | ||
87 | virtual QUnknownInterface* load( const OPluginItem& item, const QUuid& ); | 93 | virtual QUnknownInterface* load( const OPluginItem& item, const QUuid& ); |
88 | virtual void unload( QUnknownInterface* ); | 94 | virtual void unload( QUnknownInterface* ); |
89 | 95 | ||
90 | protected: | 96 | protected: |
97 | friend class OPluginManager; // we need the static unlibify | ||
91 | void readConfig(); | 98 | void readConfig(); |
92 | virtual List plugins( const QString& dir, bool sorted, bool disabled )const; | 99 | virtual List plugins( const QString& dir, bool sorted, bool disabled )const; |
93 | void setPluginDirs( const QStringList& ); | 100 | void setPluginDirs( const QStringList& ); |
94 | void setPluginDir( const QString& ); | 101 | void setPluginDir( const QString& ); |
95 | bool isSorted()const; | ||
96 | void setSafeMode(const QString& app = QString::null, bool b = false); | 102 | void setSafeMode(const QString& app = QString::null, bool b = false); |
97 | static QString unlibify( const QString& str ); | 103 | static QString unlibify( const QString& str ); |
98 | |||
99 | private: | 104 | private: |
100 | QStringList languageList(); | 105 | QStringList languageList(); |
101 | void installTranslators(const QString& type); | 106 | void installTranslators(const QString& type); |
@@ -133,42 +138,62 @@ private: | |||
133 | class OPluginLoader : public OGenericPluginLoader { | 138 | class OPluginLoader : public OGenericPluginLoader { |
134 | public: | 139 | public: |
135 | OPluginLoader( const QString& name, bool sorted = false ); | 140 | OPluginLoader( const QString& name, bool sorted = false ); |
136 | ~OPluginLoader(); | 141 | virtual ~OPluginLoader(); |
137 | 142 | ||
138 | template<class IFace> | 143 | template<class IFace> |
139 | IFace* load( const OPluginItem& item, const QUuid& ); | 144 | IFace* load( const OPluginItem& item, const QUuid& ); |
140 | }; | 145 | }; |
141 | 146 | ||
142 | /** | 147 | /** |
143 | * \brief A class to manager order and activation of plugins | 148 | * \brief A class to manage order and activation of plugins |
144 | * | 149 | * |
145 | * 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 |
146 | * This class controls the activation and order of plugins depending | 151 | * This class controls the activation and order of plugins depending |
147 | * on the OPluginLoader you supply. | 152 | * on the OPluginLoader you supply. |
153 | * You must call load() and save after construnction an instance | ||
148 | * | 154 | * |
149 | * @see OPluginConfig | 155 | * @see Opie::Ui::OPluginConfig |
150 | * | 156 | * |
151 | */ | 157 | */ |
152 | class OPluginManager { | 158 | class OPluginManager { |
153 | public: | 159 | public: |
154 | OPluginManager( OGenericPluginLoader* , const QString& name); | 160 | OPluginManager( OGenericPluginLoader* ); |
155 | OPluginManager( OConfig* conf, const QString&, | 161 | OPluginManager( const QString& name, const OPluginItem::List&, bool isSorted = false ); |
156 | const QCString& group, const OPluginItem::List& ); | 162 | virtual ~OPluginManager(); |
157 | ~OPluginManager(); | ||
158 | 163 | ||
159 | QString name(); | 164 | OPluginItem crashedPlugin()const; |
160 | void setName( const QString& ); | 165 | |
166 | OPluginItem::List managedPlugins()const; | ||
161 | 167 | ||
162 | void setPosition( const OPluginItem& ); | 168 | void setPosition( const OPluginItem& ); |
163 | void enable( const OPluginItem& ); | 169 | void enable( const OPluginItem& ); |
164 | void disable( const OPluginItem& ); | 170 | void disable( const OPluginItem& ); |
165 | void setEnabled( const OPluginItem&, bool = true); | 171 | void setEnabled( const OPluginItem&, bool = true); |
166 | 172 | ||
167 | void load(); | 173 | virtual void load(); |
168 | void save(); | 174 | virtual void save(); |
175 | |||
176 | protected: | ||
177 | QString configName()const; | ||
178 | void replace( const OPluginItem& ); | ||
179 | private: | ||
180 | OGenericPluginLoader *m_loader; | ||
181 | QString m_cfgName; | ||
182 | OPluginItem::List m_plugins; | ||
183 | OPluginItem m_crashed; | ||
184 | bool m_isSorted : 1; | ||
169 | }; | 185 | }; |
170 | 186 | ||
171 | 187 | ||
188 | /** | ||
189 | * This is a template method allowing you to safely cast | ||
190 | * your load function | ||
191 | * | ||
192 | * \code | ||
193 | * MyTypePlugin *plug = load->load<MyTypePlugin>( item, IID_MyPlugin ); | ||
194 | * \endcode | ||
195 | * | ||
196 | */ | ||
172 | template<class IFace> | 197 | template<class IFace> |
173 | IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) { | 198 | IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) { |
174 | return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) ); | 199 | return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) ); |