# HG changeset patch # User Elliott Sales de Andrade # Date 1338445222 0 # Node ID 071a0e568ac5d69101bd1957a17e0926325a0f94 # Parent 3d6528f36877b946db312fd7b3fafcdd16a221d9# Parent b31f7945d9b6f768779b85f704fdbd7b54ac7f8e merge of '688484ce559f68e7d5e5ac8e67cc667f96c3791a' and '9b2b55b0c80013fc7794f6334575fb6b7e9ed5b7' diff -r 3d6528f36877 -r 071a0e568ac5 pidgin/gtknotify.c --- a/pidgin/gtknotify.c Thu May 31 03:48:16 2012 +0000 +++ b/pidgin/gtknotify.c Thu May 31 06:20:22 2012 +0000 @@ -891,7 +891,7 @@ /* Make sure URLs are clickable */ linked_text = purple_markup_linkify(text); - webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(web_view), linked_text, ""); + gtk_webview_load_html_string(GTK_WEBVIEW(web_view), linked_text); g_free(linked_text); g_object_set_data(G_OBJECT(window), "webview-widget", web_view); @@ -1151,7 +1151,7 @@ if (pinfo != NULL) { GtkWidget *webview = g_object_get_data(G_OBJECT(pinfo->window), "webview-widget"); char *linked_text = purple_markup_linkify(info); - gtk_webview_load_html_string_with_imgstore(GTK_WEBVIEW(webview), linked_text); + gtk_webview_load_html_string(GTK_WEBVIEW(webview), linked_text); g_free(linked_text); g_free(key); ui_handle = pinfo->window; diff -r 3d6528f36877 -r 071a0e568ac5 pidgin/gtkwebview.c --- a/pidgin/gtkwebview.c Thu May 31 03:48:16 2012 +0000 +++ b/pidgin/gtkwebview.c Thu May 31 06:20:22 2012 +0000 @@ -526,7 +526,7 @@ } void -gtk_webview_load_html_string_with_imgstore(GtkWebView *webview, const char *html) +gtk_webview_load_html_string(GtkWebView *webview, const char *html) { GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); char *html_imged; @@ -551,12 +551,12 @@ gtk_webview_append_html(GtkWebView *webview, const char *html) { GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); - char *escaped = gtk_webview_quote_js_string(html); - char *script = g_strdup_printf("document.write(%s)", escaped); - webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview), script); + WebKitDOMDocument *doc; + WebKitDOMHTMLElement *body; + doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); + body = webkit_dom_document_get_body(doc); + webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL); priv->empty = FALSE; - g_free(script); - g_free(escaped); } void diff -r 3d6528f36877 -r 071a0e568ac5 pidgin/gtkwebview.h --- a/pidgin/gtkwebview.h Thu May 31 03:48:16 2012 +0000 +++ b/pidgin/gtkwebview.h Thu May 31 06:20:22 2012 +0000 @@ -120,7 +120,7 @@ * @param webview The GtkWebView object * @param html The HTML content to load */ -void gtk_webview_load_html_string_with_imgstore(GtkWebView *webview, const char *html); +void gtk_webview_load_html_string(GtkWebView *webview, const char *html); /** * Execute the JavaScript only after the webkit_webview_load_string diff -r 3d6528f36877 -r 071a0e568ac5 pidgin/plugins/xmppconsole.c --- a/pidgin/plugins/xmppconsole.c Thu May 31 03:48:16 2012 +0000 +++ b/pidgin/plugins/xmppconsole.c Thu May 31 06:20:22 2012 +0000 @@ -26,6 +26,7 @@ #include "xmlnode.h" #include "gtkimhtml.h" +#include "gtkwebview.h" #include "gtkutils.h" typedef struct { @@ -33,7 +34,7 @@ GtkWidget *window; GtkWidget *hbox; GtkWidget *dropdown; - GtkWidget *imhtml; + GtkWidget *webview; GtkWidget *entry; GtkWidget *sw; int count; @@ -43,31 +44,34 @@ XmppConsole *console = NULL; static void *xmpp_console_handle = NULL; -#define BRACKET_COLOR "#940f8c" -#define TAG_COLOR "#8b1dab" -#define ATTR_NAME_COLOR "#a02961" -#define ATTR_VALUE_COLOR "#324aa4" -#define XMLNS_COLOR "#2cb12f" +#define EMPTY_HTML \ +"" static char * -xmlnode_to_pretty_str(xmlnode *node, int *len, int depth) +xmlnode_to_pretty_str(xmlnode *node, int *len) { GString *text = g_string_new(""); xmlnode *c; - char *node_name, *esc, *esc2, *tab = NULL; + char *node_name, *esc, *esc2; gboolean need_end = FALSE, pretty = TRUE; g_return_val_if_fail(node != NULL, NULL); - if (pretty && depth) { - tab = g_strnfill(depth, '\t'); - text = g_string_append(text, tab); - } - node_name = g_markup_escape_text(node->name, -1); g_string_append_printf(text, - "<" - "%s", + "<" + "%s", node_name); if (node->xmlns) { @@ -78,8 +82,8 @@ { char *xmlns = g_markup_escape_text(node->xmlns, -1); g_string_append_printf(text, - " xmlns=" - "'%s'", + " xmlns=" + "'%s'", xmlns); g_free(xmlns); } @@ -90,8 +94,8 @@ esc = g_markup_escape_text(c->name, -1); esc2 = g_markup_escape_text(c->data, -1); g_string_append_printf(text, - " %s=" - "'%s'", + " %s=" + "'%s'", esc, esc2); g_free(esc); g_free(esc2); @@ -104,14 +108,19 @@ if (need_end) { g_string_append_printf(text, - ">%s", + ">%s", pretty ? "
" : ""); + need_end = FALSE; for (c = node->child; c; c = c->next) { if (c->type == XMLNODE_TYPE_TAG) { int esc_len; - esc = xmlnode_to_pretty_str(c, &esc_len, depth+1); + esc = xmlnode_to_pretty_str(c, &esc_len); + if (!need_end) { + g_string_append(text, "
"); + need_end = TRUE; + } text = g_string_append_len(text, esc, esc_len); g_free(esc); } else if (c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) { @@ -121,23 +130,22 @@ } } - if(tab && pretty) - text = g_string_append(text, tab); + if (need_end) + g_string_append(text, "
"); + g_string_append_printf(text, - "</" - "%s" - ">
", + "</" + "%s" + ">
", node_name); } else { g_string_append_printf(text, - "/>
"); + "/>
"); } g_free(node_name); - g_free(tab); - - if(len) + if (len) *len = text->len; return g_string_free(text, FALSE); @@ -150,9 +158,9 @@ if (!console || console->gc != gc) return; - str = xmlnode_to_pretty_str(*packet, NULL, 0); - formatted = g_strdup_printf("
%s
", str); - gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), formatted, 0); + str = xmlnode_to_pretty_str(*packet, NULL); + formatted = g_strdup_printf("
%s
", str); + gtk_webview_append_html(GTK_WEBVIEW(console->webview), formatted); g_free(formatted); g_free(str); } @@ -171,9 +179,9 @@ if (!node) return; - str = xmlnode_to_pretty_str(node, NULL, 0); - formatted = g_strdup_printf("
%s
", str); - gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), formatted, 0); + str = xmlnode_to_pretty_str(node, NULL); + formatted = g_strdup_printf("
%s
", str); + gtk_webview_append_html(GTK_WEBVIEW(console->webview), formatted); g_free(formatted); g_free(str); xmlnode_free(node); @@ -646,16 +654,24 @@ static void signing_on_cb(PurpleConnection *gc) { + PurpleAccount *account; + if (!console) return; - gtk_combo_box_append_text(GTK_COMBO_BOX(console->dropdown), purple_account_get_username(purple_connection_get_account(gc))); + account = purple_connection_get_account(gc); + if (strcmp(purple_account_get_protocol_id(account), "prpl-jabber")) + return; + + gtk_combo_box_append_text(GTK_COMBO_BOX(console->dropdown), purple_account_get_username(account)); console->accounts = g_list_append(console->accounts, gc); console->count++; - if (console->count == 1) + if (console->count == 1) { console->gc = gc; - else + gtk_webview_load_html_string(GTK_WEBVIEW(console->webview), EMPTY_HTML); + gtk_combo_box_set_active(GTK_COMBO_BOX(console->dropdown), 0); + } else gtk_widget_show_all(console->hbox); } @@ -685,9 +701,11 @@ console->count--; if (gc == console->gc) { + char *tmp = g_strdup_printf("
%s
", + _("Logged out.")); + gtk_webview_append_html(GTK_WEBVIEW(console->webview), tmp); + g_free(tmp); console->gc = NULL; - gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), - _("Logged out."), 0); } } @@ -732,18 +750,11 @@ static void dropdown_changed_cb(GtkComboBox *widget, gpointer nul) { - PurpleAccount *account; - if (!console) return; - account = purple_accounts_find(gtk_combo_box_get_active_text(GTK_COMBO_BOX(console->dropdown)), - "prpl-jabber"); - if (!account || !purple_account_get_connection(account)) - return; - - console->gc = purple_account_get_connection(account); - gtk_imhtml_clear(GTK_IMHTML(console->imhtml)); + console->gc = g_list_nth_data(console->accounts, gtk_combo_box_get_active(GTK_COMBO_BOX(console->dropdown))); + gtk_webview_load_html_string(GTK_WEBVIEW(console->webview), EMPTY_HTML); } static void @@ -785,16 +796,20 @@ console->gc = gc; } } - gtk_combo_box_set_active(GTK_COMBO_BOX(console->dropdown),0); + gtk_combo_box_set_active(GTK_COMBO_BOX(console->dropdown), 0); gtk_box_pack_start(GTK_BOX(console->hbox), console->dropdown, TRUE, TRUE, 0); g_signal_connect(G_OBJECT(console->dropdown), "changed", G_CALLBACK(dropdown_changed_cb), NULL); - console->imhtml = gtk_imhtml_new(NULL, NULL); - if (console->count == 0) - gtk_imhtml_append_text(GTK_IMHTML(console->imhtml), - _("Not connected to XMPP"), 0); + console->webview = gtk_webview_new(); + gtk_webview_load_html_string(GTK_WEBVIEW(console->webview), EMPTY_HTML); + if (console->count == 0) { + char *tmp = g_strdup_printf("
%s
", + _("Not connected to XMPP")); + gtk_webview_append_html(GTK_WEBVIEW(console->webview), tmp); + g_free(tmp); + } gtk_box_pack_start(GTK_BOX(vbox), - pidgin_make_scrollable(console->imhtml, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_SHADOW_ETCHED_IN, -1, -1), + pidgin_make_scrollable(console->webview, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_SHADOW_ETCHED_IN, -1, -1), TRUE, TRUE, 0); toolbar = gtk_toolbar_new();