/* Writes a schema, which is a struct. */ static void utils_append_schema (DBusMessageIter *main_iter, const GConfSchema *schema) { DBusMessageIter struct_iter; gint32 i; const gchar *s; GConfValue *default_value; dbus_message_iter_open_container (main_iter, DBUS_TYPE_STRUCT, NULL, /* for structs */ &struct_iter); i = gconf_schema_get_type (schema); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i); i = gconf_schema_get_list_type (schema); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i); i = gconf_schema_get_car_type (schema); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i); i = gconf_schema_get_cdr_type (schema); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &i); s = gconf_schema_get_locale (schema); utils_append_optional_string (&struct_iter, s); s = gconf_schema_get_short_desc (schema); utils_append_optional_string (&struct_iter, s); s = gconf_schema_get_long_desc (schema); utils_append_optional_string (&struct_iter, s); s = gconf_schema_get_owner (schema); utils_append_optional_string (&struct_iter, s); default_value = gconf_schema_get_default_value (schema); /* We don't need to do this, but it's much simpler */ if (default_value) { gchar *encoded; encoded = gconf_value_encode (default_value); g_assert (encoded != NULL); dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &encoded); g_free (encoded); } else { s = ""; dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s); } if (!dbus_message_iter_close_container (main_iter, &struct_iter)) g_error ("Out of memory"); }
static void install_default_macros_list (GConfClient *client, const char *key, int offset) { GConfSchema *schema; GConfValue *value; GSList *list = NULL; GError *error; int i; error = NULL; schema = gconf_client_get_schema (client, key, &error); if (error) { g_warning (_("Cannot get schema for %s: %s"), key, error->message); g_error_free (error); return; } /* gconf has started to return NULL with no error set. */ g_return_if_fail (schema != NULL); /* Some sanity checks */ g_assert (gconf_schema_get_type (schema) == GCONF_VALUE_LIST); g_assert (gconf_schema_get_list_type (schema) == GCONF_VALUE_STRING); value = gconf_value_new (GCONF_VALUE_LIST); gconf_value_set_list_type (value, GCONF_VALUE_STRING); for (i = 0; i < G_N_ELEMENTS (mc_default_macros); i++) list = g_slist_prepend (list, gconf_value_new_from_string (GCONF_VALUE_STRING, G_STRUCT_MEMBER (char *, &mc_default_macros [i], offset), NULL)); list = g_slist_reverse (list); gconf_value_set_list_nocopy (value, list); list = NULL; gconf_schema_set_default_value_nocopy (schema, value); value = NULL; error = NULL; gconf_client_set_schema (client, key, schema, &error); if (error) { g_warning (_("Cannot set schema for %s: %s"), key, error->message); g_error_free (error); } gconf_schema_free (schema); printf (_("Set default list value for %s\n"), key); }
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)); } }