diff --git a/gui/settings.c b/gui/settings.c index b916b040..64e66bad 100644 --- a/gui/settings.c +++ b/gui/settings.c @@ -18,6 +18,22 @@ void gui_settings_deinit() gui_settings = NULL; } +void gui_settings_set(const gchar *key, unsigned int value) +{ + if (gui_settings) + g_hash_table_replace(gui_settings, g_strdup(key), + GUINT_TO_POINTER(value)); +} + +unsigned int gui_settings_get(const gchar *key) +{ + unsigned int ret = 0; + if (gui_settings) + ret = GPOINTER_TO_UINT(g_hash_table_lookup(gui_settings, key)); + return ret; +} + + #ifdef CONFIG_TESTING GHashTable *test_get_gui_settings() { diff --git a/include/gui/settings.h b/include/gui/settings.h index 02bc6a10..3698bc40 100644 --- a/include/gui/settings.h +++ b/include/gui/settings.h @@ -1,5 +1,7 @@ /* * Copyright 2015 (c) Anna Schumaker. + * + * The settings layer is used to store values configured by the user. */ #ifndef OCARINA_GUI_SETTINGS_H #define OCARINA_GUI_SETTINGS_H @@ -12,6 +14,12 @@ void gui_settings_init(); /* Called to deinitialize GUI settings. */ void gui_settings_deinit(); +/* Called to configure a specific setting by key. */ +void gui_settings_set(const gchar *, unsigned int); + +/* Called to access a specific setting by key. */ +unsigned int gui_settings_get(const gchar *); + #ifdef CONFIG_TESTING GHashTable *test_get_gui_settings(); diff --git a/tests/gui/settings.c b/tests/gui/settings.c index 4a3d099d..19d0a826 100644 --- a/tests/gui/settings.c +++ b/tests/gui/settings.c @@ -7,12 +7,24 @@ static void test_settings() { test_equal((void *)test_get_gui_settings(), NULL); + gui_settings_set("test.value1", 42); + gui_settings_set("test.value2", 84); + test_equal(gui_settings_get("test.value1"), 0); + test_equal(gui_settings_get("test.value2"), 0); gui_settings_init(); test_not_equal((void *)test_get_gui_settings(), NULL); + gui_settings_set("test.value1", 42); + gui_settings_set("test.value2", 84); + test_equal(gui_settings_get("test.value1"), 42); + test_equal(gui_settings_get("test.value2"), 84); gui_settings_deinit(); test_equal((void *)test_get_gui_settings(), NULL); + gui_settings_set("test.value1", 42); + gui_settings_set("test.value2", 84); + test_equal(gui_settings_get("test.value1"), 0); + test_equal(gui_settings_get("test.value2"), 0); } DECLARE_UNIT_TESTS(