diff options
author | Victor Toso <me@victortoso.com> | 2018-08-16 00:05:02 +0200 |
---|---|---|
committer | Victor Toso <toso@posteo.net> | 2018-09-25 09:33:11 +0000 |
commit | 6ebd283df50aafa05a3d19a26b6aaed8ed2841c9 (patch) | |
tree | 6eb5d2b8588d06d8a40d3af94299ced5f8caf784 | |
parent | 7ee38142350ba9c7fd665e74b60060111895c4bf (diff) | |
download | grilo-6ebd283df50aafa05a3d19a26b6aaed8ed2841c9.tar.gz |
registry: Add per Source configs on keyfile
As mentioned on 396a0153c8, 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 <victortoso@gnome.org>
-rw-r--r-- | src/grl-registry.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/grl-registry.c b/src/grl-registry.c index f51a62c..43a3a3f 100644 --- a/src/grl-registry.c +++ b/src/grl-registry.c @@ -2000,6 +2000,28 @@ grl_registry_add_config (GrlRegistry *registry, } 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); } |