kradio4  r778
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pluginbase.h
Go to the documentation of this file.
1 /***************************************************************************
2  plugins.h - description
3  -------------------
4  begin : Mon Mar 10 2003
5  copyright : (C) 2003 by Martin Witte
6  email : emw-kradio@nocabal.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 
20 #ifndef KRADIO_PLUGINS_INTERFACES_H
21 #define KRADIO_PLUGINS_INTERFACES_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <kglobal.h>
28 
29 #include "errorlog_interfaces.h"
30 #include <QtCore/QString>
31 #include <QtCore/QObject>
32 #include <QtCore/QList>
33 
34 #include <kconfiggroup.h>
35 
36 class PluginManager;
37 class PluginBase;
38 class QWidget;
39 
40 typedef QList<PluginBase*> PluginList;
41 typedef QList<PluginBase*>::iterator PluginIterator;
42 typedef QList<PluginBase*>::const_iterator PluginConstIterator;
43 
44 /* PluginBase must be inherited from Interface so that a plugin can be used
45  in Interface::connect functions.
46 
47  PluginBase must not be inherited from QObject, because derived classes may
48  be inherited e.g. from QWidget (multiple inheritance is not possible with
49  OBjects). But we must be able to receive destroy messages e.g. from
50  configuration pages. Thus we need the special callback member
51  m_destroyNotifier.
52 
53  PluginBase is derived from Interface to provide connection facilities.
54  In case of multiple inheritance from interface classes, connect and disconnect
55  methods have to be reimplemented in order to call all inherited
56  connect/disconnect methods.
57 
58 */
59 
60 
61 class WidgetPluginBase;
62 
64 {
65  ConfigPageInfo () : page(NULL) {}
66  ConfigPageInfo (QWidget *p,
67  const QString &in,
68  const QString &ph,
69  const QString &icon)
70  : page (p),
71  itemName(in),
72  pageHeader(ph),
73  iconName(icon)
74  {}
75 
76  QWidget *page;
77  QString itemName;
78  QString pageHeader;
79  QString iconName;
80 };
81 
83 
84 
85 class KDE_EXPORT PluginBase : public IErrorLogClient
86 {
87 friend class PluginManager;
88 public :
89  PluginBase(const QString &instanceID, const QString &name, const QString &description);
90 // PluginBase(const QString &name, const QString &description);
91  virtual ~PluginBase();
92 
93  virtual QString pluginClassName() const = 0;
94 
95  const QString &name() const { return m_name; }
96  void setName(const QString &n);
97 
98  const QString &instanceID() const { return m_instanceID; }
99 
100  const QString &description() const { return m_description; }
101 
102  // workaround for compiler bugs
103  bool destructorCalled() const { return m_destructorCalled; }
104 
105  // interaction with pluginmanager
106 protected:
107  virtual bool setManager (PluginManager *);
108  virtual void unsetManager ();
109  bool isManagerSet () const;
110 
111 public:
112 
113  // these two methods will request a configuration page or
114  // plugin page from plugin manager
115  // they will be deleted automatically when this plugin
116  // is deleted, because we disconnect from pluginmanager
117  // and the plugin manager will delete all associated gui elements
118  virtual ConfigPageInfo createConfigurationPage () = 0;
119 // virtual AboutPageInfo createAboutPage () = 0;
120 
121  // save/restore status, window position, etc...
122 
123  virtual void saveState ( KConfigGroup &) const = 0;
124  virtual void restoreState (const KConfigGroup &) = 0;
125  virtual void startPlugin();
126 
127  virtual void aboutToQuit();
128 
129  //
130 
131  virtual void noticeWidgetPluginShown(WidgetPluginBase *, bool /*shown*/) {}
132  virtual void noticePluginsChanged(const PluginList &) {}
133  virtual void noticePluginRenamed(PluginBase */*p*/, const QString &/*name*/) {}
134 
135 protected :
136  QString m_instanceID;
137  QString m_name;
138  QString m_description;
141 };
142 
143 
144 #define PLUGIN_LIBRARY_FUNCTIONS(class_name, i18nName, description) \
145 extern "C" KDE_EXPORT void KRadioPlugin_LoadLibrary() \
146 { \
147  KGlobal::locale()->insertCatalog(i18nName); \
148 } \
149  \
150 extern "C" KDE_EXPORT void KRadioPlugin_UnloadLibrary() \
151 { \
152  KGlobal::locale()->removeCatalog(i18nName); \
153 } \
154  \
155 extern "C" KDE_EXPORT void KRadioPlugin_GetAvailablePlugins(QMap<QString, QString> &info) \
156 { \
157  info.insert(#class_name, (description)); \
158 } \
159  \
160 extern "C" KDE_EXPORT PluginBase *KRadioPlugin_CreatePlugin(const QString &type, const QString &instanceID, const QString &object_name) \
161 { \
162  if (type == #class_name) { \
163  return new class_name(instanceID, object_name); \
164  } else { \
165  return NULL; \
166  } \
167 }
168 
169 
170 #define PLUGIN_LIBRARY_FUNCTIONS2(class_name1, i18nName, description1, class_name2, description2) \
171 extern "C" KDE_EXPORT void KRadioPlugin_LoadLibrary() \
172 { \
173  KGlobal::locale()->insertCatalog(i18nName); \
174 } \
175  \
176 extern "C" KDE_EXPORT void KRadioPlugin_UnloadLibrary() \
177 { \
178  KGlobal::locale()->removeCatalog(i18nName); \
179 } \
180  \
181 extern "C" KDE_EXPORT void KRadioPlugin_GetAvailablePlugins(QMap<QString, QString> &info) \
182 { \
183  info.insert(#class_name1, (description1)); \
184  info.insert(#class_name2, (description2)); \
185 } \
186  \
187 extern "C" KDE_EXPORT PluginBase *KRadioPlugin_CreatePlugin(const QString &type, const QString &instanceID, const QString &object_name) \
188 { \
189  if (type == #class_name1) { \
190  return new class_name1(instanceID, object_name); \
191  } else if (type == #class_name2) { \
192  return new class_name2(instanceID, object_name); \
193  } else { \
194  return NULL; \
195  } \
196 }
197 
198 
199 #endif