[Config] Add GKeyFile reading capabilities
[tilda-gobject.git] / tilda-config.c
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;
 }