# HG changeset patch # User Nathan Walp # Date 1176936972 0 # Node ID 28b52d87392e40b82eef83be7d1f237673a794b5 # Parent 2663150c0a9fe411753619426928fad61e369c27 This lets you rename entire trees of prefs. This should help with the migration this has received exactly zero testing, but since I know a couple people wanted to work on prefs migration soon, I figured I'd commit it. diff -r 2663150c0a9f -r 28b52d87392e libpurple/prefs.c --- a/libpurple/prefs.c Sun Apr 15 20:00:30 2007 +0000 +++ b/libpurple/prefs.c Wed Apr 18 22:56:12 2007 +0000 @@ -1090,30 +1090,30 @@ return ret; } -void -purple_prefs_rename(const char *oldname, const char *newname) +static void +purple_prefs_rename_node(struct purple_pref *oldpref, struct purple_pref *newpref) { - struct purple_pref *oldpref, *newpref; - - oldpref = find_pref(oldname); - - /* it's already been renamed, call off the dogs */ - if(!oldpref) - return; + struct purple_pref *child; + char *oldname, *newname; - if (oldpref->first_child != NULL) /* can't rename parents */ + /* if we're a parent, rename the kids first */ + for(child = oldpref->first_child; child != NULL; child = child->sibling) { - purple_debug_error("prefs", "Unable to rename %s to %s: can't rename parents\n", oldname, newname); - return; - } - - - newpref = find_pref(newname); - - if (newpref == NULL) - { - purple_debug_error("prefs", "Unable to rename %s to %s: new pref not created\n", oldname, newname); - return; + struct purple_pref *newchild; + for(newchild = newpref->first_child; newchild != NULL; newchild = newchild->sibling) + { + if(!strcmp(child->name, newchild->name)) + { + purple_prefs_rename_node(child, newchild); + break; + } + } + if(newchild == NULL) { + /* no rename happened, we weren't able to find the new pref */ + char *tmpname = pref_full_name(child); + gaim_debug_error("prefs", "Unable to find rename pref for %s", tmpname); + g_free(tmpname); + } } if (oldpref->type != newpref->type) @@ -1122,7 +1122,11 @@ return; } + oldname = pref_full_name(oldpref); + newname = pref_full_name(newpref); purple_debug_info("prefs", "Renaming %s to %s\n", oldname, newname); + g_free(oldname); + g_free(newname); switch(oldpref->type) { case PURPLE_PREF_NONE: @@ -1151,6 +1155,28 @@ } void +purple_prefs_rename(const char *oldname, const char *newname) +{ + struct purple_pref *oldpref, *newpref; + + oldpref = find_pref(oldname); + + /* it's already been renamed, call off the dogs */ + if(!oldpref) + return; + + newpref = find_pref(newname); + + if (newpref == NULL) + { + purple_debug_error("prefs", "Unable to rename %s to %s: new pref not created\n", oldname, newname); + return; + } + + purple_prefs_rename_node(oldpref, newpref); +} + +void purple_prefs_rename_boolean_toggle(const char *oldname, const char *newname) { struct purple_pref *oldpref, *newpref;