From 3a353bab78ecec2bfe0397c7f7929177829417a6 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sat, 26 Jan 2008 13:48:48 -0800 Subject: [PATCH] [Config] Add GKeyFile reading capabilities This gives the configuration system the ability to read GKeyFiles, so users can set their own preferences. Currently it reads out of the same directory, which is convenient for testing. In the future, it will need to read out of the user's home directory. --- .gitignore | 1 + tilda-config.c | 22 +++++++++++++++++++--- tilda.c | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f239dc9..ed9ce42 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.o *dbus-glue.h tilda +tilda.conf diff --git a/tilda-config.c b/tilda-config.c index b1b6575..c8afbc2 100644 --- a/tilda-config.c +++ b/tilda-config.c @@ -1,8 +1,9 @@ #include "debug.h" +#include "translation.h" #include "tilda-config.h" -GHashTable *config_defaults; -GKeyFile *config_userprefs; +GHashTable *config_defaults = NULL; +GKeyFile *config_userprefs = NULL; /* * TODO: @@ -87,6 +88,8 @@ tilda_config_setup_defaults () gboolean tilda_config_init (const gchar *filename) { + GError *error = NULL; + /* Create the hashtable */ config_defaults = g_hash_table_new (g_str_hash, g_str_equal); @@ -104,7 +107,20 @@ tilda_config_init (const gchar *filename) /* Create the key file */ config_userprefs = g_key_file_new (); - /* TODO: load from a file! */ + if (!g_file_test (filename, G_FILE_TEST_EXISTS)) + { + g_warning (_("No config file found, using defaults\n")); + return TRUE; + } + + if (!g_key_file_load_from_file (config_userprefs, filename, G_KEY_FILE_NONE, &error)) + { + g_warning (_("Error reading from config file: %s\n"), error->message); + g_error_free (error); + return FALSE; + } + + /* Everything went ok */ return TRUE; } diff --git a/tilda.c b/tilda.c index 794618b..8b1de1d 100644 --- a/tilda.c +++ b/tilda.c @@ -157,7 +157,7 @@ int main (int argc, char *argv[]) tomboy_keybinder_init (); /* Initialize the configuration system */ - tilda_config_init ("FIXME"); + tilda_config_init ("tilda.conf"); /* Start our connection to DBus */ tilda_dbus_init (); -- 2.25.1