Sat, 27 Aug 2016 18:16:01 -0500
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.
| 8713 | 1 | /* |
| 12362 | 2 | * PluginPref Example Plugin |
| 8713 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16786
diff
changeset
|
19 | * 02111-1301, USA. |
| 8713 | 20 | */ |
| 21 | ||
|
35072
cb3673616d90
Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents:
34479
diff
changeset
|
22 | /* 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:
34479
diff
changeset
|
23 | * 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:
34479
diff
changeset
|
24 | * it here for our own convenience. */ |
| 8713 | 25 | #include "internal.h" |
| 26 | ||
|
35072
cb3673616d90
Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents:
34479
diff
changeset
|
27 | /* This file defines PURPLE_PLUGINS and includes all the libpurple headers */ |
|
cb3673616d90
Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents:
34479
diff
changeset
|
28 | #include <purple.h> |
| 8713 | 29 | |
| 15884 | 30 | static PurplePluginPrefFrame * |
| 31 | get_plugin_pref_frame(PurplePlugin *plugin) { | |
| 32 | PurplePluginPrefFrame *frame; | |
| 33 | PurplePluginPref *ppref; | |
| 8713 | 34 | |
| 15884 | 35 | frame = purple_plugin_pref_frame_new(); |
| 8713 | 36 | |
| 15884 | 37 | ppref = purple_plugin_pref_new_with_label("boolean"); |
| 38 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 39 | |
| 15884 | 40 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 41 | "/plugins/core/pluginpref_example/bool", |
| 8713 | 42 | "boolean pref"); |
| 15884 | 43 | purple_plugin_pref_frame_add(frame, ppref); |
| 8713 | 44 | |
| 15884 | 45 | ppref = purple_plugin_pref_new_with_label("integer"); |
| 46 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 47 | |
| 15884 | 48 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 49 | "/plugins/core/pluginpref_example/int", |
| 8713 | 50 | "integer pref"); |
| 15884 | 51 | purple_plugin_pref_set_bounds(ppref, 0, 255); |
| 52 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 53 | |
| 15884 | 54 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 55 | "/plugins/core/pluginpref_example/int_choice", |
| 8713 | 56 | "integer choice"); |
|
35378
5d9e2581005b
gtk-doc prep: *_get_type() functions are hidden as standard GType-returning funcs, so rename them.
Ankit Vani <a@nevitus.org>
parents:
35072
diff
changeset
|
57 | purple_plugin_pref_set_pref_type(ppref, PURPLE_PLUGIN_PREF_CHOICE); |
| 15884 | 58 | purple_plugin_pref_add_choice(ppref, "One", GINT_TO_POINTER(1)); |
| 59 | purple_plugin_pref_add_choice(ppref, "Two", GINT_TO_POINTER(2)); | |
| 60 | purple_plugin_pref_add_choice(ppref, "Four", GINT_TO_POINTER(4)); | |
| 61 | purple_plugin_pref_add_choice(ppref, "Eight", GINT_TO_POINTER(8)); | |
| 62 | purple_plugin_pref_add_choice(ppref, "Sixteen", GINT_TO_POINTER(16)); | |
| 63 | purple_plugin_pref_add_choice(ppref, "Thirty Two", GINT_TO_POINTER(32)); | |
| 64 | purple_plugin_pref_add_choice(ppref, "Sixty Four", GINT_TO_POINTER(64)); | |
| 65 | purple_plugin_pref_add_choice(ppref, "One Hundred Twenty Eight", GINT_TO_POINTER(128)); | |
| 66 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 67 | |
| 15884 | 68 | ppref = purple_plugin_pref_new_with_label("string"); |
| 69 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 70 | |
| 15884 | 71 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 72 | "/plugins/core/pluginpref_example/string", |
| 8713 | 73 | "string pref"); |
| 15884 | 74 | purple_plugin_pref_frame_add(frame, ppref); |
| 8713 | 75 | |
| 15884 | 76 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 77 | "/plugins/core/pluginpref_example/masked_string", |
| 9841 | 78 | "masked string"); |
| 15884 | 79 | purple_plugin_pref_set_masked(ppref, TRUE); |
| 80 | purple_plugin_pref_frame_add(frame, ppref); | |
| 9841 | 81 | |
| 15884 | 82 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 83 | "/plugins/core/pluginpref_example/max_string", |
| 8713 | 84 | "string pref\n(max length of 16)"); |
| 15884 | 85 | purple_plugin_pref_set_max_length(ppref, 16); |
| 86 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 87 | |
| 15884 | 88 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 16481 | 89 | "/plugins/core/pluginpref_example/string_choice", |
| 8713 | 90 | "string choice"); |
|
35378
5d9e2581005b
gtk-doc prep: *_get_type() functions are hidden as standard GType-returning funcs, so rename them.
Ankit Vani <a@nevitus.org>
parents:
35072
diff
changeset
|
91 | purple_plugin_pref_set_pref_type(ppref, PURPLE_PLUGIN_PREF_CHOICE); |
| 15884 | 92 | purple_plugin_pref_add_choice(ppref, "red", "red"); |
| 93 | purple_plugin_pref_add_choice(ppref, "orange", "orange"); | |
| 94 | purple_plugin_pref_add_choice(ppref, "yellow", "yellow"); | |
| 95 | purple_plugin_pref_add_choice(ppref, "green", "green"); | |
| 96 | purple_plugin_pref_add_choice(ppref, "blue", "blue"); | |
| 97 | purple_plugin_pref_add_choice(ppref, "purple", "purple"); | |
| 98 | purple_plugin_pref_frame_add(frame, ppref); | |
| 8713 | 99 | |
| 100 | return frame; | |
| 101 | } | |
| 102 | ||
|
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
|
103 | 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
|
104 | plugin_query(GError **error) |
| 8713 | 105 | { |
|
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
|
106 | const gchar * const 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
|
107 | "Gary Kramlich <amc_grim@users.sf.net>", |
|
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 | 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
|
109 | }; |
| 8713 | 110 | |
|
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
|
111 | return purple_plugin_info_new( |
|
36934
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
112 | "id", "core-pluginpref_example", |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
113 | "name", "Pluginpref Example", |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
114 | "version", DISPLAY_VERSION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
115 | "category", "Example", |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
116 | "summary", "An example of how to use pluginprefs", |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
117 | "description", "An example of how to use pluginprefs", |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
118 | "authors", authors, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
119 | "website", PURPLE_WEBSITE, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
120 | "abi-version", PURPLE_ABI_VERSION, |
|
e7268aeb3b89
Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents:
36929
diff
changeset
|
121 | "pref-frame-cb", get_plugin_pref_frame, |
|
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 | 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
|
123 | ); |
|
c96edeed7ea7
Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
124 | } |
| 8713 | 125 | |
|
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
|
126 | 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
|
127 | plugin_load(PurplePlugin *plugin, GError **error) |
| 8713 | 128 | { |
| 16481 | 129 | purple_prefs_add_none("/plugins/core/pluginpref_example"); |
| 130 | purple_prefs_add_bool("/plugins/core/pluginpref_example/bool", TRUE); | |
| 131 | purple_prefs_add_int("/plugins/core/pluginpref_example/int", 0); | |
| 132 | purple_prefs_add_int("/plugins/core/pluginpref_example/int_choice", 1); | |
| 133 | purple_prefs_add_string("/plugins/core/pluginpref_example/string", | |
| 8713 | 134 | "string"); |
| 16481 | 135 | purple_prefs_add_string("/plugins/core/pluginpref_example/max_string", |
| 8713 | 136 | "max length string"); |
| 16481 | 137 | purple_prefs_add_string("/plugins/core/pluginpref_example/masked_string", "masked"); |
| 138 | purple_prefs_add_string("/plugins/core/pluginpref_example/string_choice", "red"); | |
|
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
|
139 | |
|
c96edeed7ea7
Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
140 | return TRUE; |
| 8713 | 141 | } |
| 142 | ||
|
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
|
143 | 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
|
144 | plugin_unload(PurplePlugin *plugin, 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
|
145 | { |
|
c96edeed7ea7
Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
146 | return TRUE; |
|
c96edeed7ea7
Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
147 | } |
|
c96edeed7ea7
Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
148 | |
|
c96edeed7ea7
Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents:
36367
diff
changeset
|
149 | PURPLE_PLUGIN_INIT(ppexample, plugin_query, plugin_load, plugin_unload); |