# HG changeset patch # User John Bailey # Date 1189617753 0 # Node ID 4a38af2279c73e3f1814d77c6c7aa072c5053817 # Parent 0633ecda7ed0eb98b788ec671b156d6aca0d1f11# Parent 2c69ceca80670e63a4dd1554e93eed3b96a5e123 propagate from branch 'im.pidgin.pidgin' (head 483b6435074838149d6e95b836d4a2d9263f265d) to branch 'im.pidgin.cpw.rekkanoryo.examples' (head e9ac09439a739bbf07e7269224516dd4fc1d2b56) diff -r 0633ecda7ed0 -r 4a38af2279c7 libpurple/plugins/Makefile.am --- a/libpurple/plugins/Makefile.am Wed Sep 12 15:59:22 2007 +0000 +++ b/libpurple/plugins/Makefile.am Wed Sep 12 17:22:33 2007 +0000 @@ -28,10 +28,13 @@ 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 newline_la_LDFLAGS = -module -avoid-version +notify_example_la_LDFLAGS = -module -avoid-version offlinemsg_la_LDFLAGS = -module -avoid-version pluginpref_example_la_LDFLAGS = -module -avoid-version psychic_la_LDFLAGS = -module -avoid-version @@ -59,6 +62,9 @@ noinst_LTLIBRARIES = \ ciphertest.la \ codeinline.la \ + debug_example.la \ + helloworld.la \ + notify_example.la \ pluginpref_example.la \ signals_test.la \ simple.la @@ -67,10 +73,13 @@ 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 newline_la_SOURCES = newline.c +notify_example_la_SOURCES = notify_example.c offlinemsg_la_SOURCES = offlinemsg.c pluginpref_example_la_SOURCES = pluginpref_example.c psychic_la_SOURCES = psychic.c @@ -86,6 +95,7 @@ joinpart_la_LIBADD = $(GLIB_LIBS) log_reader_la_LIBADD = $(GLIB_LIBS) newline_la_LIBADD = $(GLIB_LIBS) +notify_example_la_LIBADD = $(GLIB_LIBS) offlinemsg_la_LIBADD = $(GLIB_LIBS) pluginpref_example_la_LIBADD = $(GLIB_LIBS) psychic_la_LIBADD = $(GLIB_LIBS) diff -r 0633ecda7ed0 -r 4a38af2279c7 libpurple/plugins/debug_example.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/plugins/debug_example.c Wed Sep 12 17:22:33 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 0633ecda7ed0 -r 4a38af2279c7 libpurple/plugins/helloworld.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/plugins/helloworld.c Wed Sep 12 17:22:33 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) diff -r 0633ecda7ed0 -r 4a38af2279c7 libpurple/plugins/notify_example.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpurple/plugins/notify_example.c Wed Sep 12 17:22:33 2007 +0000 @@ -0,0 +1,150 @@ +/* + * Notify API 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 + +#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 + +#define PLUGIN_ID "core-notifyexample" +#define PLUGIN_AUTHOR "John Bailey " + +#include +#include +#include + +static PurplePlugin *notify_example = NULL; + +static void +notify_error_cb(PurplePluginAction *action) +{ + purple_notify_error(notify_example, "Test Notification", "Test Notification", + "This is a test error notification"); +} + +static void +notify_info_cb(PurplePluginAction *action) +{ + purple_notify_info(notify_example, "Test Notification", "Test Notification", + "This is a test informative notification"); +} + +static void +notify_warn_cb(PurplePluginAction *action) +{ + purple_notify_warning(notify_example, "Test Notification", "Test Notification", + "This is a test warning notification"); +} + +static void +notify_format_cb(PurplePluginAction *action) +{ + purple_notify_formatted(notify_example, "Test Notification", "Test Notification", + "Test Notification", + "This is a test notification with formatted text.", NULL, NULL); +} + +static void +notify_uri_cb(PurplePluginAction *action) +{ + purple_notify_uri(notify_example, "http://www.pidgin.im/"); +} + +static GList * +plugin_actions(PurplePlugin *plugin, gpointer context) +{ + GList *actions = NULL; + PurplePluginAction *action = NULL; + + actions = g_list_prepend(actions, + purple_plugin_action_new("Show Error Notification", notify_error_cb)); + + actions = g_list_prepend(actions, + purple_plugin_action_new("Show Info Notification", notify_info_cb)); + + actions = g_list_prepend(actions, + purple_plugin_action_new("Show Warning Notification", notify_warn_cb)); + + actions = g_list_prepend(actions, + purple_plugin_action_new("Show Formatted Notification", notify_format_cb)); + + actions = g_list_prepend(actions, + purple_plugin_action_new("Show URI Notification", notify_uri_cb)); + + return g_list_reverse(actions); +} + +static gboolean +plugin_load(PurplePlugin *plugin) +{ + notify_example = plugin; + + 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 */ + "Notify API Example", /* name */ + VERSION, /* version */ + "Notify API Example", /* summary */ + "Notify 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 */ + plugin_actions, /* actions */ + NULL, /* reserved */ + NULL, /* reserved */ + NULL, /* reserved */ + NULL /* reserved */ +}; + +static void +init_plugin(PurplePlugin *plugin) +{ +} + +PURPLE_INIT_PLUGIN(notifyexample, init_plugin, info) +