Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Opie::Core::OGenericPluginLoader Class Reference

A generic class to easily load and manage plugins. More...

#include </home/clem/local/src/opie/libopie2/opiecore/opluginloader.h>

Inheritance diagram for Opie::Core::OGenericPluginLoader:

Inheritance graph
[legend]
Collaboration diagram for Opie::Core::OGenericPluginLoader:

Collaboration graph
[legend]
List of all members.

Public Types

typedef OPluginItem::List List

Public Member Functions

 OGenericPluginLoader (const QString &name, bool isSorted=false)
 create a PluginLoader
virtual ~OGenericPluginLoader ()
 simple d'tor that cleans up depending on autoDelete
void setAutoDelete (bool)
 Enable or disable autoDelete on destruction.
bool autoDelete () const
 See if autoDelete is enabled.
void clear ()
 unload all loaded Plugins
QString name () const
 The name of the plugins.
bool isSorted () const
bool isInSafeMode () const
 See if loading of a plugin segfaulted This tells you if by previous tries to load, loading crashed your application. If isInSafeMode you can use the GUI to configure the plugins prior to loading.
List allAvailable (bool sorted=false) const
 Return all Plugins found in the plugins dirs. Return the list of all available plugins. This will go through all plugin directories and search for your type of plugins ( by subdir ).
List filtered (bool sorted=false) const
 Return only the enabled plugins Return only activated plugins.
virtual QUnknownInterfaceload (const OPluginItem &item, const QUuid &)
 Load a OPluginItem for the specified interface This will open the resource of the OPluginItem::path() and then will query if the Interface specified in the uuid is available and then will manage the resource and Interface.
virtual void unload (QUnknownInterface *)
 unload the Plugin and the accompanied Resources.

Protected Member Functions

void readConfig ()
virtual List plugins (const QString &dir, bool sorted, bool disabled) const
 method to return available plugins. Internal and for reeimplementations
void setPluginDirs (const QStringList &)
void setPluginDir (const QString &)
void setSafeMode (const QString &app=QString::null, bool b=false)

Static Protected Member Functions

static QString unlibify (const QString &str)

Private Member Functions

QStringList languageList ()
void installTranslators (const QString &type)

Private Attributes

QString m_dir
QStringList m_plugDirs
QStringList m_languages
bool m_autoDelete: 1
bool m_isSafeMode: 1
bool m_isSorted: 1
QPtrDict< QLibrarym_library
Private * d

Friends

class OPluginManager

Detailed Description

A generic class to easily load and manage plugins.

This is the generic non sepcialised loader for plugins. Normally you would prefer using the OPluginLoader directly. This class exists to minimize the application binary size due the usage of templates in the specialized API.

Since:
1.2
See also:
OPluginLoader

Definition at line 73 of file opluginloader.h.


Member Typedef Documentation

typedef OPluginItem::List Opie::Core::OGenericPluginLoader::List
 

Definition at line 75 of file opluginloader.h.


Constructor & Destructor Documentation

Opie::Core::OGenericPluginLoader::OGenericPluginLoader const QString name,
bool  isSorted = false
 

create a PluginLoader

Create a PluginLoader autoDelete is set to false

 Opie::Core::OGenericPluginLoader loader("myapp-plugin");
 Opie::Core::OPluginItem::List  lst = loader.filtered();
 for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
    MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
 }

 Opie::Core::OGenericPluginLoader loader("myapp-plugin");
 Opie::Core::OPluginItem::List  lst = loader.filtered();
 for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
    MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
 }
 ...
 loader.clear();

Parameters:
name The name of the plugin directory.
isSorted Tell the PluginLoader if your Plugins are sorted

Definition at line 281 of file opluginloader.cpp.

References QPEApplication::qpeDir(), readConfig(), and setPluginDir().

Opie::Core::OGenericPluginLoader::~OGenericPluginLoader  )  [virtual]
 

simple d'tor that cleans up depending on autoDelete

calls clear if autoDelete is true. This will release all interfaces and remove the library from this process if the refcount falls to zero

Definition at line 296 of file opluginloader.cpp.

References clear(), and m_autoDelete.


Member Function Documentation

OPluginItem::List Opie::Core::OGenericPluginLoader::allAvailable bool  sorted = false  )  const
 

Return all Plugins found in the plugins dirs. Return the list of all available plugins. This will go through all plugin directories and search for your type of plugins ( by subdir ).

Parameters:
sorted Tell if you want to have the positions sorted. This only makes sense if you

