[network-manager-applet] gconf: handle string arrays as GPtrArrays too



commit 26614da8ff2403d6e7901e2992ba2bb18532491b
Author: Dan Williams <dcbw redhat com>
Date:   Wed Jul 28 10:59:41 2010 -0700

    gconf: handle string arrays as GPtrArrays too
    
    Necessary for some of the s390 stuff.

 src/gconf-helpers/gconf-helpers.c |   75 ++++++++++++++++++++++++++++++++++++-
 src/gconf-helpers/gconf-helpers.h |   16 +++++++-
 2 files changed, 89 insertions(+), 2 deletions(-)
---
diff --git a/src/gconf-helpers/gconf-helpers.c b/src/gconf-helpers/gconf-helpers.c
index 309be67..6fe58fc 100644
--- a/src/gconf-helpers/gconf-helpers.c
+++ b/src/gconf-helpers/gconf-helpers.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2005 - 2009 Red Hat, Inc.
+ * (C) Copyright 2005 - 2010 Red Hat, Inc.
  */
 
 #include <string.h>
@@ -284,6 +284,50 @@ out:
 	return success;
 }
 
+gboolean
+nm_gconf_get_stringarray_helper (GConfClient *client,
+                                 const char *path,
+                                 const char *key,
+                                 const char *setting,
+                                 GPtrArray **value)
+{
+	char *gc_key;
+	GConfValue *gc_value;
+	gboolean success = FALSE;
+
+	g_return_val_if_fail (key != NULL, FALSE);
+	g_return_val_if_fail (setting != NULL, FALSE);
+	g_return_val_if_fail (value != NULL, FALSE);
+	g_return_val_if_fail (*value == NULL, FALSE);
+
+	gc_key = g_strdup_printf ("%s/%s/%s", path, setting, key);
+	if (!(gc_value = gconf_client_get (client, gc_key, NULL)))
+		goto out;
+
+	if (gc_value->type == GCONF_VALUE_LIST
+	    && gconf_value_get_list_type (gc_value) == GCONF_VALUE_STRING)
+	{
+		GSList *iter, *list;
+		const char *string;
+
+		*value = g_ptr_array_sized_new (3);
+
+		list = gconf_value_get_list (gc_value);
+		for (iter = list; iter != NULL; iter = g_slist_next (iter)) {
+			string = gconf_value_get_string ((GConfValue *) iter->data);
+			g_ptr_array_add (*value, g_strdup (string));
+		}
+
+		success = TRUE;
+	}
+
+out:
+	if (gc_value)
+		gconf_value_free (gc_value);
+	g_free (gc_key);
+	return success;
+}
+
 typedef struct {
 	const char *setting_name;
 	const char *key_name;
@@ -1027,6 +1071,35 @@ nm_gconf_set_stringlist_helper (GConfClient *client,
 	return TRUE;
 }
 
+gboolean
+nm_gconf_set_stringarray_helper (GConfClient *client,
+                                 const char *path,
+                                 const char *key,
+                                 const char *setting,
+                                 GPtrArray *value)
+{
+	char *gc_key;
+	GSList *list = NULL;
+	int i;
+
+	g_return_val_if_fail (key != NULL, FALSE);
+	g_return_val_if_fail (setting != NULL, FALSE);
+
+	gc_key = g_strdup_printf ("%s/%s/%s", path, setting, key);
+	if (!gc_key) {
+		g_warning ("Not enough memory to create gconf path");
+		return FALSE;
+	}
+
+	for (i = 0; i < value->len; i++)
+		list = g_slist_append (list, g_ptr_array_index (value, i));
+
+	gconf_client_set_list (client, gc_key, GCONF_VALUE_STRING, list, NULL);
+	g_slist_free (list);
+	g_free (gc_key);
+	return TRUE;
+}
+
 static gboolean
 nm_gconf_set_mac_address_helper (GConfClient *client,
                                  const char *path,
diff --git a/src/gconf-helpers/gconf-helpers.h b/src/gconf-helpers/gconf-helpers.h
index cee0cc6..a3838ee 100644
--- a/src/gconf-helpers/gconf-helpers.h
+++ b/src/gconf-helpers/gconf-helpers.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2005 Red Hat, Inc.
+ * (C) Copyright 2005 - 2010 Red Hat, Inc.
  */
 
 #ifndef GCONF_HELPERS_H
@@ -80,6 +80,13 @@ nm_gconf_get_stringlist_helper (GConfClient *client,
 				GSList **value);
 
 gboolean
+nm_gconf_get_stringarray_helper (GConfClient *client,
+                                 const char *path,
+                                 const char *key,
+                                 const char *setting,
+                                 GPtrArray **value);
+
+gboolean
 nm_gconf_get_bytearray_helper (GConfClient *client,
 			       const char *path,
 			       const char *key,
@@ -175,6 +182,13 @@ nm_gconf_set_stringlist_helper (GConfClient *client,
                                 GSList *value);
 
 gboolean
+nm_gconf_set_stringarray_helper (GConfClient *client,
+                                 const char *path,
+                                 const char *key,
+                                 const char *setting,
+                                 GPtrArray *value);
+
+gboolean
 nm_gconf_set_bytearray_helper (GConfClient *client,
                                const char *path,
                                const char *key,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]