pluginbase.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 <QtCore/QString>
00031 #include <QtCore/QObject>
00032 #include <QtCore/QList>
00033
00034 #include <kconfiggroup.h>
00035
00036 class PluginManager;
00037 class PluginBase;
00038 class QWidget;
00039
00040 typedef QList<PluginBase*> PluginList;
00041 typedef QList<PluginBase*>::iterator PluginIterator;
00042 typedef QList<PluginBase*>::const_iterator PluginConstIterator;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class WidgetPluginBase;
00062
00063 struct ConfigPageInfo
00064 {
00065 ConfigPageInfo () : page(NULL) {}
00066 ConfigPageInfo (QWidget *p,
00067 const QString &in,
00068 const QString &ph,
00069 const QString &icon)
00070 : page (p),
00071 itemName(in),
00072 pageHeader(ph),
00073 iconName(icon)
00074 {}
00075
00076 QWidget *page;
00077 QString itemName;
00078 QString pageHeader;
00079 QString iconName;
00080 };
00081
00082 typedef ConfigPageInfo AboutPageInfo;
00083
00084
00085 class KDE_EXPORT PluginBase : public IErrorLogClient
00086 {
00087 friend class PluginManager;
00088 public :
00089 PluginBase(const QString &instanceID, const QString &name, const QString &description);
00090
00091 virtual ~PluginBase();
00092
00093 virtual QString pluginClassName() const = 0;
00094
00095 const QString &name() const { return m_name; }
00096 void setName(const QString &n);
00097
00098 const QString &instanceID() const { return m_instanceID; }
00099
00100 const QString &description() const { return m_description; }
00101
00102
00103 bool destructorCalled() const { return m_destructorCalled; }
00104
00105
00106 protected:
00107 virtual bool setManager (PluginManager *);
00108 virtual void unsetManager ();
00109 bool isManagerSet () const;
00110
00111 public:
00112
00113
00114
00115
00116
00117
00118 virtual ConfigPageInfo createConfigurationPage () = 0;
00119
00120
00121
00122
00123 virtual void saveState ( KConfigGroup &) const = 0;
00124 virtual void restoreState (const KConfigGroup &) = 0;
00125 virtual void startPlugin();
00126
00127 virtual void aboutToQuit();
00128
00129
00130
00131 virtual void noticeWidgetPluginShown(WidgetPluginBase *, bool ) {}
00132 virtual void noticePluginsChanged(const PluginList &) {}
00133 virtual void noticePluginRenamed(PluginBase *, const QString &) {}
00134
00135 protected :
00136 QString m_instanceID;
00137 QString m_name;
00138 QString m_description;
00139 PluginManager *m_manager;
00140 bool m_destructorCalled;
00141 };
00142
00143
00144 #define PLUGIN_LIBRARY_FUNCTIONS(class_name, i18nName, description) \
00145 extern "C" KDE_EXPORT void KRadioPlugin_LoadLibrary() \
00146 { \
00147 KGlobal::locale()->insertCatalog(i18nName); \
00148 } \
00149 \
00150 extern "C" KDE_EXPORT void KRadioPlugin_UnloadLibrary() \
00151 { \
00152 KGlobal::locale()->removeCatalog(i18nName); \
00153 } \
00154 \
00155 extern "C" KDE_EXPORT void KRadioPlugin_GetAvailablePlugins(QMap<QString, QString> &info) \
00156 { \
00157 info.insert(#class_name, (description)); \
00158 } \
00159 \
00160 extern "C" KDE_EXPORT PluginBase *KRadioPlugin_CreatePlugin(const QString &type, const QString &instanceID, const QString &object_name) \
00161 { \
00162 if (type == #class_name) { \
00163 return new class_name(instanceID, object_name); \
00164 } else { \
00165 return NULL; \
00166 } \
00167 }
00168
00169
00170 #define PLUGIN_LIBRARY_FUNCTIONS2(class_name1, i18nName, description1, class_name2, description2) \
00171 extern "C" KDE_EXPORT void KRadioPlugin_LoadLibrary() \
00172 { \
00173 KGlobal::locale()->insertCatalog(i18nName); \
00174 } \
00175 \
00176 extern "C" KDE_EXPORT void KRadioPlugin_UnloadLibrary() \
00177 { \
00178 KGlobal::locale()->removeCatalog(i18nName); \
00179 } \
00180 \
00181 extern "C" KDE_EXPORT void KRadioPlugin_GetAvailablePlugins(QMap<QString, QString> &info) \
00182 { \
00183 info.insert(#class_name1, (description1)); \
00184 info.insert(#class_name2, (description2)); \
00185 } \
00186 \
00187 extern "C" KDE_EXPORT PluginBase *KRadioPlugin_CreatePlugin(const QString &type, const QString &instanceID, const QString &object_name) \
00188 { \
00189 if (type == #class_name1) { \
00190 return new class_name1(instanceID, object_name); \
00191 } else if (type == #class_name2) { \
00192 return new class_name2(instanceID, object_name); \
00193 } else { \
00194 return NULL; \
00195 } \
00196 }
00197
00198
00199 #endif