Definition at line 379 of file opluginloader.cpp.

References QValueList< T >::begin(), QValueList< T >::end(), m_plugDirs, plugins(), and qHeapSort().

Referenced by Opie::Core::OPluginManager::load(), main(), DateBookSettings::pluginItemClicked(), DateBookSettings::setPluginList(), and TodayConfig::writeConfig().

bool Opie::Core::OGenericPluginLoader::autoDelete  )  const
 

See if autoDelete is enabled.

Definition at line 316 of file opluginloader.cpp.

References m_autoDelete.

void Opie::Core::OGenericPluginLoader::clear  ) 
 

unload all loaded Plugins

This will unload all returned QUnknownInterfaces by load. Unload will be called.

Definition at line 326 of file opluginloader.cpp.

References m_library, and unload().

Referenced by ~OGenericPluginLoader().

OPluginItem::List Opie::Core::OGenericPluginLoader::filtered bool  sorted = false  )  const
 

Return only the enabled plugins Return only activated plugins.

Parameters:
sorted If the list should be sorted

Definition at line 395 of file opluginloader.cpp.

References QValueList< T >::begin(), QValueList< T >::end(), m_plugDirs, plugins(), and qHeapSort().

Referenced by DateBookHoliday::init(), Today::loadPluginWidgets(), and main().

void Opie::Core::OGenericPluginLoader::installTranslators const QString type  )  [private]
 

For internal use only.

Tries to install languages using the languageList for the type

Definition at line 632 of file opluginloader.cpp.

References QValueList< T >::begin(), QValueList< T >::end(), languageList(), qApp, and QPEApplication::qpeDir().

Referenced by load().

bool Opie::Core::OGenericPluginLoader::isInSafeMode  )  const
 

See if loading of a plugin segfaulted This tells you if by previous tries to load, loading crashed your application. If isInSafeMode you can use the GUI to configure the plugins prior to loading.

Returns:
true if prior loading failed

Definition at line 367 of file opluginloader.cpp.

References m_isSafeMode.

Referenced by Today::loadPluginWidgets(), and main().

bool Opie::Core::OGenericPluginLoader::isSorted  )  const
 

For internal use only.

Definition at line 497 of file opluginloader.cpp.

References m_isSorted.

Referenced by Opie::Core::OPluginManager::load(), and Opie::Core::OPluginManager::save().

QStringList Opie::Core::OGenericPluginLoader::languageList  )  [private]
 

For internal use only.

generate a list of languages from $LANG

Definition at line 601 of file opluginloader.cpp.

References QString::find(), QValueList< T >::isEmpty(), QString::left(), m_languages, pos, and str.

Referenced by installTranslators().

QUnknownInterface * Opie::Core::OGenericPluginLoader::load const OPluginItem item,
const QUuid uuid
[virtual]
 

Load a OPluginItem for the specified interface This will open the resource of the OPluginItem::path() and then will query if the Interface specified in the uuid is available and then will manage the resource and Interface.

Parameters:
item The OPluginItem that should be loaded
uuid The Interface to query for
Returns:
Either 0 in case of failure or the Plugin as QUnknownInterface*
try to load the plugin and just in case initialize the pointer to a pointer again

Reimplemented in Opie::Core::OPluginLoader.

Definition at line 417 of file opluginloader.cpp.

References installTranslators(), QString::isEmpty(), l, m_library, Opie::Core::OPluginItem::name(), Opie::Core::OPluginItem::path(), QS_OK, QLibrary::queryInterface(), Opie::Core::Internal::OPluginLibraryHolder::self(), and setSafeMode().

Referenced by Opie::Core::OPluginLoader::load(), and main().

QString Opie::Core::OGenericPluginLoader::name  )  const
 

The name of the plugins.

Return the name/type you specified in the constructor. This is at least used by the OPluginManager to find the right config

Definition at line 354 of file opluginloader.cpp.

References m_dir.

Referenced by Opie::Core::OPluginManager::configName().

OPluginItem::List Opie::Core::OGenericPluginLoader::plugins const QString _dir,
bool  sorted,
bool  disabled
const [protected, virtual]
 

method to return available plugins. Internal and for reeimplementations

For internal use only.

Return a List of Plugins for a dir and add positions and remove disabled. If a plugin is on the excluded list assign position -2

Parameters:
_dir The dir to look in
sorted Should positions be read?
disabled Remove excluded from the list

Definition at line 530 of file opluginloader.cpp.

