Mercurial > pidgin
changeset 5346:c1e7c3f72128
[gaim-migrate @ 5722]
I think this group rename code is eleventy billion times better than the old
stuff. better in such a way that it shouldn't crash, shouldn't leak memory,
and shouldn't pain anyone's soul to look at.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 10 May 2003 17:32:05 +0000 |
parents | bfe98c4d331e |
children | ae2c9a35bc7d |
files | src/blist.c src/dialogs.c |
diffstat | 2 files changed, 45 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Sat May 10 15:33:48 2003 +0000 +++ b/src/blist.c Sat May 10 17:32:05 2003 +0000 @@ -265,10 +265,49 @@ void gaim_blist_rename_group(struct group *group, const char *name) { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; - g_free(group->name); - group->name = g_strdup(name); - if (ops) - ops->update(gaimbuddylist, (GaimBlistNode*)group); + struct group *dest_group; + GaimBlistNode *prev, *child, *next; + GSList *accts; + + if(!name || !strlen(name) || !strcmp(name, group->name)) { + /* nothing to do here */ + return; + } else if((dest_group = gaim_find_group(name))) { + /* here we're merging two groups */ + prev = gaim_blist_get_last_child((GaimBlistNode*)dest_group); + child = ((GaimBlistNode*)group)->child; + + while(child) + { + next = child->next; + if(GAIM_BLIST_NODE_IS_BUDDY(child)) { + gaim_blist_add_buddy((struct buddy *)child, dest_group, prev); + prev = child; + } else if(GAIM_BLIST_NODE_IS_CHAT(child)) { + gaim_blist_add_chat((struct chat *)child, dest_group, prev); + prev = child; + } else { + gaim_debug(GAIM_DEBUG_ERROR, "blist", + "Unknown child type in group %s\n", group->name); + } + child = next; + } + for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { + struct gaim_account *account = accts->data; + serv_rename_group(account->gc, group, name); + } + gaim_blist_remove_group(group); + } else { + /* a simple rename */ + for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { + struct gaim_account *account = accts->data; + serv_rename_group(account->gc, group, name); + } + g_free(group->name); + group->name = g_strdup(name); + if (ops) + ops->update(gaimbuddylist, (GaimBlistNode*)group); + } } struct chat *gaim_chat_new(struct gaim_account *account, const char *alias, GHashTable *components)
--- a/src/dialogs.c Sat May 10 15:33:48 2003 +0000 +++ b/src/dialogs.c Sat May 10 17:32:05 2003 +0000 @@ -4276,38 +4276,13 @@ const char *new_name; struct group *g; struct group *orig; - GSList *accts; if (resp == GTK_RESPONSE_OK) { - new_name = gtk_entry_get_text(GTK_ENTRY(entry)); g = g_object_get_data(G_OBJECT(entry), "group"); - if (new_name && (strlen(new_name) != 0) && strcmp(new_name, g->name)) { - char *prevname; - - if ((orig = gaim_find_group(new_name)) != NULL && gaim_utf8_strcasecmp(new_name, g->name)) { - gaim_blist_rename_group(orig, g->name); - accts = gaim_group_get_accounts(g); - while(accts) { - struct gaim_account *account = accts->data; - serv_rename_group(account->gc, g, new_name); - accts = g_slist_remove(accts, accts->data); - } - g_free(g); - } else { - prevname = g_strdup(g->name); - accts = gaim_group_get_accounts(g); - while(accts) { - struct gaim_account *account = accts->data; - serv_rename_group(account->gc, g, new_name); - accts = g_slist_remove(accts, accts->data); - } - gaim_blist_rename_group(g, new_name); - g_free(prevname); - } - gaim_blist_save(); - } + gaim_blist_rename_group(g, new_name); + gaim_blist_save(); } destroy_dialog(rename_dialog, rename_dialog); }