# HG changeset patch # User Sadrul Habib Chowdhury # Date 1184183072 0 # Node ID f65c287e466e2f500f5cc3404f3da620aa907b5f # Parent 53ad073898d0b44124374719b352a962cbdcf871 Update the way _get_children_names is used. applied changes from afa84ce2e5e448ce3233a9effb3136e1e23fb969 through d7c71ed89067d861b85108f04ea056f23320d33d diff -r 53ad073898d0 -r f65c287e466e finch/gntsound.c --- a/finch/gntsound.c Wed Jul 11 18:41:02 2007 +0000 +++ b/finch/gntsound.c Wed Jul 11 19:44:32 2007 +0000 @@ -597,18 +597,23 @@ GList * finch_sound_get_profiles() { - return purple_prefs_get_children_names(FINCH_PREFS_ROOT "/sound/profiles"); + GList *list = NULL, *iter; + iter = purple_prefs_get_children_names(FINCH_PREFS_ROOT "/sound/profiles"); + while (iter) { + list = g_list_append(list, g_strdup(strrchr(iter->data, '/') + 1)); + g_free(iter->data); + iter = g_list_delete_link(iter, iter); + } + return list; } static gboolean profile_exists(const char *name) { - GList *itr = NULL; - for(itr = finch_sound_get_profiles();itr;itr = itr->next){ - if(!strcmp(itr->data,name)) - return TRUE; - } - return FALSE; + char *str = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", name); + gboolean ret = purple_prefs_exists(str); + g_free(str); + return ret; } void @@ -908,6 +913,7 @@ box = gnt_hbox_new(FALSE); pref_dialog->profiles = cmbox = gnt_combo_box_new(); list = itr = finch_sound_get_profiles(); + gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, g_free); for(;itr;itr = itr->next){ gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),itr->data,itr->data); } diff -r 53ad073898d0 -r f65c287e466e libpurple/prefs.c --- a/libpurple/prefs.c Wed Jul 11 18:41:02 2007 +0000 +++ b/libpurple/prefs.c Wed Jul 11 19:44:32 2007 +0000 @@ -1325,6 +1325,24 @@ disco_callback_helper_handle(&prefs, handle); } +GList * +purple_prefs_get_children_names(const char *name) +{ + GList * list = NULL; + struct purple_pref *pref = find_pref(name), *child; + char sep[2] = "\0\0";; + + if (pref == NULL) + return NULL; + + if (name[strlen(name) - 1] != '/') + sep[0] = '/'; + for (child = pref->first_child; child; child = child->sibling) { + list = g_list_append(list, g_strdup_printf("%s%s%s", name, sep, child->name)); + } + return list; +} + void purple_prefs_update_old() { diff -r 53ad073898d0 -r f65c287e466e libpurple/prefs.h --- a/libpurple/prefs.h Wed Jul 11 18:41:02 2007 +0000 +++ b/libpurple/prefs.h Wed Jul 11 19:44:32 2007 +0000 @@ -281,6 +281,15 @@ */ 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 newly allocated strings denoting the names of the children. + * Returns @c NULL if there are no children or if pref doesn't exist. + * The caller must free all the strings and the list. + */ +GList *purple_prefs_get_children_names(const char *name); /** * Add a callback to a pref (and its children)