From 83ac3b4673de071651c8b8c57095e4de6d229ef8 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Mon, 12 Dec 2011 22:20:16 +0100 Subject: Read config from config- not data-dirs glib provides no wrapper, so we have to loop ourselves over system and user dirs. --- src/config.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index e24ece0..73bebe2 100644 --- a/src/config.c +++ b/src/config.c @@ -64,18 +64,29 @@ destroy_priority(gpointer data) int config_init(struct config *cfg) { - GError *error = NULL; + /* FIXME: Not a nicer method available in glib? */ + const gchar *home_dirs[] = { g_get_user_config_dir(), NULL }; + const gchar * const * dirs_array[] = { home_dirs, g_get_system_config_dirs() }; + GError *error; + int i; memset(cfg, 0, sizeof *cfg); cfg->keyfile = g_key_file_new(); cfg->priorities = NULL; - if (!g_key_file_load_from_data_dirs(cfg->keyfile, - "pa-sink-ctl/config.ini", - NULL, G_KEY_FILE_NONE, &error) - && error) { - g_printerr("Failed to open config file: %s\n", error->message); - return -1; + for (i = 0; i < G_N_ELEMENTS(dirs_array); ++i) { + error = NULL; + if (g_key_file_load_from_dirs(cfg->keyfile, + "pa-sink-ctl/config.ini", + (const gchar **) dirs_array[i], + NULL, G_KEY_FILE_NONE, &error) + && !error) + break; + } + if (error) { + g_printerr("Failed to open config file: %s\n", + error->message); + return -1; } if (parse_priorities(cfg) < 0) -- cgit