changeset 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 1b57012eec7b
children f4efe0c0de88
files plugins/ChangeLog.API plugins/docklet/docklet.c src/gtkblist.c src/gtkconv.c src/gtkconv.h
diffstat 5 files changed, 135 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Mon Dec 12 17:49:43 2005 +0000
+++ b/plugins/ChangeLog.API	Mon Dec 12 18:59:29 2005 +0000
@@ -166,10 +166,9 @@
 	  visibility manager - see the docs for more information
 	* gaim_gtk_blist_visibility_manager_remove() to indicate the removal of
 	  a visibility manager - see the docs for more information
-	* gaim_gtk_conversations_get_first_unseen() to find the first conv
-	  with an "unseen" state >= to the specified state
-	* gaim_gtk_conversations_fill_unseen_menu() to fill a menu with a list of
-	  conversations with an "unseen" state >= to the specified state
+	* gaim_gtk_conversations_find_unseen_list() to get a list of conversations
+	  with an "unseen" state >= to the specified state and other criteria
+	* gaim_gtk_conversations_fill_menu() fill a menu from list of conversations
 	* gaim_gtk_create_prpl_icon()
 	* gaim_gtk_create_prpl_icon_with_status()
 	* gaim_gtk_pounces_manager_show()
--- a/plugins/docklet/docklet.c	Mon Dec 12 17:49:43 2005 +0000
+++ b/plugins/docklet/docklet.c	Mon Dec 12 18:59:29 2005 +0000
@@ -95,8 +95,12 @@
 	gboolean pending = FALSE;
 
 	/* determine if any ims have unseen messages */
-	if(gaim_gtk_conversations_get_first_unseen(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT))
+	l = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
+												GAIM_UNSEEN_TEXT, FALSE, 1);
+	if (l != NULL) {
 		pending = TRUE;
+		g_list_free(l);
+	}
 
 	/* iterate through all accounts and determine which
 	 * status to show in the tray icon based on the following
@@ -118,30 +122,30 @@
 		if (!gaim_account_get_enabled(account, GAIM_GTK_UI))
 			continue;
 
-		if(gaim_account_is_disconnected(account))
+		if (gaim_account_is_disconnected(account))
 			continue;
 
 		account_status = gaim_account_get_active_status(account);
 
-		if(gaim_account_is_connecting(account)) {
+		if (gaim_account_is_connecting(account)) {
 			tmpstatus = DOCKLET_STATUS_CONNECTING;
-		}
-		else if(gaim_status_is_online(account_status)) {
-			if(!gaim_status_is_available(account_status)) {
-				if(pending)
+		} else if (gaim_status_is_online(account_status)) {
+			if (!gaim_status_is_available(account_status)) {
+				if (pending)
 					tmpstatus = DOCKLET_STATUS_AWAY_PENDING;
 				else
 					tmpstatus = DOCKLET_STATUS_AWAY;
 			}
 			else {
-				if(pending)
+				if (pending)
 					tmpstatus = DOCKLET_STATUS_ONLINE_PENDING;
 				else
 					tmpstatus = DOCKLET_STATUS_ONLINE;
 			}
 		}
 
-		if(tmpstatus>newstatus) newstatus=tmpstatus;
+		if (tmpstatus > newstatus)
+			newstatus = tmpstatus;
 	}
 
 	/* update the icon if we changed status */
@@ -170,7 +174,7 @@
 
 	while(c!=NULL) {
 		GaimConnection *gc = c->data;
-		if(GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info!=NULL)
+		if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
 			return TRUE;
 		c = c->next;
 	}
