comparison libpurple/plugins/helloworld.c @ 19906:26c73c337d8f

Adding the helloworld.c plugin used in the BasicPluginHowto and the PluginActionsHowto wiki pages
author John Bailey <rekkanoryo@rekkanoryo.org>
date Sat, 08 Sep 2007 00:06:51 +0000
parents
children 9500ab76c8dc
comparison
equal deleted inserted replaced
19679:7e2327d291fb 19906:26c73c337d8f
1 /*
2 * PluginPref Example Plugin
3 *
4 * Copyright (C) 2004, Gary Kramlich <amc_grim@users.sf.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 /* config.h may define PURPLE_PLUGINS; protect the definition here so that we
27 * don't get complaints about redefinition when it's not necessary. */
28 #ifndef PURPLE_PLUGINS
29 # define PURPLE_PLUGINS
30 #endif
31
32 #include <glib.h>
33
34 #include <notify.h>
35 #include <plugin.h>
36 #include <version.h>
37
38 /* we're adding this here and assigning it in plugin_load because we need
39 * a valid plugin handle for our call to purple_notify_message() in the
40 * plugin_action_test_cb() callback function */
41 PurplePlugin *helloworld_plugin = NULL;
42
43 /* This function is the callback for the plugin action we added. All we're
44 * doing here is displaying a message. When the user selects the plugin
45 * action, this function is called. */
46 static void
47 plugin_action_test_cb (PurplePluginAction * action)
48 {
49 purple_notify_message (helloworld_plugin, PURPLE_NOTIFY_MSG_INFO,
50 "Plugin Actions Test", "This is a plugin actions test :)", NULL, NULL,
51 NULL);
52 }
53
54 /* we tell libpurple in the PurplePluginInfo struct to call this function to
55 * get a list of plugin actions to use for the plugin. This function gives
56 * libpurple that list of actions. */
57 static GList *
58 plugin_actions (PurplePlugin * plugin, gpointer context)
59 {
60 /* some C89 (a.k.a. ANSI C) compilers will warn if any variable declaration
61 * includes an initilization that calls a function. To avoid that, we
62 * generally initialize our variables first with constant values like NULL
63 * or 0 and assign to them with function calls later */
64 GList *list = NULL;
65 PurplePluginAction *action = NULL;
66
67 /* The action gets created by specifying a name to show in the UI and a
68 * callback function to call. */
69 action = purple_plugin_action_new ("Plugin Action Test", plugin_action_test_cb);
70
71 /* libpurple requires a GList of plugin actions, even if there is only one
72 * action in the list. We append the action to a GList here. */
73 list = g_list_append (list, action);
74
75 /* Once the list is complete, we send it to libpurple. */
76 return list;
77 }
78
79 static gboolean
80 plugin_load (PurplePlugin * plugin)
81 {
82 purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!",
83 "This is the Hello World! plugin :)", NULL, NULL,
84 NULL);
85
86 helloworld_plugin = plugin; /* assign this here so we have a valid handle later */
87
88 return TRUE;
89 }
90
91 /* For specific notes on the meanings of each of these members, consult the C Plugin Howto
92 * on the website. */
93 static PurplePluginInfo info = {
94 PURPLE_PLUGIN_MAGIC,
95 PURPLE_MAJOR_VERSION,
96 PURPLE_MINOR_VERSION,
97 PURPLE_PLUGIN_STANDARD,
98 NULL,
99 0,
100 NULL,
101 PURPLE_PRIORITY_DEFAULT,
102
103 "core-hello_world",
104 "Hello World!",
105 VERSION, /* This constant is defined in version.h, but you shouldn't use it for
106 your own plugins. We use it here because it's our plugin. */
107
108 "Hello World Plugin",
109 "Hello World Plugin",
110 "John Bailey <rekkanoryo@pidgin.im>", /* correct author */
111 "http://helloworld.tld",
112
113
114 plugin_load,
115 NULL,
116 NULL,
117
118 NULL,
119 NULL,
120 NULL,
121 plugin_actions, /* this tells libpurple the address of the function to call
122 to get the list of plugin actions. */
123 NULL,
124 NULL,
125 NULL,
126 NULL
127 };
128
129 static void
130 init_plugin (PurplePlugin * plugin)
131 {
132 }
133
134 PURPLE_INIT_PLUGIN (hello_world, init_plugin, info)