[grilo] core: Use numbers to identify Grilo keys



commit f99a0c5ca14ee3ccb583f7b7aafe8bffa9460f17
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Wed Feb 16 09:34:16 2011 +0000

    core: Use numbers to identify Grilo keys
    
    Use guint32 instead of GParamSpec for Grilo keys.
    
    Mostly the API remains the same.
    
    New functions to get the name or type of a Grilo key has been introduced.
    
    Main changes are:
    - Introduced GRL_METADATA_KEY_INVALID definition
    - grl_metadata_key_list_new() needs to end with GRL_METADATA_KEY_INVALID
      instead of NULL.
    - Introduced GRLKEYID_TO_POINTER and GRLPOINTER_TO_KEYID macros to
      convert between GrlKeyID and gpointers.

 src/data/grl-data.c               |   11 ++-
 src/data/grl-media.c              |    2 +-
 src/grl-metadata-key.c            |  131 +++++++++++++++++++-------
 src/grl-metadata-key.h            |   20 +++--
 src/grl-metadata-source.c         |   15 ++--
 src/grl-plugin-registry.c         |  182 +++++++++++++++++++++++++++++++++----
 src/grl-plugin-registry.h         |   13 +++
 tools/grilo-inspect/grl-inspect.c |    3 +-
 tools/grilo-test-ui/main.c        |   14 ++-
 9 files changed, 310 insertions(+), 81 deletions(-)
---
diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index 45723b9..55d2418 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -533,7 +533,7 @@ grl_data_has_key (GrlData *data, GrlKeyID key)
     return FALSE;
   }
 
