pidgin: 60193e45: Fix a bug where right-clicking the user'...

sadrul at pidgin.im sadrul at pidgin.im
Wed Oct 29 17:45:33 EDT 2008


-----------------------------------------------------------------
Revision: 60193e450f3d2697db72618bd7b32ba469e53a31
Ancestor: 91697ef86059abe66d9821bda00c222c87e695c8
Author: sadrul at pidgin.im
Date: 2008-10-29T16:46:38
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/60193e450f3d2697db72618bd7b32ba469e53a31

Modified files:
        pidgin/gtkconv.c

ChangeLog: 

Fix a bug where right-clicking the user's name in a chat conversation
history wouldn't show a popup menu for nick-said events.

-------------- next part --------------
============================================================
--- pidgin/gtkconv.c	d5d1af9143decabb9f3f68f68b0bbc788cc5516e
+++ pidgin/gtkconv.c	611aa9dcd187a5f62f774fb20acd3a1cdda56936
@@ -161,7 +161,7 @@ static gboolean color_is_visible(GdkColo
 gboolean pidgin_conv_has_focus(PurpleConversation *conv);
 static GdkColor* generate_nick_colors(guint *numcolors, GdkColor background);
 static gboolean color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast);
-static GtkTextTag *get_buddy_tag(PurpleConversation *conv, const char *who, gboolean create);
+static GtkTextTag *get_buddy_tag(PurpleConversation *conv, const char *who, PurpleMessageFlags flag, gboolean create);
 static void pidgin_conv_update_fields(PurpleConversation *conv, PidginConvFields fields);
 static void focus_out_from_menubar(GtkWidget *wid, PidginWindow *win);
 static void pidgin_conv_tab_pack(PidginWindow *win, PidginConversation *gtkconv);
@@ -172,7 +172,8 @@ static gboolean pidgin_conv_xy_to_right_
 		int width, int height);
 static gboolean pidgin_conv_xy_to_right_infopane(PidginWindow *win, int x, int y);
 
