1 <?xml version='1.0' encoding="ISO-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
5 <chapter id="chapter-tut-c-plugins">
6 <title>C Plugins tutorial</title>
8 <sect2 id="tut-c-plugins-introduction">
9 <title>Introduction</title>
11 C plugins are native plugins. They have complete access to all of the API,
12 and can do basically whatever they want. All of the protocol plugins are
17 <sect2 id="tut-c-plugins-getting-started">
18 <title>Getting Started</title>
20 To develop a plugin you need to have the libpurple and (for UI plugins) the
21 Pidgin/Finch source code or development headers. It is generally a good idea
22 to compile against the same version of Pidgin that you are running. You may
23 also want to develop against the code in our Mercurial repository if you need
24 to use a new feature. Please do not abuse our Mercurial repository, however.
28 <sect2 id="tut-c-plugins-hello-world">
29 <title>An Example</title>
31 I know every tutorial has a hello world, so why should libpurple be any
35 <title>Hello World!</title>
37 #include <purple.h>
39 static PurplePluginInfo *
40 plugin_query(GError **error)
42 const gchar * const authors[] = {
43 "Author Name <e@mail>",
47 /* For specific notes on the meanings of each of these members, consult the
48 C Plugin Howto on the website. */
49 return purple_plugin_info_new (
50 "name", "Hello World!",
52 "category", "Example",
53 "summary", "Hello World Plugin",
54 "description", "Hello World Plugin",
56 "website", "http://helloworld.tld",
57 "abi-version", PURPLE_ABI_VERSION,
63 plugin_load(PurplePlugin *plugin, GError **error)
65 purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!",
66 "This is the Hello World! plugin :)",
67 NULL, NULL, NULL, NULL);
73 plugin_unload(PurplePlugin *plugin, GError **error)
78 PURPLE_PLUGIN_INIT(hello_world, plugin_query, plugin_load, plugin_unload);
84 Okay, so what does all this mean? We start off by including purple.h. This
85 file includes all the libpurple header files.
89 <literal>plugin_query</literal>, <literal>plugin_load</literal> and
90 <literal>plugin_unload</literal> must be implemented in every plugin. Each of
91 these functions can return an error on failure by using
92 <function>g_set_error()</function> on the <literal>error</literal> argument.
96 <literal>plugin_query</literal> is called when the plugin is probed by the
97 plugin system, and returns various information about the plugin in form of a
98 newly created <literal>PurplePluginInfo</literal> instance. For a list of all
99 available properties, see
100 <link linkend="purple-plugin-info-new"><function>purple_plugin_info_new()</function></link>.
104 <literal>plugin_load</literal> is called when the plugin is loaded so that you
105 can initialize any variables, register dynamic types, and so on. Plugins may
106 also want to add their preferences to the pref tree--more about that later.
107 In this plugin we'll just use it to display a message.
111 <literal>plugin_unload</literal> is called when the plugin is unloaded, and we
112 can use it to wrap up everything, and free our variables.
117 <link linkend="PURPLE-PLUGIN-INIT:CAPS"><function>PURPLE_PLUGIN_INIT()</function></link>.
118 It is a macro that every plugin MUST have. It tells libpurple some basic
119 things about your plugin, like what name to use if the plugin is compiled
120 statically, along with the <literal>plugin_query</literal>,
121 <literal>plugin_load</literal>, and <literal>plugin_unload</literal>