Load "bookmarks.xbel", "config" and "search" defaults from /etc
This commit is contained in:
parent
c5973c4161
commit
2bb225e7c0
3 changed files with 46 additions and 21 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue