Mon, 23 Sep 2013 14:09:28 +0530
Merged soc.2013.gobjectification branch
| 10468 | 1 | /** @page c-howto C Plugin HOWTO |
| 2 | ||
| 3 | @section Introduction | |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
4 | C plugins are native plugins. They have complete access to all of the API, |
| 10468 | 5 | and can do basically whatever they want. All of the protocol plugins, as |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
6 | well as the Mono, Perl, and Tcl loader plugins are written in C. |
| 10468 | 7 | |
| 8 | @section getting_started Getting Started | |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
9 | To develop a plugin you need to have the libpurple and (for UI plugins) the |
|
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
10 | Pidgin/Finch source code or development headers. It is generally a good idea |
|
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
11 | to compile against the same version of Pidgin that you are running. You may |
|
34961
e00be7ef0773
Replaced monotone references with mercurial in docs
Ankit Vani <a@nevitus.org>
parents:
23325
diff
changeset
|
12 | also want to develop against the code in our Mercurial repository if you need |
|
e00be7ef0773
Replaced monotone references with mercurial in docs
Ankit Vani <a@nevitus.org>
parents:
23325
diff
changeset
|
13 | to use a new feature. Please do not abuse our Mercurial repository, however. |
| 10468 | 14 | |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
15 | All plugins must have @c PURPLE_PLUGINS defined and the definition must be |
|
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
16 | before including any libpurple, Pidgin, or Finch header files. Failure to do |
|
34964
54ebd3dcae16
Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents:
34962
diff
changeset
|
17 | so can lead to strange errors that are hard to diagnose. Including purple.h |
|
54ebd3dcae16
Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents:
34962
diff
changeset
|
18 | will define this for you. |
| 10468 | 19 | |
| 20 | @section hello_world Hello World! | |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
21 | I know every tutorial has a hello world, so why should libpurple be any |
|
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
22 | different? |
| 10468 | 23 | |
| 24 | @code | |
|
34964
54ebd3dcae16
Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents:
34962
diff
changeset
|
25 | #include <purple.h> |
| 10468 | 26 | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
27 | static PurplePluginInfo * |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
28 | plugin_query(GError **error) |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
29 | { |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
30 | const gchar * const authors[] = { |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
31 | "Author Name <e@mail>", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
32 | NULL |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
33 | }; |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
34 | |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
35 | /* For specific notes on the meanings of each of these members, consult the |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
36 | C Plugin Howto on the website. */ |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
37 | return purple_plugin_info_new ( |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
38 | "name", "Hello World!", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
39 | "version", VERSION, |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
40 | "category", "Example", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
41 | "summary", "Hello World Plugin", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
42 | "description", "Hello World Plugin", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
43 | "authors", authors, |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
44 | "website", "http://helloworld.tld", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
45 | "abi-version", PURPLE_ABI_VERSION, |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
46 | NULL |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
47 | ); |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
48 | } |
| 10468 | 49 | |
| 50 | static gboolean | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
51 | plugin_load(PurplePlugin *plugin, GError **error) |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
52 | { |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
53 | purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!", |
|
34962
d18669b989b6
Updated the hello world example in the docs to use the new notify API
Ankit Vani <a@nevitus.org>
parents:
34961
diff
changeset
|
54 | "This is the Hello World! plugin :)", |
|
d18669b989b6
Updated the hello world example in the docs to use the new notify API
Ankit Vani <a@nevitus.org>
parents:
34961
diff
changeset
|
55 | NULL, NULL, NULL, NULL); |
| 10468 | 56 | |
| 57 | return TRUE; | |
| 58 | } | |
| 59 | ||
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
60 | static gboolean |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
61 | plugin_unload(PurplePlugin *plugin, GError **error) |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
62 | { |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
63 | return TRUE; |
| 10468 | 64 | } |
| 65 | ||
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
66 | PURPLE_PLUGIN_INIT(hello_world, plugin_query, plugin_load, plugin_unload); |
| 10468 | 67 | |
| 68 | @endcode | |
| 69 | ||
|
34964
54ebd3dcae16
Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents:
34962
diff
changeset
|
70 | Okay, so what does all this mean? We start off by including purple.h. This |
|
54ebd3dcae16
Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents:
34962
diff
changeset
|
71 | file defines @c PURPLE_PLUGINS as described before so that we don't have to |
|
54ebd3dcae16
Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents:
34962
diff
changeset
|
72 | manually define it. It also includes all the libpurple header files. |
| 10468 | 73 | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
74 | @c plugin_query, @c plugin_load and @c plugin_unload must be implemented in |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
75 | every plugin. Each of these functions can return an error on failure by using |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
76 | @c g_set_error on the @c error argument. |
| 10468 | 77 | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
78 | @c plugin_query is called when the plugin is probed by the plugin system, and |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
79 | returns various information about the plugin in form of a newly created |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
80 | PurplePluginInfo instance. See plugins.h for a list of available properties |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
81 | you can use in @c purple_plugin_info_new . |
| 10468 | 82 | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
83 | @c plugin_load is called when the plugin is loaded so that you can initialize |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
84 | any variables, register dynamic types, and so on. Plugins may also want to |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
85 | add their preferences to the pref tree--more about that later. In this plugin |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
86 | we'll just use it to display a message. |
| 10468 | 87 | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
88 | @c plugin_unload is called when the plugin is unloaded, and we can use it to |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
89 | wrap up everything, and free our variables. |
| 10468 | 90 | |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
91 | Finally we have @c PURPLE_PLUGIN_INIT(). @c PURPLE_PLUGIN_INIT is a macro |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
92 | that every plugin MUST have. @c PURPLE_PLUGIN_INIT tells libpurple some |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
93 | basic things about your plugin, like what name to use if the plugin is |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
94 | compiled statically, and the @c plugin_query, @c plugin_load, and |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
95 | @c plugin_unload functions. |
| 10468 | 96 | */ |
|
20897
2608e9e07913
Add some links from signal documentation back to the documentation for the
Will Thompson <resiak@pidgin.im>
parents:
18789
diff
changeset
|
97 | // vim: syntax=c.doxygen |