[grilo] registry: Add per Source configs on keyfile



commit 6ebd283df50aafa05a3d19a26b6aaed8ed2841c9
Author: Victor Toso <me victortoso com>
Date:   Thu Aug 16 00:05:02 2018 +0200

    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>

 src/grl-registry.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
---
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
@@ -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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]