Mercurial > pidgin
changeset 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 | b3a0b79131dd |
children | 43f540b0d630 |
files | src/blist.c src/dialogs.c src/gaim.h |
diffstat | 3 files changed, 84 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Thu Sep 04 15:47:09 2003 +0000 +++ b/src/blist.c Thu Sep 04 18:40:40 2003 +0000 @@ -73,6 +73,12 @@ return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); } +static void _gaim_blist_hbuddy_free_key(struct _gaim_hbuddy *hb) +{ + g_free(hb->name); + g_free(hb); +} + static void blist_pref_cb(const char *name, GaimPrefType typ, gpointer value, gpointer data) { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; @@ -108,8 +114,9 @@ gbl->ui_ops = gaim_get_blist_ui_ops(); - gbl->buddies = g_hash_table_new ((GHashFunc)_gaim_blist_hbuddy_hash, - (GEqualFunc)_gaim_blist_hbuddy_equal); + gbl->buddies = g_hash_table_new_full((GHashFunc)_gaim_blist_hbuddy_hash, + (GEqualFunc)_gaim_blist_hbuddy_equal, + (GDestroyNotify)_gaim_blist_hbuddy_free_key, NULL); if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) gbl->ui_ops->new_list(gbl); @@ -590,6 +597,15 @@ ops->remove(gaimbuddylist, bnode); save = TRUE; + + if(bnode->parent->parent != (GaimBlistNode*)g) { + hb = g_new(struct _gaim_hbuddy, 1); + hb->name = normalize(buddy->name); + hb->account = buddy->account; + hb->group = bnode->parent->parent; + g_hash_table_remove(gaimbuddylist->buddies, &hb); + g_free(hb); + } } if(node && GAIM_BLIST_NODE_IS_BUDDY(node)) { @@ -621,18 +637,12 @@ ((GaimContact*)bnode->parent)->totalsize++; - hb = g_malloc(sizeof(struct _gaim_hbuddy)); + hb = g_new(struct _gaim_hbuddy, 1); hb->name = g_strdup(normalize(buddy->name)); hb->account = buddy->account; hb->group = ((GaimBlistNode*)buddy)->parent->parent; - if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) { - /* This guy already exists */ - g_free(hb->name); - g_free(hb); - } else { - g_hash_table_insert(gaimbuddylist->buddies, (gpointer)hb, (gpointer)buddy); - } + g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); @@ -683,7 +693,7 @@ { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; GaimGroup *g; - GaimBlistNode *gnode, *cnode; + GaimBlistNode *gnode, *cnode, *bnode; gboolean save = FALSE; if(!contact) @@ -721,6 +731,25 @@ ops->remove(gaimbuddylist, cnode); save = TRUE; + + if(cnode->parent != gnode) { + for(bnode = cnode->child; bnode; bnode = bnode->next) { + GaimBuddy *b = (GaimBuddy*)bnode; + + struct _gaim_hbuddy *hb = g_new(struct _gaim_hbuddy, 1); + hb->name = g_strdup(normalize(b->name)); + hb->account = b->account; + hb->group = cnode->parent; + + g_hash_table_remove(gaimbuddylist->buddies, &hb); + + hb->group = gnode; + g_hash_table_replace(gaimbuddylist->buddies, hb, b); + + if(b->account->gc) + serv_move_buddy(b, (GaimGroup*)cnode->parent, g); + } + } } if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || @@ -836,14 +865,13 @@ } } -void gaim_blist_remove_buddy (GaimBuddy *buddy) +void gaim_blist_remove_buddy (GaimBuddy *buddy) { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; GaimBlistNode *cnode, *node = (GaimBlistNode*)buddy; GaimGroup *group; - struct _gaim_hbuddy hb, *key; - struct buddy *val; + struct _gaim_hbuddy hb; cnode = node->parent; group = (GaimGroup *)cnode->parent; @@ -873,11 +901,7 @@ hb.name = normalize(buddy->name); hb.account = buddy->account; hb.group = ((GaimBlistNode*)buddy)->parent->parent; - if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { - g_hash_table_remove(gaimbuddylist->buddies, &hb); - g_free(key->name); - g_free(key); - } + g_hash_table_remove(gaimbuddylist->buddies, &hb); if(buddy->timer > 0) g_source_remove(buddy->timer);
--- a/src/dialogs.c Thu Sep 04 15:47:09 2003 +0000 +++ b/src/dialogs.c Thu Sep 04 18:40:40 2003 +0000 @@ -414,6 +414,24 @@ g_free(name); } +static void do_remove_contact(GaimContact *c) +{ + GaimBlistNode *bnode, *cnode; + GaimGroup *g; + + if(!c) + return; + + cnode = (GaimBlistNode *)c; + g = (GaimGroup*)cnode->parent; + for(bnode = cnode->child; bnode; bnode = bnode->next) { + GaimBuddy *b = (GaimBuddy*)bnode; + if(b->account->gc) + serv_remove_buddy(b->account->gc, b->name, g->name); + } + gaim_blist_remove_contact(c); +} + void do_remove_group(GaimGroup *g) { GaimBlistNode *cnode, *bnode; @@ -492,6 +510,28 @@ g_free(text); } +void show_confirm_del_contact(GaimContact *c) +{ + GaimBuddy *b = gaim_contact_get_priority_buddy(c); + + if(!b) + return; + + if(((GaimBlistNode*)c)->child == (GaimBlistNode*)b && + !((GaimBlistNode*)b)->next) { + show_confirm_del(b); + } else { + char *text = g_strdup_printf(_("You are about to remove the contact containing %s and %d other buddies from your buddy list. Do you want to continue?"), + b->name, c->totalsize - 1); + + gaim_request_action(NULL, NULL, _("Remove Contact"), text, -1, c, 2, + _("Remove Contact"), G_CALLBACK(do_remove_contact), + _("Cancel"), NULL); + + g_free(text); + } +} + /*------------------------------------------------------------------------*/ /* The dialog for getting an error */ /*------------------------------------------------------------------------*/
--- a/src/gaim.h Thu Sep 04 15:47:09 2003 +0000 +++ b/src/gaim.h Thu Sep 04 18:40:40 2003 +0000 @@ -46,6 +46,7 @@ extern void show_confirm_del(GaimBuddy *); extern void show_confirm_del_group(GaimGroup *); extern void show_confirm_del_blist_chat(GaimBlistChat *); +extern void show_confirm_del_contact(GaimContact *); /* Functions in gaimrc.c */ extern gint sort_awaymsg_list(gconstpointer, gconstpointer);