comparison libpurple/protocols/qq/char_conv.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 48f3837a9625
children 44b4e8bd759b
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * @file char_conv.c 2 * @file char_conv.c
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Gaim is the legal property of its developers, whose names are too numerous 6 * Purple is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this 7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution. 8 * source distribution.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
56 0x50, 0x51, 0x52, 0x53, 0x54, 0x56, 0x5b, 0x5d, 56 0x50, 0x51, 0x52, 0x53, 0x54, 0x56, 0x5b, 0x5d,
57 0x5f, 0x61, 0x69, 0x6a, 0x6c, 0x6d, 0x71, 0x72 57 0x5f, 0x61, 0x69, 0x6a, 0x6c, 0x6d, 0x71, 0x72
58 }; 58 };
59 59
60 60
61 const gchar *gaim_smiley_map[QQ_SMILEY_AMOUNT] = { 61 const gchar *purple_smiley_map[QQ_SMILEY_AMOUNT] = {
62 "/jy", "/pz", "/se", "/fd", "/dy", "/ll", "/hx", "/bz", 62 "/jy", "/pz", "/se", "/fd", "/dy", "/ll", "/hx", "/bz",
63 "/shui", "/dk ", "/gg", "/fn", "/tp", "/cy", "/wx", "/ng", 63 "/shui", "/dk ", "/gg", "/fn", "/tp", "/cy", "/wx", "/ng",
64 "/kuk", "/feid", "/zk", "/tu", "/tx", "/ka", "/by", "/am", 64 "/kuk", "/feid", "/zk", "/tu", "/tx", "/ka", "/by", "/am",
65 "/jie", "/kun", "/jk", "/lh", "/hanx", "/db", "/fendou", 65 "/jie", "/kun", "/jk", "/lh", "/hanx", "/db", "/fendou",
66 "/zhm", 66 "/zhm",
113 113
114 if (error == NULL) 114 if (error == NULL)
115 return ret; /* conversion is OK */ 115 return ret; /* conversion is OK */
116 else { /* conversion error */ 116 else { /* conversion error */
117 gchar *failed = hex_dump_to_str((guint8 *) str, (len == -1) ? strlen(str) : len); 117 gchar *failed = hex_dump_to_str((guint8 *) str, (len == -1) ? strlen(str) : len);
118 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "%s\n", error->message); 118 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "%s\n", error->message);
119 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Dump failed text\n%s", failed); 119 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Dump failed text\n%s", failed);
120 g_free(failed); 120 g_free(failed);
121 g_error_free(error); 121 g_error_free(error);
122 return g_strdup(QQ_NULL_MSG); 122 return g_strdup(QQ_NULL_MSG);
123 } 123 }
124 } 124 }
136 *ret = _my_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset); 136 *ret = _my_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset);
137 137
138 return len + 1; 138 return len + 1;
139 } 139 }
140 140
141 /* convert QQ formatted msg to Gaim formatted msg (and UTF-8) */ 141 /* convert QQ formatted msg to Purple formatted msg (and UTF-8) */
142 gchar *qq_encode_to_gaim(guint8 *data, gint len, const gchar *msg) 142 gchar *qq_encode_to_purple(guint8 *data, gint len, const gchar *msg)
143 { 143 {
144 GString *encoded; 144 GString *encoded;
145 guint8 font_attr, font_size, color[3], bar, *cursor; 145 guint8 font_attr, font_size, color[3], bar, *cursor;
146 gboolean is_bold, is_italic, is_underline; 146 gboolean is_bold, is_italic, is_underline;
147 guint16 charset_code; 147 guint16 charset_code;
177 /* Henry: The range QQ sends rounds from 8 to 22, where a font size 177 /* Henry: The range QQ sends rounds from 8 to 22, where a font size
178 * of 10 is equal to 3 in html font tag */ 178 * of 10 is equal to 3 in html font tag */
179 g_string_append_printf(encoded, 179 g_string_append_printf(encoded,
180 "<font color=\"%s\"><font face=\"%s\"><font size=\"%d\">", 180 "<font color=\"%s\"><font face=\"%s\"><font size=\"%d\">",
181 color_code, font_name, font_size / 3); 181 color_code, font_name, font_size / 3);
182 gaim_debug(GAIM_DEBUG_INFO, "QQ_MESG", 182 purple_debug(PURPLE_DEBUG_INFO, "QQ_MESG",
183 "recv <font color=\"%s\"><font face=\"%s\"><font size=\"%d\">\n", 183 "recv <font color=\"%s\"><font face=\"%s\"><font size=\"%d\">\n",
184 color_code, font_name, font_size / 3); 184 color_code, font_name, font_size / 3);
185 g_string_append(encoded, msg_utf8); 185 g_string_append(encoded, msg_utf8);
186 186
187 if (is_bold) { 187 if (is_bold) {
217 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) 217 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset)
218 { 218 {
219 return _my_convert(str, -1, UTF8, from_charset); 219 return _my_convert(str, -1, UTF8, from_charset);
220 } 220 }
221 221
222 /* QQ uses binary code for smiley, while gaim uses strings. 222 /* QQ uses binary code for smiley, while purple uses strings.
223 * There is a mapping relation between these two. */ 223 * There is a mapping relation between these two. */
224 gchar *qq_smiley_to_gaim(gchar *text) 224 gchar *qq_smiley_to_purple(gchar *text)
225 { 225 {
226 gint index; 226 gint index;
227 gchar qq_smiley, *cur_seg, **segments, *ret; 227 gchar qq_smiley, *cur_seg, **segments, *ret;
228 GString *converted; 228 GString *converted;
229 229
239 break; 239 break;
240 } 240 }
241 if (index >= QQ_SMILEY_AMOUNT) { 241 if (index >= QQ_SMILEY_AMOUNT) {
242 g_string_append(converted, QQ_NULL_SMILEY); 242 g_string_append(converted, QQ_NULL_SMILEY);
243 } else { 243 } else {
244 g_string_append(converted, gaim_smiley_map[index]); 244 g_string_append(converted, purple_smiley_map[index]);
245 g_string_append(converted, (cur_seg + 1)); 245 g_string_append(converted, (cur_seg + 1));
246 } 246 }
247 } 247 }
248 248
249 ret = converted->str; 249 ret = converted->str;
250 g_string_free(converted, FALSE); 250 g_string_free(converted, FALSE);
251 return ret; 251 return ret;
252 } 252 }
253 253
254 /* convert smiley from gaim style to qq binary code */ 254 /* convert smiley from purple style to qq binary code */
255 gchar *gaim_smiley_to_qq(gchar *text) 255 gchar *purple_smiley_to_qq(gchar *text)
256 { 256 {
257 gchar *begin, *cursor, *ret; 257 gchar *begin, *cursor, *ret;
258 gint index; 258 gint index;
259 GString *converted; 259 GString *converted;
260 260
261 converted = g_string_new(text); 261 converted = g_string_new(text);
262 262
263 for (index = 0; index < QQ_SMILEY_AMOUNT; index++) { 263 for (index = 0; index < QQ_SMILEY_AMOUNT; index++) {
264 begin = cursor = converted->str; 264 begin = cursor = converted->str;
265 while ((cursor = g_strstr_len(cursor, -1, gaim_smiley_map[index]))) { 265 while ((cursor = g_strstr_len(cursor, -1, purple_smiley_map[index]))) {
266 g_string_erase(converted, (cursor - begin), strlen(gaim_smiley_map[index])); 266 g_string_erase(converted, (cursor - begin), strlen(purple_smiley_map[index]));
267 g_string_insert_c(converted, (cursor - begin), 0x14); 267 g_string_insert_c(converted, (cursor - begin), 0x14);
268 g_string_insert_c(converted, (cursor - begin + 1), qq_smiley_map[index]); 268 g_string_insert_c(converted, (cursor - begin + 1), qq_smiley_map[index]);
269 cursor++; 269 cursor++;
270 } 270 }
271 } 271 }