[Multi-valued V2 (grilo-plugins) 1/2] gravatar: Use multivalued keys



If keys dependencies are multivalued, provide an avatar for each of the values.

Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
 src/gravatar/grl-gravatar.c |   48 +++++++++++++++++++++++++++---------------
 1 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/src/gravatar/grl-gravatar.c b/src/gravatar/grl-gravatar.c
index 49d4346..72a7dee 100644
--- a/src/gravatar/grl-gravatar.c
+++ b/src/gravatar/grl-gravatar.c
@@ -103,6 +103,15 @@ grl_gravatar_source_plugin_init (GrlPluginRegistry *registry,
     return FALSE;
   }
 
+  /* Create relationship */
+  grl_plugin_registry_register_metadata_key_relation (registry,
+                                                      GRL_METADATA_KEY_ARTIST,
+                                                      GRL_METADATA_KEY_ARTIST_AVATAR);
+
+  grl_plugin_registry_register_metadata_key_relation (registry,
+                                                      GRL_METADATA_KEY_AUTHOR,
+                                                      GRL_METADATA_KEY_AUTHOR_AVATAR);
+
   GrlGravatarSource *source = grl_gravatar_source_new ();
   grl_plugin_registry_register_source (registry,
                                        plugin,
@@ -226,6 +235,26 @@ has_dependency (GrlMedia *media, GrlKeyID dependency, GList **missing_keys)
   return FALSE;
 }
 
+static void
+set_avatar (GrlData *data,
+            GrlKeyID key)
+{
+  gint length, i;
+  GrlProperty *relprop;
+  gchar *avatar_url;
+
+  length = grl_data_length (data, key);
+
+  for (i = 0; i < length; i++) {
+    relprop = grl_data_get_property (data, key, i);
+    avatar_url = get_avatar (grl_property_get_string (relprop, key));
+    if (avatar_url) {
+      grl_property_set_string (relprop, key, avatar_url);
+      g_free (avatar_url);
+    }
+  }
+}
+
 /* ================== API Implementation ================ */
 
 static const GList *
@@ -268,7 +297,6 @@ grl_gravatar_source_resolve (GrlMetadataSource *source,
 {
   gboolean artist_avatar_required = FALSE;
   gboolean author_avatar_required = FALSE;
-  gchar *avatar_url;
 
   GRL_DEBUG ("grl_gravatar_source_resolve");
 
@@ -286,25 +314,11 @@ grl_gravatar_source_resolve (GrlMetadataSource *source,
   }
 
   if (artist_avatar_required) {
-    avatar_url = get_avatar (grl_data_get_string (GRL_DATA (rs->media),
-                                                  GRL_METADATA_KEY_ARTIST));
-    if (avatar_url) {
-      grl_data_set_string (GRL_DATA (rs->media),
-                           GRL_METADATA_KEY_ARTIST_AVATAR,
-                           avatar_url);
-      g_free (avatar_url);
-    }
+    set_avatar (GRL_DATA (rs->media), GRL_METADATA_KEY_ARTIST);
   }
 
   if (author_avatar_required) {
-    avatar_url = get_avatar (grl_data_get_string (GRL_DATA (rs->media),
-                                                  GRL_METADATA_KEY_AUTHOR));
-    if (avatar_url) {
-      grl_data_set_string (GRL_DATA (rs->media),
-                           GRL_METADATA_KEY_AUTHOR_AVATAR,
-                           avatar_url);
-      g_free (avatar_url);
-    }
+    set_avatar (GRL_DATA (rs->media), GRL_METADATA_KEY_AUTHOR);
   }
 
   rs->callback (source, rs->media, rs->user_data, NULL);
-- 
1.7.4



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