@@ -202,15 +206,15 @@
 static void
 docklet_conv_updated_cb(GaimConversation *conv, GaimConvUpdateType type)
 {
-	if(type==GAIM_CONV_UPDATE_UNSEEN)
+	if (type == GAIM_CONV_UPDATE_UNSEEN)
 		docklet_update_status();
 }
 
 static void
 docklet_signed_on_cb(GaimConnection *gc)
 {
-	if(!enable_join_chat) {
-		if(GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info!=NULL)
+	if (!enable_join_chat) {
+		if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
 			enable_join_chat = TRUE;
 	}
 	docklet_update_status();
@@ -219,8 +223,8 @@
 static void
 docklet_signed_off_cb(GaimConnection *gc)
 {
-	if(enable_join_chat) {
-		if(GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info!=NULL)
+	if (enable_join_chat) {
+		if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
 			enable_join_chat = online_account_supports_chat();
 	}
 	docklet_update_status();
@@ -298,7 +302,7 @@
 	gaim_separator(menu);
 
 	menuitem = gaim_new_item_from_stock(menu, _("New Message..."), GAIM_STOCK_IM, G_CALLBACK(gaim_gtkdialogs_im), NULL, 0, 0, NULL);
-	if(status == DOCKLET_STATUS_OFFLINE)
+	if (status == DOCKLET_STATUS_OFFLINE)
 		gtk_widget_set_sensitive(menuitem, FALSE);
 
 	menuitem = gaim_new_item_from_stock(menu, _("Join A Chat..."), GAIM_STOCK_CHAT, G_CALLBACK(gaim_gtk_blist_joinchat_show), NULL, 0, 0, NULL);
@@ -347,12 +351,16 @@
 {
 	switch (button_type) {
 		case 1:
-			if(status==DOCKLET_STATUS_ONLINE_PENDING || status==DOCKLET_STATUS_AWAY_PENDING)
-				gaim_gtkconv_present_conversation(
-						gaim_gtk_conversations_get_first_unseen(
-						GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT));
-			else
+			if (status==DOCKLET_STATUS_ONLINE_PENDING || status==DOCKLET_STATUS_AWAY_PENDING) {
+				GList *l = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
+																   GAIM_UNSEEN_TEXT, FALSE, 1);
+				if (l != NULL) {
+					gaim_gtkconv_present_conversation((GaimConversation *)l->data);
+					g_list_free(l);
+				}
+			} else {
 				gaim_gtk_blist_toggle_visibility();
+			}
 			break;
 		case 3:
 			docklet_menu();
--- a/src/gtkblist.c	Mon Dec 12 17:49:43 2005 +0000
+++ b/src/gtkblist.c	Mon Dec 12 18:59:29 2005 +0000
@@ -3167,16 +3167,21 @@
 unseen_conv_menu()
 {
 	static GtkWidget *menu = NULL;
+	GList *convs = NULL;
 
 	if (menu)
 		gtk_widget_destroy(menu);
 
 	menu = gtk_menu_new();
-	if (!gaim_gtk_conversations_fill_unseen_menu(menu, GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT)) {
+
+	convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, TRUE, 0);
+	if (!convs) {
 		/* no conversations added, don't show the menu */
 		gtk_widget_destroy(menu);
 		return;
 	}
+	gaim_gtk_conversations_fill_menu(menu, convs);
+	g_list_free(convs);
 	gtk_widget_show_all(menu);
 	gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
 			gtk_get_current_event_time());
@@ -3185,13 +3190,16 @@
 static gboolean
 menutray_press_cb(GtkWidget *widget, GdkEventButton *event)
 {
-	GaimConversation *conv;
+	GList *convs;
 
 	switch (event->button) {
 		case 1:
-			conv = gaim_gtk_conversations_get_first_unseen(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT);
-			if (conv != NULL)
-				gaim_gtkconv_present_conversation(conv);
+			convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
+															GAIM_UNSEEN_TEXT, TRUE, 1);
+			if (convs) {
+				gaim_gtkconv_present_conversation((GaimConversation*)convs->data);
+				g_list_free(convs);
+			}
 			break;
 		case 3:
 			unseen_conv_menu();
@@ -3204,8 +3212,8 @@
 conversation_updated_cb(GaimConversation *conv, GaimConvUpdateType type,
                         GaimGtkBuddyList *gtkblist)
 {
-	GtkWidget *img = NULL;
-	GString *tooltip_text = NULL;
+	GList *convs = NULL;
+	GList *l = NULL;
 
 	if (type != GAIM_CONV_UPDATE_UNSEEN)
 		return;
@@ -3215,21 +3223,23 @@
 		gtkblist->menutrayicon = NULL;
 	}
 
-	if (gaim_gtk_conversations_get_first_unseen(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT)) {
-		GList *convs = gaim_get_ims();
+	convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, TRUE, 0);
+	if (convs) {
+		GtkWidget *img = NULL;
+		GString *tooltip_text = NULL;
+
 		tooltip_text = g_string_new("");
-		while (convs) {
-			if(GAIM_IS_GTK_CONVERSATION(convs->data)) {
-				GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)convs->data);
-
-				if (gtkconv->unseen_state >= GAIM_UNSEEN_TEXT && gaim_gtkconv_is_hidden(gtkconv)) {
-					g_string_append_printf(tooltip_text,
-							ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count),
-							gtkconv->unseen_count,
-							gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
-				}
+		l = convs;
+		while (l != NULL) {
+			if (GAIM_IS_GTK_CONVERSATION(l->data)) {
+				GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data);
+
+				g_string_append_printf(tooltip_text,
+						ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count),
+						gtkconv->unseen_count,
+						gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
 			}
-			convs = convs->next;
+			l = l->next;
 		}
 		if(tooltip_text->len > 0) {
 			/* get rid of the last newline */
@@ -3245,6 +3255,7 @@
 			gaim_gtk_menu_tray_append(GAIM_GTK_MENU_TRAY(gtkblist->menutray), gtkblist->menutrayicon, tooltip_text->str);
 		}
 		g_string_free(tooltip_text, TRUE);
+		g_list_free(convs);
 	}
 }
 
--- 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;
--- a/src/gtkconv.h	Mon Dec 12 17:49:43 2005 +0000
+++ b/src/gtkconv.h	Mon Dec 12 18:59:29 2005 +0000
@@ -200,31 +200,36 @@
 void gaim_gtkconv_update_buttons_by_protocol(GaimConversation *conv);
 
 /**
- * Finds the first conversation of the given type which has an unseen
- * state greater than or equal to the specified minimum state.
+ * Returns a list of conversations of the given type which have an unseen
+ * state greater than or equal to the specified minimum state. Using the
+ * hidden_only parameter, this search can be limited to hidden
+ * conversations. The max_count parameter will limit the total number of
+ * converations returned if greater than zero. The returned list should
+ * be freed by the caller.
  *
- * @param type      The type of conversation.
- * @param min_state The minimum unseen state.
- * @return          First conversation matching criteria, or NULL.
+ * @param type         The type of conversation.
+ * @param min_state    The minimum unseen state.
+ * @param hidden_only  If TRUE, only consider hidden conversations.
+ * @param max_count    Maximum number of conversations to return, or 0 for
+ *                     no maximum.
+ * @return             List of GaimConversation matching criteria, or NULL.
  */
-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);
+
 /**
- * Adds an item to a menu for each conversation of the given type
- * with an unseen state greater than or equal to the specified minimum 
- * state. The menu item will present the conversation to the user
- * when activated.
+ * Fill a menu with a list of conversations. Clicking the conversation
+ * menu item will present that conversation to the user.
  *
- * @param menu      Menu widget to add items to.
- * @param type      The type of conversation.
- * @param min_state The minimum unseen state.
- * @return          Number of conversations added to menu.
+ * @param menu   Menu widget to add items to.
+ * @param convs  List of GaimConversation to add to menu.
+ * @return       Number of conversations added to menu.
  */
 guint
-gaim_gtk_conversations_fill_unseen_menu(GtkWidget *menu,
-                                        GaimConversationType type,
-                                        GaimUnseenState min_state);
+gaim_gtk_conversations_fill_menu(GtkWidget *menu, GList *convs);
 
 /**
  * Presents a gaim conversation to the user.