summaryrefslogtreecommitdiff
authorzecke <zecke>2004-08-25 21:53:50 (UTC)
committer zecke <zecke>2004-08-25 21:53:50 (UTC)
commita64c92819cd3106584d9005e42ed972726081a94 (patch) (unidiff)
treef8ac45c7154db71a988cc5a9596587a30b9d9cce
parentdf3e4c8b13c16aeb96e70dbaa2d409f83eed988e (diff)
downloadopie-a64c92819cd3106584d9005e42ed972726081a94.zip
opie-a64c92819cd3106584d9005e42ed972726081a94.tar.gz
opie-a64c92819cd3106584d9005e42ed972726081a94.tar.bz2
Respect the value passed to the method
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opluginloader.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp
index e7eddc2..1edf3a1 100644
--- a/libopie2/opiecore/opluginloader.cpp
+++ b/libopie2/opiecore/opluginloader.cpp
@@ -1,891 +1,893 @@
1/* 1/*
2 * LGPLv2 or later 2 * LGPLv2 or later
3 * zecke@handhelds.org 3 * zecke@handhelds.org
4 */ 4 */
5 5
6#include "opluginloader.h" 6#include "opluginloader.h"
7#include "oconfig.h" 7#include "oconfig.h"
8#include "odebug.h"
8 9
9#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
10 11
11#include <qdir.h> 12#include <qdir.h>
12#include <qdict.h> 13#include <qdict.h>
13#include <qtl.h> 14#include <qtl.h>
14#include <qfile.h> 15#include <qfile.h>
15 16
16#include <stdlib.h> 17#include <stdlib.h>
17 18
18 19
19 20
20namespace Opie { 21namespace Opie {
21namespace Core { 22namespace Core {
22namespace Internal { 23namespace Internal {
23struct OPluginLibraryHolder { 24struct OPluginLibraryHolder {
24 static OPluginLibraryHolder *self(); 25 static OPluginLibraryHolder *self();
25 QLibrary *ref( const QString& ); 26 QLibrary *ref( const QString& );
26 void deref( QLibrary* ); 27 void deref( QLibrary* );
27private: 28private:
28 29
29 OPluginLibraryHolder(); 30 OPluginLibraryHolder();
30 ~OPluginLibraryHolder(); 31 ~OPluginLibraryHolder();
31 QDict<QLibrary> m_libs; 32 QDict<QLibrary> m_libs;
32 static OPluginLibraryHolder* m_self; 33 static OPluginLibraryHolder* m_self;
33}; 34};
34 35
35 OPluginLibraryHolder* OPluginLibraryHolder::m_self = 0; 36 OPluginLibraryHolder* OPluginLibraryHolder::m_self = 0;
36 OPluginLibraryHolder* OPluginLibraryHolder::self() { 37 OPluginLibraryHolder* OPluginLibraryHolder::self() {
37 if ( !m_self ) 38 if ( !m_self )
38 m_self = new OPluginLibraryHolder; 39 m_self = new OPluginLibraryHolder;
39 40
40 return m_self; 41 return m_self;
41 } 42 }
42 43
43 OPluginLibraryHolder::OPluginLibraryHolder() {} 44 OPluginLibraryHolder::OPluginLibraryHolder() {}
44 OPluginLibraryHolder::~OPluginLibraryHolder() {} 45 OPluginLibraryHolder::~OPluginLibraryHolder() {}
45 46
46 /* 47 /*
47 * We do simple ref counting... We will add the QLibrary again 48 * We do simple ref counting... We will add the QLibrary again
48 * and again to the dictionary and on deref we will pop and pop it 49 * and again to the dictionary and on deref we will pop and pop it
49 * until there are no more library and we will unload and delete the library 50 * until there are no more library and we will unload and delete the library
50 * luckily dlopen does some ref counting as well so we don't need 51 * luckily dlopen does some ref counting as well so we don't need
51 * to hack QPEApplication 52 * to hack QPEApplication
52 */ 53 */
53 QLibrary* OPluginLibraryHolder::ref(const QString& str) { 54 QLibrary* OPluginLibraryHolder::ref(const QString& str) {
54 QLibrary *lib = m_libs[str]; 55 QLibrary *lib = m_libs[str];
55 56
56 /* if not in the dict try to load it */ 57 /* if not in the dict try to load it */
57 if ( !lib ) { 58 if ( !lib ) {
58 lib = new QLibrary( str, QLibrary::Immediately ); 59 lib = new QLibrary( str, QLibrary::Immediately );
59 if ( !lib->isLoaded() ) { 60 if ( !lib->isLoaded() ) {
60 delete lib; 61 delete lib;
61 return 0l; 62 return 0l;
62 } 63 }
63 } 64 }
64 65
65 /* now refcount one up */ 66 /* now refcount one up */
66 m_libs.insert( str, lib ); 67 m_libs.insert( str, lib );
67 return lib; 68 return lib;
68 } 69 }
69 70
70 /* 71 /*
71 * 'unshadow' the items until we're the last then unload and delete 72 * 'unshadow' the items until we're the last then unload and delete
72 */ 73 */
73 void OPluginLibraryHolder::deref( QLibrary* lib ) { 74 void OPluginLibraryHolder::deref( QLibrary* lib ) {
74 if ( !lib ) 75 if ( !lib )
75 return; 76 return;
76 77
77 QString str = lib->library(); 78 QString str = lib->library();
78 /* no need to check if the lib was inserted or such */ 79 /* no need to check if the lib was inserted or such */
79 (void) m_libs.take( str ); 80 (void) m_libs.take( str );
80 if ( !m_libs[str] ) { 81 if ( !m_libs[str] ) {
81 lib->unload(); 82 lib->unload();
82 delete lib; 83 delete lib;
83 } 84 }
84 } 85 }
85} 86}
86 87
87/** 88/**
88 * We want values with 30,29,28 at the beginning of the list 89 * We want values with 30,29,28 at the beginning of the list
89 */ 90 */
90 91
91bool operator<( const OPluginItem& l, const OPluginItem& r ) { 92bool operator<( const OPluginItem& l, const OPluginItem& r ) {
92 return l.position() > r.position(); 93 return l.position() > r.position();
93} 94}
94 95
95bool operator>( const OPluginItem& l, const OPluginItem& r ) { 96bool operator>( const OPluginItem& l, const OPluginItem& r ) {
96 return l.position() < r.position(); 97 return l.position() < r.position();
97} 98}
98 99
99bool operator<=( const OPluginItem& l, const OPluginItem& r ) { 100bool operator<=( const OPluginItem& l, const OPluginItem& r ) {
100 return l.position() >= r.position(); 101 return l.position() >= r.position();
101} 102}
102 103
103/** 104/**
104 * \brief Creates an Empty OPluginItem 105 * \brief Creates an Empty OPluginItem
105 * 106 *
106 * create an empty pluginitem. Position is set to -1 and the 107 * create an empty pluginitem. Position is set to -1 and the
107 * other things are used with the default ctors 108 * other things are used with the default ctors
108 */ 109 */
109OPluginItem::OPluginItem() 110OPluginItem::OPluginItem()
110 : m_pos( -1 ) { 111 : m_pos( -1 ) {
111} 112}
112 113
113/** 114/**
114 * @todo Create Internal name so we can have the plugin names translated. Or only for the gui? I'm not yet sure 115 * @todo Create Internal name so we can have the plugin names translated. Or only for the gui? I'm not yet sure
115 * \brief Create an OPluginItem 116 * \brief Create an OPluginItem
116 * 117 *
117 * Create a Plugin Item with all information. If you for some reasons 118 * 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 * need to create your own OPluginItems make sure that 'name' is always the same
119 * as it if used for positions and exclude list. 120 * as it if used for positions and exclude list.
120 * 121 *
121 * @param name The if available translated Name 122 * @param name The if available translated Name
122 * @param path The path to the plugin must be absolute. 123 * @param path The path to the plugin must be absolute.
123 * @param b If the OPluginItem is enabled or not 124 * @param b If the OPluginItem is enabled or not
124 * @param pos The position of the plugin if used for sorting 125 * @param pos The position of the plugin if used for sorting
125 * 126 *
126 */ 127 */
127OPluginItem::OPluginItem( const QString& name, const QString& path, bool b, int pos ) 128OPluginItem::OPluginItem( const QString& name, const QString& path, bool b, int pos )
128 : m_name( name ), m_path( path ), m_enabled( b ), m_pos( pos ) 129 : m_name( name ), m_path( path ), m_enabled( b ), m_pos( pos )
129{} 130{}
130 131
131/** 132/**
132 * \brief simple d'tor 133 * \brief simple d'tor
133 */ 134 */
134OPluginItem::~OPluginItem() { 135OPluginItem::~OPluginItem() {
135} 136}
136 137
137/** 138/**
138 * \brief Test if this Item is Empty and does not represent a loadable plugin 139 * \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 * 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 * ,pos equals -1 and the item is disabled
141 * 142 *
142 * @see QString::isEmpty() 143 * @see QString::isEmpty()
143 * 144 *
144 */ 145 */
145bool OPluginItem::isEmpty()const { 146bool OPluginItem::isEmpty()const {
146 if ( m_pos != -1 ) return false; 147 if ( m_pos != -1 ) return false;
147 if ( m_enabled ) return false; 148 if ( m_enabled ) return false;
148 if ( !m_name.isEmpty() ) return false; 149 if ( !m_name.isEmpty() ) return false;
149 if ( !m_path.isEmpty() ) return false; 150 if ( !m_path.isEmpty() ) return false;
150 151
151 return true; 152 return true;
152} 153}
153 154
154/** 155/**
155 * \brief test equality 156 * \brief test equality
156 * operator to test equalness of two OPluginItem 157 * operator to test equalness of two OPluginItem
157 */ 158 */
158bool OPluginItem::operator==( const OPluginItem& r )const{ 159bool OPluginItem::operator==( const OPluginItem& r )const{
159 if ( m_pos != r.m_pos ) return false; 160 if ( m_pos != r.m_pos ) return false;
160 if ( m_enabled != r.m_enabled) return false; 161 if ( m_enabled != r.m_enabled) return false;
161 if ( m_name != r.m_name ) return false; 162 if ( m_name != r.m_name ) return false;
162 if ( m_path != r.m_path ) return false; 163 if ( m_path != r.m_path ) return false;
163 return true; 164 return true;
164} 165}
165 166
166/** 167/**
167 * \brief test non equality 168 * \brief test non equality
168 * operator to test non-equalness of two OPluginItem 169 * operator to test non-equalness of two OPluginItem
169 */ 170 */
170bool OPluginItem::operator!=( const OPluginItem& r )const{ 171bool OPluginItem::operator!=( const OPluginItem& r )const{
171 return !( *this == r ); 172 return !( *this == r );
172} 173}
173 174
174/** 175/**
175 * \brief returns the name of the plugin 176 * \brief returns the name of the plugin
176 * return the name of this Plugin 177 * return the name of this Plugin
177 */ 178 */
178QString OPluginItem::name()const { 179QString OPluginItem::name()const {
179 return m_name; 180 return m_name;
180} 181}
181 182
182/** 183/**
183 * \brief return the path of the plugin 184 * \brief return the path of the plugin
184 */ 185 */
185QString OPluginItem::path()const { 186QString OPluginItem::path()const {
186 return m_path; 187 return m_path;
187} 188}
188 189
189/** 190/**
190 * \brief Return if this item is enabled. 191 * \brief Return if this item is enabled.
191 */ 192 */
192bool OPluginItem::isEnabled()const { 193bool OPluginItem::isEnabled()const {
193 return m_enabled; 194 return m_enabled;
194} 195}
195 196
196/** 197/**
197 * \brief return the position of a plugin. 198 * \brief return the position of a plugin.
198 * return the position of the item 199 * return the position of the item
199 * -1 is the default value and means normally that the whole items are unsorted. 200 * -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 * 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 * the item with pos 20 would be the first in the list returned by the OGenericPluginLoader
202 * 203 *
203 * @see OGenericPluginLoader::allAvailable 204 * @see OGenericPluginLoader::allAvailable
204 * @see OGenericPluginLoader::filtered 205 * @see OGenericPluginLoader::filtered
205 */ 206 */
206int OPluginItem::position()const{ 207int OPluginItem::position()const{
207 return m_pos; 208 return m_pos;
208} 209}
209 210
210/** 211/**
211 * \brief set the name of a plugin 212 * \brief set the name of a plugin
212 * Set the name of the Plugin Item 213 * Set the name of the Plugin Item
213 * @param name 214 * @param name
214 */ 215 */
215void OPluginItem::setName( const QString& name ) { 216void OPluginItem::setName( const QString& name ) {
216 m_name = name; 217 m_name = name;
217} 218}
218 219
219/** 220/**
220 * \brief set the path of a plugin 221 * \brief set the path of a plugin
221 * Set the path of Plugin Item. The path must be absolute. 222 * Set the path of Plugin Item. The path must be absolute.
222 * @param name The path of the plugin 223 * @param name The path of the plugin
223 */ 224 */
224void OPluginItem::setPath( const QString& name ) { 225void OPluginItem::setPath( const QString& name ) {
225 m_path = name; 226 m_path = name;
226} 227}
227 228
228/** 229/**
229 * \brief enable or disable the to load attribute 230 * \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 * 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 * use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig
232 * for a graphical frontend. 233 * for a graphical frontend.
233 * 234 *
234 * @param enabled Enable or Disable the Enabled Attribute 235 * @param enabled Enable or Disable the Enabled Attribute
235 */ 236 */
236void OPluginItem::setEnabled( bool enabled ) { 237void OPluginItem::setEnabled( bool enabled ) {
237 m_enabled = enabled; 238 m_enabled = enabled;
238} 239}
239 240
240/** 241/**
241 * \brief Set the position. 242 * \brief Set the position.
242 * Set the position 243 * Set the position
243 * @param pos The position 244 * @param pos The position
244 * 245 *
245 * @see position() 246 * @see position()
246 */ 247 */
247void OPluginItem::setPosition( int pos ) { 248void OPluginItem::setPosition( int pos ) {
248 m_pos = pos; 249 m_pos = pos;
249} 250}
250 251
251 252
252 253
253/** 254/**
254 * \brief create a PluginLoader 255 * \brief create a PluginLoader
255 * 256 *
256 * Create a PluginLoader autoDelete is set to false 257 * Create a PluginLoader autoDelete is set to false
257 * 258 *
258 * \code 259 * \code
259 * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); 260 * Opie::Core::OGenericPluginLoader loader("myapp-plugin");
260 * Opie::Core::OPluginItem::List lst = loader.filtered(); 261 * Opie::Core::OPluginItem::List lst = loader.filtered();
261 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ 262 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
262 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); 263 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
263 * } 264 * }
264 * \endcode 265 * \endcode
265 * 266 *
266 * \code 267 * \code
267 * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); 268 * Opie::Core::OGenericPluginLoader loader("myapp-plugin");
268 * Opie::Core::OPluginItem::List lst = loader.filtered(); 269 * Opie::Core::OPluginItem::List lst = loader.filtered();
269 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ 270 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
270 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); 271 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
271 * } 272 * }
272 * ... 273 * ...
273 * loader.clear(); 274 * loader.clear();
274 * 275 *
275 * \endcode 276 * \endcode
276 * 277 *
277 * @param name The name of the plugin directory. 278 * @param name The name of the plugin directory.
278 * @param isSorted Tell the PluginLoader if your Plugins are sorted 279 * @param isSorted Tell the PluginLoader if your Plugins are sorted
279 */ 280 */
280OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted) 281OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted)
281 : m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ), 282 : m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ),
282 m_isSorted( isSorted ) 283 m_isSorted( isSorted )
283{ 284{
284 setPluginDir( QPEApplication::qpeDir() + "plugins/"+name ); 285 setPluginDir( QPEApplication::qpeDir() + "plugins/"+name );
285 readConfig(); 286 readConfig();
286} 287}
287 288
288 289
289/** 290/**
290 * \brief simple d'tor that cleans up depending on autoDelete 291 * \brief simple d'tor that cleans up depending on autoDelete
291 * 292 *
292 * calls clear if autoDelete is true. This will release all interfaces 293 * calls clear if autoDelete is true. This will release all interfaces
293 * and remove the library from this process if the refcount falls to zero 294 * and remove the library from this process if the refcount falls to zero
294 */ 295 */
295OGenericPluginLoader::~OGenericPluginLoader() { 296OGenericPluginLoader::~OGenericPluginLoader() {
296 if ( m_autoDelete ) 297 if ( m_autoDelete )
297 clear(); 298 clear();
298} 299}
299 300
300/** 301/**
301 * \brief Enable or disable autoDelete on destruction 302 * \brief Enable or disable autoDelete on destruction
302 * 303 *
303 * enable autoDelete. This will call clear on the d'tor 304 * enable autoDelete. This will call clear on the d'tor
304 * 305 *
305 * @see ~OGenericPluginLoader 306 * @see ~OGenericPluginLoader
306 * @see clear() 307 * @see clear()
307 */ 308 */
308void OGenericPluginLoader::setAutoDelete( bool t ) { 309void OGenericPluginLoader::setAutoDelete( bool t ) {
309 m_autoDelete = t; 310 m_autoDelete = t;
310} 311}
311 312
312/** 313/**
313 * \brief See if autoDelete is enabled. 314 * \brief See if autoDelete is enabled.
314 */ 315 */
315bool OGenericPluginLoader::autoDelete()const{ 316bool OGenericPluginLoader::autoDelete()const{
316 return m_autoDelete; 317 return m_autoDelete;
317} 318}
318 319
319/** 320/**
320 * \brief unload all loaded Plugins 321 * \brief unload all loaded Plugins
321 * 322 *
322 * This will unload all returned QUnknownInterfaces by load. Unload 323 * This will unload all returned QUnknownInterfaces by load. Unload
323 * will be called. 324 * will be called.
324 */ 325 */
325void OGenericPluginLoader::clear() { 326void OGenericPluginLoader::clear() {
326 QPtrDictIterator<QLibrary> it( m_library ); 327 QPtrDictIterator<QLibrary> it( m_library );
327 for ( ;it.current(); ) 328 for ( ;it.current(); )
328 unload( static_cast<QUnknownInterface*>( it.currentKey() ) ); 329 unload( static_cast<QUnknownInterface*>( it.currentKey() ) );
329} 330}
330 331
331/** 332/**
332 * \brief unload the Plugin and the accompanied Resources. 333 * \brief unload the Plugin and the accompanied Resources.
333 * 334 *
334 * This will take the iface from the internal QPtrDict, Release it, 335 * This will take the iface from the internal QPtrDict, Release it,
335 * and deref the libray used. 336 * and deref the libray used.
336 * The visibility depends on the QPtrDict. 337 * The visibility depends on the QPtrDict.
337 * @see QPtrDict::insert 338 * @see QPtrDict::insert
338 */ 339 */
339void OGenericPluginLoader::unload( QUnknownInterface* iface ) { 340void OGenericPluginLoader::unload( QUnknownInterface* iface ) {
340 if ( !iface ) 341 if ( !iface )
341 return; 342 return;
342 343
343 iface->release(); 344 iface->release();
344 Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) ); 345 Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) );
345} 346}
346 347
347/** 348/**
348 * \brief The name of the plugins. 349 * \brief The name of the plugins.
349 * 350 *
350 * Return the name/type you specified in the constructor. 351 * Return the name/type you specified in the constructor.
351 * This is at least used by the OPluginManager to find the right config 352 * This is at least used by the OPluginManager to find the right config
352 */ 353 */
353QString OGenericPluginLoader::name()const { 354QString OGenericPluginLoader::name()const {
354 return m_dir; 355 return m_dir;
355} 356}
356 357
357 358
358/** 359/**
359 * \brief See if loading of a plugin segfaulted 360 * \brief See if loading of a plugin segfaulted
360 * This tells you 361 * This tells you
361 * if by previous tries to load, loading crashed your application. 362 * if by previous tries to load, loading crashed your application.
362 * If isInSafeMode you can use the GUI to configure the plugins prior to loading 363 * If isInSafeMode you can use the GUI to configure the plugins prior to loading
363 * 364 *
364 * @return true if prior loading failed 365 * @return true if prior loading failed
365 */ 366 */
366bool OGenericPluginLoader::isInSafeMode()const { 367bool OGenericPluginLoader::isInSafeMode()const {
367 return m_isSafeMode; 368 return m_isSafeMode;
368} 369}
369 370
370 371
371/** 372/**
372 * \brief Return all Plugins found in the plugins dirs. 373 * \brief Return all Plugins found in the plugins dirs.
373 * Return the list of all available plugins. This will go through all plugin 374 * Return the list of all available plugins. This will go through all plugin
374 * directories and search for your type of plugins ( by subdir ) 375 * directories and search for your type of plugins ( by subdir )
375 * 376 *
376 * @param sorted Tell if you want to have the positions sorted. This only makes sense if you 377 * @param sorted Tell if you want to have the positions sorted. This only makes sense if you
377 */ 378 */
378OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { 379OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const {
379 OPluginItem::List lst; 380 OPluginItem::List lst;
380 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) 381 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
381 lst += plugins( *it, sorted, false ); 382 lst += plugins( *it, sorted, false );
382 383
383 if ( sorted ) 384 if ( sorted )
384 qHeapSort( lst ); 385 qHeapSort( lst );
385 return lst; 386 return lst;
386} 387}
387 388
388/** 389/**
389 * \brief Return only the enabled plugins 390 * \brief Return only the enabled plugins
390 * Return only activated plugins. 391 * Return only activated plugins.
391 * 392 *
392 * @param sorted If the list should be sorted 393 * @param sorted If the list should be sorted
393 */ 394 */
394OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { 395OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const {
395 OPluginItem::List lst; 396 OPluginItem::List lst;
396 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) 397 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
397 lst += plugins( *it, sorted, true ); 398 lst += plugins( *it, sorted, true );
398 399
399 if ( sorted ) 400 if ( sorted )
400 qHeapSort( lst ); 401 qHeapSort( lst );
401 return lst; 402 return lst;
402} 403}
403 404
404 405
405/** 406/**
406 * \brief Load a OPluginItem for the specified interface 407 * \brief Load a OPluginItem for the specified interface
407 * This will open the resource of the OPluginItem::path() and then will query 408 * 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 * if the Interface specified in the uuid is available and then will manage the
409 * resource and Interface. 410 * resource and Interface.
410 * 411 *
411 * @param item The OPluginItem that should be loaded 412 * @param item The OPluginItem that should be loaded
412 * @param uuid The Interface to query for 413 * @param uuid The Interface to query for
413 * 414 *
414 * @return Either 0 in case of failure or the Plugin as QUnknownInterface* 415 * @return Either 0 in case of failure or the Plugin as QUnknownInterface*
415 */ 416 */
416QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { 417QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) {
417 /* 418 /*
418 * Check if there could be a library 419 * Check if there could be a library
419 */ 420 */
420 QString pa = item.path(); 421 QString pa = item.path();
421 if ( pa.isEmpty() ) 422 if ( pa.isEmpty() )
422 return 0l; 423 return 0l;
423 424
424 /* 425 /*
425 * See if we get a library 426 * See if we get a library
426 * return if we've none 427 * return if we've none
427 */ 428 */
428 setSafeMode( pa, true ); 429 setSafeMode( pa, true );
429 QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); 430 QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa );
430 if ( !lib ) { 431 if ( !lib ) {
431 setSafeMode(); 432 setSafeMode();
432 return 0l; 433 return 0l;
433 } 434 }
434 435
435 /** 436 /**
436 * try to load the plugin and just in case initialize the pointer to a pointer again 437 * try to load the plugin and just in case initialize the pointer to a pointer again
437 */ 438 */
438 QUnknownInterface* iface=0; 439 QUnknownInterface* iface=0;
439 if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { 440 if ( lib->queryInterface( uuid, &iface ) == QS_OK ) {
440 installTranslators(pa.left( pa.find("."))); 441 installTranslators(pa.left( pa.find(".")));
441 m_library.insert( iface, lib ); 442 m_library.insert( iface, lib );
442 }else 443 }else
443 iface = 0; 444 iface = 0;
444 445
445 setSafeMode(); 446 setSafeMode();
446 447
447 return iface; 448 return iface;
448} 449}
449 450
450/** 451/**
451 * @internal and reads in the safe mode 452 * @internal and reads in the safe mode
452 */ 453 */
453void OGenericPluginLoader::readConfig() { 454void OGenericPluginLoader::readConfig() {
454 455
455 456
456/* read the config for SafeMode */ 457/* read the config for SafeMode */
457 OConfig conf( m_dir + "-odpplugins" ); 458 OConfig conf( m_dir + "-odpplugins" );
458 conf.setGroup( "General" ); 459 conf.setGroup( "General" );
459 m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); 460 m_isSafeMode = conf.readBoolEntry( "SafeMode", false );
460} 461}
461 462
462/** 463/**
463 * @internal Enter or leave SafeMode 464 * @internal Enter or leave SafeMode
464 */ 465 */
465void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { 466void OGenericPluginLoader::setSafeMode(const QString& str, bool b) {
466 OConfig conf( m_dir + "-odpplugins" ); 467 OConfig conf( m_dir + "-odpplugins" );
467 conf.setGroup( "General" ); 468 conf.setGroup( "General" );
468 conf.writeEntry( "SafeMode", b ); 469 conf.writeEntry( "SafeMode", b );
469 conf.writeEntry( "CrashedPlugin", str ); 470 conf.writeEntry( "CrashedPlugin", str );
470} 471}
471 472
472/** 473/**
473 * @internal 474 * @internal
474 * 475 *
475 * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype 476 * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype
476 * is used as plugin dir 477 * is used as plugin dir
477 */ 478 */
478void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { 479void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) {
479 m_plugDirs = lst; 480 m_plugDirs = lst;
480} 481}
481 482
482/** 483/**
483 * 484 *
484 * @internal 485 * @internal
485 * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs 486 * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs
486 */ 487 */
487void OGenericPluginLoader::setPluginDir( const QString& str) { 488void OGenericPluginLoader::setPluginDir( const QString& str) {
488 m_plugDirs.clear(); 489 m_plugDirs.clear();
489 m_plugDirs.append( str ); 490 m_plugDirs.append( str );
490} 491}
491 492
492 493
493/** 494/**
494 * @internal 495 * @internal
495 */ 496 */
496bool OGenericPluginLoader::isSorted()const{ 497bool OGenericPluginLoader::isSorted()const{
497 return m_isSorted; 498 return m_isSorted;
498} 499}
499 500
500/* 501/*
501 * make libfoo.so.1.0.0 -> foo on UNIX 502 * make libfoo.so.1.0.0 -> foo on UNIX
502 * make libfoo.dylib -> foo on MAC OS X Unix 503 * make libfoo.dylib -> foo on MAC OS X Unix
503 * windows is obviously missing 504 * windows is obviously missing
504 */ 505 */
505/** 506/**
506 * @internal 507 * @internal
507 */ 508 */
508QString OGenericPluginLoader::unlibify( const QString& str ) { 509QString OGenericPluginLoader::unlibify( const QString& str ) {
509 QString st = str.mid( str.find( "lib" )+3 ); 510 QString st = str.mid( str.find( "lib" )+3 );
510#ifdef Q_OS_MACX 511#ifdef Q_OS_MACX
511 return st.left( st.findRev( ".dylib" ) ); 512 return st.left( st.findRev( ".dylib" ) );
512#else 513#else
513 return st.left( st.findRev( ".so" ) ); 514 return st.left( st.findRev( ".so" ) );
514#endif 515#endif
515} 516}
516 517
517/** 518/**
518 * @internal 519 * @internal
519 * 520 *
520 * \brief method to return available plugins. Internal and for reeimplementations 521 * \brief method to return available plugins. Internal and for reeimplementations
521 * 522 *
522 *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.
523 * If a plugin is on the excluded list assign position -2 524 * If a plugin is on the excluded list assign position -2
524 * 525 *
525 * @param dir The dir to look in 526 * @param dir The dir to look in
526 * @param sorted Should positions be read? 527 * @param sorted Should positions be read?
527 * @param disabled Remove excluded from the list 528 * @param disabled Remove excluded from the list
528 */ 529 */
529OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { 530OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const {
530#ifdef Q_OS_MACX 531#ifdef Q_OS_MACX
531 QDir dir( _dir, "lib*.dylib" ); 532 QDir dir( _dir, "lib*.dylib" );
532#else 533#else
533 QDir dir( _dir, "lib*.so" ); 534 QDir dir( _dir, "lib*.so" );
534#endif 535#endif
535 536
536 537
537 OPluginItem::List lst; 538 OPluginItem::List lst;
538 539
539 /* 540 /*
540 * get excluded list and then iterate over them 541 * get excluded list and then iterate over them
541 * Excluded list contains the name 542 * Excluded list contains the name
542 * Position is a list with 'name.pos.name.pos.name.pos' 543 * Position is a list with 'name.pos.name.pos.name.pos'
543 * 544 *
544 * For the look up we will create two QMap<QString,pos> 545 * For the look up we will create two QMap<QString,pos>
545 */ 546 */
546 QMap<QString, int> positionMap; 547 QMap<QString, int> positionMap;
547 QMap<QString, int> excludedMap; 548 QMap<QString, int> excludedMap;
548 549
549 550
550 OConfig cfg( m_dir+"-odpplugins" ); 551 OConfig cfg( m_dir+"-odpplugins" );
551 cfg.setGroup( _dir ); 552 cfg.setGroup( _dir );
552 553
553 554
554 QStringList excludes = cfg.readListEntry( "Excluded", ',' ); 555 QStringList excludes = cfg.readListEntry( "Excluded", ',' );
555 for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) 556 for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it )
556 excludedMap.insert( *it, -2 ); 557 excludedMap.insert( *it, -2 );
557 558
558 if ( m_isSorted ) { 559 if ( sorted ) {
559 QStringList pos = cfg.readListEntry( "Positions", '.' ); 560 QStringList pos = cfg.readListEntry( "Positions", '.' );
560 QStringList::Iterator it = pos.begin(); 561 QStringList::Iterator it = pos.begin();
561 while ( it != pos.end() ) 562 while ( it != pos.end() )
562 positionMap.insert( *it++, (*it++).toInt() ); 563 positionMap.insert( *it++, (*it++).toInt() );
564
563 } 565 }
564 566
565 567
566 568
567 569
568 QStringList list = dir.entryList(); 570 QStringList list = dir.entryList();
569 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 571 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
570 QString str = unlibify( *it ); 572 QString str = unlibify( *it );
571 OPluginItem item( str, _dir + "/" + *it ); 573 OPluginItem item( str, _dir + "/" + *it );
572 574
573 bool ex = excludedMap.contains( str ); 575 bool ex = excludedMap.contains( str );
574 /* 576 /*
575 * if disabled but we should show all mark it as disabled 577 * if disabled but we should show all mark it as disabled
576 * else continue because we don't want to add the item 578 * else continue because we don't want to add the item
577 * else if sorted we assign the right position 579 * else if sorted we assign the right position
578 */ 580 */
579 if ( ex && !disabled) 581 if ( ex && !disabled)
580 item.setEnabled( false ); 582 item.setEnabled( false );
581 else if ( ex && disabled ) 583 else if ( ex && disabled )
582 continue; 584 continue;
583 else if ( sorted ) 585 else if ( sorted )
584 item.setPosition( positionMap[str] ); 586 item.setPosition( positionMap[str] );
585 587
586 lst.append( item ); 588 lst.append( item );
587 } 589 }
588 590
589 return lst; 591 return lst;
590} 592}
591 593
592/** 594/**
593 * @internal generate a list of languages from $LANG 595 * @internal generate a list of languages from $LANG
594 */ 596 */
595QStringList OGenericPluginLoader::languageList() { 597QStringList OGenericPluginLoader::languageList() {
596 if ( m_languages.isEmpty() ) { 598 if ( m_languages.isEmpty() ) {
597 /* 599 /*
598 * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be 600 * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be
599 * to our list of languages. 601 * to our list of languages.
600 */ 602 */
601 QString str = ::getenv( "LANG" ); 603 QString str = ::getenv( "LANG" );
602 m_languages += str; 604 m_languages += str;
603 int pos = str.find( '.' ); 605 int pos = str.find( '.' );
604 606
605 if ( pos > 0 ) 607 if ( pos > 0 )
606 m_languages += str.left( pos ); 608 m_languages += str.left( pos );
607 609
608 int n_pos = str.find( '_' ); 610 int n_pos = str.find( '_' );
609 if ( pos > 0 && n_pos >= pos ) 611 if ( pos > 0 && n_pos >= pos )
610 m_languages += str.left( n_pos ); 612 m_languages += str.left( n_pos );
611 613
612 } 614 }
613 return m_languages; 615 return m_languages;
614} 616}
615 617
616/** 618/**
617 * @internal 619 * @internal
618 * Tries to install languages using the languageList for the type 620 * Tries to install languages using the languageList for the type
619 */ 621 */
620void OGenericPluginLoader::installTranslators(const QString& type) { 622void OGenericPluginLoader::installTranslators(const QString& type) {
621 QStringList lst = languageList(); 623 QStringList lst = languageList();
622 624
623 /* 625 /*
624 * for each language and maybe later for each language dir... 626 * for each language and maybe later for each language dir...
625 * try to load a Translator 627 * try to load a Translator
626 */ 628 */
627 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { 629 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
628 QTranslator* trans = new QTranslator( qApp ); 630 QTranslator* trans = new QTranslator( qApp );
629 QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ; 631 QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/" + type + ".qm" ;
630 632
631 /* 633 /*
632 * If loaded then install else clean up and don't leak 634 * If loaded then install else clean up and don't leak
633 */ 635 */
634 if ( trans->load( tfn ) ) 636 if ( trans->load( tfn ) )
635 qApp->installTranslator( trans ); 637 qApp->installTranslator( trans );
636 else 638 else
637 delete trans; 639 delete trans;
638 } 640 }
639} 641}
640 642
641/** 643/**
642 * \brief Simple c'tor. 644 * \brief Simple c'tor.
643 * 645 *
644 * Simple C'tor same as the one of the base class. Additional this 646 * Simple C'tor same as the one of the base class. Additional this
645 * class can cast for you if you nee it. 647 * class can cast for you if you nee it.
646 * 648 *
647 * 649 *
648 * @param name The name of your plugin class 650 * @param name The name of your plugin class
649 * @param sorted If plugins are sorted 651 * @param sorted If plugins are sorted
650 * 652 *
651 * @see OGenericPluginLoader 653 * @see OGenericPluginLoader
652 */ 654 */
653OPluginLoader::OPluginLoader( const QString& name, bool sorted ) 655OPluginLoader::OPluginLoader( const QString& name, bool sorted )
654 : OGenericPluginLoader( name, sorted ) 656 : OGenericPluginLoader( name, sorted )
655{ 657{
656} 658}
657 659
658/** 660/**
659 * d'tor 661 * d'tor
660 * @see OGenericPluginLoader::~OGenericPluginLoader 662 * @see OGenericPluginLoader::~OGenericPluginLoader
661 */ 663 */
662OPluginLoader::~OPluginLoader() { 664OPluginLoader::~OPluginLoader() {
663} 665}
664 666
665/** 667/**
666 * \brief C'Tor using a OGenericPluginLoader 668 * \brief C'Tor using a OGenericPluginLoader
667 * The C'tor. Pass your OGenericPluginLoader to manage 669 * The C'tor. Pass your OGenericPluginLoader to manage
668 * OGenericPluginLoader::allAvailable plugins. 670 * OGenericPluginLoader::allAvailable plugins.
669 * 671 *
670 * 672 *
671 * @param loader A Pointer to your OGenericPluginLoader 673 * @param loader A Pointer to your OGenericPluginLoader
672 * @param name The name 674 * @param name The name
673 */ 675 */
674OPluginManager::OPluginManager( OGenericPluginLoader* loader) 676OPluginManager::OPluginManager( OGenericPluginLoader* loader)
675 : m_loader( loader ), m_isSorted( false ) 677 : m_loader( loader ), m_isSorted( false )
676{ 678{
677} 679}
678 680
679/** 681/**
680 * \brief Overloaded c'tor using a List of Plugins and a type name 682 * \brief Overloaded c'tor using a List of Plugins and a type name
681 * Overloaded Constructor to work with a 'Type' of plugins 683 * Overloaded Constructor to work with a 'Type' of plugins
682 * and a correspending list of those. In this case calling load 684 * and a correspending list of those. In this case calling load
683 * is a no operation. 685 * is a no operation.
684 * 686 *
685 * @param name The name of your plugin ('today','inputmethods','applets') 687 * @param name The name of your plugin ('today','inputmethods','applets')
686 * @param lst A List with plugins of your type to manage 688 * @param lst A List with plugins of your type to manage
687 * @param isSorted If the List should be treated sorted 689 * @param isSorted If the List should be treated sorted
688 */ 690 */
689OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) 691OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted)
690 : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) 692 : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted )
691{ 693{
692} 694}
693 695
694/** 696/**
695 * \brief A simple d'tor 697 * \brief A simple d'tor
696 */ 698 */
697OPluginManager::~OPluginManager() { 699OPluginManager::~OPluginManager() {
698} 700}
699 701
700/** 702/**
701 * \brief Return the OPluginItem where loading is likely to have crashed on. 703 * \brief Return the OPluginItem where loading is likely to have crashed on.
702 704
703 * Return the Item that made the OGenericPluginLoader crash 705 * Return the Item that made the OGenericPluginLoader crash
704 * the returned OPluginItem could be empty if no crash occured 706 * 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 707 * 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 708 * plugin is not in the current list of available/managed plugins
707 * 709 *
708 * @see OPluginItem::isEmpty 710 * @see OPluginItem::isEmpty
709 * @return OPluginItem that crashed the loader 711 * @return OPluginItem that crashed the loader
710 */ 712 */
711OPluginItem OPluginManager::crashedPlugin()const { 713OPluginItem OPluginManager::crashedPlugin()const {
712 return m_crashed; 714 return m_crashed;
713} 715}
714 716
715/** 717/**
716 * \brief Return a list of plugins that are managed by this OPluginManager 718 * \brief Return a list of plugins that are managed by this OPluginManager
717 * 719 *
718 * Return the list of managed plugins. This could either result 720 * Return the list of managed plugins. This could either result
719 * from passing a OGenericPluginLoader and calling load or by 721 * from passing a OGenericPluginLoader and calling load or by
720 * giving name and a list of plugins. 722 * giving name and a list of plugins.
721 */ 723 */
722OPluginItem::List OPluginManager::managedPlugins()const { 724OPluginItem::List OPluginManager::managedPlugins()const {
723 return m_plugins; 725 return m_plugins;
724} 726}
725 727
726/** 728/**
727 * \brief Set the position of the items 729 * \brief Set the position of the items
728 * 730 *
729 * Replace the OPluginItem with the name and path and this way 731 * 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) 732 * 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 733 * 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 734 * a call to OGenericPluginLoader::filtered() returns the newly configured order and items
733 * 735 *
734 * @param item The OPluginItem to be replaced internall 736 * @param item The OPluginItem to be replaced internall
735 * 737 *
736 */ 738 */
737void OPluginManager::setPosition( const OPluginItem& item) { 739void OPluginManager::setPosition( const OPluginItem& item) {
738 replace( item ); 740 replace( item );
739} 741}
740 742
741/** 743/**
742 * \brief Enable the item specified as argument 744 * \brief Enable the item specified as argument
743 * 745 *
744 * This will make sure that OPluginItem::setEnabled is called and then will replace 746 * This will make sure that OPluginItem::setEnabled is called and then will replace
745 * the item with one that matches name and path internally. 747 * the item with one that matches name and path internally.
746 * @see setPosition 748 * @see setPosition
747 * 749 *
748 * @param the Item to enable 750 * @param the Item to enable
749 */ 751 */
750void OPluginManager::enable( const OPluginItem& item ) { 752void OPluginManager::enable( const OPluginItem& item ) {
751 setEnabled( item, true ); 753 setEnabled( item, true );
752} 754}
753 755
754/** 756/**
755 * \brief disable the Item. 757 * \brief disable the Item.
756 * 758 *
757 * Disable the OPluginItem. Same applies as in 759 * Disable the OPluginItem. Same applies as in
758 * @see setPosition and @see enable 760 * @see setPosition and @see enable
759 * 761 *
760 * @param item Item to disable 762 * @param item Item to disable
761 */ 763 */
762void OPluginManager::disable( const OPluginItem& item) { 764void OPluginManager::disable( const OPluginItem& item) {
763 setEnabled( item, false ); 765 setEnabled( item, false );
764} 766}
765 767
766/** 768/**
767 * \brief Enable or disable the OPluginItem. 769 * \brief Enable or disable the OPluginItem.
768 * Depending on the value of the parameter this will either disable 770 * Depending on the value of the parameter this will either disable
769 * or enable the pluginitem. 771 * or enable the pluginitem.
770 * Beside that same as in @see disable, @see enable, @see setPosition 772 * Beside that same as in @see disable, @see enable, @see setPosition
771 * applies. 773 * applies.
772 * 774 *
773 * @param _item The OPluginItem to enable or to disable. 775 * @param _item The OPluginItem to enable or to disable.
774 * @param b Enable or disable the plugin. 776 * @param b Enable or disable the plugin.
775 * 777 *
776 */ 778 */
777void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { 779void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) {
778 OPluginItem item = _item; 780 OPluginItem item = _item;
779 item.setEnabled( b ); 781 item.setEnabled( b );
780 replace( item ); 782 replace( item );
781} 783}
782 784
783/** 785/**
784 * \brief Load necessary information after constructing the object 786 * \brief Load necessary information after constructing the object
785 * If you speified a OGenericPluginLoader you need to call this method 787 * 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 788 * 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 789 * For the name and the list of plugins this does only try to find out the crashed plugin
788 */ 790 */
789void OPluginManager::load() { 791void OPluginManager::load() {
790 OConfig cfg( configName() ); 792 OConfig cfg( configName() );
791 cfg.setGroup( "General" ); 793 cfg.setGroup( "General" );
792 QString crashedPath = cfg.readEntry( "CrashedPlugin" ); 794 QString crashedPath = cfg.readEntry( "CrashedPlugin" );
793 795
794 /* if we've a loader this applies if we were called from the first part */ 796 /* if we've a loader this applies if we were called from the first part */
795 if ( m_loader ) 797 if ( m_loader )
796 m_plugins = m_loader->allAvailable( m_loader->isSorted() ); 798 m_plugins = m_loader->allAvailable( m_loader->isSorted() );
797 799
798 /* fast and normal route if we did not crash... */ 800 /* fast and normal route if we did not crash... */
799 if ( crashedPath.isEmpty() ) 801 if ( crashedPath.isEmpty() )
800 return; 802 return;
801 803
802 /* lets try to find the plugin path and this way the associated item */ 804 /* 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 ) 805 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it )
804 if ( (*it).path() == crashedPath ) { 806 if ( (*it).path() == crashedPath ) {
805 m_crashed = *it; 807 m_crashed = *it;
806 break; 808 break;
807 } 809 }
808} 810}
809 811
810 812
811/** 813/**
812 * \brief Save the values and this way make it available. 814 * \brief Save the values and this way make it available.
813 * 815 *
814 * Save the current set of data. A call to @see OGenericPluginLoader::filtered 816 * Save the current set of data. A call to @see OGenericPluginLoader::filtered
815 * now would return your saved changes. 817 * now would return your saved changes.
816 */ 818 */
817void OPluginManager::save() { 819void OPluginManager::save() {
818 QMap<QString, QStringList> excluded; // map for path to excluded name 820 QMap<QString, QStringList> excluded; // map for path to excluded name
819 QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs 821 QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs
820 bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; 822 bool sorted = m_loader ? m_loader->isSorted() : m_isSorted;
821 823
822 /* 824 /*
823 * We will create some maps for the groups to include positions a 825 * We will create some maps for the groups to include positions a
824 */ 826 */
825 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { 827 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) {
826 OPluginItem item = *it; 828 OPluginItem item = *it;
827 QString path = QFileInfo( item.path() ).dirPath(true); 829 QString path = QFileInfo( item.path() ).dirPath(true);
828 if ( sorted ) { 830 if ( sorted ) {
829 positions[path].append( item.name() ); 831 positions[path].append( item.name() );
830 positions[path].append( QString::number( item.position() ) ); 832 positions[path].append( QString::number( item.position() ) );
831 } 833 }
832 834
833 if ( !item.isEnabled() ) 835 if ( !item.isEnabled() )
834 excluded[path].append( item.name() ); 836 excluded[path].append( item.name() );
835 } 837 }
836 838
837/* 839/*
838 * The code below wouldn't work because we can't delete groups/keys from the config 840 * The code below wouldn't work because we can't delete groups/keys from the config
839 * ### for ODP make Config right! 841 * ### for ODP make Config right!
840 */ 842 */
841// if ( excluded.isEmpty() && positions.isEmpty() ) return; 843// if ( excluded.isEmpty() && positions.isEmpty() ) return;
842 /* 844 /*
843 * Now safe for each path 845 * Now safe for each path
844 */ 846 */
845 OConfig cfg( configName() ); 847 OConfig cfg( configName() );
846 848
847 /* safe excluded items */ 849 /* safe excluded items */
848 for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { 850 for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) {
849 OConfigGroupSaver saver( &cfg, it.key() ); 851 OConfigGroupSaver saver( &cfg, it.key() );
850 cfg.writeEntry("Excluded", it.data(), ',' ); 852 cfg.writeEntry("Excluded", it.data(), ',' );
851 } 853 }
852 854
853 /* safe positions we could also see if positions.contains(path) and remove/write in the above loop 855 /* 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... 856 * ### Write a Test Suite that can profile these runs...
855 */ 857 */
856 for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { 858 for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) {
857 OConfigGroupSaver saver( &cfg, it.key() ); 859 OConfigGroupSaver saver( &cfg, it.key() );
858 cfg.writeEntry("Positions", it.data(), '.' ); 860 cfg.writeEntry("Positions", it.data(), '.' );
859 } 861 }
860} 862}
861 863
862/** 864/**
863 * @internal 865 * @internal
864 */ 866 */
865QString OPluginManager::configName()const { 867QString OPluginManager::configName()const {
866 QString str = m_loader ? m_loader->name() : m_cfgName; 868 QString str = m_loader ? m_loader->name() : m_cfgName;
867 return str + "-odpplugins"; 869 return str + "-odpplugins";
868} 870}
869 871
870/** 872/**
871 * @internal.. replace in m_plugins by path... this is linear search O(n/2) 873 * @internal.. replace in m_plugins by path... this is linear search O(n/2)
872 */ 874 */
873void OPluginManager::replace( const OPluginItem& item ) { 875void OPluginManager::replace( const OPluginItem& item ) {
874 OPluginItem _item; 876 OPluginItem _item;
875 877
876 /* for all plugins */ 878 /* for all plugins */
877 for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { 879 for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) {
878 _item = *it; 880 _item = *it;
879 /* if path and name are the same we will remove, readd and return */ 881 /* if path and name are the same we will remove, readd and return */
880 if ( _item.path() == item.path() && 882 if ( _item.path() == item.path() &&
881 _item.name() == item.name() ) { 883 _item.name() == item.name() ) {
882 it = m_plugins.remove( it ); 884 it = m_plugins.remove( it );
883 m_plugins.append( item ); 885 m_plugins.append( item );
884 return; 886 return;
885 } 887 }
886 888
887 } 889 }
888} 890}
889 891
890} 892}
891} 893}