[Xfce4-commits] <xfconf:gvalue-array-conv> add xfconf_array_values_from_gvalue() -- convenient array decomposer

Brian J. Tarricone noreply at xfce.org
Fri Jan 29 07:16:04 CET 2010


Updating branch refs/heads/gvalue-array-conv
         to dc429d734fb39bb73791b16220edc0f33eb94d46 (commit)
       from f7effe6907669d8ed9d1ee4fa2c09bc451df66cd (commit)

commit dc429d734fb39bb73791b16220edc0f33eb94d46
Author: Brian J. Tarricone <bjt23 at cornell.edu>
Date:   Wed Aug 27 23:46:52 2008 -0700

    add xfconf_array_values_from_gvalue() -- convenient array decomposer
    
    FIXME: handles int16 as if they were int32

 docs/reference/tmpl/xfconf.sgml    |   11 +++++++
 docs/reference/xfconf-sections.txt |    1 +
 xfconf/xfconf.c                    |   57 ++++++++++++++++++++++++++++++++++++
 xfconf/xfconf.h                    |    4 ++
 xfconf/xfconf.symbols              |    1 +
 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>
+
+ at value: 
+ at member_index: 
+ at Varargs: 
+ at 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



More information about the Xfce4-commits mailing list