# HG changeset patch # User Sean Egan # Date 1132129637 0 # Node ID 875f59f9c0bb1bfd89a11359fb1772941bc8a5cc # Parent b528f37d8e957b2cb89fa016ef72f9d9e03a3415 [gaim-migrate @ 14412] A better interface for iterating the buddy list from none other than Sadrul committer: Tailor Script diff -r b528f37d8e95 -r 875f59f9c0bb src/blist.c --- 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) { diff -r b528f37d8e95 -r 875f59f9c0bb src/blist.h --- 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(); diff -r b528f37d8e95 -r 875f59f9c0bb src/gtkblist.c --- 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); } }