summaryrefslogtreecommitdiff
path: root/conf.c
blob: 8e39a8917e839d0905cc24b37b6cfdc5f548b8e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#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;
}

gchar **conf_get_string_list(const gchar *group, const gchar *key, gsize *length) {
	GError *error = NULL;

	gchar **s = g_key_file_get_string_list(kf, group, key, length, &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);
}