Thu, 21 Jul 2022 01:10:22 -0500
Update pidgin for the purple_account_manager_get_(in)active deprecations
Testing Done:
Compiled and made sure the menus still functioned as expected.
Reviewed at https://reviews.imfreedom.org/r/1536/
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
1 | Title: C Plugin Tutorial |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
2 | Slug: c-plugin-tutorial |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
3 | |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
4 | ## C Plugin Tutorial |
| 10468 | 5 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
6 | ### Introduction |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
7 | |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
8 | C plugins are native plugins. They have complete access to all of the API, |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
9 | and can do basically whatever they want. All of the protocol plugins are |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
10 | also written in C. |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
11 | |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
12 | ### Getting Started |
| 10468 | 13 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
14 | To develop a plugin you need to have the libpurple and (for UI plugins) the |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
15 | Pidgin/Finch source code or development headers. It is generally a good idea |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
16 | to compile against the same version of Pidgin that you are running. You may |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
17 | also want to develop against the code in our Mercurial repository if you need |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
18 | to use a new feature. Please do not abuse our Mercurial repository, however. |
| 10468 | 19 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
20 | ### An Example |
| 10468 | 21 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
22 | I know every tutorial has a hello world, so why should libpurple be any |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
23 | different? |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
24 | |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
25 | ```c |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
26 | #include <purple.h> |
| 10468 | 27 | |
|
40933
60f4b2a6d66a
Update the C plugin tutorial to use the gplugin macros
Gary Kramlich <grim@reaperworld.com>
parents:
39413
diff
changeset
|
28 | static GPluginPluginInfo * |
|
60f4b2a6d66a
Update the C plugin tutorial to use the gplugin macros
Gary Kramlich <grim@reaperworld.com>
parents:
39413
diff
changeset
|
29 | hello_world_query(GError **error) |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
30 | { |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
31 | const gchar * const authors[] = { |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
32 | "Author Name <e@mail>", |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
33 | NULL |
|
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 | |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
36 | /* 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
|
37 | 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
|
38 | 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
|
39 | "name", "Hello World!", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
40 | "version", VERSION, |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
41 | "category", "Example", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
42 | "summary", "Hello World Plugin", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
43 | "description", "Hello World Plugin", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
44 | "authors", authors, |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
45 | "website", "http://helloworld.tld", |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
46 | "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
|
47 | NULL |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
48 | ); |
|
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
49 | } |
| 10468 | 50 | |
| 51 | static gboolean | |
|
40933
60f4b2a6d66a
Update the C plugin tutorial to use the gplugin macros
Gary Kramlich <grim@reaperworld.com>
parents:
39413
diff
changeset
|
52 | hello_world_load(GPluginPlugin *plugin, GError **error) |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
53 | { |
|
16260
3e2e3df543f0
Effect the rename in the C-HOWTO and clean it up.
Richard Laager <rlaager@pidgin.im>
parents:
15864
diff
changeset
|
54 | purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!", |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
55 | "This is the Hello World! plugin :)", |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
56 | NULL, NULL, NULL, NULL); |
| 10468 | 57 | |
| 58 | return TRUE; | |
| 59 | } | |
| 60 | ||
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
61 | static gboolean |
|
40933
60f4b2a6d66a
Update the C plugin tutorial to use the gplugin macros
Gary Kramlich <grim@reaperworld.com>
parents:
39413
diff
changeset
|
62 | hello_world_unload(GPluginPlugin *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
|
63 | { |
|
36796
ebb632962d4e
Updated C-HOWTO.dox according to the new plugin API
Ankit Vani <a@nevitus.org>
parents:
36793
diff
changeset
|
64 | return TRUE; |
| 10468 | 65 | } |
| 66 | ||
|
40933
60f4b2a6d66a
Update the C plugin tutorial to use the gplugin macros
Gary Kramlich <grim@reaperworld.com>
parents:
39413
diff
changeset
|
67 | GPLUGIN_NATIVE_PLUGIN_DECLARE(hello_world) |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
68 | ``` |
| 10468 | 69 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
70 | Okay, so what does all this mean? We start off by including purple.h. This |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
71 | file includes all the libpurple header files. |
| 10468 | 72 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
73 | `hello_world_query`, `hello_world_load` and `hello_world_unload` are functions |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
74 | that must be implemented in every plugin. These functions are named according |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
75 | to the value passed to `GPLUGIN_NATIVE_PLUGIN_DECLARE` which is described |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
76 | below. |
| 10468 | 77 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
78 | `hello_world_query` is called when the plugin is queried by the plugin system, |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
79 | and returns various information about the plugin in form of a newly created |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
80 | instance of `GPluginPluginInfo` or a subclass. For a list of all available |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
81 | properties, see `purple_plugin_info_new()`. |
| 10468 | 82 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
83 | If anything should go wrong during the query you can return an error by using |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
84 | `g_set_error()` on the `error` argument. |
|
40933
60f4b2a6d66a
Update the C plugin tutorial to use the gplugin macros
Gary Kramlich <grim@reaperworld.com>
parents:
39413
diff
changeset
|
85 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
86 | `hello_world_load` is called when the plugin is loaded. That is the user has |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
87 | enabled the plugin or libpurple is loading a plugin that was previously loaded. |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
88 | You can initialize any variables, register dynamic types, and so on in this |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
89 | function. Plugins may also want to add their preferences to the pref |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
90 | tree--more about that later. In this plugin we'll just use it to display a |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
91 | message. Just like `hello_world_query` if there are any errors that arise, you |
|
41165
24e2c88a7fc2
Ran codespell on the libpurple docs that were converted to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
41164
diff
changeset
|
92 | can call `g_set_error()` on the `error` argument and return `FALSE`. |
|
36905
d256e7a2ec4c
Changed dox files to xml files for gtk-doc, and included them in the top-level XMLs.
Ankit Vani <a@nevitus.org>
parents:
36900
diff
changeset
|
93 | |
|
41164
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
94 | `hello_world_unload` is called when the plugin is unloaded. That is, when the |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
95 | user has manually unloaded the plugin or the program is shutting down. We can |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
96 | use it to wrap up everything, and free our variables. Again, if there are any |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
97 | errors, you can call `g_set_error()` on the `error` argument and return `FALSE`. |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
98 | |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
99 | Finally we have `GPLUGIN_NATIVE_PLUGIN_DECLARE()`. It is a helper macro that |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
100 | makes creating plugins easier. It has a single argument which is the prefix |
|
d861b10105fb
Convert the libpurple docs to gi-docgen
Gary Kramlich <grim@reaperworld.com>
parents:
40933
diff
changeset
|
101 | used for the `_query`, `_load`, and `_unload` functions. |