[Config] Add GKeyFile reading capabilities
authorIra W. Snyder <devel@irasnyder.com>
Sat, 26 Jan 2008 21:48:48 +0000 (13:48 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sat, 26 Jan 2008 21:48:48 +0000 (13:48 -0800)
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
tilda-config.c
tilda.c

index f239dc9..ed9ce42 100644 (file)
@@ -2,3 +2,4 @@
 *.o
 *dbus-glue.h
 tilda
+tilda.conf
index b1b6575..c8afbc2 100644 (file)
@@ -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 (file)
--- 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 ();