# HG changeset patch # User Eric Polino # Date 1184016548 0 # Node ID 0e30dfac1f46e1cb80867906a671333098c6a4a8 # Parent 3bec25803a00f18fb201633c04e25a04f543763d Added a function to the prefs API to get a list of children names. diff -r 3bec25803a00 -r 0e30dfac1f46 libpurple/prefs.c --- a/libpurple/prefs.c Sat Jul 07 01:30:42 2007 +0000 +++ b/libpurple/prefs.c Mon Jul 09 21:29:08 2007 +0000 @@ -35,6 +35,7 @@ #include "prefs.h" #include "debug.h" #include "util.h" +#include "xmlnode.h" #ifdef _WIN32 #include "win32dep.h" @@ -126,6 +127,7 @@ xmlnode_set_attrib(node, "name", pref->name); /* Set the type of this node (if type == PURPLE_PREF_NONE then do nothing) */ + /* XXX: Why aren't we using a switch here? */ if (pref->type == PURPLE_PREF_INT) { xmlnode_set_attrib(node, "type", "int"); snprintf(buf, sizeof(buf), "%d", pref->value.integer); @@ -1325,6 +1327,36 @@ disco_callback_helper_handle(&prefs, handle); } +static xmlnode* +single_pref_to_xmlnode(const struct purple_pref *pref) +{ + xmlnode *node; + struct purple_pref *child; + + node = xmlnode_new("pref"); + xmlnode_set_attrib(node,"name",pref->name); + + for(child = pref->first_child; child != NULL; child = child->sibling) + pref_to_xmlnode(node, child); + + return node; +} + +GList * +purple_prefs_get_children_names(const char *name) +{ + struct purple_pref *pref = find_pref(name); + xmlnode * node = single_pref_to_xmlnode(pref); + xmlnode * child = node->child; + GList * list = NULL; + + for(child = node->child;child;child = child->next){ + list = g_list_append(list,xmlnode_get_attrib(child,"name")); + } + return list; + +} + void purple_prefs_update_old() { diff -r 3bec25803a00 -r 0e30dfac1f46 libpurple/prefs.h --- a/libpurple/prefs.h Sat Jul 07 01:30:42 2007 +0000 +++ b/libpurple/prefs.h Mon Jul 09 21:29:08 2007 +0000 @@ -281,6 +281,14 @@ */ GList *purple_prefs_get_path_list(const char *name); +/* + * Returns a list of children for a pref + * + * @param name The parent pref + * @return A list of strings denoting the names of the children, NULL if there are no children or if pref doesn't exist. + * + */ +GList *purple_prefs_get_children_names(const char *name); /** * Add a callback to a pref (and its children)