libqutim  0.3.1.0
plugin.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
6 **
7 *****************************************************************************
8 **
9 ** $QUTIM_BEGIN_LICENSE$
10 ** This program is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation, either version 3 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ** See the GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see http://www.gnu.org/licenses/.
22 ** $QUTIM_END_LICENSE$
23 **
24 ****************************************************************************/
25 
26 #ifndef PLUGIN_H
27 #define PLUGIN_H
28 
29 #include "libqutim_version.h"
30 #include "extensioninfo.h"
31 #include <QtCore/QtPlugin>
32 #include <QtCore/QObject>
33 #include <QtCore/QSharedDataPointer>
34 
35 #define PLUGIN_VERSION(major, minor, secminor, patch) QUTIM_MAKE_VERSION(major, minor, secminor, patch)
36 
37 namespace qutim_sdk_0_3
38 {
39 class ModuleManager;
40 class PluginInfoData;
41 class PluginPrivate;
42 
43 LIBQUTIM_EXPORT void debugAddPluginId(quint64, const QMetaObject *meta);
44 
46 {
47 public:
48  // Keep in sync with Plugin::Capability
50  {
51  Loadable = 0x01
52  };
53  Q_DECLARE_FLAGS(Capabilities, Capability)
54 
56  const LocalizedString &description = LocalizedString(),
57  quint32 version = 0, ExtensionIcon icon = ExtensionIcon());
58  PluginInfo(const PluginInfo &other);
59  ~PluginInfo();
60  PluginInfo &operator =(const PluginInfo &other);
61  PluginInfo &addAuthor(const PersonInfo &author);
62  PluginInfo &addAuthor(const QString &ocsUsername);
63  PluginInfo &addAuthor(const LocalizedString &name, const LocalizedString &task,
64  const QString &email = QString(), const QString &web = QString());
65  PluginInfo &setName(const LocalizedString &name);
66  PluginInfo &setDescription(const LocalizedString &description);
67  PluginInfo &setIcon(const ExtensionIcon &icon);
68  PluginInfo &setVersion(quint32 version);
69  Capabilities capabilities() const;
70  PluginInfo &setCapabilities(Capabilities capabilities);
71  QList<PersonInfo> authors() const;
72  LocalizedString name() const;
73  LocalizedString description() const;
74  quint32 version() const;
75  ExtensionIcon icon() const;
76 #ifndef Q_QDOC
77  QString fileName() const;
78 private:
79  QSharedDataPointer<PluginInfoData> d;
80 public:
81  typedef PluginInfoData Data;
82  Data *data();
83 #endif
84 };
85 
86 class CommandArgumentPrivate;
87 
89 {
90 public:
91  enum Type {
92  NoValue = 0,
93  ValueOptional = 1,
94  ValueRequired = 2,
95  AllowMultiple = 4,
96  Undocumented = 8
97  };
98  Q_DECLARE_FLAGS(Types, Type)
99 
100  CommandArgument(const QString &name, const QString &desc = QString(), Types types = NoValue, int group = -1);
102  CommandArgument &operator =(const CommandArgument &o);
103  ~CommandArgument();
104 
105  QString name() const;
106  QString description() const;
107  Types types() const;
108  int group() const;
109  void setAliases(const QStringList &aliases);
110  void addAlias(const QStringList &alias);
111  QStringList aliases() const;
112 
113 private:
114  QSharedPointer<CommandArgumentPrivate> d;
115 };
116 
118 {
119 public:
120  virtual ~CommandArgumentsHandler();
121 
122  virtual QStringList commands() = 0;
123  virtual QList<CommandArgument> commandOptions(const QString &name) = 0;
124 };
125 
126 #ifndef Q_QDOC
127 typedef void ( /*QObject::*/ *ModuleInit)();
128 #endif
129 
130 class LIBQUTIM_EXPORT Plugin : public QObject
131 {
132  Q_OBJECT
133  Q_DISABLE_COPY(Plugin)
134  Q_DECLARE_PRIVATE(Plugin)
135 public:
136  // Keep in sync with PluginInfo::Capability
138  {
139  Loadable = 0x01
140  };
141  Q_DECLARE_FLAGS(Capabilities, Capability)
142  Plugin();
143  virtual ~Plugin();
144  PluginInfo info() const;
145  ExtensionInfoList avaiableExtensions() const;
146  virtual void init() = 0;
147  virtual bool load() = 0;
148  virtual bool unload() = 0;
149 protected:
150  // Should be called at init
151  void addAuthor(const LocalizedString &name, const LocalizedString &task,
152  const QString &email = QString(), const QString &web = QString());
153  void addAuthor(const QString &ocsUsername);
154  void setInfo(const LocalizedString &name, const LocalizedString &description,
155  quint32 version = 0, ExtensionIcon icon = ExtensionIcon());
156  void setCapabilities(Capabilities capabilities);
157  void addExtension(const LocalizedString &name, const LocalizedString &description,
158  const ObjectGenerator *generator, ExtensionIcon icon = ExtensionIcon());
159  template<typename T>
160  void addExtension(const LocalizedString &name, const LocalizedString &description,
161  ExtensionIcon icon = ExtensionIcon())
162  { addExtension(name, description, new GeneralGenerator<T>(), icon); }
163  template<typename T, typename I0>
164  void addExtension(const LocalizedString &name, const LocalizedString &description,
165  ExtensionIcon icon = ExtensionIcon())
166  { addExtension(name, description, new GeneralGenerator<T, I0>(), icon); }
167  template<typename T, typename I0, typename I1>
168  void addExtension(const LocalizedString &name, const LocalizedString &description,
169  ExtensionIcon icon = ExtensionIcon())
170  { addExtension(name, description, new GeneralGenerator<T, I0, I1>(), icon); }
171 #ifndef Q_QDOC
172 private:
173  QScopedPointer<PluginPrivate> p;
174  friend class ModuleManager;
175 #endif
176 };
177 
179 {
180 public:
181  virtual ~PluginFactory() {}
182  // Will be called after ::load() method
183  virtual QList<Plugin*> loadPlugins() = 0;
184 };
185 
186 LIBQUTIM_EXPORT QList<QPointer<Plugin> > pluginsList();
187 }
188 
189 Q_DECLARE_OPERATORS_FOR_FLAGS(qutim_sdk_0_3::PluginInfo::Capabilities)
190 Q_DECLARE_OPERATORS_FOR_FLAGS(qutim_sdk_0_3::Plugin::Capabilities)
191 
192 #ifdef QUTIM_STATIC_PLUGIN
193 
194 # define QUTIM_DEBUG_ID_CONVERT_HELPER(A) 0x ## A ## ULL
195 # define QUTIM_DEBUG_ID_CONVERT(A) QUTIM_DEBUG_ID_CONVERT_HELPER(A)
196 # define QUTIM_PLUGIN_INSTANCE_BODY(IMPLEMENTATION) \
197  { \
198  static QT_PREPEND_NAMESPACE(QPointer)<QT_PREPEND_NAMESPACE(QObject)> _instance; \
199  if (!_instance) { \
200  _instance = new IMPLEMENTATION; \
201  debugAddPluginId(QUTIM_DEBUG_ID_CONVERT(QUTIM_PLUGIN_ID), &IMPLEMENTATION::staticMetaObject);\
202  } \
203  return _instance; \
204  }
205 # define QUTIM_EXPORT_PLUGIN_HELPER(PluginInstance, Class) \
206  QT_PREPEND_NAMESPACE(QObject) \
207  *PluginInstance() \
208  QUTIM_PLUGIN_INSTANCE_BODY(Class)
209 # undef QUTIM_DEBUG_ID_CONVERT_HELPER
210 # undef QUTIM_DEBUG_ID_CONVERT
211 
212 # define QUTIM_EXPORT_PLUGIN(Class) \
213  QUTIM_EXPORT_PLUGIN_HELPER(QUTIM_PLUGIN_INSTANCE_BODY, Class)
214 # define QUTIM_EXPORT_PLUGIN2(Plugin,Class) \
215  QUTIM_EXPORT_PLUGIN(Class)
216 #else
217 # define QUTIM_EXPORT_STRING_HELPER(ID) #ID
218 # define QUTIM_EXPORT_STRING(ID) QUTIM_EXPORT_STRING_HELPER(ID)
219 # define QUTIM_EXPORT_PLUGIN2(Plugin,Class) \
220  Q_EXPORT_PLUGIN2(Plugin,Class) \
221  static const char *qutim_plugin_verification_data = \
222  "pattern=""QUTIM_PLUGIN_VERIFICATION_DATA""\n" \
223  "debugid=" QUTIM_EXPORT_STRING(QUTIM_PLUGIN_ID)"\n" \
224  "libqutim=" QUTIM_VERSION_STRING"\0"; \
225  Q_EXTERN_C Q_DECL_EXPORT \
226  const char * Q_STANDARD_CALL qutim_plugin_query_verification_data() \
227 { return qutim_plugin_verification_data; }
228 
229 #define QUTIM_EXPORT_PLUGIN(Plugin) \
230  QUTIM_EXPORT_PLUGIN2(Plugin, Plugin)
231 #endif
232 Q_DECLARE_INTERFACE(qutim_sdk_0_3::PluginFactory, "org.qutim.PluginFactory")
233 Q_DECLARE_INTERFACE(qutim_sdk_0_3::CommandArgumentsHandler, "org.qutim.CommandArgumentsHandler")
234 
235 #endif // PLUGIN_H
236 

Generated by Doxygen