comparison src/blist.c @ 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 ffb5f76d6188
children c432b927b0b1
comparison
equal deleted inserted replaced
10377:a7a4db67040c 10378:28135f8c226d
119 } 119 }
120 } 120 }
121 } 121 }
122 } 122 }
123 123
124 void gaim_contact_compute_priority_buddy(GaimContact *contact) 124 void gaim_contact_invalidate_priority_buddy(GaimContact *contact)
125 {
126 g_return_if_fail(contact != NULL);
127
128 contact->priority_valid = FALSE;
129 }
130
131 static void gaim_contact_compute_priority_buddy(GaimContact *contact)
125 { 132 {
126 GaimBlistNode *bnode; 133 GaimBlistNode *bnode;
127 GaimBuddy *new_priority = NULL; 134 GaimBuddy *new_priority = NULL;
128 135
129 g_return_if_fail(contact != NULL); 136 g_return_if_fail(contact != NULL);
158 } 165 }
159 } 166 }
160 } 167 }
161 168
162 contact->priority = new_priority; 169 contact->priority = new_priority;
170 contact->priority_valid = TRUE;
163 } 171 }
164 172
165 static gboolean blist_save_callback(gpointer data) 173 static gboolean blist_save_callback(gpointer data)
166 { 174 {
167 gaim_blist_sync(); 175 gaim_blist_sync();
325 * 333 *
326 * It's a safe assumption that SOMETHING called this function. PROBABLY 334 * It's a safe assumption that SOMETHING called this function. PROBABLY
327 * because something, somewhere changed. Calling the stuff below 335 * because something, somewhere changed. Calling the stuff below
328 * certainly won't hurt anything. Unless you're on a K6-2 300. 336 * certainly won't hurt anything. Unless you're on a K6-2 300.
329 */ 337 */
330 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); 338 gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy));
331 if (ops && ops->update) 339 if (ops && ops->update)
332 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); 340 ops->update(gaimbuddylist, (GaimBlistNode *)buddy);
333 } 341 }
334 342
335 void gaim_blist_update_buddy_signon(GaimBuddy *buddy, time_t signon) 343 void gaim_blist_update_buddy_signon(GaimBuddy *buddy, time_t signon)
819 } 827 }
820 828
821 if (!bnode->parent->child) { 829 if (!bnode->parent->child) {
822 gaim_blist_remove_contact((GaimContact*)bnode->parent); 830 gaim_blist_remove_contact((GaimContact*)bnode->parent);
823 } else { 831 } else {
824 gaim_contact_compute_priority_buddy((GaimContact*)bnode->parent); 832 gaim_contact_invalidate_priority_buddy((GaimContact*)bnode->parent);
825 ops->update(gaimbuddylist, bnode->parent); 833 ops->update(gaimbuddylist, bnode->parent);
826 } 834 }
827 } 835 }
828 836
829 if (node && GAIM_BLIST_NODE_IS_BUDDY(node)) { 837 if (node && GAIM_BLIST_NODE_IS_BUDDY(node)) {
859 hb->account = buddy->account; 867 hb->account = buddy->account;
860 hb->group = ((GaimBlistNode*)buddy)->parent->parent; 868 hb->group = ((GaimBlistNode*)buddy)->parent->parent;
861 869
862 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); 870 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy);
863 871
864 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); 872 gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy));
865 873
866 schedule_blist_save(); 874 schedule_blist_save();
867 875
868 if (ops && ops->update) 876 if (ops && ops->update)
869 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 877 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
911 g_return_val_if_fail(contact != NULL, NULL); 919 g_return_val_if_fail(contact != NULL, NULL);
912 920
913 if (contact->alias) 921 if (contact->alias)
914 return contact->alias; 922 return contact->alias;
915 923
916 return gaim_buddy_get_alias(contact->priority); 924 return gaim_buddy_get_alias(gaim_contact_get_priority_buddy(contact));
917 } 925 }
918 926
919 gboolean gaim_contact_on_account(GaimContact *c, GaimAccount *account) 927 gboolean gaim_contact_on_account(GaimContact *c, GaimAccount *account)
920 { 928 {
921 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) c; 929 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) c;
1253 1261
1254 schedule_blist_save(); 1262 schedule_blist_save();
1255 1263
1256 /* Re-sort the contact */ 1264 /* Re-sort the contact */
1257 if (contact->priority == buddy) { 1265 if (contact->priority == buddy) {
1258 gaim_contact_compute_priority_buddy(contact); 1266 gaim_contact_invalidate_priority_buddy(contact);
1259 if (ops && ops->update) 1267 if (ops && ops->update)
1260 ops->update(gaimbuddylist, cnode); 1268 ops->update(gaimbuddylist, cnode);
1261 } 1269 }
1262 1270
1263 /* Remove this buddy from the buddies hash table */ 1271 /* Remove this buddy from the buddies hash table */
1389 } 1397 }
1390 1398
1391 GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) 1399 GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact)
1392 { 1400 {
1393 g_return_val_if_fail(contact != NULL, NULL); 1401 g_return_val_if_fail(contact != NULL, NULL);
1402
1403 if (!contact->priority_valid)
1404 gaim_contact_compute_priority_buddy(contact);
1394 1405
1395 return contact->priority; 1406 return contact->priority;
1396 } 1407 }
1397 1408
1398 const char *gaim_buddy_get_alias_only(GaimBuddy *buddy) 1409 const char *gaim_buddy_get_alias_only(GaimBuddy *buddy)
1713 ops->update(gaimbuddylist, bnode); 1724 ops->update(gaimbuddylist, bnode);
1714 } 1725 }
1715 } 1726 }
1716 if (recompute || 1727 if (recompute ||
1717 gaim_blist_node_get_bool(cnode, "show_offline")) { 1728 gaim_blist_node_get_bool(cnode, "show_offline")) {
1718 gaim_contact_compute_priority_buddy((GaimContact*)cnode); 1729 gaim_contact_invalidate_priority_buddy((GaimContact*)cnode);
1719 ops->update(gaimbuddylist, cnode); 1730 ops->update(gaimbuddylist, cnode);
1720 } 1731 }
1721 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) && 1732 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) &&
1722 ((GaimChat*)cnode)->account == account) { 1733 ((GaimChat*)cnode)->account == account) {
1723 ((GaimGroup *)gnode)->online++; 1734 ((GaimGroup *)gnode)->online++;
1766 if (ops && ops->remove) 1777 if (ops && ops->remove)
1767 ops->remove(gaimbuddylist, bnode); 1778 ops->remove(gaimbuddylist, bnode);
1768 } 1779 }
1769 } 1780 }
1770 if (recompute) { 1781 if (recompute) {
1771 gaim_contact_compute_priority_buddy((GaimContact*)cnode); 1782 gaim_contact_invalidate_priority_buddy((GaimContact*)cnode);
1772 if (ops && ops->update) 1783 if (ops && ops->update)
1773 ops->update(gaimbuddylist, cnode); 1784 ops->update(gaimbuddylist, cnode);
1774 } 1785 }
1775 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) && 1786 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) &&
1776 ((GaimChat*)cnode)->account == account) { 1787 ((GaimChat*)cnode)->account == account) {
2321 2332
2322 if (! GAIM_BLIST_NODE_SHOULD_SAVE(gnode)) 2333 if (! GAIM_BLIST_NODE_SHOULD_SAVE(gnode))
2323 return; 2334 return;
2324 2335
2325 if (exp_acct && ! gaim_group_on_account(group, exp_acct)) 2336 if (exp_acct && ! gaim_group_on_account(group, exp_acct))
2326 return; 2337 return;
2327 2338
2328 group_name = g_markup_escape_text(group->name, -1); 2339 group_name = g_markup_escape_text(group->name, -1);
2329 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); 2340 fprintf(file, "\t\t<group name=\"%s\">\n", group_name);
2330 g_free(group_name); 2341 g_free(group_name);
2331 2342