changeset 27749:6b74c3255901

- revise pidgin_gtk_ellipsis_text(). - disable idle call back to resize_imhtml_cb(). it raised CPU usage to 100%.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 15 Dec 2007 13:57:42 +0000
parents d0df170ca20a
children 7dbac2598d51
files pidgin/gtkconv.c pidgin/gtkimhtmltoolbar.c pidgin/gtkutils.c
diffstat 3 files changed, 30 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkconv.c	Sat Dec 15 08:52:04 2007 +0000
+++ b/pidgin/gtkconv.c	Sat Dec 15 13:57:42 2007 +0000
@@ -5148,7 +5148,8 @@
 		gtk_widget_show(gtkconv->toolbar);
 	else
 		gtk_widget_hide(gtkconv->toolbar);
-	g_idle_add((GSourceFunc)resize_imhtml_cb, gtkconv);
+
+//	g_idle_add((GSourceFunc)resize_imhtml_cb, gtkconv);
 
 	if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/im/show_buddy_icons"))
 		gtk_widget_show(gtkconv->infopane_hbox);
@@ -6559,7 +6560,7 @@
 			(fields & PIDGIN_CONV_SET_TITLE) ||
     			(fields & PIDGIN_CONV_TOPIC))
 	{
-		char *title, *title_tmp;
+		char *title;
 		PurpleConvIm *im = NULL;
 		PurpleAccount *account = purple_conversation_get_account(conv);
 	 	PurpleBuddy *buddy = NULL;
@@ -6662,11 +6663,11 @@
 			&& purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/trim_vertical_tabs"))
 			ellipsis = TRUE;
 
-		title_tmp = title;
-		if (ellipsis)
+		if (ellipsis) {
+			gchar *title_tmp = title;
 			title = pidgin_gtk_ellipsis_text(gtkconv->tab_label, title_tmp, 60, "...");
-		else
-			title = title_tmp;
+			g_free(title_tmp);
+        }
 
 		gtk_widget_set_name(gtkconv->tab_label, style);
 		gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title);
@@ -7211,7 +7212,7 @@
 		else
 			gtk_widget_hide(gtkconv->toolbar);
 
-		g_idle_add((GSourceFunc)resize_imhtml_cb,gtkconv);
+//		g_idle_add((GSourceFunc)resize_imhtml_cb,gtkconv);
 	}
 }
 
--- a/pidgin/gtkimhtmltoolbar.c	Sat Dec 15 08:52:04 2007 +0000
+++ b/pidgin/gtkimhtmltoolbar.c	Sat Dec 15 13:57:42 2007 +0000
@@ -1304,7 +1304,7 @@
 	gtk_container_add(GTK_CONTAINER(smiley_button), bbox);
 	image = gtk_image_new_from_stock(PIDGIN_STOCK_TOOLBAR_SMILEY, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL));
 	gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
-	label = gtk_label_new_with_mnemonic(_("_Smile!"));
+	label = gtk_label_new_with_mnemonic(_("Smile!"));
 	gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(box), smiley_button, FALSE, FALSE, 0);
 	g_signal_connect_swapped(G_OBJECT(smiley_button), "clicked", G_CALLBACK(gtk_button_clicked), toolbar->smiley);
--- a/pidgin/gtkutils.c	Sat Dec 15 08:52:04 2007 +0000
+++ b/pidgin/gtkutils.c	Sat Dec 15 13:57:42 2007 +0000
@@ -3274,38 +3274,25 @@
 {
 	PangoLayout *layout;
 	gint width, height;
+	gint ewidth;
 	glong len0, len1, len2;
-	static gchar buf[1024], buf_tmp[1024];
-	gint ewidth;
+	gchar *buf, *buf_tmp;
 	gboolean with_ellipsis = FALSE;
-
-	g_strlcpy(buf_tmp, text, sizeof(buf_tmp));
-
-	if (strlen(text) >= sizeof(buf)) {
-		/* cutting off */
-		if (! g_utf8_validate(buf_tmp, -1, NULL)) {
-			buf_tmp[sizeof(buf_tmp) - 1] = '\0';
-			if (! g_utf8_validate(buf_tmp, -1, NULL)) {
-				buf_tmp[sizeof(buf_tmp) - 2] = '\0';
-				if (! g_utf8_validate(buf_tmp, -1, NULL)) {
-					return NULL; /* failed */
-				}
-			}
-		}
-	}
-
-	buf[0] = '\0';
-
-#define ELLIPSIS "..."
-
-	layout = gtk_widget_create_pango_layout(widget, 
-						ellipsis ? ellipsis : ELLIPSIS);
-
+	const gchar default_ellipsis[] = "...";
+
+	if(!ellipsis)
+		ellipsis = default_ellipsis;
+
+	/* allocate buf */
+	buf = g_malloc0(strlen(text) * 2);
+
+	/* create layout */
+	layout = gtk_widget_create_pango_layout(widget, ellipsis);
 	pango_layout_get_pixel_size(layout, &width, &height);
-	ewidth = width;
+	ewidth = width; /* length of ellisis text. */
 
 	len0 = 0;
-	len1 = g_utf8_strlen(buf_tmp, -1);
+	len1 = g_utf8_strlen(text, -1);
 	len2 = len1;
 
 	while (1) {
@@ -3313,11 +3300,11 @@
 		if (len2 == len0)
 			break;
 
-		g_utf8_strncpy (buf, buf_tmp, len2);
+		g_utf8_strncpy(buf, text, len2);
 		pango_layout_set_text(layout, buf, -1);
 		pango_layout_get_pixel_size(layout, &width, &height);
 
-		if (! with_ellipsis && width <= min_width)
+		if(!with_ellipsis && width <= min_width)
 			break;
 		else
 			with_ellipsis = TRUE;
@@ -3330,14 +3317,13 @@
 		len2 = (len0 + len1) / 2;
 	}
 
-	g_utf8_strncpy (buf, buf_tmp, len2);
 	g_object_unref(layout);
 
-
-	if (with_ellipsis) 
-		g_strlcat (buf, ellipsis ? ellipsis : ELLIPSIS, sizeof(buf));
-
-#undef ELLIPSIS
+	if (with_ellipsis) {
+		buf_tmp = buf;
+		buf = g_strdup_printf("%s%s", buf_tmp, ellipsis);
+		g_free(buf_tmp);
+	}
 
 	return buf;
 }