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