From 18ab34bdc82aa1890f7924c3ab9422739f7ddb3b Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Fri, 2 Oct 2009 23:07:36 +0200 Subject: [PATCH] Load extension settings from global config folders For example, /etc/xdg/midori/extensions/extension_name/config --- midori/main.c | 6 +++--- midori/midori-extension.c | 12 +++++++++++- midori/sokoke.c | 11 ++++++++--- midori/sokoke.h | 3 ++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/midori/main.c b/midori/main.c index 738e7f94..dfe9489f 100644 --- a/midori/main.c +++ b/midori/main.c @@ -94,7 +94,7 @@ settings_new_from_file (const gchar* filename, { if (error->code == G_FILE_ERROR_NOENT) { - gchar* config_file = sokoke_find_config_filename ("config"); + gchar* config_file = sokoke_find_config_filename (NULL, "config"); g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL); } @@ -1818,7 +1818,7 @@ main (int argc, search_engines = search_engines_new_from_file (config_file, NULL); #else katze_assign (config_file, - sokoke_find_config_filename ("search")); + sokoke_find_config_filename (NULL, "search")); search_engines = search_engines_new_from_file (config_file, NULL); #endif } @@ -1839,7 +1839,7 @@ main (int argc, if (error->code == G_FILE_ERROR_NOENT) { katze_assign (config_file, - sokoke_find_config_filename ("bookmarks.xbel")); + sokoke_find_config_filename (NULL, "bookmarks.xbel")); midori_array_from_file (bookmarks, config_file, "xbel", NULL); } else diff --git a/midori/midori-extension.c b/midori/midori-extension.c index ece419fd..27ab9df9 100644 --- a/midori/midori-extension.c +++ b/midori/midori-extension.c @@ -272,11 +272,21 @@ midori_extension_activate_cb (MidoriExtension* extension, if (!g_key_file_load_from_file (extension->priv->key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, &error)) { - if (error->code != G_FILE_ERROR_NOENT) + if (error->code == G_FILE_ERROR_NOENT) + { + gchar* filename = g_object_get_data (G_OBJECT (extension), "filename"); + gchar* folder = g_strconcat ("extensions/", filename, NULL); + katze_assign (config_file, + sokoke_find_config_filename (folder, "config")); + g_key_file_load_from_file (extension->priv->key_file, config_file, + G_KEY_FILE_KEEP_COMMENTS, NULL); + } + else printf (_("The configuration of the extension '%s' couldn't be loaded: %s\n"), extension->priv->name, error->message); g_error_free (error); } + g_free (config_file); } while (lsettings) diff --git a/midori/sokoke.c b/midori/sokoke.c index bc169703..35b95d5a 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -963,6 +963,7 @@ sokoke_remove_path (const gchar* path, /** * sokoke_find_config_filename: + * @folder: a subfolder * @filename: a filename or relative path * * Looks for the specified filename in the system config @@ -971,20 +972,24 @@ sokoke_remove_path (const gchar* path, * Return value: a full path **/ gchar* -sokoke_find_config_filename (const gchar* filename) +sokoke_find_config_filename (const gchar* folder, + const gchar* filename) { const gchar* const* config_dirs = g_get_system_config_dirs (); guint i = 0; const gchar* config_dir; + if (!folder) + folder = ""; + while ((config_dir = config_dirs[i++])) { - gchar* path = g_build_filename (config_dir, PACKAGE_NAME, filename, NULL); + gchar* path = g_build_filename (config_dir, PACKAGE_NAME, folder, 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); + return g_build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, folder, filename, NULL); } /** diff --git a/midori/sokoke.h b/midori/sokoke.h index 9deee903..e2dbb210 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -152,7 +152,8 @@ sokoke_remove_path (const gchar* path, gboolean ignore_errors); gchar* -sokoke_find_config_filename (const gchar* filename); +sokoke_find_config_filename (const gchar* folder, + const gchar* filename); gchar* sokoke_find_data_filename (const gchar* filename); -- 2.39.5