From: Christian Dywan Date: Thu, 27 Aug 2009 21:32:13 +0000 (+0200) Subject: Load "bookmarks.xbel", "config" and "search" defaults from /etc X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bb225e7c05c64b6b0ac639e94b8d78f4ae91cf0;p=midori Load "bookmarks.xbel", "config" and "search" defaults from /etc --- diff --git a/midori/main.c b/midori/main.c index 528ebe57..b464718b 100644 --- a/midori/main.c +++ b/midori/main.c @@ -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); diff --git a/midori/sokoke.c b/midori/sokoke.c index 9b802290..4ed87fc2 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -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 diff --git a/midori/sokoke.h b/midori/sokoke.h index a39b3e6f..9deee903 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -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);