changeset 12112:875f59f9c0bb

[gaim-migrate @ 14412] A better interface for iterating the buddy list from none other than Sadrul committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 16 Nov 2005 08:27:17 +0000
parents b528f37d8e95
children 46fcc0765187
files src/blist.c src/blist.h src/gtkblist.c
diffstat 3 files changed, 46 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Wed Nov 16 06:07:42 2005 +0000
+++ b/src/blist.c	Wed Nov 16 08:27:17 2005 +0000
@@ -710,6 +710,33 @@
 		ops->set_visible(gaimbuddylist, show);
 }
 
+static GaimBlistNode *get_next_node(GaimBlistNode *node, gboolean godeep)
+{
+	if (node == NULL)
+		return NULL;
+
+	if (godeep && node->child)
+		return node->child;
+
+	if (node->next)
+		return node->next;
+
+	return get_next_node(node->parent, FALSE);
+}
+
+GaimBlistNode *gaim_blist_node_next(GaimBlistNode *node, gboolean offline)
+{
+	GaimBlistNode *ret = node;
+	
+	do
+	{
+		ret = get_next_node(ret, TRUE);
+	} while (ret && !offline && GAIM_BLIST_NODE_IS_BUDDY(ret) &&
+			!gaim_account_is_connected(gaim_buddy_get_account((GaimBuddy *)ret)));
+	
+	return ret;
+}
+
 void
 gaim_blist_update_buddy_status(GaimBuddy *buddy, GaimStatus *old_status)
 {
--- a/src/blist.h	Wed Nov 16 06:07:42 2005 +0000
+++ b/src/blist.h	Wed Nov 16 08:27:17 2005 +0000
@@ -221,6 +221,16 @@
 GaimBuddyList *gaim_get_blist(void);
 
 /**
+ * Returns the next node of a given node. This function is to be used to iterate
+ * over the tree returned by gaim_get_blist.
+ *
+ * @param node		A node.
+ * @param offline	Whether to include nodes for offline accounts
+ * @return	The next node
+ */
+GaimBlistNode *gaim_blist_node_next(GaimBlistNode *node, gboolean offline);
+
+/**
  * Shows the buddy list, creating a new one if necessary.
  */
 void gaim_blist_show();
--- a/src/gtkblist.c	Wed Nov 16 06:07:42 2005 +0000
+++ b/src/gtkblist.c	Wed Nov 16 08:27:17 2005 +0000
@@ -3534,36 +3534,17 @@
 	gaim_signal_emit(handle, "gtkblist-created", list);
 }
 
-/* XXX: does this need fixing? */
 static void redo_buddy_list(GaimBuddyList *list, gboolean remove)
 {
-	GaimBlistNode *gnode, *cnode, *bnode;
-
-	for(gnode = list->root; gnode; gnode = gnode->next) {
-		if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for(cnode = gnode->child; cnode; cnode = cnode->next) {
-			if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) {
-				if(remove)
-					gaim_gtk_blist_hide_node(list, cnode);
-
-				for(bnode = cnode->child; bnode; bnode = bnode->next) {
-					if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
-						continue;
-					if(remove)
-						gaim_gtk_blist_hide_node(list, bnode);
-					gaim_gtk_blist_update(list, bnode);
-				}
-
-				gaim_gtk_blist_update(list, cnode);
-			} else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) {
-				if(remove)
-					gaim_gtk_blist_hide_node(list, cnode);
-
-				gaim_gtk_blist_update(list, cnode);
-			}
-		}
-		gaim_gtk_blist_update(list, gnode);
+	GaimBlistNode *node = list->root;
+
+	while (node)
+	{
+		if (!GAIM_BLIST_NODE_IS_GROUP(node) && remove)
+			gaim_gtk_blist_hide_node(list, node);
+
+		gaim_gtk_blist_update(list, node);
+		node = gaim_blist_node_next(node, FALSE);
 	}
 }