-static const GdkColor *get_nick_color(PidginConversation *gtkconv, const char *name) {
+static const GdkColor *get_nick_color(PidginConversation *gtkconv, const char *name)
+{
 	static GdkColor col;
 	GtkStyle *style = gtk_widget_get_style(gtkconv->imhtml);
 	float scale;
@@ -4423,7 +4424,7 @@ buddy_cb_common(PurpleBuddy *buddy, Purp
 
 	blist_node_aliased_cb((PurpleBlistNode *)buddy, NULL, conv);
 
-	texttag = get_buddy_tag(conv, purple_buddy_get_name(buddy), FALSE); /* XXX: do we want the normalized name? */
+	texttag = get_buddy_tag(conv, purple_buddy_get_name(buddy), 0, FALSE); /* XXX: do we want the normalized name? */
 	if (texttag) {
 		g_object_set(texttag, "weight", is_buddy ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL, NULL);
 	}
@@ -5343,16 +5344,35 @@ pidgin_conv_write_im(PurpleConversation 
 	purple_conversation_write(conv, who, message, flags, mtime);
 }
 
+static const char *
+get_text_tag_color(GtkTextTag *tag)
+{
+	GdkColor *color = NULL;
+	gboolean set = FALSE;
+	static char colcode[] = "#XXXXXX";
+	if (tag)
+		g_object_get(G_OBJECT(tag), "foreground-set", &set, "foreground-gdk", &color, NULL);
+	if (set && color)
+		g_snprintf(colcode, sizeof(colcode), "#%02x%02x%02x",
+				color->red >> 8, color->green >> 8, color->blue >> 8);
+	else
+		colcode[0] = '\0';
+	if (color)
+		gdk_color_free(color);
+	return colcode;
+}
+
 /* The callback for an event on a link tag. */
 static gboolean buddytag_event(GtkTextTag *tag, GObject *imhtml,
-		GdkEvent *event, GtkTextIter *arg2, gpointer data) {
+		GdkEvent *event, GtkTextIter *arg2, gpointer data)
+{
 	if (event->type == GDK_BUTTON_PRESS
 			|| event->type == GDK_2BUTTON_PRESS) {
 		GdkEventButton *btn_event = (GdkEventButton*) event;
 		PurpleConversation *conv = data;
 		char *buddyname;
 
-		/* strlen("BUDDY ") == 6 */
+		/* strlen("BUDDY " or "HILIT ") == 6 */
 		g_return_val_if_fail((tag->name != NULL)
 				&& (strlen(tag->name) > 6), FALSE);
 
@@ -5392,24 +5412,33 @@ static gboolean buddytag_event(GtkTextTa
 	return FALSE;
 }
 
-static GtkTextTag *get_buddy_tag(PurpleConversation *conv, const char *who, gboolean create)
+static GtkTextTag *get_buddy_tag(PurpleConversation *conv, const char *who, PurpleMessageFlags flag,
+		gboolean create)
 {
 	PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
 	GtkTextTag *buddytag;
 	gchar *str;
+	gboolean highlight = (flag & PURPLE_MESSAGE_NICK);
+	GtkTextBuffer *buffer = GTK_IMHTML(gtkconv->imhtml)->text_buffer;
 
-	str = g_strdup_printf("BUDDY %s", who);
+	str = g_strdup_printf(highlight ? "HILIT %s" : "BUDDY %s", who);
 
 	buddytag = gtk_text_tag_table_lookup(
-			gtk_text_buffer_get_tag_table(
-				GTK_IMHTML(gtkconv->imhtml)->text_buffer), str);
+			gtk_text_buffer_get_tag_table(buffer), str);
 
 	if (buddytag == NULL && create) {
-		buddytag = gtk_text_buffer_create_tag(
-				GTK_IMHTML(gtkconv->imhtml)->text_buffer, str,
-				"foreground-gdk", get_nick_color(gtkconv, who),
-				"weight", purple_find_buddy(purple_conversation_get_account(conv), who) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
-				NULL);
+		if (highlight)
+			buddytag = gtk_text_buffer_create_tag(buffer, str,
+					"foreground", get_text_tag_color(gtk_text_tag_table_lookup(
+							gtk_text_buffer_get_tag_table(buffer), "highlight-name")),
+					"weight", PANGO_WEIGHT_BOLD,
+					NULL);
+		else
+			buddytag = gtk_text_buffer_create_tag(
+					buffer, str,
+					"foreground-gdk", get_nick_color(gtkconv, who),
+					"weight", purple_find_buddy(purple_conversation_get_account(conv), who) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
+					NULL);
 
 		g_signal_connect(G_OBJECT(buddytag), "event",
 				G_CALLBACK(buddytag_event), conv);
@@ -5766,7 +5795,9 @@ pidgin_conv_write_conv(PurpleConversatio
 				}
 
 				if (flags & PURPLE_MESSAGE_NICK) {
-					tagname = "highlight-name";
+					if (type == PURPLE_CONV_TYPE_IM) {
+						tagname = "highlight-name";
+					}
 				} else if (flags & PURPLE_MESSAGE_RECV) {
 					/* The tagname for chats is handled by get_buddy_tag */
 					if (type == PURPLE_CONV_TYPE_IM) {
@@ -5785,7 +5816,7 @@ pidgin_conv_write_conv(PurpleConversatio
 		if (tagname)
 			tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), tagname);
 		else
-			tag = get_buddy_tag(conv, name, TRUE);
+			tag = get_buddy_tag(conv, name, flags, TRUE);
 
 		if (GTK_IMHTML(gtkconv->imhtml)->show_comments) {
 			/* The color for the timestamp has to be set in the font-tags, unfortunately.
@@ -5793,19 +5824,10 @@ pidgin_conv_write_conv(PurpleConversatio
 			 * bold. I thought applying the "comment" tag again, which has "weight" set
 			 * to PANGO_WEIGHT_NORMAL, would remove the boldness. But it doesn't. So
 			 * this will have to do. I don't terribly like it.  -- sadrul */
-			GdkColor *color = NULL;
-			gboolean set = FALSE;
-			char colcode[] = "COLOR=\"#XXXXXX\"";
-			g_object_get(G_OBJECT(tag), "foreground-set", &set, "foreground-gdk", &color, NULL);
-			if (set && color)
-				g_snprintf(colcode, sizeof(colcode), "COLOR=\"#%02x%02x%02x\"",
-						color->red >> 8, color->green >> 8, color->blue >> 8);
-			else
-				colcode[0] = '\0';
-			g_snprintf(buf2, BUF_LONG, "<FONT %s SIZE=\"2\"><!--%s --></FONT>", colcode, mdate);
+			const char *color = get_text_tag_color(tag);
+			g_snprintf(buf2, BUF_LONG, "<FONT %s%s%s SIZE=\"2\"><!--%s --></FONT>",
+					color ? "COLOR=\"" : "", color ? color : "", color ? "\"" : "", mdate);
 			gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), buf2, gtk_font_options_all | GTK_IMHTML_NO_SCROLL);
-			if (color)
-				gdk_color_free(color);
 		}
 
 		gtk_text_buffer_get_end_iter(buffer, &end);


More information about the Commits mailing list