libpurple/plugins/helloworld.c

Sat, 27 Aug 2016 18:16:01 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Sat, 27 Aug 2016 18:16:01 -0500
changeset 37959
e76677ed819c
parent 36957
95cfd176b193
child 39413
f45e8a9c6fc1
permissions
-rw-r--r--

connection: Add purple_connection_take_error()

This patch adds a purple_connection_take_error() function, which
is functionally equivalent to purple_connection_g_error(), except
that it takes ownership of the passed GError.

This is useful to simplify error handling so that the GError doesn't
have to be freed, or, in the future potentially copied, if it's no
longer needed where it's generated. It can also allow for GErrors
being generated without storing them in a variable. This would be
reasonably common if/when all PurpleConnection errors are passed
in via GError.

19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
19874
5cf8fc23a5db Fix the top of the header and also correct for the new FSF address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19873
diff changeset
2 * Hello World Plugin
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
19874
5cf8fc23a5db Fix the top of the header and also correct for the new FSF address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19873
diff changeset
4 * Copyright (C) 2004, Gary Kramlich <grim@guifications.org>,
19878
aa9d2cfa70bf Fix my e-mail address to match my MTN key since it now is a real e-mail address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19874
diff changeset
5 * 2007, John Bailey <rekkanoryo@cpw.pidgin.im>
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 *
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * published by the Free Software Foundation; either version 2 of the
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 * License, or (at your option) any later version.
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 *
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 * General Public License for more details.
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 *
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19874
5cf8fc23a5db Fix the top of the header and also correct for the new FSF address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19873
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
5cf8fc23a5db Fix the top of the header and also correct for the new FSF address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19873
diff changeset
20 * 02111-1301, USA.
5cf8fc23a5db Fix the top of the header and also correct for the new FSF address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19873
diff changeset
21 *
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22 */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
23
35072
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
24 /* When writing a third-party plugin, do not include libpurple's internal.h
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
25 * included below. This file is for internal libpurple use only. We're including
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
26 * it here for our own convenience. */
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
27 #include "internal.h"
35026
fde23518e1e5 Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents: 34964
diff changeset
28
34964
54ebd3dcae16 Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents: 34963
diff changeset
29 /* This file defines PURPLE_PLUGINS and includes all the libpurple headers */
54ebd3dcae16 Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents: 34963
diff changeset
30 #include <purple.h>
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 /* This function is the callback for the plugin action we added. All we're
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 * doing here is displaying a message. When the user selects the plugin
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34 * action, this function is called. */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35 static void
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36 plugin_action_test_cb (PurplePluginAction * action)
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
38 purple_notify_message (action->plugin, PURPLE_NOTIFY_MSG_INFO,
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
39 "Plugin Actions Test", "This is a plugin actions test :)", NULL, NULL,
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 20288
diff changeset
40 NULL, NULL);
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 }
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 /* we tell libpurple in the PurplePluginInfo struct to call this function to
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44 * get a list of plugin actions to use for the plugin. This function gives
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 * libpurple that list of actions. */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46 static GList *
36742
5d43951cabc0 More refactoring
Ankit Vani <a@nevitus.org>
parents: 36740
diff changeset
47 plugin_actions (PurplePlugin * plugin)
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48 {
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 /* some C89 (a.k.a. ANSI C) compilers will warn if any variable declaration
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 * includes an initilization that calls a function. To avoid that, we
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51 * generally initialize our variables first with constant values like NULL
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 * or 0 and assign to them with function calls later */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53 GList *list = NULL;
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 PurplePluginAction *action = NULL;
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 /* The action gets created by specifying a name to show in the UI and a
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 * callback function to call. */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58 action = purple_plugin_action_new ("Plugin Action Test", plugin_action_test_cb);
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 /* libpurple requires a GList of plugin actions, even if there is only one
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61 * action in the list. We append the action to a GList here. */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62 list = g_list_append (list, action);
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 /* Once the list is complete, we send it to libpurple. */
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65 return list;
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 }
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67
36740
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
68 static PurplePluginInfo *
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
69 plugin_query (GError ** error)
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
70 {
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
71 const gchar * const authors[] = {
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
72 "John Bailey <rekkanoryo@cpw.pidgin.im>", /* correct author */
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
73 NULL
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
74 };
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
75
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
76 /* For specific notes on the meanings of each of these members, consult the
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
77 C Plugin Howto on the website. */
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
78 return purple_plugin_info_new (
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
79 "id", "core-hello_world",
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
80 "name", "Hello World!",
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
81 "version", DISPLAY_VERSION, /* This constant is defined in config.h, but you shouldn't use it for your
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
82 own plugins. We use it here because it's our plugin. And we're lazy. */
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
83 "category", "Example",
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
84 "summary", "Hello World Plugin",
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
85 "description", "Hello World Plugin",
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
86 "authors", authors,
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
87 "website", "http://helloworld.tld",
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
88 "abi-version", PURPLE_ABI_VERSION,
36934
e7268aeb3b89 Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents: 36909
diff changeset
89 "actions-cb", plugin_actions, /* this tells libpurple the address of the function to call to get the list
36740
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
90 of plugin actions. */
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
91 NULL
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
92 );
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
93 }
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
94
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95 static gboolean
36740
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
96 plugin_load (PurplePlugin * plugin, GError ** error)
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 {
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
98 purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!",
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 "This is the Hello World! plugin :)", NULL, NULL,
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 20288
diff changeset
100 NULL, NULL);
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
101
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
102 return TRUE;
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
103 }
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
104
36740
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
105 static gboolean
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
106 plugin_unload (PurplePlugin * plugin, GError ** error)
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
107 {
36740
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
108 return TRUE;
19873
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
109 }
84d19abe0d67 Adding the helloworld.c plugin used in the BasicPluginHowto and the
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
110
36740
569f0d81876a Refactored the helloworld plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
111 PURPLE_PLUGIN_INIT (hello_world, plugin_query, plugin_load, plugin_unload);

mercurial