static void check_unset(MateConfEngine* conf) { GError* err = NULL; const gchar** keyp = NULL; MateConfChangeSet* cs; cs = mateconf_change_set_new(); keyp = keys; while (*keyp) { mateconf_change_set_unset(cs, *keyp); ++keyp; } mateconf_engine_commit_change_set(conf, cs, TRUE, &err); if (err != NULL) { fprintf(stderr, "unset commit failed: %s\n", err->message); g_error_free(err); err = NULL; exit(1); } mateconf_change_set_unref(cs); keyp = keys; while (*keyp) { MateConfValue* val; gchar* valstr; val = mateconf_engine_get (conf, *keyp, &err); if (val) valstr = mateconf_value_to_string(val); else valstr = g_strdup("(none)"); check(val == NULL, "unsetting a previously-set value `%s' the value `%s' existed", *keyp, valstr); g_free(valstr); ++keyp; } }
static gchar* get_default_string_from_key(MateConfClient* client, const char* key) { gchar* str = NULL; MateConfValue* value = mateconf_client_get_default_from_schema(client, key, NULL); if (value) { if (value->type == MATECONF_VALUE_STRING) { str = mateconf_value_to_string (value); } mateconf_value_free (value); } return str; }
gchar* mateconf_value_to_string(const MateConfValue* value) { /* These strings shouldn't be translated; they're primarily intended for machines to read, not humans, though I do use them in some debug spew */ gchar* retval = NULL; switch (value->type) { case MATECONF_VALUE_INT: retval = g_strdup_printf("%d", mateconf_value_get_int(value)); break; case MATECONF_VALUE_FLOAT: retval = mateconf_double_to_string(mateconf_value_get_float(value)); break; case MATECONF_VALUE_STRING: retval = g_strdup(mateconf_value_get_string(value)); break; case MATECONF_VALUE_BOOL: retval = mateconf_value_get_bool(value) ? g_strdup("true") : g_strdup("false"); break; case MATECONF_VALUE_LIST: { GSList* list; list = mateconf_value_get_list(value); if (list == NULL) retval = g_strdup("[]"); else { gchar* buf = NULL; guint bufsize = 64; guint cur = 0; g_assert(list != NULL); buf = g_malloc(bufsize+3); /* my +3 superstition */ buf[0] = '['; ++cur; g_assert(cur < bufsize); while (list != NULL) { gchar* tmp; gchar* elem; guint len; tmp = mateconf_value_to_string((MateConfValue*)list->data); g_assert(tmp != NULL); elem = escape_string(tmp, ",]"); g_free(tmp); len = strlen(elem); if ((cur + len + 2) >= bufsize) /* +2 for '\0' and comma */ { bufsize = MAX(bufsize*2, bufsize+len+4); buf = g_realloc(buf, bufsize+3); } g_assert(cur < bufsize); strcpy(&buf[cur], elem); cur += len; g_assert(cur < bufsize); g_free(elem); buf[cur] = ','; ++cur; g_assert(cur < bufsize); list = g_slist_next(list); } g_assert(cur < bufsize); buf[cur-1] = ']'; /* overwrites last comma */ buf[cur] = '\0'; retval = buf; } } break; case MATECONF_VALUE_PAIR: { gchar* tmp; gchar* car; gchar* cdr; if (mateconf_value_get_car (value)) tmp = mateconf_value_to_string(mateconf_value_get_car(value)); else tmp = g_strdup ("nil"); car = escape_string(tmp, ",)"); g_free(tmp); if (mateconf_value_get_cdr (value)) tmp = mateconf_value_to_string(mateconf_value_get_cdr(value)); else tmp = g_strdup ("nil"); cdr = escape_string(tmp, ",)"); g_free(tmp); retval = g_strdup_printf("(%s,%s)", car, cdr); g_free(car); g_free(cdr); } break; /* These remaining shouldn't really be used outside of debug spew... */ case MATECONF_VALUE_INVALID: retval = g_strdup("Invalid"); break; case MATECONF_VALUE_SCHEMA: { const gchar* locale; const gchar* type; const gchar* list_type; const gchar* car_type; const gchar* cdr_type; locale = mateconf_schema_get_locale(mateconf_value_get_schema(value)); type = mateconf_value_type_to_string(mateconf_schema_get_type(mateconf_value_get_schema(value))); list_type = mateconf_value_type_to_string(mateconf_schema_get_list_type(mateconf_value_get_schema(value))); car_type = mateconf_value_type_to_string(mateconf_schema_get_car_type(mateconf_value_get_schema(value))); cdr_type = mateconf_value_type_to_string(mateconf_schema_get_cdr_type(mateconf_value_get_schema(value))); retval = g_strdup_printf("Schema (type: `%s' list_type: '%s' " "car_type: '%s' cdr_type: '%s' locale: `%s')", type, list_type, car_type, cdr_type, locale ? locale : "(null)"); } break; default: g_assert_not_reached(); break; } return retval; }