plugins.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           plugins.h  -  description
00003                              -------------------
00004     begin                : Mon Mär 10 2003
00005     copyright            : (C) 2003 by Martin Witte
00006     email                : witte@kawo1.rwth-aachen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00019 
00020 #ifndef KRADIO_PLUGINS_INTERFACES_H
00021 #define KRADIO_PLUGINS_INTERFACES_H
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <kglobal.h>
00028 
00029 #include "errorlog-interfaces.h"
00030 #include <qstring.h>
00031 #include <qobject.h>
00032 #include <qptrlist.h>
00033 
00034 class PluginManager;
00035 class PluginBase;
00036 class QWidget;
00037 class KConfig;
00038 
00039 typedef QPtrList<PluginBase>           PluginList;
00040 typedef QPtrListIterator<PluginBase>   PluginIterator;
00041 
00042 /* PluginBase must be inherited from Interface so that a plugin can be used
00043    in Interface::connect functions.
00044 
00045    PluginBase must not be inherited from QObject, because derived classes may
00046    be inherited e.g. from QWidget (multiple inheritance is not possible with
00047    OBjects). But we must be able to receive destroy messages e.g. from
00048    configuration pages. Thus we need the special callback member
00049    m_destroyNotifier.
00050 
00051    PluginBase is derived from Interface to provide connection facilities.
00052    In case of multiple inheritance from interface classes, connect and disconnect
00053    methods have to be reimplemented in order to call all inherited
00054    connect/disconnect methods.
00055 
00056 */
00057 
00058 
00059 class WidgetPluginBase;
00060 
00061 struct ConfigPageInfo
00062 {
00063     ConfigPageInfo () : page(NULL) {}
00064     ConfigPageInfo (QWidget *p,
00065                     const QString &in,
00066                     const QString &ph,
00067                     const QString &icon)
00068       : page (p),
00069         itemName(in),
00070         pageHeader(ph),
00071         iconName(icon)
00072     {}
00073 
00074     QWidget  *page;
00075     QString   itemName,
00076               pageHeader,
00077               iconName;
00078 };
00079 
00080 typedef ConfigPageInfo AboutPageInfo;
00081 
00082 
00083 class PluginBase : public IErrorLogClient
00084 {
00085 friend class PluginManager;
00086 public :
00087              PluginBase(const QString &name, const QString &description);
00088     virtual ~PluginBase();
00089 
00090     virtual  QString pluginClassName() const = 0;
00091 
00092     const QString &name() const { return m_name; }
00093           QString &name()       { return m_name; }
00094 
00095     const QString &description() const { return m_description; }
00096 
00097     // workaround for compiler bugs
00098     bool           destructorCalled() const { return m_destructorCalled; }
00099 
00100     // interaction with pluginmanager
00101 protected:
00102     bool setManager (PluginManager *);
00103     void unsetManager ();
00104     bool isManagerSet () const;
00105 
00106 public:
00107 
00108     // these two methods will request a configuration page or
00109     // plugin page from plugin manager
00110     // they will be deleted automatically when this plugin
00111     // is deleted, because we disconnect from pluginmanager
00112     // and the plugin manager will delete all associated gui elements
00113     virtual ConfigPageInfo createConfigurationPage () = 0;
00114     virtual AboutPageInfo  createAboutPage () = 0;
00115 
00116     // save/restore status, window position, etc...
00117 
00118     virtual void   saveState (KConfig *) const = 0;
00119     virtual void   restoreState (KConfig *) = 0;
00120     virtual void   startPlugin();
00121 
00122     virtual void   aboutToQuit();
00123 
00124     //
00125 
00126     virtual void noticeWidgetPluginShown(WidgetPluginBase *, bool /*shown*/) {}
00127     virtual void noticePluginsChanged(const PluginList &) {}
00128 
00129 protected :
00130     QString            m_name;
00131     QString            m_description;
00132     PluginManager     *m_manager;
00133     bool               m_destructorCalled;
00134 };
00135 
00136 
00137 #define PLUGIN_LIBRARY_FUNCTIONS(class_name, i18nName, description) \
00138 extern "C" void KRadioPlugin_LoadLibrary() \
00139 {                                                                 \
00140     KGlobal::locale()->insertCatalogue(i18nName);                 \
00141 }                                                                 \
00142                                                                   \
00143 extern "C" void KRadioPlugin_UnloadLibrary() \
00144 {                                                                 \
00145     KGlobal::locale()->removeCatalogue(i18nName);                 \
00146 }                                                                 \
00147                                                                   \
00148 extern "C" void KRadioPlugin_GetAvailablePlugins(QMap<QString, QString> &info) \
00149 {                                                                 \
00150     info.insert(#class_name, (description));                      \
00151 }                                                                 \
00152                                                                   \
00153 extern "C" PluginBase *KRadioPlugin_CreatePlugin(const QString &type, const QString &object_name) \
00154 {                                                                                    \
00155     if (type == #class_name) {                                                       \
00156         return new class_name(object_name);                                          \
00157     } else {                                                                         \
00158         return NULL;                                                                 \
00159     }                                                                                \
00160 }
00161 
00162 
00163 #define PLUGIN_LIBRARY_FUNCTIONS2(class_name1, i18nName, description1, class_name2, description2) \
00164 extern "C" void KRadioPlugin_LoadLibrary() \
00165 {                                                                 \
00166     KGlobal::locale()->insertCatalogue(i18nName);                 \
00167 }                                                                 \
00168                                                                   \
00169 extern "C" void KRadioPlugin_UnloadLibrary() \
00170 {                                                                 \
00171     KGlobal::locale()->removeCatalogue(i18nName);                 \
00172 }                                                                 \
00173                                                                   \
00174 extern "C" void KRadioPlugin_GetAvailablePlugins(QMap<QString, QString> &info) \
00175 {                                                                 \
00176     info.insert(#class_name1, (description1));                    \
00177     info.insert(#class_name2, (description2));                    \
00178 }                                                                 \
00179                                                                   \
00180 extern "C" PluginBase *KRadioPlugin_CreatePlugin(const QString &type, const QString &object_name) \
00181 {                                                                                       \
00182     if (type == #class_name1) {                                                         \
00183         return new class_name1(object_name);                                            \
00184     } else if (type == #class_name2) {                                                  \
00185         return new class_name2(object_name);                                            \
00186     } else {                                                                            \
00187         return NULL;                                                                    \
00188     }                                                                                   \
00189 }
00190 
00191 
00192 #endif

Generated on Fri Jan 28 16:42:13 2011 for kradio by  doxygen 1.4.7