Commit 6ebd283d authored by Victor Toso's avatar Victor Toso Committed by Victor Toso
Browse files

registry: Add per Source configs on keyfile

As mentioned on 396a0153, we could add GrlConfig data per Plugin on
the config file. This commit extends the configuration to support
GrlSource configuration.

This can be done by adding the Source ID to the Group's name in the
keyfile, after the Plugin ID. This format is suggested by
specification at "Extending the format"

    https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html



e.g:
 | [grl-youtube]
 | api-key=value1
 |
 | [grl-lua-factory grl-theaudiodb-cover]
 | api-key=value2
Signed-off-by: Victor Toso's avatarVictor Toso <victortoso@gnome.org>
parent 7ee38142
Pipeline #32421 passed with stage
in 2 minutes and 43 seconds
......@@ -1999,6 +1999,28 @@ grl_registry_add_config (GrlRegistry *registry,
return TRUE;
}
static void
get_plugin_and_source_from_group_name (const gchar *group_name,
gchar **plugin_name,
gchar **source_name)
{
gchar *plugin = g_strdup (group_name);
gchar **arr;
*plugin_name = *source_name = NULL;
plugin = g_strstrip (plugin);
arr = g_strsplit (plugin, " ", 2);
g_free (plugin);
*plugin_name = g_strstrip (arr[0]);
if (arr[1] != NULL)
*source_name = g_strstrip (arr[1]);
g_free (arr);
}
static void
add_config_from_keyfile (GKeyFile *keyfile,
GrlRegistry *registry)
......@@ -2013,19 +2035,28 @@ add_config_from_keyfile (GKeyFile *keyfile,
/* Look up for defined plugins */
plugins = g_key_file_get_groups (keyfile, NULL);
for (groupname = plugins; *groupname; groupname++) {
config = grl_config_new (*groupname, NULL);
gchar *plugin_name, *source_name;
get_plugin_and_source_from_group_name (*groupname, &plugin_name, &source_name);
config = grl_config_new (plugin_name, source_name);
/* Look up configuration keys for this plugin */
keys = g_key_file_get_keys (keyfile, *groupname, NULL, NULL);
for (key = keys; *key; key++) {
value = g_key_file_get_string (keyfile, *groupname, *key, NULL);
if (value) {
GRL_DEBUG ("Config found: %s : %s : %s", plugin_name,
source_name != NULL ? source_name : plugin_name,
*key);
grl_config_set_string (config, *key, value);
g_free (value);
}
}
grl_registry_add_config (registry, config, NULL);
g_strfreev (keys);
g_free (source_name);
g_free (plugin_name);
}
g_strfreev (plugins);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment