Mercurial > pidgin
changeset 10378:28135f8c226d
[gaim-migrate @ 11603]
I call this lazy contact priority computation.
Be careful not to use contact->priority directly, unless
you know what you're doing.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Wed, 15 Dec 2004 02:29:58 +0000 |
parents | a7a4db67040c |
children | cf7b1970039e |
files | src/blist.c src/blist.h src/status.c |
diffstat | 3 files changed, 27 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Wed Dec 15 02:17:59 2004 +0000 +++ b/src/blist.c Wed Dec 15 02:29:58 2004 +0000 @@ -121,7 +121,14 @@ } } -void gaim_contact_compute_priority_buddy(GaimContact *contact) +void gaim_contact_invalidate_priority_buddy(GaimContact *contact) +{ + g_return_if_fail(contact != NULL); + + contact->priority_valid = FALSE; +} + +static void gaim_contact_compute_priority_buddy(GaimContact *contact) { GaimBlistNode *bnode; GaimBuddy *new_priority = NULL; @@ -160,6 +167,7 @@ } contact->priority = new_priority; + contact->priority_valid = TRUE; } static gboolean blist_save_callback(gpointer data) @@ -327,7 +335,7 @@ * because something, somewhere changed. Calling the stuff below * certainly won't hurt anything. Unless you're on a K6-2 300. */ - gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); + gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops && ops->update) ops->update(gaimbuddylist, (GaimBlistNode *)buddy); } @@ -821,7 +829,7 @@ if (!bnode->parent->child) { gaim_blist_remove_contact((GaimContact*)bnode->parent); } else { - gaim_contact_compute_priority_buddy((GaimContact*)bnode->parent); + gaim_contact_invalidate_priority_buddy((GaimContact*)bnode->parent); ops->update(gaimbuddylist, bnode->parent); } } @@ -861,7 +869,7 @@ g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); - gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); + gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy)); schedule_blist_save(); @@ -913,7 +921,7 @@ if (contact->alias) return contact->alias; - return gaim_buddy_get_alias(contact->priority); + return gaim_buddy_get_alias(gaim_contact_get_priority_buddy(contact)); } gboolean gaim_contact_on_account(GaimContact *c, GaimAccount *account) @@ -1255,7 +1263,7 @@ /* Re-sort the contact */ if (contact->priority == buddy) { - gaim_contact_compute_priority_buddy(contact); + gaim_contact_invalidate_priority_buddy(contact); if (ops && ops->update) ops->update(gaimbuddylist, cnode); } @@ -1392,6 +1400,9 @@ { g_return_val_if_fail(contact != NULL, NULL); + if (!contact->priority_valid) + gaim_contact_compute_priority_buddy(contact); + return contact->priority; } @@ -1715,7 +1726,7 @@ } if (recompute || gaim_blist_node_get_bool(cnode, "show_offline")) { - gaim_contact_compute_priority_buddy((GaimContact*)cnode); + gaim_contact_invalidate_priority_buddy((GaimContact*)cnode); ops->update(gaimbuddylist, cnode); } } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) && @@ -1768,7 +1779,7 @@ } } if (recompute) { - gaim_contact_compute_priority_buddy((GaimContact*)cnode); + gaim_contact_invalidate_priority_buddy((GaimContact*)cnode); if (ops && ops->update) ops->update(gaimbuddylist, cnode); } @@ -2323,7 +2334,7 @@ return; if (exp_acct && ! gaim_group_on_account(group, exp_acct)) - return; + return; group_name = g_markup_escape_text(group->name, -1); fprintf(file, "\t\t<group name=\"%s\">\n", group_name);
--- a/src/blist.h Wed Dec 15 02:17:59 2004 +0000 +++ b/src/blist.h Wed Dec 15 02:29:58 2004 +0000 @@ -131,6 +131,7 @@ int currentsize; /**< The number of buddies in this contact corresponding to online accounts */ int online; /**< The number of buddies in this contact who are currently online */ GaimBuddy *priority; /**< The "top" buddy for this contact */ + gboolean priority_valid; /**< Is priority valid? */ }; @@ -511,14 +512,14 @@ */ gboolean gaim_contact_on_account(GaimContact *contact, GaimAccount *account); - /** - * Re-calculates the priority buddy for a contact. + * Invalidates the priority buddy so that the next call to + * gaim_contact_get_priority_buddy recomputes it. * - * @param contact The contact. + * @param contact The contact + * @return The highest priority buddy */ -void gaim_contact_compute_priority_buddy(GaimContact *contact); - +void gaim_contact_invalidate_priority_buddy(GaimContact *contact); /** * Removes a buddy from the buddy list and frees the memory allocated to it. *
--- a/src/status.c Wed Dec 15 02:17:59 2004 +0000 +++ b/src/status.c Wed Dec 15 02:29:58 2004 +0000 @@ -1341,7 +1341,7 @@ } } - gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); + gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy)); if (ops != NULL && ops->update != NULL) ops->update(gaim_get_blist(), (GaimBlistNode *)buddy);