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
|
/* ksim - a system monitor for kde
*
* Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLUGINLOADER_H
#define PLUGINLOADER_H
#include "pluginglobal.h"
#include <tqobject.h>
#include <kdemacros.h>
namespace KSim
{
class KDE_EXPORT PluginInfo
{
friend class PluginLoader;
public:
~PluginInfo();
/**
* @return the name of the plugin
*/
const TQString &name() const;
/**
* @return the library name of the plugin
*/
TQCString libName(bool includePrefix = false) const;
/**
* @return the location of the desktop file
*/
const TQString &location() const;
private:
PluginInfo();
TQString m_name;
TQString m_location;
TQCString m_libName;
class Private;
Private *d;
};
/**
* Provides a loader for the plugins
* @author Robbie Ward <linuxphreak@gmx.co.uk>
*/
class KDE_EXPORT PluginLoader : public TQObject
{
Q_OBJECT
friend class MainView;
public:
enum SearchType { Name = 0, DesktopFile, LibName };
enum ErrorCode { EmptyLibName = -3, LibNotFound = -2,
UnSymbols = -1, LibLoaded = 0 };
/**
* @return a reference to the instance
*/
static PluginLoader &self();
/**
* loads a plugin, example:
* <pre>
* KDesktopFile destdefile("/home/user/foo.desktop");
* KSim::PluginLoader::self().loadPlugin(deskFile);
* </pre>
* you can then use @ref pluginList() to access the plugin, view,
* config page and plugin information
* @param file is the desktop file of the lib
* @return true if the plugin is successfully loaded
*/
bool loadPlugin(const KDesktopFile &file);
/**
* unloads a loaded plugin and removes plugin entries from pluginList()
*/
bool unloadPlugin(const TQCString &name);
/**
* unloads all loaded plugins
*/
void unloadAllPlugins();
/**
* convenience function
*
* returns true if info is loaded
*/
bool isLoaded(const KSim::Plugin &info) const;
/**
* returns true if library is loaded
*/
bool isLoaded(const TQCString &library) const;
/**
* finds the plugins desktopfile and returns information
* on the plugin
* @return a KSim::PluginInfo object
* @see KSim::PluginInfo
*/
KSim::PluginInfo findPluginInfo(const TQString &name,
SearchType type = DesktopFile) const;
/**
* looks through the list of loaded plugins and returns
* the one that matches libName, or returns
* KSim::Plugin::null if a plugin could not be found.
*
* if libName does not start with "ksim_" then the function
* will prepend this automatically.
* @return a KSim::Plugin object
* @see KSim::Plugin
*/
KSim::Plugin &find(const TQCString &libName);
/**
* convenience function, see the above function for details.
*/
const KSim::Plugin &find(const TQCString &libName) const;
/**
* equivalent to find(info.libName());
*/
KSim::Plugin &find(const KSim::PluginInfo &info);
/**
* convenience function, see the above function for details.
*/
const KSim::Plugin &find(const KSim::PluginInfo &info) const;
/**
* provides plugin(), view(), config page and plugin information
* @see KSim::Plugin KSim::PluginList
*/
const KSim::PluginList &pluginList() const;
/**
* Overloaded member function, This behaves essentially like
* the above function
*/
KSim::PluginList &pluginList();
/**
* @return a reference to the last plugin loaded (or a null plugin
* if the plugin was unable to load)
*/
const KSim::Plugin &plugin() const;
/**
* Overloaded member function, This behaves essentially like
* the above function
*/
KSim::Plugin &plugin();
signals:
void pluginLoaded(const KSim::Plugin &);
protected:
/**
* constructor for PluginLoader, use self() to get an instance
*/
PluginLoader();
~PluginLoader();
private:
PluginLoader(const PluginLoader &);
PluginLoader &operator=(const PluginLoader &);
/**
* Deletes the instance and cleans up after itself
*/
static void cleanup();
ErrorCode createPlugin(const KDesktopFile &file);
class Private;
Private *d;
static PluginLoader *m_instance;
};
}
#endif
|