/* Helper for utils_append_value, writes a pair. The pair is a struct with the * two values and two fundamental values (type, value, type value). */ static void utils_append_value_helper_pair (DBusMessageIter *main_iter, const GConfValue *value) { DBusMessageIter struct_iter; GConfValue *car, *cdr; gint32 type; d(g_print ("Append value (pair)\n")); g_assert (value->type == GCONF_VALUE_PAIR); dbus_message_iter_open_container (main_iter, DBUS_TYPE_STRUCT, NULL, /* for struct */ &struct_iter); car = gconf_value_get_car (value); cdr = gconf_value_get_cdr (value); /* The pair types. */ if (car) type = car->type; else type = GCONF_VALUE_INVALID; dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &type); if (cdr) type = cdr->type; else type = GCONF_VALUE_INVALID; dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &type); /* The values. */ if (car) utils_append_value_helper_fundamental (&struct_iter, car); if (cdr) utils_append_value_helper_fundamental (&struct_iter, cdr); dbus_message_iter_close_container (main_iter, &struct_iter); }
SCM gconf_value_to_scm(GConfValue* val) { SCM retval = SCM_EOL; if (val == NULL) return SCM_EOL; switch (val->type) { case GCONF_VALUE_INVALID: /* EOL */ break; case GCONF_VALUE_STRING: retval = gh_str02scm(gconf_value_get_string(val)); break; case GCONF_VALUE_INT: retval = gh_int2scm(gconf_value_get_int(val)); break; case GCONF_VALUE_FLOAT: retval = gh_double2scm(gconf_value_get_float(val)); break; case GCONF_VALUE_BOOL: retval = gh_bool2scm(gconf_value_get_bool(val)); break; case GCONF_VALUE_SCHEMA: /* FIXME this is more complicated, we need a smob or something */ break; case GCONF_VALUE_LIST: /* FIXME This is complicated too... */ break; case GCONF_VALUE_PAIR: retval = gh_cons(gconf_value_to_scm(gconf_value_get_car(val)), gconf_value_to_scm(gconf_value_get_cdr(val))); break; default: g_warning("Unhandled type in %s", G_STRFUNC); break; } return retval; }
static GVariant * gconf_settings_backend_gconf_value_to_gvariant (GConfValue *gconf_value, const GVariantType *expected_type) { switch (gconf_value->type) { case GCONF_VALUE_STRING: case GCONF_VALUE_INT: case GCONF_VALUE_FLOAT: case GCONF_VALUE_BOOL: if (!gconf_settings_backend_simple_gconf_value_type_is_compatible (gconf_value->type, expected_type)) return NULL; return gconf_settings_backend_simple_gconf_value_type_to_gvariant (gconf_value, expected_type); case GCONF_VALUE_LIST: { GConfValueType list_type; const GVariantType *array_type; GSList *list; GPtrArray *array; GVariant *result; if (!g_variant_type_is_array (expected_type)) return NULL; list_type = gconf_value_get_list_type (gconf_value); array_type = g_variant_type_element (expected_type); if (!gconf_settings_backend_simple_gconf_value_type_is_compatible (list_type, array_type)) return NULL; array = g_ptr_array_new (); for (list = gconf_value_get_list (gconf_value); list != NULL; list = list->next) { GVariant *variant; variant = gconf_settings_backend_simple_gconf_value_type_to_gvariant (list->data, array_type); g_ptr_array_add (array, variant); } result = g_variant_new_array (array_type, (GVariant **) array->pdata, array->len); g_ptr_array_free (array, TRUE); return result; } break; case GCONF_VALUE_PAIR: { GConfValue *car; GConfValue *cdr; const GVariantType *first_type; const GVariantType *second_type; GVariant *tuple[2]; GVariant *result; if (!g_variant_type_is_tuple (expected_type) || g_variant_type_n_items (expected_type) != 2) return NULL; car = gconf_value_get_car (gconf_value); cdr = gconf_value_get_cdr (gconf_value); first_type = g_variant_type_first (expected_type); second_type = g_variant_type_next (first_type); if (!gconf_settings_backend_simple_gconf_value_type_is_compatible (car->type, first_type) || !gconf_settings_backend_simple_gconf_value_type_is_compatible (cdr->type, second_type)) return NULL; tuple[0] = gconf_settings_backend_simple_gconf_value_type_to_gvariant (car, first_type); tuple[1] = gconf_settings_backend_simple_gconf_value_type_to_gvariant (cdr, second_type); result = g_variant_new_tuple (tuple, 2); return result; } break; default: return NULL; } g_assert_not_reached (); return NULL; }
static void node_set_value(xmlNodePtr node, GConfValue* value) { const gchar* type; gchar* value_str; g_return_if_fail(node != NULL); g_return_if_fail(value != NULL); g_return_if_fail(value->type != GCONF_VALUE_INVALID); type = gconf_value_type_to_string(value->type); g_assert(type != NULL); my_xmlSetProp(node, "type", type); switch (value->type) { case GCONF_VALUE_INT: case GCONF_VALUE_FLOAT: case GCONF_VALUE_BOOL: free_childs(node); value_str = gconf_value_to_string(value); my_xmlSetProp(node, "value", value_str); g_free(value_str); break; case GCONF_VALUE_STRING: { xmlChar* encoded; free_childs(node); encoded = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)gconf_value_get_string(value)); xmlNewChild(node, NULL, (xmlChar *)"stringvalue", encoded); xmlFree(encoded); } break; case GCONF_VALUE_SCHEMA: { node_set_schema_value(node, value); } break; case GCONF_VALUE_LIST: { GSList* list; free_childs(node); my_xmlSetProp(node, "ltype", gconf_value_type_to_string(gconf_value_get_list_type(value))); /* Add a new child for each node */ list = gconf_value_get_list(value); while (list != NULL) { xmlNodePtr child; /* this is O(1) because libxml saves the list tail */ child = xmlNewChild(node, NULL, (xmlChar *)"li", NULL); g_return_if_fail(list->data != NULL); node_set_value(child, (GConfValue*)list->data); list = g_slist_next(list); } } break; case GCONF_VALUE_PAIR: { xmlNodePtr car, cdr; free_childs(node); car = xmlNewChild(node, NULL, (xmlChar *)"car", NULL); cdr = xmlNewChild(node, NULL, (xmlChar *)"cdr", NULL); g_return_if_fail(gconf_value_get_car(value) != NULL); g_return_if_fail(gconf_value_get_cdr(value) != NULL); node_set_value(car, gconf_value_get_car(value)); node_set_value(cdr, gconf_value_get_cdr(value)); } break; default: g_assert_not_reached(); break; } }