kradio4 r778
|
00001 /*************************************************************************** 00002 plugins.h - description 00003 ------------------- 00004 begin : Mon Mär 10 2003 00005 copyright : (C) 2003 by Martin Witte 00006 email : emw-kradio@nocabal.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 <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 /* PluginBase must be inherited from Interface so that a plugin can be used 00045 in Interface::connect functions. 00046 00047 PluginBase must not be inherited from QObject, because derived classes may 00048 be inherited e.g. from QWidget (multiple inheritance is not possible with 00049 OBjects). But we must be able to receive destroy messages e.g. from 00050 configuration pages. Thus we need the special callback member 00051 m_destroyNotifier. 00052 00053 PluginBase is derived from Interface to provide connection facilities. 00054 In case of multiple inheritance from interface classes, connect and disconnect 00055 methods have to be reimplemented in order to call all inherited 00056 connect/disconnect methods. 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 // PluginBase(const QString &name, const QString &description); 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 // workaround for compiler bugs 00103 bool destructorCalled() const { return m_destructorCalled; } 00104 00105 // interaction with pluginmanager 00106 protected: 00107 virtual bool setManager (PluginManager *); 00108 virtual void unsetManager (); 00109 bool isManagerSet () const; 00110 00111 public: 00112 00113 // these two methods will request a configuration page or 00114 // plugin page from plugin manager 00115 // they will be deleted automatically when this plugin 00116 // is deleted, because we disconnect from pluginmanager 00117 // and the plugin manager will delete all associated gui elements 00118 virtual ConfigPageInfo createConfigurationPage () = 0; 00119 // virtual AboutPageInfo createAboutPage () = 0; 00120 00121 // save/restore status, window position, etc... 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 /*shown*/) {} 00132 virtual void noticePluginsChanged(const PluginList &) {} 00133 virtual void noticePluginRenamed(PluginBase */*p*/, const QString &/*name*/) {} 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