-  related_keys = g_hash_table_lookup (data->priv->data, sample_key);
+  related_keys = g_hash_table_lookup (data->priv->data, GRLKEYID_TO_POINTER (sample_key));
   while (related_keys && !found) {
     found = grl_related_keys_has_key (related_keys->data, key);
     related_keys = g_list_next (related_keys);
@@ -636,7 +636,7 @@ grl_data_add_related_keys (GrlData *data,
     return;
   }
 
-  sample_key = get_sample_key (keys->data);
+  sample_key = get_sample_key (GRLPOINTER_TO_KEYID (keys->data));
   g_list_free (keys);
 
   if (!sample_key) {
@@ -644,9 +644,12 @@ grl_data_add_related_keys (GrlData *data,
     return;
   }
 
-  list_relkeys = g_hash_table_lookup (data->priv->data, sample_key);
+  list_relkeys = g_hash_table_lookup (data->priv->data,
+                                      GRLKEYID_TO_POINTER (sample_key));
   list_relkeys = g_list_append (list_relkeys, relkeys);
-  g_hash_table_insert (data->priv->data, sample_key, list_relkeys);
+  g_hash_table_insert (data->priv->data,
+                       GRLKEYID_TO_POINTER (sample_key),
+                       list_relkeys);
 }
 
 /**
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index d467920..0757a06 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -339,7 +339,7 @@ grl_media_serialize_extended (GrlMedia *media,
       va_start (va_serial, serial_type);
       keylist = va_arg (va_serial, GList *);
       for (key = keylist; key; key = g_list_next (key)) {
-        grlkey = key->data;
+        grlkey = GRLPOINTER_TO_KEYID (key->data);
         /* Skip id and source keys */
         if (grlkey == GRL_METADATA_KEY_ID ||
             grlkey == GRL_METADATA_KEY_SOURCE) {
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index 848186d..e561a04 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -26,40 +26,40 @@
 
 #include <stdarg.h>
 
-GrlKeyID GRL_METADATA_KEY_ALBUM = NULL;
-GrlKeyID GRL_METADATA_KEY_ARTIST = NULL;
-GrlKeyID GRL_METADATA_KEY_AUTHOR = NULL;
-GrlKeyID GRL_METADATA_KEY_DATE = NULL;
-GrlKeyID GRL_METADATA_KEY_DESCRIPTION = NULL;
-GrlKeyID GRL_METADATA_KEY_GENRE = NULL;
-GrlKeyID GRL_METADATA_KEY_ID = NULL;
-GrlKeyID GRL_METADATA_KEY_LAST_PLAYED = NULL;
-GrlKeyID GRL_METADATA_KEY_LYRICS = NULL;
-GrlKeyID GRL_METADATA_KEY_MIME = NULL;
-GrlKeyID GRL_METADATA_KEY_SITE = NULL;
-GrlKeyID GRL_METADATA_KEY_SOURCE = NULL;
-GrlKeyID GRL_METADATA_KEY_THUMBNAIL = NULL;
-GrlKeyID GRL_METADATA_KEY_THUMBNAIL_BINARY = NULL;
-GrlKeyID GRL_METADATA_KEY_TITLE = NULL;
-
-GrlKeyID GRL_METADATA_KEY_URL = NULL;
-GrlKeyID GRL_METADATA_KEY_EXTERNAL_URL = NULL;
-GrlKeyID GRL_METADATA_KEY_EXTERNAL_PLAYER = NULL;
-
-GrlKeyID GRL_METADATA_KEY_BITRATE = NULL;
-GrlKeyID GRL_METADATA_KEY_CHILDCOUNT = NULL;
-GrlKeyID GRL_METADATA_KEY_DURATION = NULL;
-GrlKeyID GRL_METADATA_KEY_HEIGHT = NULL;
-GrlKeyID GRL_METADATA_KEY_LAST_POSITION = NULL;
-GrlKeyID GRL_METADATA_KEY_PLAY_COUNT = NULL;
-GrlKeyID GRL_METADATA_KEY_WIDTH = NULL;
-
-GrlKeyID GRL_METADATA_KEY_FRAMERATE = NULL;
-GrlKeyID GRL_METADATA_KEY_RATING = NULL;
-
-GrlKeyID GRL_METADATA_KEY_STUDIO = NULL;
-GrlKeyID GRL_METADATA_KEY_CERTIFICATE = NULL;
-GrlKeyID GRL_METADATA_KEY_LICENSE = NULL;
+GrlKeyID GRL_METADATA_KEY_ALBUM = 0;
+GrlKeyID GRL_METADATA_KEY_ARTIST = 0;
+GrlKeyID GRL_METADATA_KEY_AUTHOR = 0;
+GrlKeyID GRL_METADATA_KEY_DATE = 0;
+GrlKeyID GRL_METADATA_KEY_DESCRIPTION = 0;
+GrlKeyID GRL_METADATA_KEY_GENRE = 0;
+GrlKeyID GRL_METADATA_KEY_ID = 0;
+GrlKeyID GRL_METADATA_KEY_LAST_PLAYED = 0;
+GrlKeyID GRL_METADATA_KEY_LYRICS = 0;
+GrlKeyID GRL_METADATA_KEY_MIME = 0;
+GrlKeyID GRL_METADATA_KEY_SITE = 0;
+GrlKeyID GRL_METADATA_KEY_SOURCE = 0;
+GrlKeyID GRL_METADATA_KEY_THUMBNAIL = 0;
+GrlKeyID GRL_METADATA_KEY_THUMBNAIL_BINARY = 0;
+GrlKeyID GRL_METADATA_KEY_TITLE = 0;
+
+GrlKeyID GRL_METADATA_KEY_URL = 0;
+GrlKeyID GRL_METADATA_KEY_EXTERNAL_URL = 0;
+GrlKeyID GRL_METADATA_KEY_EXTERNAL_PLAYER = 0;
+
+GrlKeyID GRL_METADATA_KEY_BITRATE = 0;
+GrlKeyID GRL_METADATA_KEY_CHILDCOUNT = 0;
+GrlKeyID GRL_METADATA_KEY_DURATION = 0;
+GrlKeyID GRL_METADATA_KEY_HEIGHT = 0;
+GrlKeyID GRL_METADATA_KEY_LAST_POSITION = 0;
+GrlKeyID GRL_METADATA_KEY_PLAY_COUNT = 0;
+GrlKeyID GRL_METADATA_KEY_WIDTH = 0;
+
+GrlKeyID GRL_METADATA_KEY_FRAMERATE = 0;
+GrlKeyID GRL_METADATA_KEY_RATING = 0;
+
+GrlKeyID GRL_METADATA_KEY_STUDIO = 0;
+GrlKeyID GRL_METADATA_KEY_CERTIFICATE = 0;
+GrlKeyID GRL_METADATA_KEY_LICENSE = 0;
 
 GrlKeyID GRL_METADATA_KEY_SEASON = NULL;
 GrlKeyID GRL_METADATA_KEY_EPISODE = NULL;
@@ -452,7 +452,13 @@ GRL_METADATA_KEY_STUDIO =
 const gchar *
 grl_metadata_key_get_name (GrlKeyID key)
 {
-  return GRL_METADATA_KEY_GET_NAME (key);
+  GrlPluginRegistry *registry = grl_plugin_registry_get_default ();
+
+  if (registry) {
+    return grl_plugin_registry_lookup_metadata_key_name (registry, key);
+  } else {
+    return NULL;
+  }
 }
 
 /**
@@ -468,5 +474,58 @@ grl_metadata_key_get_name (GrlKeyID key)
 const gchar *
 grl_metadata_key_get_desc (GrlKeyID key)
 {
-  return GRL_METADATA_KEY_GET_DESC (key);
+  GrlPluginRegistry *registry = grl_plugin_registry_get_default ();
+
+  if (registry) {
+    return grl_plugin_registry_lookup_metadata_key_desc (registry, key);
+  } else {
+    return NULL;
+  }
+}
+
+/**
+ * grl_metadata_key_get_type:
+ * @key: key to look up
+ *
+ * Retrieves the expected type for values associated with this key
+ *
+ * Returns: the expected value type
+ **/
+GType grl_metadata_key_get_type (GrlKeyID key)
+{
+  GrlPluginRegistry *registry = grl_plugin_registry_get_default ();
+
+  if (registry) {
+    return grl_plugin_registry_lookup_metadata_key_type (registry, key);
+  } else {
+    return G_TYPE_INVALID;
+  }
+}
+
+/**
+ * grl_metadata_key_list_new: (skip)
+ * @first_key: first key
+ * @...: va_list keys
+ *
+ * Returns a #GList containing the va_list keys. Use #GRL_METADATA_KEY_INVALID
+ * to finalize them.
+ *
+ * Returns: a #GList
+ **/
+GList *
+grl_metadata_key_list_new(GrlKeyID first_key, ...)
+{
+  GList *key_list = NULL;
+  GrlKeyID next_key;
+  va_list va_keys;
+
+  va_start (va_keys, first_key);
+  next_key = first_key;
+  while (next_key) {
+    key_list = g_list_prepend (key_list, GRLKEYID_TO_POINTER (next_key));
+    next_key = va_arg (va_keys, GrlKeyID);
+  }
+  va_end (va_keys);
+
+  return g_list_reverse (key_list);
 }
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index 35474a7..c13046e 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -31,17 +31,17 @@
 #include <glib-object.h>
 
 #define GRL_METADATA_KEY_GET_ID(key)   (key)
-#define GRL_METADATA_KEY_GET_NAME(key) (g_param_spec_get_name (key))
-#define GRL_METADATA_KEY_GET_DESC(key) (g_param_spec_get_blurb(key))
-#define GRL_METADATA_KEY_GET_TYPE(key) (G_PARAM_SPEC_VALUE_TYPE(key))
+#define GRL_METADATA_KEY_GET_NAME(key) (grl_metadata_key_get_name (key))
+#define GRL_METADATA_KEY_GET_DESC(key) (grl_metadata_key_get_desc (key))
+#define GRL_METADATA_KEY_GET_TYPE(key) (grl_metadata_key_get_type (key))
 
-#define GRL_KEYID_FORMAT "p"
+#define GRL_KEYID_FORMAT "u"
+#define GRL_METADATA_KEY_INVALID 0
 
-#define grl_metadata_key_list_new(first_key, ...)       \
-  grl_list_from_va(first_key, ##__VA_ARGS__)
+#define GRLPOINTER_TO_KEYID(p) (GPOINTER_TO_UINT(p))
+#define GRLKEYID_TO_POINTER(k) (GUINT_TO_POINTER(k))
 
-
-typedef GParamSpec* GrlKeyID;
+typedef guint32 GrlKeyID;
 
 extern GrlKeyID GRL_METADATA_KEY_ALBUM;
 extern GrlKeyID GRL_METADATA_KEY_ARTIST;
@@ -87,4 +87,8 @@ const gchar *grl_metadata_key_get_name (GrlKeyID key);
 
 const gchar *grl_metadata_key_get_desc (GrlKeyID key);
 
+GType grl_metadata_key_get_type (GrlKeyID key);
+
+GList *grl_metadata_key_list_new(GrlKeyID first_key, ...);
+
 #endif /* _GRL_METADATA_KEY_H_ */
diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c
index c7a73e7..cc50850 100644
--- a/src/grl-metadata-source.c
+++ b/src/grl-metadata-source.c
@@ -275,7 +275,7 @@ print_keys (gchar *label, const GList *keys)
 {
   g_print ("%s: [", label);
   while (keys) {
-    g_print (" %" GRL_KEYID_FORMAT, keys->data);
+    g_print (" %" GRL_KEYID_FORMAT, GRLPOINTER_TO_KEYID (keys->data));
     keys = g_list_next (keys);
   }
   g_print (" ]\n");
@@ -623,7 +623,7 @@ missing_in_data (GrlData *data, const GList *deps)
     return g_list_copy ((GList *) deps);
 
   for (iter = (GList *)deps; iter; iter = g_list_next (iter)) {
-    if (!grl_data_has_key (data, iter->data))
+    if (!grl_data_has_key (data, GRLPOINTER_TO_KEYID (iter->data)))
       result = g_list_append (result, iter->data);
   }
 
@@ -640,7 +640,7 @@ may_directly_resolve (GrlMetadataSource *source,
 {
   const GList *iter;
   for (iter = keys; iter; iter = g_list_next (iter)) {
-    GrlKeyID key = (GrlKeyID)iter->data;
+    GrlKeyID key = GRLPOINTER_TO_KEYID (iter->data);
 
     if (!grl_metadata_source_may_resolve (source, media, key, NULL))
       return FALSE;
@@ -884,7 +884,8 @@ grl_metadata_source_may_resolve (GrlMetadataSource *source,
      * all of their supported_keys() in that case. If a media source wants to
      * behave differently, it should implement may_resolve().*/
     const GList *supported_keys = grl_metadata_source_supported_keys (source);
-    ret = NULL != g_list_find ((GList *)supported_keys, key_id);
+    ret = NULL != g_list_find ((GList *)supported_keys,
+                               GRLKEYID_TO_POINTER (key_id));
   } else {
     GRL_WARNING ("Source %s does not implement may_resolve(), considering it "
                  "can't resolve %s",
@@ -1165,13 +1166,13 @@ grl_metadata_source_expand_operation_keys (GrlMetadataSource *source,
    * have to ask from other sources.
    */
   for (iter = keys; iter; iter = g_list_next (iter)) {
-    GrlKeyID key = (GrlKeyID) iter->data;
+    GrlKeyID key = GRLPOINTER_TO_KEYID (iter->data);
     if (grl_metadata_source_may_resolve (source, media, key, NULL)) {
       GRL_INFO ("We (%s) can resolve %s",
                  grl_metadata_source_get_name (source),
                  GRL_METADATA_KEY_GET_NAME (key));
     } else {
-      remaining_keys = g_list_append (remaining_keys, key);
+      remaining_keys = g_list_append (remaining_keys, iter->data);
     }
   }
 
@@ -1227,7 +1228,7 @@ grl_metadata_source_get_additional_sources (GrlMetadataSource *source,
                                                            TRUE);
 
   for (iter = missing_keys; iter; iter = g_list_next (iter)) {
-    GrlKeyID key = (GrlKeyID) iter->data;
+    GrlKeyID key = GRLPOINTER_TO_KEYID (iter->data);
     GrlMetadataSource *_source;
     GList *needed_keys = NULL;
 
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index 583523e..0a3a50a 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -956,8 +956,7 @@ grl_plugin_registry_unload (GrlPluginRegistry *registry,
  *
  * Registers a metadata key
  *
- * Returns: (type GObject.ParamSpec) (transfer none): The #GrlKeyID registered
- * or @NULL on error.
+ * Returns: The #GrlKeyID registered.
  *
  * Since: 0.1.7
  */
@@ -966,12 +965,16 @@ grl_plugin_registry_register_metadata_key (GrlPluginRegistry *registry,
                                            GParamSpec *key,
                                            GError **error)
 {
-  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), NULL);
-  g_return_val_if_fail (G_IS_PARAM_SPEC (key), NULL);
+  const gchar *key_name;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), 0);
+  g_return_val_if_fail (G_IS_PARAM_SPEC (key), 0);
+
+  key_name = g_param_spec_get_name (key);
 
   /* Check if key is already registered */
   if (g_param_spec_pool_lookup (registry->priv->system_keys,
-                                g_param_spec_get_name (key),
+                                key_name,
                                 GRL_TYPE_MEDIA,
                                 FALSE)) {
     GRL_WARNING ("metadata key '%s' already registered",
@@ -981,16 +984,16 @@ grl_plugin_registry_register_metadata_key (GrlPluginRegistry *registry,
                  GRL_CORE_ERROR_REGISTER_METADATA_KEY_FAILED,
                  "Metadata key '%s' was already registered",
                  g_param_spec_get_name (key));
-    return NULL;
+    return 0;
   } else {
     g_param_spec_pool_insert (registry->priv->system_keys,
                               key,
                               GRL_TYPE_MEDIA);
     /* Each key is related with itself */
     g_hash_table_insert (registry->priv->related_keys,
-                         key,
+                         GRLKEYID_TO_POINTER (key),
                          g_list_prepend (NULL, key));
-    return key;
+    return (GrlKeyID) g_quark_from_static_string (key_name);
   }
 }
 
@@ -1054,7 +1057,7 @@ grl_plugin_registry_register_metadata_key_relation (GrlPluginRegistry *registry,
  *
  * Look up for the metadata key with name @key_name.
  *
- * Returns: (type GObject.ParamSpec) (transfer none): The metadata key, or @NULL if not found
+ * Returns: The metadata key, or 0 if not found
  *
  * Since: 0.1.6
  */
@@ -1062,13 +1065,154 @@ GrlKeyID
 grl_plugin_registry_lookup_metadata_key (GrlPluginRegistry *registry,
                                          const gchar *key_name)
 {
-  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), NULL);
-  g_return_val_if_fail (key_name, NULL);
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), 0);
+  g_return_val_if_fail (key_name, 0);
+
+  if (g_param_spec_pool_lookup (registry->priv->system_keys,
+                                key_name,
+                                GRL_TYPE_MEDIA,
+                                FALSE)) {
+    return (GrlKeyID) g_quark_try_string (key_name);
+  } else {
+    return 0;
+  }
+}
+
+/**
+ * grl_plugin_registry_lookup_metadata_key_name:
+ * @registry: the registry instance
+ * @key: a metadata key
+ *
+ * Returns @key name.
+ *
+ * Returns: metadata key name, or @NULL if not found
+ */
+const gchar *
+grl_plugin_registry_lookup_metadata_key_name (GrlPluginRegistry *registry,
+                                              GrlKeyID key)
+{
+  const gchar *key_name;
+  GParamSpec *key_pspec;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), 0);
+
+  key_name = g_quark_to_string (key);
+  if (!key_name) {
+    return NULL;
+  }
+  key_pspec = g_param_spec_pool_lookup (registry->priv->system_keys,
+                                        key_name,
+                                        GRL_TYPE_MEDIA,
+                                        FALSE);
+  if (key_pspec) {
+    return g_param_spec_get_name (key_pspec);
+  } else {
+    return NULL;
+  }
+}
+
+/**
+ * grl_plugin_registry_lookup_metadata_key_desc:
+ * @registry: the registry instance
+ * @key: a metadata key
+ *
+ * Returns @key description.
+ *
+ * Returns: metadata key description, or @NULL if not found
+ */
+const gchar *
+grl_plugin_registry_lookup_metadata_key_desc (GrlPluginRegistry *registry,
+                                              GrlKeyID key)
+{
+  const gchar *key_name;
+  GParamSpec *key_pspec;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), 0);
 
-  return g_param_spec_pool_lookup (registry->priv->system_keys,
-                                   key_name,
-                                   GRL_TYPE_MEDIA,
-                                   FALSE);
+  key_name = g_quark_to_string (key);
+  if (!key_name) {
+    return NULL;
+  }
+  key_pspec = g_param_spec_pool_lookup (registry->priv->system_keys,
+                                        key_name,
+                                        GRL_TYPE_MEDIA,
+                                        FALSE);
+  if (key_pspec) {
+    return g_param_spec_get_blurb (key_pspec);
+  } else {
+    return NULL;
+  }
+}
+
+/**
+ * grl_plugin_registry_lookup_metadata_key_type:
+ * @registry: the registry instance
+ * @key: a metadata key
+ *
+ * Returns @key expected value type.
+ *
+ * Returns: metadata key type, or @G_TYPE_INVALID if not found
+ */
+GType
+grl_plugin_registry_lookup_metadata_key_type (GrlPluginRegistry *registry,
+                                              GrlKeyID key)
+{
+  const gchar *key_name;
+  GParamSpec *key_pspec;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), 0);
+
+  key_name = g_quark_to_string (key);
+  if (!key_name) {
+    return G_TYPE_INVALID;
+  }
+  key_pspec = g_param_spec_pool_lookup (registry->priv->system_keys,
+                                        key_name,
+                                        GRL_TYPE_MEDIA,
+                                        FALSE);
+  if (key_pspec) {
+    return G_PARAM_SPEC_VALUE_TYPE (key_pspec);
+  } else {
+    return G_TYPE_INVALID;
+  }
+}
+
+/**
+ * grl_plugin_registry_metadata_key_validate:
+ * @registry: the registry instance
+ * @key: a metadata key
+ * @value: value to be validate
+ *
+ * Validates @value content complies with the key specification. That is, it has
+ * the expected type, and value are within the range specified in key (for
+ * integer values).
+ *
+ * Returns: %TRUE if complies
+ **/
+gboolean
+grl_plugin_registry_metadata_key_validate (GrlPluginRegistry *registry,
+                                           GrlKeyID key,
+                                           GValue *value)
+{
+  const gchar *key_name;
+  GParamSpec *key_pspec;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), FALSE);
+  g_return_val_if_fail (G_IS_VALUE (value), FALSE);
+
+  key_name = g_quark_to_string (key);
+  if (!key_name) {
+    return FALSE;
+  }
+  key_pspec = g_param_spec_pool_lookup (registry->priv->system_keys,
+                                        key_name,
+                                        GRL_TYPE_MEDIA,
+                                        FALSE);
+  if (key_pspec) {
+    return !g_param_value_validate (key_pspec, value);
+  } else {
+    return FALSE;
+  }
 }
 
 /**
@@ -1100,9 +1244,9 @@ grl_plugin_registry_lookup_metadata_key_relation (GrlPluginRegistry *registry,
  *
  * Returns a list with all registered keys in system.
  *
- * Returns: (element-type GObject.ParamSpec) (transfer container): a #GList
- * with all the available #GrlKeyID<!-- -->s. The content of the list should
- * not be modified or freed. Use g_list_free() when done using the list.
+ * Returns: (transfer container): a #GList with all the available
+ * #GrlKeyID<!-- -->s. The content of the list should not be modified or freed.
+ * Use g_list_free() when done using the list.
  *
  * Since: 0.1.6
  **/
