| 6566 g_string_append(str, prev); |
6568 g_string_append(str, prev); |
| 6567 |
6569 |
| 6568 return g_string_free(str, FALSE); |
6570 return g_string_free(str, FALSE); |
| 6569 } |
6571 } |
| 6570 |
6572 |
| 6571 static gulong |
6573 static gboolean |
| 6572 pidgin_smiley_get_unique_id(PurpleSmiley *smiley) |
6574 pidgin_conv_write_smiley(GString *out, PurpleSmiley *smiley, |
| 6573 { |
6575 PurpleConversation *conv, gpointer _proto_name) |
| 6574 static gulong max_id = 0; |
6576 { |
| 6575 gulong id; |
6577 PurpleImage *image; |
| 6576 g_return_val_if_fail(smiley != NULL, 0); |
6578 gchar *escaped_shortcut; |
| 6577 |
6579 gchar *uri; |
| 6578 id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(smiley), |
6580 |
| 6579 "pidgin-conv-smiley-unique-id")); |
6581 escaped_shortcut = g_markup_escape_text( |
| 6580 if (id != 0) |
6582 purple_smiley_get_shortcut(smiley), -1); |
| 6581 return id; |
6583 image = purple_smiley_get_image(smiley); |
| 6582 |
6584 uri = purple_image_store_get_uri(image); |
| 6583 id = ++max_id; |
6585 |
| 6584 |
6586 g_string_append_printf(out, |
| 6585 g_object_set_data(G_OBJECT(smiley), "pidgin-conv-smiley-unique-id", |
6587 "<img class=\"emoticon\" alt=\"%s\" title=\"%s\" " |
| 6586 GINT_TO_POINTER(id)); |
6588 "src=\"%s\" />", escaped_shortcut, |
| 6587 |
6589 escaped_shortcut, uri); |
| 6588 return id; |
6590 |
| 6589 } |
6591 g_free(uri); |
| 6590 |
6592 g_free(escaped_shortcut); |
| 6591 static void |
6593 |
| 6592 pidgin_conv_remote_smiley_got(PurpleSmiley *smiley, gpointer _conv) |
6594 return TRUE; |
| |
6595 } |
| |
6596 |
| |
6597 static void |
| |
6598 remote_image_got(PurpleImage *image, gpointer _conv) |
| 6593 { |
6599 { |
| 6594 PurpleConversation *conv = _conv; |
6600 PurpleConversation *conv = _conv; |
| 6595 PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv); |
6601 PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv); |
| 6596 PurpleImage *img; |
|
| 6597 gulong smiley_id; |
|
| 6598 guint image_id; |
6602 guint image_id; |
| 6599 gchar *js; |
6603 gchar *js; |
| 6600 |
6604 |
| 6601 if (!gtkconv) |
6605 if (!gtkconv) |
| 6602 return; |
6606 return; |
| 6603 |
6607 |
| 6604 img = purple_smiley_get_image(smiley); |
6608 image_id = purple_image_store_add_temporary(image); |
| 6605 smiley_id = pidgin_smiley_get_unique_id(smiley); |
6609 |
| 6606 image_id = purple_image_store_add(img); |
6610 purple_debug_info("gtkconv", "Remote image %u is ready for display", |
| 6607 |
6611 image_id); |
| 6608 purple_debug_info("gtkconv", "Smiley '%s' (%ld) is ready for display", |
6612 |
| 6609 purple_smiley_get_shortcut(smiley), smiley_id); |
6613 js = g_strdup_printf("remoteImageIsReady(%u)", image_id); |
| 6610 |
|
| 6611 js = g_strdup_printf("emoticonIsReady(%ld, '" |
|
| 6612 PURPLE_IMAGE_STORE_PROTOCOL "%u')", smiley_id, image_id); |
|
| 6613 pidgin_webview_safe_execute_script( |
6614 pidgin_webview_safe_execute_script( |
| 6614 PIDGIN_WEBVIEW(gtkconv->webview), js); |
6615 PIDGIN_WEBVIEW(gtkconv->webview), js); |
| 6615 g_free(js); |
6616 g_free(js); |
| 6616 } |
6617 } |
| 6617 |
6618 |
| 6618 static gboolean |
6619 static gboolean |
| 6619 pidgin_conv_write_smiley(GString *out, PurpleSmiley *smiley, |
6620 box_remote_image_cb(const GMatchInfo *info, GString *result, gpointer _conv) |
| 6620 PurpleConversation *conv, gpointer _proto_name) |
6621 { |
| 6621 { |
6622 PurpleConversation *conv = _conv; |
| 6622 gchar *escaped_shortcut; |
6623 gchar *uri, *before, *after, *full, *alt; |
| 6623 const gchar *path = purple_smiley_get_path(smiley); |
6624 PurpleImage *image; |
| 6624 const gchar *path_prefix = ""; |
6625 guint img_id; |
| 6625 |
6626 |
| 6626 #ifdef _WIN32 |
6627 uri = g_match_info_fetch(info, 2); |
| 6627 path_prefix = "file:///"; |
6628 image = purple_image_store_get_from_uri(uri); |
| 6628 #endif |
6629 g_free(uri); |
| 6629 |
6630 |
| 6630 escaped_shortcut = g_markup_escape_text( |
6631 full = g_match_info_fetch(info, 0); |
| 6631 purple_smiley_get_shortcut(smiley), -1); |
6632 |
| 6632 |
6633 if (purple_image_is_ready(image)) { |
| 6633 if (purple_smiley_is_ready(smiley) && path) { |
6634 g_string_append(result, full); |
| 6634 g_string_append_printf(out, |
6635 g_free(full); |
| 6635 "<img class=\"emoticon\" alt=\"%s\" title=\"%s\" " |
6636 return FALSE; |
| 6636 "src=\"%s%s\" />", escaped_shortcut, |
6637 } |
| 6637 escaped_shortcut, path_prefix, path); |
6638 |
| 6638 } else if (purple_smiley_is_ready(smiley) && !path) { |
6639 /* search for alt */ |
| 6639 PurpleImage *img = purple_smiley_get_image(smiley); |
6640 alt = strstr(full, "alt=\""); |
| 6640 guint imgid = purple_image_store_add(img); |
6641 if (alt) { |
| 6641 |
6642 gchar *end; |
| 6642 g_string_append_printf(out, "<img class=\"emoticon\" " |
6643 alt += strlen("alt=\""); |
| 6643 "alt=\"%s\" title=\"%s\" src=\"" |
6644 end = strstr(alt, "\""); |
| 6644 PURPLE_IMAGE_STORE_PROTOCOL "%u\" />", |
6645 if (end) |
| 6645 escaped_shortcut, escaped_shortcut, imgid); |
6646 end[0] = '\0'; |
| 6646 } else { |
6647 else |
| 6647 g_string_append_printf(out, "<span class=\"emoticon pending " |
6648 alt = NULL; |
| 6648 "emoticon-id-%ld\">%s</span>", |
6649 if (alt[0] == '\0') |
| 6649 pidgin_smiley_get_unique_id(smiley), escaped_shortcut); |
6650 alt = NULL; |
| 6650 g_signal_connect_object(smiley, "ready", |
6651 } |
| 6651 G_CALLBACK(pidgin_conv_remote_smiley_got), conv, 0); |
6652 |
| 6652 } |
6653 /* add for ever - we don't know, when transfer finishes */ |
| 6653 |
6654 img_id = purple_image_store_add(image); |
| 6654 g_free(escaped_shortcut); |
6655 |
| 6655 |
6656 before = g_match_info_fetch(info, 1); |
| 6656 return TRUE; |
6657 after = g_match_info_fetch(info, 3); |
| |
6658 |
| |
6659 g_string_append_printf(result, "<span class=\"pending-image " |
| |
6660 "pending-image-id-%u\">", img_id); |
| |
6661 |
| |
6662 if (alt) |
| |
6663 g_string_append(result, alt); |
| |
6664 else |
| |
6665 g_string_append(result, "<img>"); |
| |
6666 |
| |
6667 g_string_append(result, before); |
| |
6668 g_string_append(result, "about:blank"); |
| |
6669 g_string_append(result, after); |
| |
6670 |
| |
6671 g_string_append(result, "</span>"); |
| |
6672 |
| |
6673 g_free(before); |
| |
6674 g_free(after); |
| |
6675 g_free(full); |
| |
6676 |
| |
6677 g_signal_connect_object(image, "ready", |
| |
6678 G_CALLBACK(remote_image_got), conv, 0); |
| |
6679 |
| |
6680 return FALSE; |
| |
6681 } |
| |
6682 |
| |
6683 static gchar * |
| |
6684 box_remote_images(PurpleConversation *conv, const gchar *msg) |
| |
6685 { |
| |
6686 return g_regex_replace_eval(image_store_tag_re, msg, -1, 0, 0, |
| |
6687 box_remote_image_cb, conv, NULL); |
| 6657 } |
6688 } |
| 6658 |
6689 |
| 6659 static void |
6690 static void |
| 6660 pidgin_conv_write_conv(PurpleConversation *conv, const char *name, const char *alias, |
6691 pidgin_conv_write_conv(PurpleConversation *conv, const char *name, const char *alias, |
| 6661 const char *message, PurpleMessageFlags flags, |
6692 const char *message, PurpleMessageFlags flags, |
| 6783 gtkconv->last_conversed = conv; |
6815 gtkconv->last_conversed = conv; |
| 6784 |
6816 |
| 6785 smileyed = purple_smiley_parser_smileify(conv, displaying, |
6817 smileyed = purple_smiley_parser_smileify(conv, displaying, |
| 6786 (flags & PURPLE_MESSAGE_RECV), pidgin_conv_write_smiley, |
6818 (flags & PURPLE_MESSAGE_RECV), pidgin_conv_write_smiley, |
| 6787 (gpointer)purple_account_get_protocol_name(account)); |
6819 (gpointer)purple_account_get_protocol_name(account)); |
| 6788 msg = replace_message_tokens(message_html, conv, name, alias, smileyed, flags, mtime); |
6820 imgized = box_remote_images(conv, smileyed); |
| |
6821 msg = replace_message_tokens(message_html, conv, name, alias, imgized, flags, mtime); |
| 6789 escape = pidgin_webview_quote_js_string(msg ? msg : ""); |
6822 escape = pidgin_webview_quote_js_string(msg ? msg : ""); |
| 6790 script = g_strdup_printf("%s(%s)", func, escape); |
6823 script = g_strdup_printf("%s(%s)", func, escape); |
| 6791 |
6824 |
| 6792 purple_debug_info("webkit", "JS: %s\n", script); |
6825 purple_debug_info("webkit", "JS: %s\n", script); |
| 6793 pidgin_webview_safe_execute_script(PIDGIN_WEBVIEW(gtkconv->webview), script); |
6826 pidgin_webview_safe_execute_script(PIDGIN_WEBVIEW(gtkconv->webview), script); |
| 6794 |
6827 |
| 6795 g_free(script); |
6828 g_free(script); |
| 6796 g_free(smileyed); |
6829 g_free(smileyed); |
| |
6830 g_free(imgized); |
| 6797 g_free(msg); |
6831 g_free(msg); |
| 6798 g_free(escape); |
6832 g_free(escape); |
| 6799 |
6833 |
| 6800 #if 0 |
6834 #if 0 |
| 6801 /* if the buffer is not empty add a <br> */ |
6835 /* if the buffer is not empty add a <br> */ |