# HG changeset patch # User John Bailey # Date 1189284613 0 # Node ID 3792a88141669688886ae9400968ee55733d1469 # Parent 8021fe1e2a63dc1e8cb333425451783bb2a5a29a# Parent 2729cdff43cd0c514624d4ef37d7a850f7e9ac56 propagate from branch 'im.pidgin.pidgin' (head 15bcbcfaf120a8a662c8c97ac73c5f6eb0fe6813) to branch 'im.pidgin.cpw.rekkanoryo.examples' (head e5d6939973abdfa0b120cd0fb8341d99e6f24a63) diff -r 8021fe1e2a63 -r 3792a8814166 libpurple/plugins/Makefile.am --- a/libpurple/plugins/Makefile.am Sat Sep 08 20:43:59 2007 +0000 +++ b/libpurple/plugins/Makefile.am Sat Sep 08 20:50:13 2007 +0000 @@ -28,6 +28,8 @@ buddynote_la_LDFLAGS = -module -avoid-version ciphertest_la_LDFLAGS = -module -avoid-version codeinline_la_LDFLAGS = -module -avoid-version +debug_example_la_LDFLAGS = -module -avoid-version +helloworld_la_LDFLAGS = -module -avoid-version idle_la_LDFLAGS = -module -avoid-version joinpart_la_LDFLAGS = -module -avoid-version log_reader_la_LDFLAGS = -module -avoid-version @@ -59,6 +61,8 @@ noinst_LTLIBRARIES = \ ciphertest.la \ codeinline.la \ + debug_example.la \ + helloworld.la \ pluginpref_example.la \ signals_test.la \ simple.la @@ -67,6 +71,8 @@ buddynote_la_SOURCES = buddynote.c ciphertest_la_SOURCES = ciphertest.c codeinline_la_SOURCES = codeinline.c +debug_example_la_SOURCES = debug_example.c +helloworld_la_SOURCES = helloworld.c idle_la_SOURCES = idle.c joinpart_la_SOURCES = joinpart.c log_reader_la_SOURCES = log_reader.c diff -r 8021fe1e2a63 -r 3792a8814166 libpurple/plugins/debug_example.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/plugins/debug_example.c Sat Sep 08 20:50:13 2007 +0000 @@ -0,0 +1,128 @@ +/* + * Debug Example Plugin + * + * Copyright (C) 2007, John Bailey + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02111-1301, USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* We're including glib.h again for the gboolean type. */ +#include + +/* This is the required definition of PURPLE_PLUGINS as required for a plugin, + * but we protect it with an #ifndef because config.h may define it for us + * already and this would cause an unneeded compiler warning. */ +#ifndef PURPLE_PLUGINS +# define PURPLE_PLUGINS +#endif + +/* Here we're including the necessary libpurple headers for this plugin. Note + * that we're including them in alphabetical order. This isn't necessary but + * we do this throughout our source for consistency. */ +#include "debug.h" +#include "plugin.h" +#include "version.h" + +/* It's more convenient to type PLUGIN_ID all the time than it is to type + * "core-debugexample", so define this convenience macro. */ +#define PLUGIN_ID "core-debugexample" + +/* Common practice in third-party plugins is to define convenience macros for + * many of the fields of the plugin info struct, so we'll do that for the + * purposes of demonstration. */ +#define PLUGIN_AUTHOR "John Bailey " + +/* As we've covered before, libpurple calls this function, if present, when it + * loads the plugin. Here we're using it to show off the capabilities of the + * debug API and just blindly returning TRUE to tell libpurple it's safe to + * continue loading. */ +static gboolean +plugin_load(PurplePlugin *plugin) +{ + /* Define these for convenience--we're just using them to show the + * similarities of the debug functions to the standard printf(). */ + gint i = 256; + gfloat f = 512.1024; + const gchar *s = "example string"; + + /* Introductory message */ + purple_debug_info(PLUGIN_ID, + "Called plugin_load. Beginning debug demonstration\n"); + + /* Show off the debug API a bit */ + purple_debug_misc(PLUGIN_ID, + "MISC level debug message. i = %d, f = %f, s = %s\n", i, f, s); + + purple_debug_info(PLUGIN_ID, + "INFO level debug message. i = %d, f = %f, s = %s\n", i, f, s); + + purple_debug_warning(PLUGIN_ID, + "WARNING level debug message. i = %d, f = %f, s = %s\n", i, f, s); + + purple_debug_error(PLUGIN_ID, + "ERROR level debug message. i = %d, f = %f, s = %s\n", i, f, s); + + purple_debug_fatal(PLUGIN_ID, + "FATAL level debug message. i = %d, f = %f, s = %s\n", i, f, s); + + /* Now just return TRUE to tell libpurple to finish loading. */ + return TRUE; +} + +static PurplePluginInfo info = { + PURPLE_PLUGIN_MAGIC, /* magic number */ + PURPLE_MAJOR_VERSION, /* purple major */ + PURPLE_MINOR_VERSION, /* purple minor */ + PURPLE_PLUGIN_STANDARD, /* plugin type */ + NULL, /* UI requirement */ + 0, /* flags */ + NULL, /* dependencies */ + PURPLE_PRIORITY_DEFAULT, /* priority */ + + PLUGIN_ID, /* id */ + "Debug API Example", /* name */ + VERSION, /* version */ + "Debug API Example", /* summary */ + "Debug API Example", /* description */ + PLUGIN_AUTHOR, /* author */ + "http://pidgin.im", /* homepage */ + + plugin_load, /* load */ + NULL, /* unload */ + NULL, /* destroy */ + + NULL, /* ui info */ + NULL, /* extra info */ + NULL, /* prefs info */ + NULL, /* actions */ + NULL, /* reserved */ + NULL, /* reserved */ + NULL, /* reserved */ + NULL /* reserved */ +}; + +static void +init_plugin(PurplePlugin *plugin) +{ +} + +PURPLE_INIT_PLUGIN(debugexample, init_plugin, info) + diff -r 8021fe1e2a63 -r 3792a8814166 libpurple/plugins/helloworld.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/plugins/helloworld.c Sat Sep 08 20:50:13 2007 +0000 @@ -0,0 +1,136 @@ +/* + * Hello World Plugin + * + * Copyright (C) 2004, Gary Kramlich , + * 2007, John Bailey + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02111-1301, USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* config.h may define PURPLE_PLUGINS; protect the definition here so that we + * don't get complaints about redefinition when it's not necessary. */ +#ifndef PURPLE_PLUGINS +# define PURPLE_PLUGINS +#endif + +#include + +#include +#include +#include + +/* we're adding this here and assigning it in plugin_load because we need + * a valid plugin handle for our call to purple_notify_message() in the + * plugin_action_test_cb() callback function */ +PurplePlugin *helloworld_plugin = NULL; + +/* This function is the callback for the plugin action we added. All we're + * doing here is displaying a message. When the user selects the plugin + * action, this function is called. */ +static void +plugin_action_test_cb (PurplePluginAction * action) +{ + purple_notify_message (helloworld_plugin, PURPLE_NOTIFY_MSG_INFO, + "Plugin Actions Test", "This is a plugin actions test :)", NULL, NULL, + NULL); +} + +/* we tell libpurple in the PurplePluginInfo struct to call this function to + * get a list of plugin actions to use for the plugin. This function gives + * libpurple that list of actions. */ +static GList * +plugin_actions (PurplePlugin * plugin, gpointer context) +{ + /* some C89 (a.k.a. ANSI C) compilers will warn if any variable declaration + * includes an initilization that calls a function. To avoid that, we + * generally initialize our variables first with constant values like NULL + * or 0 and assign to them with function calls later */ + GList *list = NULL; + PurplePluginAction *action = NULL; + + /* The action gets created by specifying a name to show in the UI and a + * callback function to call. */ + action = purple_plugin_action_new ("Plugin Action Test", plugin_action_test_cb); + + /* libpurple requires a GList of plugin actions, even if there is only one + * action in the list. We append the action to a GList here. */ + list = g_list_append (list, action); + + /* Once the list is complete, we send it to libpurple. */ + return list; +} + +static gboolean +plugin_load (PurplePlugin * plugin) +{ + purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!", + "This is the Hello World! plugin :)", NULL, NULL, + NULL); + + helloworld_plugin = plugin; /* assign this here so we have a valid handle later */ + + return TRUE; +} + +/* For specific notes on the meanings of each of these members, consult the C Plugin Howto + * on the website. */ +static PurplePluginInfo info = { + PURPLE_PLUGIN_MAGIC, + PURPLE_MAJOR_VERSION, + PURPLE_MINOR_VERSION, + PURPLE_PLUGIN_STANDARD, + NULL, + 0, + NULL, + PURPLE_PRIORITY_DEFAULT, + + "core-hello_world", + "Hello World!", + VERSION, /* This constant is defined in version.h, but you shouldn't use it for + your own plugins. We use it here because it's our plugin. */ + + "Hello World Plugin", + "Hello World Plugin", + "John Bailey ", /* correct author */ + "http://helloworld.tld", + + + plugin_load, + NULL, + NULL, + + NULL, + NULL, + NULL, + plugin_actions, /* this tells libpurple the address of the function to call + to get the list of plugin actions. */ + NULL, + NULL, + NULL, + NULL +}; + +static void +init_plugin (PurplePlugin * plugin) +{ +} + +PURPLE_INIT_PLUGIN (hello_world, init_plugin, info)