/* * OH-Puzzles: configuration.c * Routines for loading/saving configuration details * * Copyright (C) 2007 Openedhand Ltd. * Authors: iain */ #include #include "puzzles.h" static GConfValue * get_value (GConfClient *client, const char *key) { GError *error = NULL; GConfValue *value; value = gconf_client_get (client, key, &error); if (error) { g_warning ("Error getting %s: %s", key, error->message); g_error_free (error); } return value; } int configuration_get_int (const char *game, const char *option, int def) { GConfClient *client; char *key; GConfValue *value; int ret; key = g_strdup_printf ("/apps/oh-puzzles/%s/%s", game, option); client = gconf_client_get_default (); value = get_value (client, key); if (value) { ret = gconf_value_get_int (value); gconf_value_free (value); } else { ret = def; } g_free (key); g_object_unref (G_OBJECT (client)); return ret; } void configuration_set_int (const char *game, const char *option, int value) { GConfClient *client; char *key; key = g_strdup_printf ("/apps/oh-puzzles/%s/%s", game, option); client = gconf_client_get_default (); gconf_client_set_int (client, key, value, NULL); g_free (key); g_object_unref (G_OBJECT (client)); } char * configuration_get_string (const char *game, const char *option, const char *def) { GConfClient *client; GConfValue *value; char *key, *ret; key = g_strdup_printf ("/apps/oh-puzzles/%s/%s", game, option); client = gconf_client_get_default (); value = get_value (client, key); if (value) { ret = g_strdup (gconf_value_get_string (value)); gconf_value_free (value); } else { ret = g_strdup (def); } g_free (key); g_object_unref (G_OBJECT (client)); return ret; } void configuration_set_string (const char *game, const char *option, const char *value) { GConfClient *client; char *key; key = g_strdup_printf ("/apps/oh-puzzles/%s/%s", game, option); client = gconf_client_get_default (); gconf_client_set_string (client, key, value, NULL); g_free (key); g_object_unref (G_OBJECT (client)); } gboolean configuration_get_bool (const char *game, const char *option, gboolean def) { GConfClient *client; GConfValue *value; char *key; gboolean ret; key = g_strdup_printf ("/apps/oh-puzzles/%s/%s", game, option); client = gconf_client_get_default (); value = get_value (client, key); if (value) { ret = gconf_value_get_bool (value); gconf_value_free (value); } else { ret = def; } g_free (key); g_object_unref (G_OBJECT (client)); return ret; } void configuration_set_bool (const char *game, const char *option, gboolean value) { GConfClient *client; char *key; key = g_strdup_printf ("/apps/oh-puzzles/%s/%s", game, option); client = gconf_client_get_default (); gconf_client_set_bool (client, key, value, NULL); g_free (key); g_object_unref (G_OBJECT (client)); }