diff src/gtkconv.c @ 12468:6faefbebcd24

[gaim-migrate @ 14778] SF Patch #1372898 from charkins "This patch updates the unseen conversation api in gtkconv to ensure consistancy and avoid code duplication. The ...first_unseen() function is renamed and expanded to return a list of conversations that match the specified criteria. A max_count parameter is used to allow this to short circuit early (using 1 gives old behavior). An additional flag was added to allow this function to only consider hidden conversations (used by the buddy list). The blist is currently inconsistant in which conversations it loops over for showing the menu tray icon, creating the tooltip and the unseen menu. This patch fixes that. The ...find_unseen_list() now handles contact-aware conversations correctly as well (based on sadrul's patches in #1362579 which are obsoleted by this patch). I also included the fix from #1362579 which increments unseen_count only when state>=UNSEEN_TEXT." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 12 Dec 2005 18:59:29 +0000
parents b1717befbb26
children f4efe0c0de88
line wrap: on
line diff
--- a/src/gtkconv.c	Mon Dec 12 17:49:43 2005 +0000
+++ b/src/gtkconv.c	Mon Dec 12 18:59:29 2005 +0000
@@ -2416,27 +2416,40 @@
 	gtk_window_present(GTK_WINDOW(gtkconv->win->window));
 }
 
-GaimConversation *
-gaim_gtk_conversations_get_first_unseen(GaimConversationType type,
-                                        GaimUnseenState min_state)
+GList *
+gaim_gtk_conversations_find_unseen_list(GaimConversationType type,
+										GaimUnseenState min_state,
+										gboolean hidden_only,
+										guint max_count)
 {
 	GList *l;
-
-	if(type==GAIM_CONV_TYPE_IM) {
+	GList *r = NULL;
+	guint c = 0;
+
+	if (type==GAIM_CONV_TYPE_IM) {
 		l = gaim_get_ims();
-	} else if(type==GAIM_CONV_TYPE_CHAT) {
+	} else if (type==GAIM_CONV_TYPE_CHAT) {
 		l = gaim_get_chats();
 	} else {
 		l = gaim_get_conversations();
 	}
 
-	for(; l!=NULL; l=l->next) {
+	for (; l!=NULL && (max_count==0 || c < max_count); l = l->next) {
 		GaimConversation *conv = (GaimConversation*)l->data;
-		if (GAIM_GTK_CONVERSATION(conv)->unseen_state >= min_state)
-			return conv;
-	}
-
-	return NULL;
+		GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
+
+		if(gtkconv->active_conv != conv)
+			continue;
+
+		if (gtkconv->unseen_state >= min_state  && (!hidden_only ||
+				(hidden_only && gtkconv->win==hidden_convwin))) {
+
+			r = g_list_prepend(r, conv);
+			c++;
+		}
+	}
+
+	return r;
 }
 
 static void
@@ -2447,45 +2460,34 @@
 }
 
 guint
-gaim_gtk_conversations_fill_unseen_menu(GtkWidget *menu,
-                                        GaimConversationType type,
-                                        GaimUnseenState min_state)
+gaim_gtk_conversations_fill_menu(GtkWidget *menu, GList *convs)
 {
 	GList *l;
-	guint ret = 0;
+	guint ret=0;
 
 	g_return_val_if_fail(menu != NULL, 0);
-
-	if (type == GAIM_CONV_TYPE_IM) {
-		l = gaim_get_ims();
-	} else if (type == GAIM_CONV_TYPE_CHAT) {
-		l = gaim_get_chats();
-	} else {
-		l = gaim_get_conversations();
-	}
-
-	for (; l != NULL ; l = l->next) {
+	g_return_val_if_fail(convs != NULL, 0);
+
+	for (l = convs; l != NULL ; l = l->next) {
 		GaimConversation *conv = (GaimConversation*)l->data;
 		GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
 
-		if (gtkconv->unseen_state >= min_state && gtkconv->win == hidden_convwin) {
-			GtkWidget *icon = gtk_image_new();
-			GdkPixbuf *pbuf = gaim_gtkconv_get_tab_icon(conv, TRUE);
-			GtkWidget *item;
-			gchar *text = g_strdup_printf("%s (%d)", 
-					gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)),
-					gtkconv->unseen_count);
-
-			gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pbuf);
-			g_object_unref(pbuf);
-
-			item = gtk_image_menu_item_new_with_label(text);
-			gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon);
-			g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(unseen_conv_menu_cb), conv);
-			gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
-			g_free(text);
-			ret++;
-		}
+		GtkWidget *icon = gtk_image_new();
+		GdkPixbuf *pbuf = gaim_gtkconv_get_tab_icon(conv, TRUE);
+		GtkWidget *item;
+		gchar *text = g_strdup_printf("%s (%d)",
+				gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)),
+				gtkconv->unseen_count);
+
+		gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pbuf);
+		g_object_unref(pbuf);
+
+		item = gtk_image_menu_item_new_with_label(text);
+		gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon);
+		g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(unseen_conv_menu_cb), conv);
+		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+		g_free(text);
+		ret++;
 	}
 
 	return ret;
@@ -6196,7 +6198,8 @@
 	}
 	else
 	{
-		gtkconv->unseen_count++;
+		if (state >= GAIM_UNSEEN_TEXT)
+			gtkconv->unseen_count++;
 
 		if (state > gtkconv->unseen_state)
 			gtkconv->unseen_state = state;