static GConfValue * utils_get_schema_value (DBusMessageIter *iter) { GConfSchema *schema; GConfValue *value; schema = utils_get_schema (iter); value = gconf_value_new (GCONF_VALUE_SCHEMA); gconf_value_set_schema_nocopy (value, schema); return value; }
/* Helper for utils_get_value, reads int/string/float/bool/schema. */ static GConfValue * utils_get_value_helper_fundamental (DBusMessageIter *iter, GConfValueType value_type) { GConfValue *value; GConfSchema *schema; gint32 i; const gchar *s; gdouble d; gboolean b; d(g_print ("Get value (fundamental)\n")); if (value_type == GCONF_VALUE_INVALID) return NULL; value = gconf_value_new (value_type); switch (value_type) { case GCONF_VALUE_INT: dbus_message_iter_get_basic (iter, &i); gconf_value_set_int (value, i); break; case GCONF_VALUE_STRING: dbus_message_iter_get_basic (iter, &s); gconf_value_set_string (value, s); break; case GCONF_VALUE_FLOAT: dbus_message_iter_get_basic (iter, &d); gconf_value_set_float (value, d); break; case GCONF_VALUE_BOOL: dbus_message_iter_get_basic (iter, &b); gconf_value_set_bool (value, b); break; case GCONF_VALUE_SCHEMA: schema = utils_get_schema (iter); gconf_value_set_schema_nocopy (value, schema); break; default: g_assert_not_reached (); } return value; }
static GConfValue* schema_node_extract_value(xmlNodePtr node, const gchar** locales) { GConfValue* value = NULL; gchar* owner_str; gchar* stype_str; gchar* list_type_str; gchar* car_type_str; gchar* cdr_type_str; GConfSchema* sc; xmlNodePtr iter; guint i; xmlNodePtr* localized_nodes; xmlNodePtr best = NULL; /* owner, type are for all locales; default value, descriptions are per-locale */ owner_str = my_xmlGetProp(node, "owner"); stype_str = my_xmlGetProp(node, "stype"); list_type_str = my_xmlGetProp(node, "list_type"); car_type_str = my_xmlGetProp(node, "car_type"); cdr_type_str = my_xmlGetProp(node, "cdr_type"); sc = gconf_schema_new(); if (owner_str) { gconf_schema_set_owner(sc, owner_str); xmlFree(owner_str); } if (stype_str) { GConfValueType stype; stype = gconf_value_type_from_string(stype_str); gconf_schema_set_type(sc, stype); xmlFree(stype_str); } if (list_type_str) { GConfValueType type; type = gconf_value_type_from_string(list_type_str); gconf_schema_set_list_type(sc, type); xmlFree(list_type_str); } if (car_type_str) { GConfValueType type; type = gconf_value_type_from_string(car_type_str); gconf_schema_set_car_type(sc, type); xmlFree(car_type_str); } if (cdr_type_str) { GConfValueType type; type = gconf_value_type_from_string(cdr_type_str); gconf_schema_set_cdr_type(sc, type); xmlFree(cdr_type_str); } if (locales != NULL && locales[0]) { /* count the number of possible locales */ int n_locales; n_locales = 0; while (locales[n_locales]) ++n_locales; localized_nodes = g_new0(xmlNodePtr, n_locales); /* Find the node for each possible locale */ iter = node->xmlChildrenNode; while (iter != NULL) { if (iter->type == XML_ELEMENT_NODE && strcmp((char *)iter->name, "local_schema") == 0) { char* locale_name; locale_name = my_xmlGetProp(iter, "locale"); if (locale_name != NULL) { i = 0; while (locales[i]) { if (strcmp(locales[i], locale_name) == 0) { localized_nodes[i] = iter; break; } ++i; } xmlFree(locale_name); /* Quit as soon as we have the best possible locale */ if (localized_nodes[0] != NULL) break; } } iter = iter->next; } /* See which is the best locale we managed to load, they are in order of preference. */ i = 0; best = localized_nodes[i]; while (best == NULL && i < n_locales) { best = localized_nodes[i]; ++i; } g_free(localized_nodes); } /* If no locale matched, try picking the the null localization, * and then try picking the first node */ if (best == NULL) best = find_schema_subnode_by_locale (node, NULL); if (best == NULL) { best = node->xmlChildrenNode; while (best && best->type != XML_ELEMENT_NODE) best = best->next; } /* Extract info from the best locale node */ if (best != NULL) schema_subnode_extract_data(best, sc); /* Create a GConfValue with this schema and return it */ value = gconf_value_new(GCONF_VALUE_SCHEMA); gconf_value_set_schema_nocopy(value, sc); return value; }