Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 10243:e450f24d1fe1
[gaim-migrate @ 11383]
I used to think Mozilla was a good thing. Now I'm not so sure.
Who would think "text/html" is "for internal use only" - yup, mozilla.
Oh well.
"No operating systems or external applications understand this flavor" eh? we
know the taste now!
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Tue, 23 Nov 2004 02:22:24 +0000 |
parents | 6f49ce1d394d |
children | ec140184437b |
comparison
equal
deleted
inserted
replaced
10242:c66da6503db8 | 10243:e450f24d1fe1 |
---|---|
1330 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | 1330 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
1331 GtkTextIter iter; | 1331 GtkTextIter iter; |
1332 | 1332 |
1333 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | 1333 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
1334 | 1334 |
1335 | |
1336 if(gtk_imhtml_get_editable(imhtml) && sd->data){ | 1335 if(gtk_imhtml_get_editable(imhtml) && sd->data){ |
1337 switch (info) { | 1336 switch (info) { |
1338 case GTK_IMHTML_DRAG_URL: | 1337 case GTK_IMHTML_DRAG_URL: |
1339 gaim_str_strip_cr(sd->data); | 1338 gaim_str_strip_cr(sd->data); |
1340 | 1339 |
1350 /* Special reasons, aka images being put in via other tag, etc. */ | 1349 /* Special reasons, aka images being put in via other tag, etc. */ |
1351 } | 1350 } |
1352 } | 1351 } |
1353 break; | 1352 break; |
1354 case GTK_IMHTML_DRAG_HTML: | 1353 case GTK_IMHTML_DRAG_HTML: |
1355 if (sd->length >= 2 && | 1354 { |
1356 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | 1355 char *utf8 = NULL; |
1357 /* This is UCS-2 */ | 1356 /* Ewww. This is all because mozilla thinks that text/html is 'for internal use only.' |
1358 char *tmp; | 1357 * as explained by this comment in gtkhtml: |
1359 char *utf8 = g_convert(text, sd->length, "UTF-8", "UCS-2", NULL, NULL, NULL); | 1358 * |
1360 g_free(text); | 1359 * FIXME This hack decides the charset of the selection. It seems that |
1361 text = utf8; | 1360 * mozilla/netscape alway use ucs2 for text/html |
1362 if (!text) { | 1361 * and openoffice.org seems to always use utf8 so we try to validate |
1362 * the string as utf8 and if that fails we assume it is ucs2 | |
1363 * | |
1364 * See also the comment on text/html here: | |
1365 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html | |
1366 */ | |
1367 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { | |
1368 utf8 = g_convert(text, sd->length, "UTF-8", "UCS-2", NULL, NULL, NULL); | |
1369 | |
1370 if (!utf8) { | |
1363 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); | 1371 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); |
1364 return; | 1372 return; |
1365 } | 1373 } |
1366 tmp = g_utf8_next_char(text); | 1374 |
1367 memmove(text, tmp, strlen(tmp) + 1); | 1375 if (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe || TRUE) { |
1368 } | 1376 char *tmp; |
1369 | 1377 tmp = g_utf8_next_char(utf8); |
1370 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { | 1378 memmove(utf8, tmp, strlen(tmp) + 1); |
1379 } | |
1380 } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) { | |
1371 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); | 1381 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); |
1372 g_free(text); | |
1373 return; | 1382 return; |
1374 } | 1383 } |
1375 gtk_imhtml_insert_html_at_iter(imhtml, text, 0, &iter); | 1384 |
1385 gtk_imhtml_insert_html_at_iter(imhtml, utf8 ? utf8 : text, 0, &iter); | |
1386 g_free(utf8); | |
1376 break; | 1387 break; |
1388 } | |
1377 case GTK_IMHTML_DRAG_TEXT: | 1389 case GTK_IMHTML_DRAG_TEXT: |
1378 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { | 1390 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
1379 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); | 1391 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); |
1380 g_free(text); | |
1381 return; | 1392 return; |
1382 } else { | 1393 } else { |
1383 char *tmp = gaim_escape_html(text); | 1394 char *tmp = gaim_escape_html(text); |
1384 gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter); | 1395 gtk_imhtml_insert_html_at_iter(imhtml, tmp, 0, &iter); |
1385 g_free(tmp); | 1396 g_free(tmp); |