summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/opluginloader.h
authorzecke <zecke>2004-05-10 21:11:25 (UTC)
committer zecke <zecke>2004-05-10 21:11:25 (UTC)
commit23a70b8db47ea571bf9a35f4ff8f5696a6c9c1d3 (patch) (side-by-side diff)
treeb084195bd871b12c3ea1b01e52a4916d17c8a2c6 /libopie2/opiecore/opluginloader.h
parent613e0a6b246d8dcfd808089b2b6a1dc0501732da (diff)
downloadopie-23a70b8db47ea571bf9a35f4ff8f5696a6c9c1d3.zip
opie-23a70b8db47ea571bf9a35f4ff8f5696a6c9c1d3.tar.gz
opie-23a70b8db47ea571bf9a35f4ff8f5696a6c9c1d3.tar.bz2
First draft of PluginLoader
-actual loading of plugins is 80% done -Manager no code is there yet. I hope to have some time in uni tomorrow
Diffstat (limited to 'libopie2/opiecore/opluginloader.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/opluginloader.h191
1 files changed, 191 insertions, 0 deletions
diff --git a/libopie2/opiecore/opluginloader.h b/libopie2/opiecore/opluginloader.h
new file mode 100644
index 0000000..a7df4a8
--- a/dev/null
+++ b/libopie2/opiecore/opluginloader.h
@@ -0,0 +1,191 @@
+/*
+ * LGPLv2 or later
+ * zecke@handhelds.org
+ */
+#ifndef ODP_CORE_OPLUGIN_LOADER_H
+#define ODP_CORE_OPLUGIN_LOADER_H
+
+#include <qpe/qlibrary.h>
+
+#include <qstringlist.h>
+
+namespace Opie {
+namespace Core {
+class OConfig;
+namespace Internal {
+class OPluginLibraryHolder;
+}
+
+template class QPtrDict<QLibrary>;
+
+/**
+ * \brief A small item representing the Plugin Information
+ * This class contains the information about a Plugin. It contains
+ * a translated name if available to the system, a config key,
+ * and the path location.
+ *
+ * @since 1.2
+ *
+ */
+class OPluginItem {
+public:
+ typedef QValueList<OPluginItem> List;
+ OPluginItem();
+ OPluginItem( const QString& name, const QCString& confopt, const QString& path, int pos = -1 );
+ ~OPluginItem();
+
+ bool operator==( const OPluginItem& )const;
+ bool operator!=( const OPluginItem& )const;
+
+
+ QString name()const;
+ QCString configKey()const;
+ QString path()const;
+ int position()const;
+
+ void setName( const QString& );
+ void setConfigKey( const QCString& );
+ void setPath( const QString& );
+ void setPosition( int );
+
+private:
+ QString m_name;
+ QCString m_conf;
+ QString m_path;
+ int m_pos;
+ struct Private;
+ Private *d;
+};
+
+/**
+ * \brief 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 OPluginLoader
+ */
+class OGenericPluginLoader {
+public:
+ typedef OPluginItem::List List;
+ OGenericPluginLoader( const QString &name, bool isSorted = false );
+ virtual ~OGenericPluginLoader();
+
+ void setAutoDelete( bool );
+ bool autoDelete()const;
+ void clear();
+
+
+ bool isInSafeMode()const;
+
+
+ List allAvailable(bool sorted = FALSE)const;
+ List filtered(bool sorted = FALSE)const;
+
+
+ virtual QUnknownInterface* load( const OPluginItem& item, const QUuid& );
+ virtual void unload( QUnknownInterface* );
+
+protected:
+ virtual void readConfig();
+ virtual List plugins( const QString& dir, bool sorted, bool disabled )const;
+ void setPluginDirs( const QStringList& );
+ void setPluginDir( const QString& );
+ bool &isSafeMode()const;
+ bool &isSorted()const;
+ void readConfig()const;
+ void setSafeMode(bool b = false);
+
+private:
+ QString languageList();
+ void installTranslators(const QString& type);
+ QString m_dir;
+ QStringList m_plugDirs;
+ QStringList m_languages;
+ bool m_autoDelete : 1;
+ bool m_isSafeMode : 1;
+ bool m_readConfig : 1;
+ bool m_isSorted : 1;
+ QPtrDict<QLibrary> m_library;
+
+ struct Private;
+ Private* d;
+};
+
+/**
+ * \brief The class to load your QCOM+ plugins
+ *
+ * This class takes care of activation and even the order
+ * if you need it. It is normally good to place a .directory file
+ * into your plugin directory if you need order of activation.
+ *
+ * You'll create the OPluginLoader and then use it to load the filtered
+ * plugins.
+ *
+ * There is also a GUI for the configuration and a Manager to write the
+ * mentioned .directory file
+ *
+ * On crash the safe mode is activated for the next run. You can then decide
+ * if you want to load plugins or come up with the Configuration on
+ * next start yourself then.
+ *
+ * @since 1.2
+ */
+class OPluginLoader : public OGenericPluginLoader {
+public:
+ OPluginLoader( const QString& name, bool sorted = false );
+ ~OPluginLoader();
+
+ temlate<class IFace>
+ IFace* load( const QString& name, const QUuid& );
+ temlate<class IFace>
+ IFace* load( const OPluginItem& item, const QUuid& );
+};
+
+/**
+ * \brief A class to manager order and activation of plugins
+ *
+ * Manage order and activation. This is used by the Opie::Ui::OPluginConfig
+ * This class controls the activation and order of plugins depending
+ * on the OPluginLoader you supply.
+ *
+ * @see OPluginConfig
+ *
+ */
+class OPluginManager {
+public:
+ OPluginManager( OGenericPluginLoader* , const QString& name);
+ OPluginManager( OConfig* conf, const QString&,
+ const QCString& group, const OPluginItem::List& );
+ ~OPluginManager();
+
+ QString name();
+ void setName( const QString& );
+
+ void setPosition( const OPluginItem& );
+ void enable( const OPluginItem& );
+ void disable( const OPluginItem& );
+ void setEnabled( const OPluginItem&, bool = true);
+
+ void load();
+ void save();
+};
+
+template<class IFace>
+IFace* OPluginLoader::load( const QString& name, const QUuid& uid ) {
+ return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) );
+}
+
+template<class IFace>
+IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) {
+ return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) );
+}
+
+}
+}
+
+
+#endif