summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian J. Tarricone <bjt23@cornell.edu>2008-08-27 23:46:52 -0700
committerBrian J. Tarricone <brian@tarricone.org>2009-08-13 00:48:26 -0700
commitdc429d734fb39bb73791b16220edc0f33eb94d46 (patch)
tree3f0365e1bdf04f029e09c23bfbd48a8e5645e43e
parentf7effe6907669d8ed9d1ee4fa2c09bc451df66cd (diff)
downloadxfconf-gvalue-array-conv.tar.gz
add xfconf_array_values_from_gvalue() -- convenient array decomposergvalue-array-conv
FIXME: handles int16 as if they were int32
-rw-r--r--docs/reference/tmpl/xfconf.sgml11
-rw-r--r--docs/reference/xfconf-sections.txt1
-rw-r--r--xfconf/xfconf.c57
-rw-r--r--xfconf/xfconf.h4
-rw-r--r--xfconf/xfconf.symbols1
5 files changed, 74 insertions, 0 deletions
diff --git a/docs/reference/tmpl/xfconf.sgml b/docs/reference/tmpl/xfconf.sgml
index c991b63..a803a34 100644
--- a/docs/reference/tmpl/xfconf.sgml
+++ b/docs/reference/tmpl/xfconf.sgml
@@ -48,6 +48,17 @@ resources.
@member_types:
+<!-- ##### FUNCTION xfconf_array_values_from_gvalue ##### -->
+<para>
+
+</para>
+
+@value:
+@member_index:
+@Varargs:
+@Returns:
+
+
<!-- ##### FUNCTION xfconf_array_free ##### -->
<para>
diff --git a/docs/reference/xfconf-sections.txt b/docs/reference/xfconf-sections.txt
index 1cdc0f2..71b8b1f 100644
--- a/docs/reference/xfconf-sections.txt
+++ b/docs/reference/xfconf-sections.txt
@@ -72,6 +72,7 @@ xfconf_backend_get_type
xfconf_init
xfconf_shutdown
xfconf_named_struct_register
+xfconf_array_values_from_gvalue
xfconf_array_free
</SECTION>
diff --git a/xfconf/xfconf.c b/xfconf/xfconf.c
index 04218f8..cb94708 100644
--- a/xfconf/xfconf.c
+++ b/xfconf/xfconf.c
@@ -26,6 +26,7 @@
#endif
#include <glib-object.h>
+#include <gobject/gvaluecollector.h>
#include <dbus/dbus-glib.h>
@@ -224,6 +225,62 @@ xfconf_named_struct_register(const gchar *struct_name,
}
}
+/**
+ * xfconf_array_values_from_gvalue:
+ * @value: A #GValue containing a #GPtrArray
+ * @member_index: the index of the first item to retrieve from the array
+ * @...: variable arguments
+ *
+ * Convenience function to retrieve array values from a #GValue returned
+ * by Xfconf. The variable arguments should start with a pointer to a
+ * location to store the value at index @member_index. Further vararg
+ * pairs should be (index, pointer location). Terminate the argument
+ * list with G_MAXUINT.
+ *
+ * Returns: %TRUE if all values were copied, %FALSE on error.
+ **/
+gboolean
+xfconf_array_values_from_gvalue(const GValue *value,
+ gint member_index,
+ ...)
+{
+ va_list var_args;
+ GPtrArray *arr;
+ guint cur_i;
+ GValue *val_arr;
+
+ arr = g_value_get_boxed(value);
+ if(!arr)
+ return FALSE;
+
+ va_start(var_args, member_index);
+
+ for(cur_i = member_index; cur_i != G_MAXUINT; cur_i = va_arg(var_args,
+ guint))
+ {
+ gchar *errstr = NULL;
+
+ if(cur_i >= arr->len) {
+ va_end(var_args);
+ return FALSE;
+ }
+
+ val_arr = g_ptr_array_index(arr, cur_i);
+ G_VALUE_LCOPY(val_arr, var_args, 0, &errstr);
+ if(errstr) {
+ g_warning("Unable to convert value at position %d: %s",
+ cur_i, errstr);
+ g_free(errstr);
+ va_end(var_args);
+ return FALSE;
+ }
+ }
+
+ va_end(var_args);
+
+ return TRUE;
+}
+
#if 0
/**
* xfconf_array_new:
diff --git a/xfconf/xfconf.h b/xfconf/xfconf.h
index 1d3258a..7e1bb13 100644
--- a/xfconf/xfconf.h
+++ b/xfconf/xfconf.h
@@ -40,6 +40,10 @@ void xfconf_named_struct_register(const gchar *struct_name,
guint n_members,
const GType *member_types);
+gboolean xfconf_array_values_from_gvalue(const GValue *value,
+ gint member_index,
+ ...);
+
void xfconf_array_free(GPtrArray *arr);
gchar **xfconf_list_channels(void) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/xfconf/xfconf.symbols b/xfconf/xfconf.symbols
index d047bb1..f1a037f 100644
--- a/xfconf/xfconf.symbols
+++ b/xfconf/xfconf.symbols
@@ -28,6 +28,7 @@
xfconf_init
xfconf_shutdown
xfconf_named_struct_register
+xfconf_array_values_from_gvalue
xfconf_array_free
#endif
#endif