changeset 4701:ac7ca2bd6d4f

[gaim-migrate @ 5012] now groups go away when they're empty, like you would think they should. also fixes a segfault if someone signs on and off very quickly. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 11 Mar 2003 03:59:42 +0000
parents e52e19e33227
children cb5b23dfd82b
files src/buddy.c src/list.c src/list.h
diffstat 3 files changed, 89 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddy.c	Tue Mar 11 02:19:50 2003 +0000
+++ b/src/buddy.c	Tue Mar 11 03:59:42 2003 +0000
@@ -356,15 +356,18 @@
 		sw = nw = ne = NULL; /* So that only the se icon will composite */
 	}
 
-		
+
 	if (b->present == 2) {
+		struct gaim_gtk_blist_node *gtknode;
 		/* If b->present is 2, that means this buddy has just signed on.  We use the "login" icon for the
 		 * status, and we set a timeout to change it to a normal icon after 10 seconds. */
 		filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL);
 		status = gdk_pixbuf_new_from_file(filename,NULL);
 		g_free(filename);
-		g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b);
-		
+
+		gtknode = GAIM_GTK_BLIST_NODE((GaimBlistNode*)b);
+		gtknode->timer = g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b);
+
 		/* "Hey, what's all this crap?" you ask.  Status icons will be themeable too, and 
 		   then it will look up protoname from the theme */
 	} else {
@@ -730,6 +733,32 @@
 		gtk_widget_show_all(gtkblist->bbox);
 }
 
+static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node)
+{
+	struct gaim_gtk_blist_node *gtknode;
+	GtkTreeIter iter;
+
+	if (!node->ui_data)
+		return;
+
+	gtknode = (struct gaim_gtk_blist_node *)node->ui_data;
+
+	if (gtknode->timer > 0) {
+		g_source_remove(gtknode->timer);
+		gtknode->timer = 0;
+	}
+
+	if (get_iter_from_node(node, &iter)) {
+		gtk_tree_store_remove(gtkblist->treemodel, &iter);
+		if(GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_blist_get_group_online_count((struct group *)node->parent) == 0) {
+			GtkTreeIter groupiter;
+			if(get_iter_from_node(node->parent, &groupiter))
+				gtk_tree_store_remove(gtkblist->treemodel, &groupiter);
+		}
+	}
+}
+
+
 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node)
 {
 	struct gaim_gtk_blist_node *gtknode;
@@ -832,28 +861,11 @@
 		if (avatar != NULL)
 			g_object_unref(avatar);
 
-	} else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry){
-		gtk_tree_store_remove(gtkblist->treemodel, &iter);
+	} else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) {
+		gaim_gtk_blist_remove(list, node);
 	}
 }
 
-static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node)
-{
-	struct gaim_gtk_blist_node *gtknode;
-	GtkTreeIter iter;
-
-	if (!node->ui_data)
-		return;
-
-	gtknode = (struct gaim_gtk_blist_node *)node->ui_data;
-
-	if (gtknode->timer > 0)
-		g_source_remove(gtknode->timer);
-
-	if (get_iter_from_node(node, &iter))
-		gtk_tree_store_remove(gtkblist->treemodel, &iter);
-}
-
 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list)
 {
 	gtk_widget_destroy(gtkblist->window);
--- a/src/list.c	Tue Mar 11 02:19:50 2003 +0000
+++ b/src/list.c	Tue Mar 11 03:59:42 2003 +0000
@@ -1283,3 +1283,41 @@
 {
 	return blist_ui_ops;
 }
+
+int gaim_blist_get_group_size(struct group *group, gboolean offline) {
+	GaimBlistNode *node;
+	int count = 0;
+
+	if(!group)
+		return 0;
+
+	for(node = group->node.child; node; node = node->next) {
+		if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
+			struct buddy *b = (struct buddy *)node;
+			if(b->account->gc || offline)
+				count++;
+		}
+	}
+
+	return count;
+}
+
+int gaim_blist_get_group_online_count(struct group *group) {
+	GaimBlistNode *node;
+	int count = 0;
+
+	if(!group)
+		return 0;
+
+	for(node = group->node.child; node; node = node->next) {
+		if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
+			struct buddy *b = (struct buddy *)node;
+			if(b->present)
+				count++;
+		}
+	}
+
+	return count;
+}
+
+
--- a/src/list.h	Tue Mar 11 02:19:50 2003 +0000
+++ b/src/list.h	Tue Mar 11 03:59:42 2003 +0000
@@ -355,6 +355,23 @@
 void gaim_blist_remove_account(struct gaim_account *account);
 
 
+/**
+ * Determines the total size of a group
+ *
+ * @param group  The group
+ * @param offline Count buddies in offline accounts
+ * @return The number of buddies in the group
+ */
+int gaim_blist_get_group_size(struct group *group, gboolean offline);
+
+/**
+ * Determines the number of online buddies in a group
+ *
+ * @param group The group
+ * @return The number of online buddies in the group, or 0 if the group is NULL
+ */
+int gaim_blist_get_group_online_count(struct group *group);
+
 /*@}*/
 
 /****************************************************************************************/