Mercurial > pidgin
annotate src/protocols/msn/utils.c @ 8986:8cf32769ba1b
[gaim-migrate @ 9761]
" This patch adds a Plugin Actions menu item after the
Account Actions menu. The Plugin Actions menu is
populated from the added 'actions' slot in
GaimPluginInfo. As a demonstration, the Idle Maker
plugin has been converted to no longer require GTK code
and the Preferences interface just to perform its
actions. Instead, it uses a Plugin Action to spawn a
Fields Request.
There's also a minor fix for consistency in the menu
building for buddy actions. The pre-existing method for
instructing a menu list to display a separator was to
insert a NULL rather than a proto_buddy_menu into the
GList of actions. The code for the buddy menus was
instead checking for a proto_buddy_menu with a '-'
label. This has been fixed, and it now correctly uses
NULL to indicate a separator."
"Date: 2004-05-16 02:25
Sender: taliesein
Logged In: YES
user_id=77326
I need to add a callback to this patch to watch for
loading/unloading of plugins (to determine when to rebuild
the menu). Since the appropriate way to handle Plugin
Actions is still mildly up for debate, I'm holding of on
correcting the patch until I know for sure whether I should
fix this patch, or scrap it and write a new one using a
different method."
"Date: 2004-05-18 12:26
Sender: taliesein
Logged In: YES
user_id=77326
I've completed changes to this patch to also add plugin load
and unload signals (it looks like plugin.c actually had
pre-signal callbacks in place, but they were never used or
converted to signals)
This patch now will correctly update the Plugin Action menu
as plugins load and unload."
I'm not entirely sure i like the ui of a plugins actions menu, but i think
that having some way for plugins to add actions on an account is a good
thing, and i'm not sure that every viable action fits under the accounts
actions menu. we may want to merge the two (the existing accounts actions
and this plugins actions), but both times it came up in #gaim no one seemed
to want to comment, and on one commented to the gaim-devel post either.
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Thu, 20 May 2004 05:11:44 +0000 |
| parents | 3ea82ab12cb9 |
| children | cab225a333b5 |
| rev | line source |
|---|---|
| 5309 | 1 /** |
|
5312
89948fedf782
[gaim-migrate @ 5684]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
2 * @file utils.c Utility functions |
| 5309 | 3 * |
| 4 * gaim | |
| 5 * | |
|
8475
06f57183e29f
[gaim-migrate @ 9208]
Christian Hammond <chipx86@chipx86.com>
parents:
7134
diff
changeset
|
6 * Copyright (C) 2003-2004 Christian Hammond <chipx86@gnupdate.org> |
|
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
6359
diff
changeset
|
7 * |
| 5309 | 8 * This program is free software; you can redistribute it and/or modify |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 */ | |
| 22 #include "msn.h" | |
| 23 | |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
24 void |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
25 msn_parse_format(const char *mime, char **pre_ret, char **post_ret) |
| 5309 | 26 { |
| 27 char *cur; | |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
28 GString *pre = g_string_new(NULL); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
29 GString *post = g_string_new(NULL); |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
30 unsigned int colors[3]; |
| 5309 | 31 |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
32 if (pre_ret != NULL) *pre_ret = NULL; |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
33 if (post_ret != NULL) *post_ret = NULL; |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
34 |
| 5309 | 35 cur = strstr(mime, "FN="); |
| 36 | |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
37 if (cur && (*(cur = cur + 3) != ';')) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
38 { |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
39 pre = g_string_append(pre, "<FONT FACE=\""); |
| 5309 | 40 |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
41 while (*cur && *cur != ';') |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
42 { |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
43 pre = g_string_append_c(pre, *cur); |
| 5309 | 44 cur++; |
| 45 } | |
| 46 | |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
47 pre = g_string_append(pre, "\">"); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
48 post = g_string_prepend(post, "</FONT>"); |
| 5309 | 49 } |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
50 |
| 5309 | 51 cur = strstr(mime, "EF="); |
| 52 | |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
53 if (cur && (*(cur = cur + 3) != ';')) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
54 { |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
55 while (*cur && *cur != ';') |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
56 { |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
57 pre = g_string_append_c(pre, '<'); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
58 pre = g_string_append_c(pre, *cur); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
59 pre = g_string_append_c(pre, '>'); |
|
8691
0eb5161ef333
[gaim-migrate @ 9444]
Christian Hammond <chipx86@chipx86.com>
parents:
8678
diff
changeset
|
60 post = g_string_prepend_c(post, '>'); |
|
0eb5161ef333
[gaim-migrate @ 9444]
Christian Hammond <chipx86@chipx86.com>
parents:
8678
diff
changeset
|
61 post = g_string_prepend_c(post, *cur); |
|
0eb5161ef333
[gaim-migrate @ 9444]
Christian Hammond <chipx86@chipx86.com>
parents:
8678
diff
changeset
|
62 post = g_string_prepend_c(post, '/'); |
|
0eb5161ef333
[gaim-migrate @ 9444]
Christian Hammond <chipx86@chipx86.com>
parents:
8678
diff
changeset
|
63 post = g_string_prepend_c(post, '<'); |
| 5309 | 64 cur++; |
| 65 } | |
| 66 } | |
| 67 | |
| 68 cur = strstr(mime, "CO="); | |
| 69 | |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
70 if (cur && (*(cur = cur + 3) != ';')) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
71 { |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
72 int i; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
73 |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
74 i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]); |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
75 |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
76 if (i > 0) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
77 { |
| 5309 | 78 char tag[64]; |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
79 |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
80 if (i == 1) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
81 { |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
82 colors[1] = 0; |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
83 colors[2] = 0; |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
84 } |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
85 else if (i == 2) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
86 { |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
87 unsigned int temp = colors[0]; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
88 |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
89 colors[0] = colors[1]; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
90 colors[1] = temp; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
91 colors[2] = 0; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
92 } |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
93 else if (i == 3) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
94 { |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
95 unsigned int temp = colors[2]; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
96 |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
97 colors[2] = colors[0]; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
98 colors[0] = temp; |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
99 } |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
100 |
| 5309 | 101 g_snprintf(tag, sizeof(tag), |
| 102 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">", | |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
103 colors[0], colors[1], colors[2]); |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
104 |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
105 pre = g_string_append(pre, tag); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
106 post = g_string_prepend(post, "</FONT>"); |
| 5309 | 107 } |
| 108 } | |
| 109 | |
| 7134 | 110 cur = g_strdup(gaim_url_decode(pre->str)); |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
111 g_string_free(pre, TRUE); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
112 |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
113 if (pre_ret != NULL) |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
114 *pre_ret = cur; |
|
6359
dfde69e105ae
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
115 else |
|
dfde69e105ae
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
116 g_free(cur); |
| 5309 | 117 |
| 7134 | 118 cur = g_strdup(gaim_url_decode(post->str)); |
|
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
119 g_string_free(post, TRUE); |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
120 |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
121 if (post_ret != NULL) |
|
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
122 *post_ret = cur; |
|
6359
dfde69e105ae
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
123 else |
|
dfde69e105ae
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
124 g_free(cur); |
| 5309 | 125 } |
|
8518
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
126 |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
127 /* |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
128 * We need this because we're only supposed to encode spaces in the font |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
129 * names. gaim_url_encode() isn't acceptable. |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
130 */ |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
131 const char * |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
132 encode_spaces(const char *str) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
133 { |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
134 static char buf[BUF_LEN]; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
135 const char *c; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
136 char *d; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
137 |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
138 g_return_val_if_fail(str != NULL, NULL); |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
139 |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
140 for (c = str, d = buf; *c != '\0'; c++) |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
141 { |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
142 if (*c == ' ') |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
143 { |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
144 *d++ = '%'; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
145 *d++ = '2'; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
146 *d++ = '0'; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
147 } |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
148 else |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
149 *d++ = *c; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
150 } |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
151 |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
152 return buf; |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
153 } |
|
833dd756dcc3
[gaim-migrate @ 9257]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
154 |
|
8595
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
155 /* |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
156 * Taken from the zephyr plugin. |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
157 * This parses HTML formatting (put out by one of the gtkimhtml widgets |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
158 * and converts it to msn formatting. It doesn't deal with the tag closing, |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
159 * but gtkimhtml widgets give valid html. |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
160 * It currently deals properly with <b>, <u>, <i>, <font face=...>, |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
161 * <font color=...>. |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
162 * It ignores <font back=...> and <font size=...> |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
163 */ |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
164 void |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
165 msn_import_html(const char *html, char **attributes, char **message) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
166 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
167 int len, retcount = 0; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
168 const char *c; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
169 char *msg; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
170 char *fontface = NULL; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
171 char fonteffect[4]; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
172 char fontcolor[7]; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
173 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
174 g_return_if_fail(html != NULL); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
175 g_return_if_fail(attributes != NULL); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
176 g_return_if_fail(message != NULL); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
177 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
178 len = strlen(html); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
179 msg = g_malloc0(len + 1); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
180 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
181 memset(fontcolor, 0, sizeof(fontcolor)); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
182 memset(fonteffect, 0, sizeof(fontcolor)); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
183 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
184 for (c = html; *c != '\0';) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
185 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
186 if (*c == '<') |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
187 { |
| 8923 | 188 if (!g_ascii_strncasecmp(c + 1, "br>", 3)) |
| 189 { | |
| 190 msg[retcount++] = '\r'; | |
| 191 msg[retcount++] = '\n'; | |
| 192 c += 4; | |
| 193 } | |
| 194 else if (!g_ascii_strncasecmp(c + 1, "i>", 2)) | |
|
8595
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
195 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
196 strcat(fonteffect, "I"); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
197 c += 3; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
198 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
199 else if (!g_ascii_strncasecmp(c + 1, "b>", 2)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
200 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
201 strcat(fonteffect, "B"); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
202 c += 3; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
203 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
204 else if (!g_ascii_strncasecmp(c + 1, "u>", 2)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
205 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
206 strcat(fonteffect, "U"); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
207 c += 3; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
208 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
209 else if (!g_ascii_strncasecmp(c + 1, "a href=\"", 8)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
210 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
211 c += 9; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
212 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
213 while (g_ascii_strncasecmp(c, "\">", 2)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
214 msg[retcount++] = *c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
215 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
216 c += 2; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
217 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
218 /* ignore descriptive string */ |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
219 while (g_ascii_strncasecmp(c, "</a>", 4)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
220 c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
221 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
222 c += 4; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
223 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
224 else if (!g_ascii_strncasecmp(c + 1, "font", 4)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
225 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
226 c += 5; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
227 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
228 while (!g_ascii_strncasecmp(c, " ", 1)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
229 c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
230 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
231 if (!g_ascii_strncasecmp(c, "color=\"#", 7)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
232 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
233 c += 8; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
234 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
235 fontcolor[0] = *(c + 4); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
236 fontcolor[1] = *(c + 5); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
237 fontcolor[2] = *(c + 2); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
238 fontcolor[3] = *(c + 3); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
239 fontcolor[4] = *c; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
240 fontcolor[5] = *(c + 1); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
241 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
242 c += 8; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
243 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
244 else if (!g_ascii_strncasecmp(c, "face=\"", 6)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
245 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
246 const char *end = NULL; |
| 8921 | 247 const char *comma = NULL; |
|
8595
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
248 unsigned int namelen = 0; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
249 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
250 c += 6; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
251 end = strchr(c, '\"'); |
| 8921 | 252 comma = strchr(c, ','); |
| 253 | |
| 254 namelen = (unsigned int)((comma != NULL ? comma : end) - c); | |
| 255 | |
|
8595
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
256 fontface = g_strndup(c, namelen); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
257 c = end + 2; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
258 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
259 else |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
260 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
261 /* Drop all unrecognized/misparsed font tags */ |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
262 while (g_ascii_strncasecmp(c, "\">", 2)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
263 c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
264 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
265 c += 2; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
266 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
267 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
268 else |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
269 { |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
270 while (g_ascii_strncasecmp(c, ">", 1)) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
271 c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
272 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
273 c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
274 } |
| 8921 | 275 } |
| 276 else if (*c == '&') | |
| 277 { | |
| 278 if (!g_ascii_strncasecmp(c, "<", 4)) | |
| 279 { | |
| 8678 | 280 msg[retcount++] = '<'; |
| 281 c += 4; | |
| 8921 | 282 } |
| 283 else if (!g_ascii_strncasecmp(c, ">", 4)) | |
| 284 { | |
| 8678 | 285 msg[retcount++] = '>'; |
| 286 c += 4; | |
| 8921 | 287 } |
| 288 else if (!g_ascii_strncasecmp(c, """, 6)) | |
| 289 { | |
| 8678 | 290 msg[retcount++] = '"'; |
| 291 c += 6; | |
| 8921 | 292 } |
| 293 else if (!g_ascii_strncasecmp(c, "&", 5)) | |
| 294 { | |
| 8678 | 295 msg[retcount++] = '&'; |
| 296 c += 5; | |
| 297 } | |
| 8921 | 298 } |
| 299 else | |
|
8595
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
300 msg[retcount++] = *c++; |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
301 } |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
302 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
303 if (fontface == NULL) |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
304 fontface = g_strdup("MS Sans Serif"); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
305 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
306 *attributes = g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0", |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
307 encode_spaces(fontface), |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
308 fonteffect, fontcolor); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
309 *message = g_strdup(msg); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
310 |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
311 g_free(fontface); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
312 g_free(msg); |
|
1d5e31e518fc
[gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents:
8530
diff
changeset
|
313 } |
