libpurple/plugins/notify_example.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 36974
77e5418ff1ba
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.

19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * Notify API Example Plugin
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
4 * Copyright (C) 2007, John Bailey <rekkanoryo@cpw.pidgin.im>
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * License, or (at your option) any later version.
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * General Public License for more details.
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * 02111-1301, USA.
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 */
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22
35072
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
23 /* 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
24 * 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
25 * 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
26 #include "internal.h"
35027
bf4e1f00ec72 Included internal.h in notify_example
Ankit Vani <a@nevitus.org>
parents: 34964
diff changeset
27
34964
54ebd3dcae16 Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents: 34963
diff changeset
28 /* 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
29 #include <purple.h>
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31 #define PLUGIN_ID "core-notifyexample"
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
32 #define PLUGIN_AUTHORS { "John Bailey <rekkanoryo@cpw.pidgin.im>", NULL }
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33
20011
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
34 /* The next four functions and the calls within them should cause dialog boxes to appear
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
35 * when you select the plugin action from the Tools->Notify Example menu */
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 notify_error_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
39 purple_notify_error(action->plugin, "Test Notification", "Test Notification",
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33955
diff changeset
40 "This is a test error notification", NULL);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
43 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44 notify_info_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
46 purple_notify_info(action->plugin, "Test Notification", "Test Notification",
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33955
diff changeset
47 "This is a test informative notification", NULL);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
50 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
51 notify_warn_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
53 purple_notify_warning(action->plugin, "Test Notification", "Test Notification",
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33955
diff changeset
54 "This is a test warning notification", NULL);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
57 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58 notify_format_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
60 purple_notify_formatted(action->plugin, "Test Notification", "Test Notification",
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61 "Test Notification",
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62 "<I>This is a test notification with formatted text.</I>", NULL, NULL);
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 notify_uri_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 {
20011
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
68 /* This one should open your web browser of choice. */
35160
3a32622cd352 Prefer https pidgin.im rather than http
Mark Doliner <mark@kingant.net>
parents: 35072
diff changeset
69 purple_notify_uri(action->plugin, "https://pidgin.im/");
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 static GList *
36742
5d43951cabc0 More refactoring
Ankit Vani <a@nevitus.org>
parents: 36741
diff changeset
73 plugin_actions(PurplePlugin *plugin)
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74 {
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 GList *actions = NULL;
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76
20011
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
77 /* Here we take advantage of return values to avoid the need for a temp variable */
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79 purple_plugin_action_new("Show Error Notification", notify_error_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 purple_plugin_action_new("Show Info Notification", notify_info_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 purple_plugin_action_new("Show Warning Notification", notify_warn_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 purple_plugin_action_new("Show Formatted Notification", notify_format_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91 purple_plugin_action_new("Show URI Notification", notify_uri_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 return g_list_reverse(actions);
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
95
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
96 static PurplePluginInfo *
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
97 plugin_query(GError **error)
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
98 {
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
99 const gchar * const authors[] = PLUGIN_AUTHORS;
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
100
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
101 return purple_plugin_info_new(
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
102 "id", PLUGIN_ID,
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
103 "name", "Notify API Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
104 "version", DISPLAY_VERSION,
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
105 "category", "Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
106 "summary", "Notify API Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
107 "description", "Notify API Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
108 "authors", authors,
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
109 "website", "https://pidgin.im",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
110 "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
111 "actions-cb", plugin_actions,
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
112 NULL
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
113 );
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
114 }
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
115
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 static gboolean
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
117 plugin_load(PurplePlugin *plugin, GError **error)
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118 {
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
119 return TRUE;
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
120 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
122 static gboolean
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
123 plugin_unload(PurplePlugin *plugin, GError **error)
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124 {
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
125 return TRUE;
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
127
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
128 PURPLE_PLUGIN_INIT(notifyexample, plugin_query, plugin_load, plugin_unload);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
129

mercurial