pidgin.next.minor: bd4c2ebb: Fix the offset for coloring nicknames, e...

sadrul at pidgin.im sadrul at pidgin.im
Thu May 22 14:45:48 EDT 2008


-----------------------------------------------------------------
Revision: bd4c2ebb9b819fcf7a27ec53f01ccc93263ecf9c
Ancestor: dce1df02eabf1f97260290d86d75e01d6b392a04
Author: sadrul at pidgin.im
Date: 2008-05-22T17:47:50
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/bd4c2ebb9b819fcf7a27ec53f01ccc93263ecf9c

Modified files:
        pidgin/gtkconv.c

ChangeLog: 

Fix the offset for coloring nicknames, especially for auto-replies, and
non-ascii nicks. The timestamp also gets the formatting of the nick. I
tried to make it non-bold, but that doesn't seem to quite work. I'll give
it another go soon.

-------------- next part --------------
============================================================
--- pidgin/gtkconv.c	5349d842b1a88cd107ec753c30c4611b334d433b
+++ pidgin/gtkconv.c	76f2309ed714716a423d17056d9a42d85dff356d
@@ -5687,10 +5687,14 @@ pidgin_conv_write_conv(PurpleConversatio
 		char *alias_escaped = (alias ? g_markup_escape_text(alias, strlen(alias)) : g_strdup(""));
 		/* The initial offset is to deal with
 		 * escaped entities making the string longer */
-		int tag_start_offset = alias ? (strlen(alias_escaped) - strlen(alias)) : 0;
+		int tag_start_offset = 0;
 		int tag_end_offset = 0;
 		const char *tagname = NULL;
 
+		GtkTextIter start, end;
+		GtkTextTag *tag;
+		GtkTextBuffer *buffer = GTK_IMHTML(gtkconv->imhtml)->text_buffer;
+
 		/* Enforce direction on alias */
 		if (is_rtl_message)
 			str_embed_direction_chars(&alias_escaped);
@@ -5713,8 +5717,7 @@ pidgin_conv_write_conv(PurpleConversatio
 			if (purple_message_meify(new_message, -1)) {
 				if (flags & PURPLE_MESSAGE_AUTO_RESP) {
 					g_snprintf(str, 1024, "%s ***%s", AUTO_RESPONSE, alias_escaped);
-					tag_start_offset += 4
-						+ strlen(AUTO_RESPONSE);
+					tag_start_offset += strlen(AUTO_RESPONSE) - 6 + 4;
 				} else {
 					g_snprintf(str, 1024, "***%s", alias_escaped);
 					tag_start_offset += 3;
@@ -5727,8 +5730,7 @@ pidgin_conv_write_conv(PurpleConversatio
 			} else {
 				if (flags & PURPLE_MESSAGE_AUTO_RESP) {
 					g_snprintf(str, 1024, "%s %s", alias_escaped, AUTO_RESPONSE);
-					tag_start_offset += 1
-						+ strlen(AUTO_RESPONSE);
+					tag_start_offset += strlen(AUTO_RESPONSE) - 6 + 1;
 				} else {
 					g_snprintf(str, 1024, "%s:", alias_escaped);
 					tag_end_offset = 1;
@@ -5756,27 +5758,20 @@ pidgin_conv_write_conv(PurpleConversatio
 				sml_attrib ? sml_attrib : "", mdate, str);
 		gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, gtk_font_options_all | GTK_IMHTML_NO_SCROLL);
 
-		if (tagname ||
-				(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT &&
-				 !(flags & PURPLE_MESSAGE_SEND))) {
-			GtkTextIter start, end;
-			GtkTextTag *tag;
-			GtkTextBuffer *buffer = GTK_IMHTML(gtkconv->imhtml)->text_buffer;
+		gtk_text_buffer_get_end_iter(buffer, &end);
+		gtk_text_iter_backward_chars(&end, tag_end_offset + 1);
 
-			if (tagname)
-				tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), tagname);
-			else
-				tag = get_buddy_tag(conv, name, TRUE);
+		start = end;
+		gtk_text_iter_backward_chars(&start, tag_start_offset +
+				(alias ? g_utf8_strlen(alias, -1) : 0) + strlen(mdate) + 1);
 
-			gtk_text_buffer_get_end_iter(buffer, &end);
-			gtk_text_iter_backward_chars(&end, tag_end_offset + 1);
+		if (tagname)
+			tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), tagname);
+		else
+			tag = get_buddy_tag(conv, name, TRUE);
 
-			gtk_text_buffer_get_end_iter(buffer, &start);
-			gtk_text_iter_backward_chars(&start, strlen(str) + 1 - tag_start_offset);
+		gtk_text_buffer_apply_tag(buffer, tag, &start, &end);
 
-			gtk_text_buffer_apply_tag(buffer, tag, &start, &end);
-		}
-
 		g_free(str);
 
 		if(gc){


More information about the Commits mailing list