Load extension settings from global config folders
For example, /etc/xdg/midori/extensions/extension_name/config
This commit is contained in:
parent
255018aeaa
commit
18ab34bdc8
4 changed files with 24 additions and 8 deletions
|
@ -94,7 +94,7 @@ settings_new_from_file (const gchar* filename,
|
||||||
{
|
{
|
||||||
if (error->code == G_FILE_ERROR_NOENT)
|
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_load_from_file (key_file, config_file,
|
||||||
G_KEY_FILE_KEEP_COMMENTS, NULL);
|
G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1818,7 +1818,7 @@ main (int argc,
|
||||||
search_engines = search_engines_new_from_file (config_file, NULL);
|
search_engines = search_engines_new_from_file (config_file, NULL);
|
||||||
#else
|
#else
|
||||||
katze_assign (config_file,
|
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);
|
search_engines = search_engines_new_from_file (config_file, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1839,7 +1839,7 @@ main (int argc,
|
||||||
if (error->code == G_FILE_ERROR_NOENT)
|
if (error->code == G_FILE_ERROR_NOENT)
|
||||||
{
|
{
|
||||||
katze_assign (config_file,
|
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);
|
midori_array_from_file (bookmarks, config_file, "xbel", NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -272,11 +272,21 @@ midori_extension_activate_cb (MidoriExtension* extension,
|
||||||
if (!g_key_file_load_from_file (extension->priv->key_file, config_file,
|
if (!g_key_file_load_from_file (extension->priv->key_file, config_file,
|
||||||
G_KEY_FILE_KEEP_COMMENTS, &error))
|
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"),
|
printf (_("The configuration of the extension '%s' couldn't be loaded: %s\n"),
|
||||||
extension->priv->name, error->message);
|
extension->priv->name, error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
|
g_free (config_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (lsettings)
|
while (lsettings)
|
||||||
|
|
|
@ -963,6 +963,7 @@ sokoke_remove_path (const gchar* path,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sokoke_find_config_filename:
|
* sokoke_find_config_filename:
|
||||||
|
* @folder: a subfolder
|
||||||
* @filename: a filename or relative path
|
* @filename: a filename or relative path
|
||||||
*
|
*
|
||||||
* Looks for the specified filename in the system config
|
* Looks for the specified filename in the system config
|
||||||
|
@ -971,20 +972,24 @@ sokoke_remove_path (const gchar* path,
|
||||||
* Return value: a full path
|
* Return value: a full path
|
||||||
**/
|
**/
|
||||||
gchar*
|
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 ();
|
const gchar* const* config_dirs = g_get_system_config_dirs ();
|
||||||
guint i = 0;
|
guint i = 0;
|
||||||
const gchar* config_dir;
|
const gchar* config_dir;
|
||||||
|
|
||||||
|
if (!folder)
|
||||||
|
folder = "";
|
||||||
|
|
||||||
while ((config_dir = config_dirs[i++]))
|
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))
|
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||||
return path;
|
return path;
|
||||||
g_free (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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -152,7 +152,8 @@ sokoke_remove_path (const gchar* path,
|
||||||
gboolean ignore_errors);
|
gboolean ignore_errors);
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
sokoke_find_config_filename (const gchar* filename);
|
sokoke_find_config_filename (const gchar* folder,
|
||||||
|
const gchar* filename);
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
sokoke_find_data_filename (const gchar* filename);
|
sokoke_find_data_filename (const gchar* filename);
|
||||||
|
|
Loading…
Reference in a new issue