Commit dc429d73 authored by Brian J. Tarricone's avatar Brian J. Tarricone Committed by Brian Tarricone
Browse files

add xfconf_array_values_from_gvalue() -- convenient array decomposer

FIXME: handles int16 as if they were int32
parent f7effe69
......@@ -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>
......
......@@ -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>
......
......@@ -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:
......
......@@ -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;
......
......@@ -28,6 +28,7 @@
xfconf_init
xfconf_shutdown
xfconf_named_struct_register
xfconf_array_values_from_gvalue
xfconf_array_free
#endif
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment