]> spindle.queued.net Git - midori/commitdiff
Load "bookmarks.xbel", "config" and "search" defaults from /etc
authorChristian Dywan <christian@twotoasts.de>
Thu, 27 Aug 2009 21:32:13 +0000 (23:32 +0200)
committerChristian Dywan <christian@twotoasts.de>
Thu, 27 Aug 2009 21:59:26 +0000 (23:59 +0200)
midori/main.c
midori/sokoke.c
midori/sokoke.h

index 528ebe571d83ca343a42aef2edf8c5985e9fedd7..b464718b9b5b834825bde17cf5fef6142400123b 100644 (file)
@@ -92,7 +92,13 @@ settings_new_from_file (const gchar* filename,
     if (!g_key_file_load_from_file (key_file, filename,
                                    G_KEY_FILE_KEEP_COMMENTS, &error))
     {
-        if (error->code != G_FILE_ERROR_NOENT)
+        if (error->code == G_FILE_ERROR_NOENT)
+        {
+            gchar* config_file = sokoke_find_config_filename ("config");
+            g_key_file_load_from_file (key_file, config_file,
+                                       G_KEY_FILE_KEEP_COMMENTS, NULL);
+        }
+        else
             printf (_("The configuration couldn't be loaded: %s\n"),
                     error->message);
         g_error_free (error);
@@ -1716,25 +1722,9 @@ main (int    argc,
         g_free (dir);
         search_engines = search_engines_new_from_file (config_file, NULL);
         #else
-        const gchar* const * config_dirs = g_get_system_config_dirs ();
-        i = 0;
-        while (config_dirs[i])
-        {
-            g_object_unref (search_engines);
-            katze_assign (config_file,
-                g_build_filename (config_dirs[i], PACKAGE_NAME, "search", NULL));
-            search_engines = search_engines_new_from_file (config_file, NULL);
-            if (!katze_array_is_empty (search_engines))
-                break;
-            i++;
-        }
-        if (katze_array_is_empty (search_engines))
-        {
-            g_object_unref (search_engines);
-            katze_assign (config_file,
-                g_build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, "search", NULL));
-            search_engines = search_engines_new_from_file (config_file, NULL);
-        }
+        katze_assign (config_file,
+            sokoke_find_config_filename ("search"));
+        search_engines = search_engines_new_from_file (config_file, NULL);
         #endif
     }
     else if (error)
@@ -1751,7 +1741,13 @@ main (int    argc,
     error = NULL;
     if (!midori_array_from_file (bookmarks, config_file, "xbel", &error))
     {
-        if (error->code != G_FILE_ERROR_NOENT)
+        if (error->code == G_FILE_ERROR_NOENT)
+        {
+            katze_assign (config_file,
+                sokoke_find_config_filename ("bookmarks.xbel"));
+            midori_array_from_file (bookmarks, config_file, "xbel", NULL);
+        }
+        else
             g_string_append_printf (error_messages,
                 _("The bookmarks couldn't be loaded: %s\n"), error->message);
         g_error_free (error);
index 9b80229097e0da7a85c6deeaf2f12a06f4f35e51..4ed87fc2603352885489d7d99993b60bb0100ad0 100644 (file)
@@ -948,6 +948,32 @@ sokoke_remove_path (const gchar* path,
     return TRUE;
 }
 
+/**
+ * sokoke_find_config_filename:
+ * @filename: a filename or relative path
+ *
+ * Looks for the specified filename in the system config
+ * directories, depending on the platform.
+ *
+ * Return value: a full path
+ **/
+gchar*
+sokoke_find_config_filename (const gchar* filename)
+{
+    const gchar* const* config_dirs = g_get_system_config_dirs ();
+    guint i = 0;
+    const gchar* config_dir;
+
+    while ((config_dir = config_dirs[i++]))
+    {
+        gchar* path = g_build_filename (config_dir, PACKAGE_NAME, filename, NULL);
+        if (g_file_test (path, G_FILE_TEST_EXISTS))
+            return path;
+        g_free (path);
+    }
+    return g_build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, filename, NULL);
+}
+
 /**
  * sokoke_find_data_filename:
  * @filename: a filename or relative path
index a39b3e6f7f3c67da417ed0a7a537437b9cca33c8..9deee903bb8ebbb95bf78c172ae1b75a107064b6 100644 (file)
@@ -151,6 +151,9 @@ gboolean
 sokoke_remove_path                      (const gchar*    path,
                                          gboolean        ignore_errors);
 
+gchar*
+sokoke_find_config_filename             (const gchar*    filename);
+
 gchar*
 sokoke_find_data_filename               (const gchar*    filename);