Mercurial > pidgin
comparison src/blist.c @ 6742:d93c6a1fadf2
[gaim-migrate @ 7274]
this should let you delete contacts, and should make ChipX86 happy by telling
the prpls when we move buddies around
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 04 Sep 2003 18:40:40 +0000 |
parents | b4943b9cea2b |
children | a781689ca455 |
comparison
equal
deleted
inserted
replaced
6741:b3a0b79131dd | 6742:d93c6a1fadf2 |
---|---|
71 static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) | 71 static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) |
72 { | 72 { |
73 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); | 73 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
74 } | 74 } |
75 | 75 |
76 static void _gaim_blist_hbuddy_free_key(struct _gaim_hbuddy *hb) | |
77 { | |
78 g_free(hb->name); | |
79 g_free(hb); | |
80 } | |
81 | |
76 static void blist_pref_cb(const char *name, GaimPrefType typ, gpointer value, gpointer data) | 82 static void blist_pref_cb(const char *name, GaimPrefType typ, gpointer value, gpointer data) |
77 { | 83 { |
78 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | 84 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
79 GaimBlistNode *gnode, *cnode, *bnode; | 85 GaimBlistNode *gnode, *cnode, *bnode; |
80 | 86 |
106 { | 112 { |
107 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | 113 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); |
108 | 114 |
109 gbl->ui_ops = gaim_get_blist_ui_ops(); | 115 gbl->ui_ops = gaim_get_blist_ui_ops(); |
110 | 116 |
111 gbl->buddies = g_hash_table_new ((GHashFunc)_gaim_blist_hbuddy_hash, | 117 gbl->buddies = g_hash_table_new_full((GHashFunc)_gaim_blist_hbuddy_hash, |
112 (GEqualFunc)_gaim_blist_hbuddy_equal); | 118 (GEqualFunc)_gaim_blist_hbuddy_equal, |
119 (GDestroyNotify)_gaim_blist_hbuddy_free_key, NULL); | |
113 | 120 |
114 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) | 121 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
115 gbl->ui_ops->new_list(gbl); | 122 gbl->ui_ops->new_list(gbl); |
116 | 123 |
117 gaim_prefs_connect_callback("/core/buddies/use_server_alias", | 124 gaim_prefs_connect_callback("/core/buddies/use_server_alias", |
588 } | 595 } |
589 | 596 |
590 ops->remove(gaimbuddylist, bnode); | 597 ops->remove(gaimbuddylist, bnode); |
591 | 598 |
592 save = TRUE; | 599 save = TRUE; |
600 | |
601 if(bnode->parent->parent != (GaimBlistNode*)g) { | |
602 hb = g_new(struct _gaim_hbuddy, 1); | |
603 hb->name = normalize(buddy->name); | |
604 hb->account = buddy->account; | |
605 hb->group = bnode->parent->parent; | |
606 g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
607 g_free(hb); | |
608 } | |
593 } | 609 } |
594 | 610 |
595 if(node && GAIM_BLIST_NODE_IS_BUDDY(node)) { | 611 if(node && GAIM_BLIST_NODE_IS_BUDDY(node)) { |
596 if(node->next) | 612 if(node->next) |
597 node->next->prev = bnode; | 613 node->next->prev = bnode; |
619 ((GaimGroup*)bnode->parent->parent)->currentsize++; | 635 ((GaimGroup*)bnode->parent->parent)->currentsize++; |
620 } | 636 } |
621 ((GaimContact*)bnode->parent)->totalsize++; | 637 ((GaimContact*)bnode->parent)->totalsize++; |
622 | 638 |
623 | 639 |
624 hb = g_malloc(sizeof(struct _gaim_hbuddy)); | 640 hb = g_new(struct _gaim_hbuddy, 1); |
625 hb->name = g_strdup(normalize(buddy->name)); | 641 hb->name = g_strdup(normalize(buddy->name)); |
626 hb->account = buddy->account; | 642 hb->account = buddy->account; |
627 hb->group = ((GaimBlistNode*)buddy)->parent->parent; | 643 hb->group = ((GaimBlistNode*)buddy)->parent->parent; |
628 | 644 |
629 if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) { | 645 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); |
630 /* This guy already exists */ | |
631 g_free(hb->name); | |
632 g_free(hb); | |
633 } else { | |
634 g_hash_table_insert(gaimbuddylist->buddies, (gpointer)hb, (gpointer)buddy); | |
635 } | |
636 | 646 |
637 if (ops) | 647 if (ops) |
638 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | 648 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); |
639 if (save) | 649 if (save) |
640 gaim_blist_save(); | 650 gaim_blist_save(); |
681 | 691 |
682 void gaim_blist_add_contact(GaimContact *contact, GaimGroup *group, GaimBlistNode *node) | 692 void gaim_blist_add_contact(GaimContact *contact, GaimGroup *group, GaimBlistNode *node) |
683 { | 693 { |
684 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | 694 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
685 GaimGroup *g; | 695 GaimGroup *g; |
686 GaimBlistNode *gnode, *cnode; | 696 GaimBlistNode *gnode, *cnode, *bnode; |
687 gboolean save = FALSE; | 697 gboolean save = FALSE; |
688 | 698 |
689 if(!contact) | 699 if(!contact) |
690 return; | 700 return; |
691 | 701 |
719 ((GaimGroup*)cnode->parent)->totalsize--; | 729 ((GaimGroup*)cnode->parent)->totalsize--; |
720 | 730 |
721 ops->remove(gaimbuddylist, cnode); | 731 ops->remove(gaimbuddylist, cnode); |
722 | 732 |
723 save = TRUE; | 733 save = TRUE; |
734 | |
735 if(cnode->parent != gnode) { | |
736 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
737 GaimBuddy *b = (GaimBuddy*)bnode; | |
738 | |
739 struct _gaim_hbuddy *hb = g_new(struct _gaim_hbuddy, 1); | |
740 hb->name = g_strdup(normalize(b->name)); | |
741 hb->account = b->account; | |
742 hb->group = cnode->parent; | |
743 | |
744 g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
745 | |
746 hb->group = gnode; | |
747 g_hash_table_replace(gaimbuddylist->buddies, hb, b); | |
748 | |
749 if(b->account->gc) | |
750 serv_move_buddy(b, (GaimGroup*)cnode->parent, g); | |
751 } | |
752 } | |
724 } | 753 } |
725 | 754 |
726 if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || | 755 if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || |
727 GAIM_BLIST_NODE_IS_CHAT(node))) { | 756 GAIM_BLIST_NODE_IS_CHAT(node))) { |
728 if(node->next) | 757 if(node->next) |
834 | 863 |
835 g_free(contact); | 864 g_free(contact); |
836 } | 865 } |
837 } | 866 } |
838 | 867 |
839 void gaim_blist_remove_buddy (GaimBuddy *buddy) | 868 void gaim_blist_remove_buddy (GaimBuddy *buddy) |
840 { | 869 { |
841 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | 870 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
842 | 871 |
843 GaimBlistNode *cnode, *node = (GaimBlistNode*)buddy; | 872 GaimBlistNode *cnode, *node = (GaimBlistNode*)buddy; |
844 GaimGroup *group; | 873 GaimGroup *group; |
845 struct _gaim_hbuddy hb, *key; | 874 struct _gaim_hbuddy hb; |
846 struct buddy *val; | |
847 | 875 |
848 cnode = node->parent; | 876 cnode = node->parent; |
849 group = (GaimGroup *)cnode->parent; | 877 group = (GaimGroup *)cnode->parent; |
850 | 878 |
851 if(GAIM_BUDDY_IS_ONLINE(buddy)) { | 879 if(GAIM_BUDDY_IS_ONLINE(buddy)) { |
871 } | 899 } |
872 | 900 |
873 hb.name = normalize(buddy->name); | 901 hb.name = normalize(buddy->name); |
874 hb.account = buddy->account; | 902 hb.account = buddy->account; |
875 hb.group = ((GaimBlistNode*)buddy)->parent->parent; | 903 hb.group = ((GaimBlistNode*)buddy)->parent->parent; |
876 if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { | 904 g_hash_table_remove(gaimbuddylist->buddies, &hb); |
877 g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
878 g_free(key->name); | |
879 g_free(key); | |
880 } | |
881 | 905 |
882 if(buddy->timer > 0) | 906 if(buddy->timer > 0) |
883 g_source_remove(buddy->timer); | 907 g_source_remove(buddy->timer); |
884 | 908 |
885 ops->remove(gaimbuddylist, node); | 909 ops->remove(gaimbuddylist, node); |