pidgin 2.14.14dev
|
C plugins are native plugins. They have complete access to all of the API, and can do basically whatever they want. All of the protocol plugins, as well as the Mono, Perl, and Tcl loader plugins are written in C.
To develop a plugin you need to have the libpurple and (for UI plugins) the Pidgin/Finch source code or development headers. It is generally a good idea to compile against the same version of Pidgin that you are running. You may also want to develop against the code in our Monotone repository if you need to use a new feature. Please do not abuse our Monotone repository, however.
All plugins must have PURPLE_PLUGINS
defined and the definition must be before including any libpurple, Pidgin, or Finch header files. Failure to do so can lead to strange errors that are hard to diagnose. Just don't forget!
I know every tutorial has a hello world, so why should libpurple be any different?
Okay, so what does all this mean? We start off by defining PURPLE_PLUGINS
like described before. Next we include glib.h, mainly for gboolean and the glib wrappers of the standard C types.
Next, we include plugin.h which has all the plugin specific stuff that we need. For example: PurplePlugin
, PurplePluginInfo
, PURPLE_PLUGIN_MAGIC
, and PURPLE_INIT_PLUGIN()
.
Our last include is version.h which defines PURPLE_MAJOR_VERSION
, and PURPLE_MINOR_VERSION
. There is not much you need to know about these, except that they are required and will stop your plugin from crashing Pidgin when something has changed that your plugin does not know about yet.
plugin_load
is not required. It is called when the plugin is loaded so that you can initialize any variables and so on. In this plugin we'll just use it to display a message.
Next we have the PurplePluginInfo
structure. Every plugin MUST have one of these. Below is a code snipet of the same struct used in hello_world
with comments describing what each is.
Finally we have init_plugin
and PURPLE_INIT_PLUGIN
. init_plugin
is a function that gets called when libpurple probes the plugin. Most plugins will add their preferences to the pref tree here–more about that later. PURPLE_INIT_PLUGIN
is a macro that EVERY plugin MUST have. PURPLE_INIT_PLUGIN
tells libpurple some very basic things about your plugin, like what name to use if the plugin is compiled staticly, the init_plugin
function, and the name of the PurplePluginInfo structure. As you may have guessed, this also gets read when libpurple is probing your plugin. If this is missing, the plugin will not load.