GConfValue* entry_get_value(Entry* e, const gchar** locales, GError** err) { const gchar* sl; g_return_val_if_fail(e != NULL, NULL); if (e->cached_value == NULL) return NULL; /* only schemas have locales for now anyway */ if (e->cached_value->type != GCONF_VALUE_SCHEMA) return e->cached_value; g_assert(e->cached_value->type == GCONF_VALUE_SCHEMA); sl = gconf_schema_get_locale(gconf_value_get_schema(e->cached_value)); gconf_log (GCL_DEBUG, "Cached schema value has locale \"%s\", looking for %s", sl ? sl : "null", locales && locales [0] ? locales[0] : "null"); /* optimize most common cases first */ if (sl == NULL && (locales == NULL || *locales == NULL)) return e->cached_value; else if (sl && locales && *locales && strcmp(sl, *locales) == 0) return e->cached_value; else { /* We want a locale other than the currently-loaded one */ GConfValue* newval; GError* error = NULL; entry_sync_if_needed(e); newval = node_extract_value(e->node, locales, &error); if (newval != NULL) { /* We found a schema with an acceptable locale */ gconf_value_free(e->cached_value); e->cached_value = newval; g_return_val_if_fail(error == NULL, e->cached_value); } else if (error != NULL) { /* There was an error */ gconf_log(GCL_WARNING, _("Ignoring XML node with name `%s': %s"), e->name, error->message); g_error_free(error); /* Fall back to currently-loaded thing if any */ } /* else fall back to the currently-loaded schema */ } return e->cached_value; }
/* Helper for utils_append_value, writes a int/string/float/bool/schema. */ static void utils_append_value_helper_fundamental (DBusMessageIter *iter, const GConfValue *value) { gint32 i; gboolean b; const gchar *s; gdouble d; d(g_print ("Append value (fundamental)\n")); switch (value->type) { case GCONF_VALUE_INT: i = gconf_value_get_int (value); dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &i); break; case GCONF_VALUE_STRING: s = gconf_value_get_string (value); dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &s); break; case GCONF_VALUE_FLOAT: d = gconf_value_get_float (value); dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &d); break; case GCONF_VALUE_BOOL: b = gconf_value_get_bool (value); dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &b); break; case GCONF_VALUE_SCHEMA: utils_append_schema (iter, gconf_value_get_schema (value)); break; default: g_assert_not_reached (); } }
/* Helper for utils_append_value, writes a list. The "list" is a struct with the * list type and an array with the values directly in it. */ static void utils_append_value_helper_list (DBusMessageIter *main_iter, const GConfValue *value) { DBusMessageIter struct_iter; DBusMessageIter array_iter; GConfValueType list_type; const gchar *array_type; GSList *list; d(g_print ("Append value (list)\n")); g_assert (value->type == GCONF_VALUE_LIST); dbus_message_iter_open_container (main_iter, DBUS_TYPE_STRUCT, NULL, /* for struct */ &struct_iter); /* Write the list type. */ list_type = gconf_value_get_list_type (value); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &list_type); /* And the value. */ switch (list_type) { case GCONF_VALUE_INT: array_type = DBUS_TYPE_INT32_AS_STRING; break; case GCONF_VALUE_STRING: array_type = DBUS_TYPE_STRING_AS_STRING; break; case GCONF_VALUE_FLOAT: array_type = DBUS_TYPE_DOUBLE_AS_STRING; break; case GCONF_VALUE_BOOL: array_type = DBUS_TYPE_BOOLEAN_AS_STRING; break; case GCONF_VALUE_SCHEMA: array_type = DBUS_TYPE_STRUCT_AS_STRING; break; default: array_type = NULL; g_assert_not_reached (); } dbus_message_iter_open_container (&struct_iter, DBUS_TYPE_ARRAY, array_type, &array_iter); list = gconf_value_get_list (value); switch (list_type) { case GCONF_VALUE_STRING: while (list) { const gchar *s; s = gconf_value_get_string (list->data); dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &s); list = list->next; } break; case GCONF_VALUE_INT: while (list) { gint32 i; i = gconf_value_get_int (list->data); dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_INT32, &i); list = list->next; } break; case GCONF_VALUE_FLOAT: while (list) { gdouble d; d = gconf_value_get_float (list->data); dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_DOUBLE, &d); list = list->next; } break; case GCONF_VALUE_BOOL: while (list) { gboolean b; b = gconf_value_get_bool (list->data); dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_BOOLEAN, &b); list = list->next; } break; case GCONF_VALUE_SCHEMA: while (list) { GConfSchema *schema; schema = gconf_value_get_schema (list->data); utils_append_schema (&array_iter, schema); list = list->next; } break; default: g_assert_not_reached (); } dbus_message_iter_close_container (&struct_iter, &array_iter); dbus_message_iter_close_container (main_iter, &struct_iter); }
static void node_set_schema_value(xmlNodePtr node, GConfValue* value) { GConfSchema* sc; const gchar* locale; const gchar* type; xmlNodePtr found = NULL; sc = gconf_value_get_schema (value); /* Set the types */ if (gconf_schema_get_list_type (sc) != GCONF_VALUE_INVALID) { type = gconf_value_type_to_string(gconf_schema_get_list_type (sc)); g_assert(type != NULL); my_xmlSetProp(node, "list_type", type); } if (gconf_schema_get_car_type (sc) != GCONF_VALUE_INVALID) { type = gconf_value_type_to_string(gconf_schema_get_car_type (sc)); g_assert(type != NULL); my_xmlSetProp(node, "car_type", type); } if (gconf_schema_get_cdr_type (sc) != GCONF_VALUE_INVALID) { type = gconf_value_type_to_string(gconf_schema_get_cdr_type (sc)); g_assert(type != NULL); my_xmlSetProp(node, "cdr_type", type); } /* unset this in case the node was previously a different type */ my_xmlSetProp(node, "value", NULL); /* set the cross-locale attributes */ my_xmlSetProp(node, "stype", gconf_value_type_to_string(gconf_schema_get_type (sc))); my_xmlSetProp(node, "owner", gconf_schema_get_owner (sc)); locale = gconf_schema_get_locale(sc); gconf_log(GCL_DEBUG, "Setting XML node to schema with locale `%s'", locale); /* Find the node for this locale */ found = find_schema_subnode_by_locale(node, locale); if (found == NULL) found = xmlNewChild(node, NULL, (xmlChar *)"local_schema", NULL); /* OK if these are set to NULL, since that unsets the property */ my_xmlSetProp(found, "locale", gconf_schema_get_locale (sc)); my_xmlSetProp(found, "short_desc", gconf_schema_get_short_desc (sc)); free_childs(found); if (gconf_schema_get_default_value (sc) != NULL) { xmlNodePtr default_value_node; default_value_node = xmlNewChild(found, NULL, (xmlChar *)"default", NULL); node_set_value(default_value_node, gconf_schema_get_default_value (sc)); } if (gconf_schema_get_long_desc (sc)) { xmlNewChild(found, NULL, (xmlChar *)"longdesc", (xmlChar *)gconf_schema_get_long_desc (sc)); } }