libpurple/plugins/codeinline.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 37482
922720634101
child 39959
e47fcffd061b
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.

12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
1 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2 * purple
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
3 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
6 * source distribution.
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
7 *
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
12 *
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
17 *
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
19 * 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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
21 */
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
22
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
23 #include "internal.h"
36367
891eea799578 Renamed plugin.[ch] to plugins.[ch], since we (will) no longer have a PurplePlugin structure.
Ankit Vani <a@nevitus.org>
parents: 31294
diff changeset
24 #include "plugins.h"
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
25 #include "notify.h"
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
26 #include "util.h"
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
27 #include "version.h"
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
28
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
29 PurplePlugin *plugin_handle = NULL;
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
30
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
31 static char *
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
32 outgoing_msg_common(const char *message)
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
33 {
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
34 char *m;
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
35 char **ms = g_strsplit(message, "<u>", -1);
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
36 m = g_strjoinv("<font face=\"monospace\" color=\"#00b025\">", ms);
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
37 g_strfreev(ms);
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
38
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
39 ms = g_strsplit(m, "</u>", -1);
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
40 g_free(m);
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
41 return g_strjoinv("</font>", ms);
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
42 }
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
43
37482
922720634101 Fix the writing-im-msg callback in codeinline.c
Richard Laager <rlaager@pidgin.im>
parents: 37148
diff changeset
44 static gboolean outgoing_msg_cb1(PurpleConversation *conv, PurpleMessage *msg,
922720634101 Fix the writing-im-msg callback in codeinline.c
Richard Laager <rlaager@pidgin.im>
parents: 37148
diff changeset
45 gpointer null)
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
46 {
37482
922720634101 Fix the writing-im-msg callback in codeinline.c
Richard Laager <rlaager@pidgin.im>
parents: 37148
diff changeset
47 purple_message_set_contents(msg,
922720634101 Fix the writing-im-msg callback in codeinline.c
Richard Laager <rlaager@pidgin.im>
parents: 37148
diff changeset
48 outgoing_msg_common(purple_message_get_contents(msg)));
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
49 return FALSE;
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
50 }
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
51
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
52 static void
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
53 outgoing_msg_cb2(PurpleAccount *account, PurpleMessage *msg,
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
54 PurpleConversation *conv, PurpleMessageFlags flags, gpointer null)
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
55 {
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
56 purple_message_set_contents(msg,
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
57 outgoing_msg_common(purple_message_get_contents(msg)));
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
58 }
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
59
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
60 static PurplePluginInfo *
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
61 plugin_query(GError **error)
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
62 {
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
63 const gchar * const authors[] = {
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
64 "Sean Egan <seanegan@gmail.com>",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
65 NULL
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
66 };
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
67
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
68 return purple_plugin_info_new(
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
69 "id", "codeinline",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
70 "name", "Code Inline",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
71 "version", "1.0",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
72 "category", "Formatting",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
73 "summary", "Formats text as code",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
74 "description", "Changes the formatting of any outgoing text such "
36742
5d43951cabc0 More refactoring
Ankit Vani <a@nevitus.org>
parents: 36739
diff changeset
75 "that anything underlined will be received green and "
5d43951cabc0 More refactoring
Ankit Vani <a@nevitus.org>
parents: 36739
diff changeset
76 "monospace.",
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
77 "authors", authors,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
78 "website", PURPLE_WEBSITE,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
79 "abi-version", PURPLE_ABI_VERSION,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
80 NULL
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
81 );
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
82 }
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
83
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
84 static gboolean
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
85 plugin_load(PurplePlugin *plugin, GError **error)
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 13234
diff changeset
86 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
87 void *handle = purple_conversations_get_handle();
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
88 plugin_handle = plugin;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
89 purple_signal_connect(handle, "writing-im-msg", plugin,
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
90 PURPLE_CALLBACK(outgoing_msg_cb1), NULL);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
91 purple_signal_connect(handle, "sending-im-msg", plugin,
36079
2e449140fe0b Switch sending-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 31294
diff changeset
92 PURPLE_CALLBACK(outgoing_msg_cb2), NULL);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 13234
diff changeset
93
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
94 return TRUE;
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
95 }
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
96
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
97 static gboolean
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
98 plugin_unload(PurplePlugin *plugin, GError **error)
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
99 {
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
100 return TRUE;
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
101 }
12055
48460d77deaa [gaim-migrate @ 14350]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
102
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
103 PURPLE_PLUGIN_INIT(codeinline, plugin_query, plugin_load, plugin_unload);

mercurial