From: Nathan W. <fac...@us...> - 2003-05-10 17:32:12
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1:/tmp/cvs-serv7198/src Modified Files: blist.c dialogs.c Log Message: 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. Index: blist.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/blist.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- blist.c 6 May 2003 05:28:41 -0000 1.13 +++ blist.c 10 May 2003 17:32:02 -0000 1.14 @@ -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) Index: dialogs.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/dialogs.c,v retrieving revision 1.469 retrieving revision 1.470 diff -u -d -r1.469 -r1.470 --- dialogs.c 6 May 2003 05:48:02 -0000 1.469 +++ dialogs.c 10 May 2003 17:32:05 -0000 1.470 @@ -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); } |