@@ -1121,7 +1265,7 @@ grl_plugin_registry_get_metadata_keys (GrlPluginRegistry *registry)
                                  &keys_length);
 
   for (i = 0; i < keys_length; i++) {
-    key_list = g_list_prepend (key_list, keys[i]);
+    key_list = g_list_prepend (key_list, GRLKEYID_TO_POINTER (keys[i]));
   }
 
   g_free (keys);
diff --git a/src/grl-plugin-registry.h b/src/grl-plugin-registry.h
index 3a957eb..2f5e641 100644
--- a/src/grl-plugin-registry.h
+++ b/src/grl-plugin-registry.h
@@ -257,6 +257,19 @@ GrlKeyID grl_plugin_registry_lookup_metadata_key (GrlPluginRegistry *registry,
 const GList *grl_plugin_registry_lookup_metadata_key_relation (GrlPluginRegistry *registry,
                                                                GrlKeyID key);
 
+const gchar *grl_plugin_registry_lookup_metadata_key_name (GrlPluginRegistry *registry,
+                                                           GrlKeyID key);
+
+const gchar *grl_plugin_registry_lookup_metadata_key_desc (GrlPluginRegistry *registry,
+                                                           GrlKeyID key);
+
+GType grl_plugin_registry_lookup_metadata_key_type (GrlPluginRegistry *registry,
+                                                    GrlKeyID key);
+
+gboolean grl_plugin_registry_metadata_key_validate (GrlPluginRegistry *registry,
+                                                    GrlKeyID key,
+                                                    GValue *value);
+
 GList *grl_plugin_registry_get_metadata_keys (GrlPluginRegistry *registry);
 
 gboolean grl_plugin_registry_add_config (GrlPluginRegistry *registry,
diff --git a/tools/grilo-inspect/grl-inspect.c b/tools/grilo-inspect/grl-inspect.c
index 967bc44..8be16bf 100644
--- a/tools/grilo-inspect/grl-inspect.c
+++ b/tools/grilo-inspect/grl-inspect.c
@@ -72,7 +72,8 @@ static void
 print_keys (const GList *keys)
 {
   while (keys) {
-    g_print ("%s", GRL_METADATA_KEY_GET_NAME (keys->data));
+    g_print ("%s",
+             GRL_METADATA_KEY_GET_NAME (GRLPOINTER_TO_KEYID (keys->data)));
     keys = g_list_next (keys);
     if (keys) {
       g_print (", ");
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index 37ac2fd..77ea9b6 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -361,7 +361,7 @@ browse_keys (void)
     keys = grl_metadata_key_list_new (GRL_METADATA_KEY_ID,
                                       GRL_METADATA_KEY_TITLE,
                                       GRL_METADATA_KEY_CHILDCOUNT,
-                                      NULL);
+                                      GRL_METADATA_KEY_INVALID);
   }
 
   return keys;
@@ -526,6 +526,8 @@ metadata_cb (GrlMediaSource *source,
   GList *keys, *i;
   GtkTreeIter iter;
   GrlPluginRegistry *registry;
+  GrlKeyID key;
+  const gchar *key_name;
 
   /* Not interested if not the last media we
      requested metadata for */
@@ -557,17 +559,19 @@ metadata_cb (GrlMediaSource *source,
     keys = grl_data_get_keys (GRL_DATA (media));
     i = keys;
     while (i) {
-      if (grl_data_has_key (GRL_DATA (media), i->data)) {
-        const GValue *g_value = grl_data_get (GRL_DATA (media), i->data);
+      key = GRLPOINTER_TO_KEYID (i->data);
+      key_name = grl_metadata_key_get_name (key);
+      if (grl_data_has_key (GRL_DATA (media), key)) {
+        const GValue *g_value = grl_data_get (GRL_DATA (media), key);
         gchar *value = g_value ? g_strdup_value_contents (g_value) : "";
         gtk_list_store_append (GTK_LIST_STORE (view->metadata_model), &iter);
         gtk_list_store_set (GTK_LIST_STORE (view->metadata_model),
                             &iter,
                             METADATA_MODEL_NAME,
-                            GRL_METADATA_KEY_GET_NAME (i->data),
+                            key_name,
                             METADATA_MODEL_VALUE, value,
                             -1);
-        GRL_DEBUG ("  %s: %s", GRL_METADATA_KEY_GET_NAME (i->data), value);
+        GRL_DEBUG ("  %s: %s", key_name, value);
       }
       i = g_list_next (i);
     }



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