comparison src/blist.c @ 5257:e131ab86ead7

[gaim-migrate @ 5629] our 0(1)-ness is changeloged committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 29 Apr 2003 00:15:21 +0000
parents 60983a46700e
children 750e4801819f
comparison
equal deleted inserted replaced
5256:1d1c45d9b7fc 5257:e131ab86ead7
170 170
171 if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { 171 if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) {
172 buddy->present = GAIM_BUDDY_SIGNING_ON; 172 buddy->present = GAIM_BUDDY_SIGNING_ON;
173 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); 173 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name);
174 do_timer = TRUE; 174 do_timer = TRUE;
175 ((struct group *)((GaimBlistNode *)buddy)->parent)->online++;
175 } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { 176 } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) {
176 buddy->present = GAIM_BUDDY_SIGNING_OFF; 177 buddy->present = GAIM_BUDDY_SIGNING_OFF;
177 gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name); 178 gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name);
178 do_timer = TRUE; 179 do_timer = TRUE;
180 ((struct group *)((GaimBlistNode *)buddy)->parent)->online--;
179 } 181 }
180 182
181 if(do_timer) { 183 if(do_timer) {
182 if(buddy->timer > 0) 184 if(buddy->timer > 0)
183 g_source_remove(buddy->timer); 185 g_source_remove(buddy->timer);
328 330
329 if (cnode->parent) { 331 if (cnode->parent) {
330 /* This chat was already in the list and is 332 /* This chat was already in the list and is
331 * being moved. 333 * being moved.
332 */ 334 */
335 ((struct group *)cnode->parent)->totalsize--;
336 if (chat->account->gc)
337 ((struct group *)cnode->parent)->currentsize--;
333 if(cnode->next) 338 if(cnode->next)
334 cnode->next->prev = cnode->prev; 339 cnode->next->prev = cnode->prev;
335 if(cnode->prev) 340 if(cnode->prev)
336 cnode->prev->next = cnode->next; 341 cnode->prev->next = cnode->next;
337 if(cnode->parent->child == cnode) 342 if(cnode->parent->child == cnode)
347 n->next->prev = cnode; 352 n->next->prev = cnode;
348 cnode->next = n->next; 353 cnode->next = n->next;
349 cnode->prev = n; 354 cnode->prev = n;
350 cnode->parent = n->parent; 355 cnode->parent = n->parent;
351 n->next = cnode; 356 n->next = cnode;
357 ((struct group *)n->parent)->totalsize++;
358 if (chat->account->gc)
359 ((struct group *)n->parent)->currentsize++;
352 } else { 360 } else {
353 ((GaimBlistNode*)g)->child = cnode; 361 ((GaimBlistNode*)g)->child = cnode;
354 cnode->next = cnode->prev = NULL; 362 cnode->next = cnode->prev = NULL;
355 cnode->parent = (GaimBlistNode*)g; 363 cnode->parent = (GaimBlistNode*)g;
364 g->totalsize++;
365 if (chat->account->gc)
366 g->currentsize++;
356 } 367 }
357 368
358 if (ops) 369 if (ops)
359 ops->update(gaimbuddylist, (GaimBlistNode*)cnode); 370 ops->update(gaimbuddylist, (GaimBlistNode*)cnode);
360 if (save) 371 if (save)
385 396
386 if (bnode->parent) { 397 if (bnode->parent) {
387 /* This buddy was already in the list and is 398 /* This buddy was already in the list and is
388 * being moved. 399 * being moved.
389 */ 400 */
401 ((struct group *)bnode->parent)->totalsize--;
402 if (buddy->account->gc)
403 ((struct group *)bnode->parent)->currentsize--;
404
390 if(bnode->next) 405 if(bnode->next)
391 bnode->next->prev = bnode->prev; 406 bnode->next->prev = bnode->prev;
392 if(bnode->prev) 407 if(bnode->prev)
393 bnode->prev->next = bnode->next; 408 bnode->prev->next = bnode->next;
394 if(bnode->parent->child == bnode) 409 if(bnode->parent->child == bnode)
395 bnode->parent->child = bnode->next; 410 bnode->parent->child = bnode->next;
396 411
397 ops->remove(gaimbuddylist, bnode); 412 ops->remove(gaimbuddylist, bnode);
398 413
399 if (bnode->parent != ((GaimBlistNode*)g)) 414 if (bnode->parent != ((GaimBlistNode*)g)) {
400 serv_move_buddy(buddy, (struct group*)bnode->parent, g); 415 serv_move_buddy(buddy, (struct group*)bnode->parent, g);
416 }
401 save = TRUE; 417 save = TRUE;
402 } 418 }
403 419
404 if (n) { 420 if (n) {
405 if(n->next) 421 if(n->next)
406 n->next->prev = (GaimBlistNode*)buddy; 422 n->next->prev = (GaimBlistNode*)buddy;
407 ((GaimBlistNode*)buddy)->next = n->next; 423 ((GaimBlistNode*)buddy)->next = n->next;
408 ((GaimBlistNode*)buddy)->prev = n; 424 ((GaimBlistNode*)buddy)->prev = n;
409 ((GaimBlistNode*)buddy)->parent = n->parent; 425 ((GaimBlistNode*)buddy)->parent = n->parent;
410 n->next = (GaimBlistNode*)buddy; 426 n->next = (GaimBlistNode*)buddy;
427 ((struct group *)n->parent)->totalsize++;
428 if (buddy->account->gc)
429 ((struct group *)n->parent)->currentsize++;
411 } else { 430 } else {
412 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; 431 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy;
413 ((GaimBlistNode*)buddy)->next = NULL; 432 ((GaimBlistNode*)buddy)->next = NULL;
414 ((GaimBlistNode*)buddy)->prev = NULL; 433 ((GaimBlistNode*)buddy)->prev = NULL;
415 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; 434 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g;
435 g->totalsize++;
436 if (buddy->account->gc)
437 g->currentsize++;
416 } 438 }
417 439
418 hb = g_malloc(sizeof(struct _gaim_hbuddy)); 440 hb = g_malloc(sizeof(struct _gaim_hbuddy));
419 hb->name = g_strdup(normalize(buddy->name)); 441 hb->name = g_strdup(normalize(buddy->name));
420 hb->account = buddy->account; 442 hb->account = buddy->account;
439 461
440 if (!g) { 462 if (!g) {
441 struct gaim_blist_ui_ops *ops; 463 struct gaim_blist_ui_ops *ops;
442 g= g_new0(struct group, 1); 464 g= g_new0(struct group, 1);
443 g->name = g_strdup(name); 465 g->name = g_strdup(name);
466 g->totalsize = 0;
467 g->currentsize = 0;
468 g->online = 0;
444 g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, 469 g->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
445 g_free, g_free); 470 g_free, g_free);
446 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; 471 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE;
447 472
448 ops = gaim_get_blist_ui_ops(); 473 ops = gaim_get_blist_ui_ops();
522 gnode->child = node->next; 547 gnode->child = node->next;
523 if (node->prev) 548 if (node->prev)
524 node->prev->next = node->next; 549 node->prev->next = node->next;
525 if (node->next) 550 if (node->next)
526 node->next->prev = node->prev; 551 node->next->prev = node->prev;
552 group->totalsize--;
553 if (buddy->account->gc)
554 group->currentsize--;
527 555
528 hb.name = normalize(buddy->name); 556 hb.name = normalize(buddy->name);
529 hb.account = buddy->account; 557 hb.account = buddy->account;
530 if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { 558 if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) {
531 g_hash_table_remove(gaimbuddylist->buddies, &hb); 559 g_hash_table_remove(gaimbuddylist->buddies, &hb);
554 gnode->child = node->next; 582 gnode->child = node->next;
555 if (node->prev) 583 if (node->prev)
556 node->prev->next = node->next; 584 node->prev->next = node->next;
557 if (node->next) 585 if (node->next)
558 node->next->prev = node->prev; 586 node->next->prev = node->prev;
587 group->totalsize--;
588 if (chat->account->gc)
589 group->currentsize--;
559 590
560 ops->remove(gaimbuddylist, node); 591 ops->remove(gaimbuddylist, node);
561 g_hash_table_destroy(chat->components); 592 g_hash_table_destroy(chat->components);
562 g_free(chat->alias); 593 g_free(chat->alias);
563 g_free(chat); 594 g_free(chat);
678 if(!GAIM_BLIST_NODE_IS_GROUP(group)) 709 if(!GAIM_BLIST_NODE_IS_GROUP(group))
679 continue; 710 continue;
680 for(buddy = group->child; buddy; buddy = buddy->next) { 711 for(buddy = group->child; buddy; buddy = buddy->next) {
681 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { 712 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
682 if (account == ((struct buddy*)buddy)->account) { 713 if (account == ((struct buddy*)buddy)->account) {
714 ((struct group *)group)->currentsize++;
683 if(ops) 715 if(ops)
684 ops->update(gaimbuddylist, buddy); 716 ops->update(gaimbuddylist, buddy);
685 } 717 }
686 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { 718 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) {
687 if (account == ((struct chat*)buddy)->account) { 719 if (account == ((struct chat*)buddy)->account) {
720 ((struct group *)group)->currentsize++;
688 if(ops) 721 if(ops)
689 ops->update(gaimbuddylist, buddy); 722 ops->update(gaimbuddylist, buddy);
690 } 723 }
691 } 724 }
692 } 725 }
705 if(!GAIM_BLIST_NODE_IS_GROUP(group)) 738 if(!GAIM_BLIST_NODE_IS_GROUP(group))
706 continue; 739 continue;
707 for(buddy = group->child; buddy; buddy = buddy->next) { 740 for(buddy = group->child; buddy; buddy = buddy->next) {
708 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { 741 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) {
709 if (account == ((struct buddy*)buddy)->account) { 742 if (account == ((struct buddy*)buddy)->account) {
743 if (((struct buddy *)buddy)->present)
744 ((struct group *)group)->online--;
710 ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; 745 ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE;
746 ((struct group *)group)->currentsize--;
711 if(ops) 747 if(ops)
712 ops->remove(gaimbuddylist, buddy); 748 ops->remove(gaimbuddylist, buddy);
713 } 749 }
714 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { 750 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) {
715 if (account == ((struct chat*)buddy)->account) { 751 if (account == ((struct chat*)buddy)->account) {
752 ((struct group *)group)->online--;
753 ((struct group *)group)->currentsize--;
716 if(ops) 754 if(ops)
717 ops->remove(gaimbuddylist, buddy); 755 ops->remove(gaimbuddylist, buddy);
718 } 756 }
719 } 757 }
720 } 758 }
1785 { 1823 {
1786 return blist_ui_ops; 1824 return blist_ui_ops;
1787 } 1825 }
1788 1826
1789 int gaim_blist_get_group_size(struct group *group, gboolean offline) { 1827 int gaim_blist_get_group_size(struct group *group, gboolean offline) {
1790 GaimBlistNode *node;
1791 int count = 0;
1792
1793 if(!group) 1828 if(!group)
1794 return 0; 1829 return 0;
1795 1830
1796 for(node = group->node.child; node; node = node->next) { 1831 return offline ? group->totalsize : group->currentsize;
1797 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
1798 struct buddy *b = (struct buddy *)node;
1799 if(b->account->gc || offline)
1800 count++;
1801 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
1802 struct chat *chat = (struct chat *)node;
1803 if(chat->account->gc || offline)
1804 count++;
1805 }
1806 }
1807
1808 return count;
1809 } 1832 }
1810 1833
1811 int gaim_blist_get_group_online_count(struct group *group) { 1834 int gaim_blist_get_group_online_count(struct group *group) {
1812 GaimBlistNode *node;
1813 int count = 0;
1814
1815 if(!group) 1835 if(!group)
1816 return 0; 1836 return 0;
1817 1837
1818 for(node = group->node.child; node; node = node->next) { 1838 return group->online;
1819 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { 1839 }
1820 struct buddy *b = (struct buddy *)node; 1840
1821 if(GAIM_BUDDY_IS_ONLINE(b)) 1841
1822 count++;
1823 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
1824 count++;
1825 }
1826 }
1827
1828 return count;
1829 }
1830
1831