Make return clearer
[pidgin-git.git] / libpurple / plugins.h
blobaebb6448dc9d4646ea77a3548b9c876dd8ff13d3
1 /* purple
3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef PURPLE_PLUGINS_H
23 #define PURPLE_PLUGINS_H
24 /**
25 * SECTION:plugins
26 * @section_id: libpurple-plugins
27 * @short_description: <filename>plugins.h</filename>
28 * @title: Plugin API
29 * @see_also: <link linkend="chapter-signals-plugin">Plugin signals</link>,
30 * <link linkend="chapter-plugin-ids">Plugin IDs</link>,
31 * <link linkend="chapter-plugin-i18n">Third Party Plugin Translation</link>
34 #include <gplugin.h>
35 #include <gplugin-native.h>
37 #include "version.h"
39 #define PURPLE_PLUGINS_DOMAIN (g_quark_from_static_string("plugins"))
41 #define PURPLE_TYPE_PLUGIN GPLUGIN_TYPE_PLUGIN
42 #define PURPLE_PLUGIN(obj) GPLUGIN_PLUGIN(obj)
43 #define PURPLE_IS_PLUGIN(obj) GPLUGIN_IS_PLUGIN(obj)
44 #define PURPLE_PLUGIN_GET_IFACE(obj) GPLUGIN_PLUGIN_GET_IFACE(obj)
46 /**
47 * PurplePlugin:
49 * Represents a plugin handle.
50 * This type is an alias for GPluginPlugin.
52 typedef GPluginPlugin PurplePlugin;
54 typedef GPluginPluginInterface PurplePluginInterface;
56 #define PURPLE_TYPE_PLUGIN_INFO (purple_plugin_info_get_type())
57 typedef struct _PurplePluginInfo PurplePluginInfo;
59 #define PURPLE_TYPE_PLUGIN_ACTION (purple_plugin_action_get_type())
60 typedef struct _PurplePluginAction PurplePluginAction;
62 #include "pluginpref.h"
64 /**
65 * PurplePluginActionCb:
66 * @action: the action information.
68 * A function called when the related Action Menu is activated.
70 typedef void (*PurplePluginActionCb)(PurplePluginAction *action);
72 /**
73 * PurplePluginActionsCb:
74 * @plugin: the plugin associated with this callback.
76 * Returns a list of actions the plugin can perform.
78 * Returns: (transfer none): A list of actions the plugin can perform.
80 typedef GList *(*PurplePluginActionsCb)(PurplePlugin *plugin);
82 /**
83 * PurplePluginExtraCb:
84 * @plugin: the plugin associated with this callback.
86 * Gives extra information about the plguin.
88 * Returns: a newly allocated string denoting extra information
89 * about a plugin.
91 typedef gchar *(*PurplePluginExtraCb)(PurplePlugin *plugin);
93 /**
94 * PurplePluginPrefFrameCb:
95 * @plugin: the plugin associated with this callback.
97 * Returns the preferences frame for the plugin.
99 * Returns: Preference frame.
101 typedef PurplePluginPrefFrame *(*PurplePluginPrefFrameCb)(PurplePlugin *plugin);
104 * PurplePrefRequestCb:
106 * Returns the preferences request handle for a plugin.
108 * Returns: Preferences request handle.
110 typedef gpointer (*PurplePluginPrefRequestCb)(PurplePlugin *plugin);
113 * PurplePluginInfoFlags:
114 * @PURPLE_PLUGIN_INFO_FLAGS_INTERNAL: Plugin is not shown in UI lists
115 * @PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD: Auto-load the plugin
117 * Flags that can be used to treat plugins differently.
119 typedef enum /*< flags >*/
121 PURPLE_PLUGIN_INFO_FLAGS_INTERNAL = 1 << 1,
122 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD = 1 << 2,
124 } PurplePluginInfoFlags;
127 * PurplePluginInfo:
128 * @ui_data: The UI data associated with the plugin. This is a convenience
129 * field provided to the UIs -- it is not used by the libpurple core.
131 * Holds information about a plugin.
133 struct _PurplePluginInfo {
134 GPluginPluginInfo parent;
136 /*< public >*/
137 gpointer ui_data;
141 * PurplePluginAction:
142 * @label: The label to display in the user interface.
143 * @callback: The function to call when the user wants to perform this action.
144 * @plugin: The plugin that this action belongs to.
145 * @user_data: User data to pass to @callback.
147 * Represents an action that the plugin can perform. This shows up in the Tools
148 * menu, under a submenu with the name of the plugin.
150 struct _PurplePluginAction {
151 char *label;
152 PurplePluginActionCb callback;
153 PurplePlugin *plugin;
154 gpointer user_data;
158 * PURPLE_PLUGIN_ABI_VERSION:
160 * Note: The lower six nibbles represent the ABI version for libpurple, the
161 * rest are required by GPlugin.
163 * Returns: An ABI version to set in plugins using major and minor versions.
165 #define PURPLE_PLUGIN_ABI_VERSION(major,minor) \
166 (0x01000000 | ((major) << 16) | (minor))
169 * PURPLE_PLUGIN_ABI_MAJOR_VERSION:
171 * Returns: The major version from an ABI version
173 #define PURPLE_PLUGIN_ABI_MAJOR_VERSION(abi) \
174 ((abi >> 16) & 0xff)
177 * PURPLE_PLUGIN_ABI_MINOR_VERSION:
179 * Returns: The minor version from an ABI version
181 #define PURPLE_PLUGIN_ABI_MINOR_VERSION(abi) \
182 (abi & 0xffff)
185 * PURPLE_ABI_VERSION:
187 * A convenienceā€Ž macro that returns an ABI version using PURPLE_MAJOR_VERSION
188 * and PURPLE_MINOR_VERSION
190 #define PURPLE_ABI_VERSION PURPLE_PLUGIN_ABI_VERSION(PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION)
193 * PURPLE_PLUGIN_INIT:
195 * Defines the plugin's entry points.
197 #define PURPLE_PLUGIN_INIT(pluginname,pluginquery,pluginload,pluginunload) \
198 G_MODULE_EXPORT GPluginPluginInfo *gplugin_query(GError **e); \
199 G_MODULE_EXPORT GPluginPluginInfo *gplugin_query(GError **e) { \
200 return GPLUGIN_PLUGIN_INFO(pluginquery(e)); \
202 G_MODULE_EXPORT gboolean gplugin_load(GPluginNativePlugin *p, GError **e); \
203 G_MODULE_EXPORT gboolean gplugin_load(GPluginNativePlugin *p, GError **e) { \
204 return pluginload(PURPLE_PLUGIN(p), e); \
206 G_MODULE_EXPORT gboolean gplugin_unload(GPluginNativePlugin *p, GError **e); \
207 G_MODULE_EXPORT gboolean gplugin_unload(GPluginNativePlugin *p, GError **e) { \
208 return pluginunload(PURPLE_PLUGIN(p), e); \
211 G_BEGIN_DECLS
213 /**************************************************************************/
214 /* Plugin API */
215 /**************************************************************************/
218 * purple_plugin_load:
219 * @plugin: The plugin to load.
220 * @error: Return location for a #GError or %NULL. If provided, this
221 * will be set to the reason if the load fails.
223 * Attempts to load a plugin.
225 * Also see purple_plugin_unload().
227 * Returns: %TRUE if successful or already loaded, %FALSE otherwise.
229 gboolean purple_plugin_load(PurplePlugin *plugin, GError **error);
232 * purple_plugin_unload:
233 * @plugin: The plugin handle.
234 * @error: Return location for a #GError or %NULL. If provided, this
235 * will be set to the reason if the unload fails.
237 * Unloads the specified plugin.
239 * Also see purple_plugin_load().
241 * Returns: %TRUE if successful or not loaded, %FALSE otherwise.
243 gboolean purple_plugin_unload(PurplePlugin *plugin, GError **error);
246 * purple_plugin_is_loaded:
247 * @plugin: The plugin.
249 * Returns whether or not a plugin is currently loaded.
251 * Returns: %TRUE if loaded, or %FALSE otherwise.
253 gboolean purple_plugin_is_loaded(PurplePlugin *plugin);
256 * purple_plugin_get_info:
257 * @plugin: The plugin.
259 * Returns a plugin's #PurplePluginInfo instance.
261 * Returns: (transfer none): The plugin's #PurplePluginInfo instance.
262 * GPlugin refs the plugin info object before returning it. This workaround
263 * is to avoid managing the reference counts everywhere in our codebase
264 * where we use the plugin info. The plugin info instance is guaranteed to
265 * exist as long as the plugin exists.
267 PurplePluginInfo *purple_plugin_get_info(PurplePlugin *plugin);
270 * purple_plugin_disable:
272 * Disable a plugin.
274 * This function adds the plugin to a list of plugins to "disable at the next
275 * startup" by excluding said plugins from the list of plugins to save. The
276 * UI needs to call purple_plugins_save_loaded() after calling this for it
277 * to have any effect.
279 void purple_plugin_disable(PurplePlugin *plugin);
282 * purple_plugin_is_internal:
283 * @plugin: The plugin.
285 * Returns whether a plugin is an internal plugin. Internal plugins provide
286 * required additional functionality to the libpurple core. These plugins must
287 * not be shown in plugin lists. Examples of such plugins are in-tree protocol
288 * plugins, loaders etc.
290 * Returns: %TRUE if the plugin is an internal plugin, %FALSE otherwise.
292 gboolean purple_plugin_is_internal(PurplePlugin *plugin);
295 * purple_plugin_get_dependent_plugins:
296 * @plugin: The plugin whose dependent plugins are returned.
298 * Returns a list of plugins that depend on a particular plugin.
300 * Returns: (element-type PurplePlugin) (transfer none): The list of a plugins that depend on the specified
301 * plugin.
303 GSList *purple_plugin_get_dependent_plugins(PurplePlugin *plugin);
305 /**************************************************************************/
306 /* PluginInfo API */
307 /**************************************************************************/
310 * purple_plugin_info_get_type:
312 * Returns: The #GType for the #PurplePluginInfo object.
314 G_DECLARE_FINAL_TYPE(PurplePluginInfo, purple_plugin_info, PURPLE, PLUGIN_INFO,
315 GPluginPluginInfo)
318 * purple_plugin_info_new:
319 * @first_property: The first property name
320 * @...: The value of the first property, followed optionally by more
321 * name/value pairs, followed by %NULL
323 * Creates a new #PurplePluginInfo instance to be returned from
324 * #plugin_query of a plugin, using the provided name/value pairs.
326 * All properties except <literal>"id"</literal> and
327 * <literal>"purple-abi"</literal> are optional.
329 * Valid property names are:
330 * <informaltable frame='none'>
331 * <tgroup cols='2'><tbody>
332 * <row><entry><literal>"id"</literal></entry>
333 * <entry>(string) The ID of the plugin.</entry>
334 * </row>
335 * <row><entry><literal>"abi-version"</literal></entry>
336 * <entry>(<type>guint32</type>) The ABI version required by the
337 * plugin.</entry>
338 * </row>
339 * <row><entry><literal>"name"</literal></entry>
340 * <entry>(string) The translated name of the plugin.</entry>
341 * </row>
342 * <row><entry><literal>"version"</literal></entry>
343 * <entry>(string) Version of the plugin.</entry>
344 * </row>
345 * <row><entry><literal>"category"</literal></entry>
346 * <entry>(string) Primary category of the plugin.</entry>
347 * </row>
348 * <row><entry><literal>"summary"</literal></entry>
349 * <entry>(string) Brief summary of the plugin.</entry>
350 * </row>
351 * <row><entry><literal>"description"</literal></entry>
352 * <entry>(string) Full description of the plugin.</entry>
353 * </row>
354 * <row><entry><literal>"authors"</literal></entry>
355 * <entry>(<type>const gchar * const *</type>) A %NULL-terminated list of
356 * plugin authors. format: First Last &lt;user\@domain.com&gt;</entry>
357 * </row>
358 * <row><entry><literal>"website"</literal></entry>
359 * <entry>(string) Website of the plugin.</entry>
360 * </row>
361 * <row><entry><literal>"icon"</literal></entry>
362 * <entry>(string) Path to a plugin's icon.</entry>
363 * </row>
364 * <row><entry><literal>"license-id"</literal></entry>
365 * <entry>(string) Short name of the plugin's license. This should
366 * either be an identifier of the license from
367 * <ulink url="http://dep.debian.net/deps/dep5/#license-specification">
368 * DEP5</ulink> or "Other" for custom licenses.</entry>
369 * </row>
370 * <row><entry><literal>"license-text"</literal></entry>
371 * <entry>(string) The text of the plugin's license, if unlisted on
372 * DEP5.</entry>
373 * </row>
374 * <row><entry><literal>"license-url"</literal></entry>
375 * <entry>(string) The plugin's license URL, if unlisted on DEP5.</entry>
376 * </row>
377 * <row><entry><literal>"dependencies"</literal></entry>
378 * <entry>(<type>const gchar * const *</type>) A %NULL-terminated list of
379 * plugin IDs required by the plugin.</entry>
380 * </row>
381 * <row><entry><literal>"actions-cb"</literal></entry>
382 * <entry>(#PurplePluginActionsCb) Callback that returns a list of
383 * actions the plugin can perform.</entry>
384 * </row>
385 * <row><entry><literal>"extra-cb"</literal></entry>
386 * <entry>(#PurplePluginExtraCb) Callback that returns a newly
387 * allocated string denoting extra information about a plugin.</entry>
388 * </row>
389 * <row><entry><literal>"pref-frame-cb"</literal></entry>
390 * <entry>(#PurplePluginPrefFrameCb) Callback that returns a
391 * preferences frame for the plugin.</entry>
392 * </row>
393 * <row><entry><literal>"pref-request-cb"</literal></entry>
394 * <entry>(#PurplePluginPrefRequestCb) Callback that returns a
395 * preferences request handle for the plugin.</entry>
396 * </row>
397 * <row><entry><literal>"flags"</literal></entry>
398 * <entry>(#PurplePluginInfoFlags) The flags for a plugin.</entry>
399 * </row>
400 * </tbody></tgroup>
401 * </informaltable>
403 * See #PURPLE_PLUGIN_ABI_VERSION,
404 * <link linkend="chapter-plugin-ids">Plugin IDs</link>.
406 * Returns: A new #PurplePluginInfo instance.
408 PurplePluginInfo *purple_plugin_info_new(const char *first_property, ...)
409 G_GNUC_NULL_TERMINATED;
412 * purple_plugin_info_get_actions_cb:
413 * @info: The plugin info to get the callback from.
415 * Returns the callback that retrieves the list of actions a plugin can perform
416 * at that moment.
418 * Returns: The callback that returns a list of #PurplePluginAction
419 * instances corresponding to the actions a plugin can perform.
421 PurplePluginActionsCb
422 purple_plugin_info_get_actions_cb(PurplePluginInfo *info);
425 * purple_plugin_info_get_extra_cb:
426 * @info: The plugin info to get extra information from.
428 * Returns a callback that gives extra information about a plugin. You must
429 * free the string returned by this callback.
431 * Returns: The callback that returns extra information about a plugin.
433 PurplePluginExtraCb
434 purple_plugin_info_get_extra_cb(PurplePluginInfo *info);
437 * purple_plugin_info_get_pref_frame_cb:
438 * @info: The plugin info to get the callback from.
440 * Returns the callback that retrieves the preferences frame for a plugin, set
441 * via the "pref-frame-cb" property of the plugin info.
443 * Returns: The callback that returns the preferences frame.
445 PurplePluginPrefFrameCb
446 purple_plugin_info_get_pref_frame_cb(PurplePluginInfo *info);
449 * purple_plugin_info_get_pref_request_cb:
450 * @info: The plugin info to get the callback from.
452 * Returns the callback that retrieves the preferences request handle for a
453 * plugin, set via the "pref-request-cb" property of the plugin info.
455 * Returns: The callback that returns the preferences request handle.
457 PurplePluginPrefRequestCb
458 purple_plugin_info_get_pref_request_cb(PurplePluginInfo *info);
461 * purple_plugin_info_get_flags:
462 * @info: The plugin's info instance.
464 * Returns the plugin's flags.
466 * Returns: The flags of the plugin.
468 PurplePluginInfoFlags
469 purple_plugin_info_get_flags(PurplePluginInfo *info);
472 * purple_plugin_info_get_error:
473 * @info: The plugin info.
475 * Returns an error in the plugin info that would prevent the plugin from being
476 * loaded.
478 * Returns: The plugin info error, or %NULL.
480 const gchar *purple_plugin_info_get_error(PurplePluginInfo *info);
483 * purple_plugin_info_set_ui_data:
484 * @info: The plugin's info instance.
485 * @ui_data: A pointer to associate with this object.
487 * Set the UI data associated with a plugin.
489 void purple_plugin_info_set_ui_data(PurplePluginInfo *info, gpointer ui_data);
492 * purple_plugin_info_get_ui_data:
493 * @info: The plugin's info instance.
495 * Returns the UI data associated with a plugin.
497 * Returns: The UI data associated with this plugin. This is a
498 * convenience field provided to the UIs--it is not
499 * used by the libpurple core.
501 gpointer purple_plugin_info_get_ui_data(PurplePluginInfo *info);
503 /**************************************************************************/
504 /* PluginAction API */
505 /**************************************************************************/
508 * purple_plugin_action_get_type:
510 * Returns: The #GType for the #PurplePluginAction boxed structure.
512 GType purple_plugin_action_get_type(void);
515 * purple_plugin_action_new:
516 * @label: The description of the action to show to the user.
517 * @callback: (scope call): The callback to call when the user selects this
518 * action.
520 * Allocates and returns a new PurplePluginAction. Use this to add actions in a
521 * list in the "actions-cb" callback for your plugin.
523 PurplePluginAction *purple_plugin_action_new(const char* label,
524 PurplePluginActionCb callback);
527 * purple_plugin_action_free:
528 * @action: The PurplePluginAction to free.
530 * Frees a PurplePluginAction
532 void purple_plugin_action_free(PurplePluginAction *action);
534 /**************************************************************************/
535 /* Plugins API */
536 /**************************************************************************/
539 * purple_plugins_find_all:
541 * Returns a list of all plugins, whether loaded or not.
543 * Returns: (element-type PurplePlugin) (transfer full): A list of all plugins.
544 * The list is owned by the caller, and must be
545 * g_list_free()d to avoid leaking the nodes.
547 GList *purple_plugins_find_all(void);
550 * purple_plugins_get_loaded:
552 * Returns a list of all loaded plugins.
554 * Returns: (element-type PurplePlugin) (transfer none): A list of all loaded plugins.
556 GList *purple_plugins_get_loaded(void);
559 * purple_plugins_add_search_path:
560 * @path: The new search path.
562 * Add a new directory to search for plugins
564 void purple_plugins_add_search_path(const gchar *path);
567 * purple_plugins_refresh:
569 * Forces a refresh of all plugins found in the search paths, and loads plugins
570 * that are to be auto-loaded.
572 * See purple_plugins_add_search_path().
574 void purple_plugins_refresh(void);
577 * purple_plugins_find_plugin:
578 * @id: The plugin ID.
580 * Finds a plugin with the specified plugin ID.
582 * Returns: (transfer none): The plugin if found, or %NULL if not found.
584 PurplePlugin *purple_plugins_find_plugin(const gchar *id);
587 * purple_plugins_find_by_filename:
588 * @filename: The plugin filename.
590 * Finds a plugin with the specified filename (filename with a path).
592 * Returns: (transfer none): The plugin if found, or %NULL if not found.
594 PurplePlugin *purple_plugins_find_by_filename(const char *filename);
597 * purple_plugins_save_loaded:
598 * @key: The preference key to save the list of plugins to.
600 * Saves the list of loaded plugins to the specified preference key.
601 * Plugins that are set to auto-load are not saved.
603 void purple_plugins_save_loaded(const char *key);
606 * purple_plugins_load_saved:
607 * @key: The preference key containing the list of plugins.
609 * Attempts to load all the plugins in the specified preference key
610 * that were loaded when purple last quit.
612 void purple_plugins_load_saved(const char *key);
614 /**************************************************************************/
615 /* Plugins Subsystem API */
616 /**************************************************************************/
619 * purple_plugins_get_handle:
621 * Returns the plugin subsystem handle.
623 * Returns: (transfer none): The plugin sybsystem handle.
625 void *purple_plugins_get_handle(void);
628 * purple_plugins_init:
630 * Initializes the plugin subsystem
632 void purple_plugins_init(void);
635 * purple_plugins_uninit:
637 * Uninitializes the plugin subsystem
639 void purple_plugins_uninit(void);
641 G_END_DECLS
643 #endif /* PURPLE_PLUGINS_H */