changeset 32813:b31f7945d9b6

Use 'div's for indent which allows WebKit to do better word-wrapping.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Thu, 31 May 2012 06:09:59 +0000
parents 43e89b279eb4
children 071a0e568ac5
files pidgin/plugins/xmppconsole.c
diffstat 1 files changed, 15 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/plugins/xmppconsole.c	Thu May 31 05:45:28 2012 +0000
+++ b/pidgin/plugins/xmppconsole.c	Thu May 31 06:09:59 2012 +0000
@@ -46,7 +46,8 @@
 
 #define EMPTY_HTML \
 "<html><head><style type='text/css'>" \
-	"body { white-space: pre-wrap; margin: 0; }" \
+	"body { word-wrap: break-word; margin: 0; }" \
+	"div.tab { padding-left: 1em; }" \
 	"div.info { color: #777777; }" \
 	"div.incoming { background-color: #ffcece; }" \
 	"div.outgoing { background-color: #dcecc4; }" \
@@ -58,20 +59,15 @@
 "</style></head></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,
 	                       "<span class=bracket>&lt;</span>"
@@ -115,11 +111,16 @@
 		                       "<span class=bracket>&gt;</span>%s",
 		                       pretty ? "<br>" : "");
 
+		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, "<div class=tab>");
+					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) {
@@ -129,8 +130,9 @@
 			}
 		}
 
-		if(tab && pretty)
-			text = g_string_append(text, tab);
+		if (need_end)
+			g_string_append(text, "</div>");
+
 		g_string_append_printf(text,
 		                       "<span class=bracket>&lt;</span>/"
 		                       "<span class=tag>%s</span>"
@@ -143,8 +145,6 @@
 
 	g_free(node_name);
 
-	g_free(tab);
-
 	if (len)
 		*len = text->len;
 
@@ -158,7 +158,7 @@
 
 	if (!console || console->gc != gc)
 		return;
-	str = xmlnode_to_pretty_str(*packet, NULL, 0);
+	str = xmlnode_to_pretty_str(*packet, NULL);
 	formatted = g_strdup_printf("<div class=incoming>%s</div>", str);
 	gtk_webview_append_html(GTK_WEBVIEW(console->webview), formatted);
 	g_free(formatted);
@@ -179,7 +179,7 @@
 	if (!node)
 		return;
 
-	str = xmlnode_to_pretty_str(node, NULL, 0);
+	str = xmlnode_to_pretty_str(node, NULL);
 	formatted = g_strdup_printf("<div class=outgoing>%s</div>", str);
 	gtk_webview_append_html(GTK_WEBVIEW(console->webview), formatted);
 	g_free(formatted);
@@ -750,8 +750,6 @@
 static void
 dropdown_changed_cb(GtkComboBox *widget, gpointer nul)
 {
-	PurpleAccount *account;
-
 	if (!console)
 		return;