References QValueList< T >::append(), QValueList< T >::begin(), QMap< Key, T >::contains(), QValueList< T >::end(), QDir::entryList(), i, QMap< Key, T >::insert(), list, m_dir, pos, Config::readListEntry(), Opie::Core::OPluginItem::setEnabled(), Config::setGroup(), Opie::Core::OPluginItem::setPosition(), str, QString::toInt(), and unlibify().

Referenced by allAvailable(), and filtered().

void Opie::Core::OGenericPluginLoader::readConfig  )  [protected]
 

For internal use only.

and reads in the safe mode

Definition at line 454 of file opluginloader.cpp.

References m_dir, m_isSafeMode, Config::readBoolEntry(), and Config::setGroup().

Referenced by OGenericPluginLoader().

void Opie::Core::OGenericPluginLoader::setAutoDelete bool  t  ) 
 

Enable or disable autoDelete on destruction.

enable autoDelete. This will call clear on the d'tor

See also:
~OGenericPluginLoader

clear()

Definition at line 309 of file opluginloader.cpp.

References m_autoDelete.

Referenced by DateBookHoliday::DateBookHoliday(), TheNSResources::findAvailableNetNodes(), Today::loadPlugins(), and main().

void Opie::Core::OGenericPluginLoader::setPluginDir const QString str  )  [protected]
 

For internal use only.

Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs

Definition at line 488 of file opluginloader.cpp.

References QValueList< T >::append(), QValueList< T >::clear(), and m_plugDirs.

Referenced by OGenericPluginLoader().

void Opie::Core::OGenericPluginLoader::setPluginDirs const QStringList lst  )  [protected]
 

For internal use only.

Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"plugins/"+mytype is used as plugin dir

Definition at line 479 of file opluginloader.cpp.

References m_plugDirs.

void Opie::Core::OGenericPluginLoader::setSafeMode const QString str = QString::null,
bool  b = false
[protected]
 

For internal use only.

Enter or leave SafeMode

Definition at line 466 of file opluginloader.cpp.

References m_dir, Config::setGroup(), and Config::writeEntry().

Referenced by load().

QString Opie::Core::OGenericPluginLoader::unlibify const QString str  )  [static, protected]
 

For internal use only.

Definition at line 509 of file opluginloader.cpp.

References QString::find(), QString::findRev(), QString::left(), and QString::mid().

Referenced by plugins().

void Opie::Core::OGenericPluginLoader::unload QUnknownInterface iface  )  [virtual]
 

unload the Plugin and the accompanied Resources.

This will take the iface from the internal QPtrDict, Release it, and deref the libray used. The visibility depends on the QPtrDict.

See also:
QPtrDict::insert

Definition at line 340 of file opluginloader.cpp.

References m_library, and Opie::Core::Internal::OPluginLibraryHolder::self().

Referenced by clear().


Friends And Related Function Documentation

friend class OPluginManager [friend]
 

Definition at line 96 of file opluginloader.h.


Member Data Documentation

Private* Opie::Core::OGenericPluginLoader::d [private]
 

Definition at line 114 of file opluginloader.h.

bool Opie::Core::OGenericPluginLoader::m_autoDelete [private]
 

Definition at line 109 of file opluginloader.h.

Referenced by autoDelete(), setAutoDelete(), and ~OGenericPluginLoader().

QString Opie::Core::OGenericPluginLoader::m_dir [private]
 

Definition at line 106 of file opluginloader.h.

Referenced by name(), plugins(), readConfig(), and setSafeMode().

bool Opie::Core::OGenericPluginLoader::m_isSafeMode [private]
 

Definition at line 110 of file opluginloader.h.

Referenced by isInSafeMode(), and readConfig().

bool Opie::Core::OGenericPluginLoader::m_isSorted [private]
 

Definition at line 111 of file opluginloader.h.

Referenced by isSorted().

QStringList Opie::Core::OGenericPluginLoader::m_languages [private]
 

Definition at line 108 of file opluginloader.h.

Referenced by languageList().

QPtrDict<QLibrary> Opie::Core::OGenericPluginLoader::m_library [private]
 

Definition at line 112 of file opluginloader.h.

Referenced by clear(), load(), and unload().

QStringList Opie::Core::OGenericPluginLoader::m_plugDirs [private]
 

Definition at line 107 of file opluginloader.h.

Referenced by allAvailable(), filtered(), setPluginDir(), and setPluginDirs().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 18:00:46 2005 for OPIE by  doxygen 1.4.2