plugins.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
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
00098 bool destructorCalled() const { return m_destructorCalled; }
00099
00100
00101 protected:
00102 bool setManager (PluginManager *);
00103 void unsetManager ();
00104 bool isManagerSet () const;
00105
00106 public:
00107
00108
00109
00110
00111
00112
00113 virtual ConfigPageInfo createConfigurationPage () = 0;
00114 virtual AboutPageInfo createAboutPage () = 0;
00115
00116
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 ) {}
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