From 2d2b889bb25f9db008bdac54babf84c2120d2a45 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 20 Aug 2010 20:36:38 +0200 Subject: Implemented some basic configuration stuff. --- conf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 conf.c (limited to 'conf.c') diff --git a/conf.c b/conf.c new file mode 100644 index 0000000..eb978e7 --- /dev/null +++ b/conf.c @@ -0,0 +1,46 @@ +#include "conf.h" + +static GKeyFile *kf = NULL; + +gchar *conf_get_string(const gchar *group, const gchar *key) { + GError *error = NULL; + + gchar *s = g_key_file_get_string(kf, group, key, &error); + if(s == NULL) { + g_warning(error->message); + g_error_free(error); + } + + return s; +} + +gint conf_get_int(const gchar *group, const gchar *key) { + GError *error = NULL; + + gint i = g_key_file_get_integer(kf, group, key, &error); + if(i == 0 && error != NULL) { + g_warning(error->message); + g_error_free(error); + } + + return i; +} + +gboolean conf_load() { + GError *error = NULL; + kf = g_key_file_new(); + + if(kf == NULL) { + return FALSE; + } + + if(g_key_file_load_from_file(kf, "audist.conf", G_KEY_FILE_NONE, &error) == FALSE) { + g_warning("could not load config file: %s", error->message); + } + + return TRUE; +} + +void conf_free() { + g_key_file_free(kf); +} -- cgit v1.2.3