summaryrefslogtreecommitdiffstats
path: root/src/include/plugins.h
blob: cb79d145742ba933f95a34b1f51adafc97f56cef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/***************************************************************************
                          plugins.h  -  description
                             -------------------
    begin                : Mon Mär 10 2003
    copyright            : (C) 2003 by Martin Witte
    email                : witte@kawo1.rwth-aachen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

/////////////////////////////////////////////////////////////////////////////

#ifndef KRADIO_PLUGINS_INTERFACES_H
#define KRADIO_PLUGINS_INTERFACES_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tdeglobal.h>

#include "errorlog-interfaces.h"
#include <tqstring.h>
#include <tqobject.h>
#include <tqptrlist.h>

class PluginManager;
class PluginBase;
class TQWidget;
class TDEConfig;

typedef TQPtrList<PluginBase>           PluginList;
typedef TQPtrListIterator<PluginBase>   PluginIterator;

/* PluginBase must be inherited from Interface so that a plugin can be used
   in Interface::connect functions.

   PluginBase must not be inherited from TQObject, because derived classes may
   be inherited e.g. from TQWidget (multiple inheritance is not possible with
   OBjects). But we must be able to receive destroy messages e.g. from
   configuration pages. Thus we need the special callback member
   m_destroyNotifier.

   PluginBase is derived from Interface to provide connection facilities.
   In case of multiple inheritance from interface classes, connect and disconnect
   methods have to be reimplemented in order to call all inherited
   connect/disconnect methods.

*/


class WidgetPluginBase;

struct ConfigPageInfo
{
    ConfigPageInfo () : page(NULL) {}
    ConfigPageInfo (TQWidget *p,
                    const TQString &in,
                    const TQString &ph,
                    const TQString &icon)
      : page (p),
        itemName(in),
        pageHeader(ph),
        iconName(icon)
    {}

    TQWidget  *page;
    TQString   itemName,
              pageHeader,
              iconName;
};

typedef ConfigPageInfo AboutPageInfo;


class KDE_EXPORT PluginBase : public IErrorLogClient
{
friend class PluginManager;
public :
             PluginBase(const TQString &name, const TQString &description);
    virtual ~PluginBase();

    virtual  TQString pluginClassName() const = 0;

    const TQString &name() const { return m_name; }
          TQString &name()       { return m_name; }

    const TQString &description() const { return m_description; }

    // workaround for compiler bugs
    bool           destructorCalled() const { return m_destructorCalled; }

    // interaction with pluginmanager
protected:
    bool setManager (PluginManager *);
    void unsetManager ();
    bool isManagerSet () const;

public:

    // these two methods will request a configuration page or
    // plugin page from plugin manager
    // they will be deleted automatically when this plugin
    // is deleted, because we disconnect from pluginmanager
    // and the plugin manager will delete all associated gui elements
    virtual ConfigPageInfo createConfigurationPage () = 0;
    virtual AboutPageInfo  createAboutPage () = 0;

    // save/restore status, window position, etc...

    virtual void   saveState (TDEConfig *) const = 0;
    virtual void   restoreState (TDEConfig *) = 0;
    virtual void   startPlugin();

    virtual void   aboutToQuit();

    //

    virtual void noticeWidgetPluginShown(WidgetPluginBase *, bool /*shown*/) {}
    virtual void noticePluginsChanged(const PluginList &) {}

protected :
    TQString            m_name;
    TQString            m_description;
    PluginManager     *m_manager;
    bool               m_destructorCalled;
};


#define PLUGIN_LIBRARY_FUNCTIONS(class_name, i18nName, description) \
extern "C" KDE_EXPORT void TDERadioPlugin_LoadLibrary() \
{                                                                 \
    TDEGlobal::locale()->insertCatalogue(i18nName);                 \
}                                                                 \
                                                                  \
extern "C" KDE_EXPORT void TDERadioPlugin_UnloadLibrary() \
{                                                                 \
    TDEGlobal::locale()->removeCatalogue(i18nName);                 \
}                                                                 \
                                                                  \
extern "C" KDE_EXPORT void TDERadioPlugin_GetAvailablePlugins(TQMap<TQString, TQString> &info) \
{                                                                 \
    info.insert(#class_name, (description));                      \
}                                                                 \
                                                                  \
extern "C" KDE_EXPORT PluginBase *TDERadioPlugin_CreatePlugin(const TQString &type, const TQString &object_name) \
{                                                                                    \
    if (type == #class_name) {                                                       \
        return new class_name(object_name);                                          \
    } else {                                                                         \
        return NULL;                                                                 \
    }                                                                                \
}


#define PLUGIN_LIBRARY_FUNCTIONS2(class_name1, i18nName, description1, class_name2, description2) \
extern "C" KDE_EXPORT void TDERadioPlugin_LoadLibrary() \
{                                                                 \
    TDEGlobal::locale()->insertCatalogue(i18nName);                 \
}                                                                 \
                                                                  \
extern "C" KDE_EXPORT void TDERadioPlugin_UnloadLibrary() \
{                                                                 \
    TDEGlobal::locale()->removeCatalogue(i18nName);                 \
}                                                                 \
                                                                  \
extern "C" KDE_EXPORT void TDERadioPlugin_GetAvailablePlugins(TQMap<TQString, TQString> &info) \
{                                                                 \
    info.insert(#class_name1, (description1));                    \
    info.insert(#class_name2, (description2));                    \
}                                                                 \
                                                                  \
extern "C" KDE_EXPORT PluginBase *TDERadioPlugin_CreatePlugin(const TQString &type, const TQString &object_name) \
{                                                                                       \
    if (type == #class_name1) {                                                         \
        return new class_name1(object_name);                                            \
    } else if (type == #class_name2) {                                                  \
        return new class_name2(object_name);                                            \
    } else {                                                                            \
        return NULL;                                                                    \
    }                                                                                   \
}


#endif