[PATCH 2/6] core: updated recent code to the new GrlKeyID format



From: Guillaume Emont <gemont igalia com>

---
 src/data/grl-data.c         |   32 ++++++++++++++++++++------------
 src/data/grl-related-keys.c |   16 +++++++++++-----
 src/grl-metadata-key.c      |   18 +++++++++---------
 src/grl-plugin-registry.c   |    6 +++---
 4 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index 55d2418..dcd78a0 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -173,9 +173,9 @@ get_sample_key (GrlKeyID key)
   if (!related_keys) {
     GRL_WARNING ("Related keys not found for key \"%s\"",
                  grl_metadata_key_get_name (key));
-    return NULL;
+    return GRL_METADATA_KEY_INVALID;
   } else {
-    return related_keys->data;
+    return GRLPOINTER_TO_KEYID (related_keys->data);
   }
 }
 
@@ -568,10 +568,11 @@ grl_data_get_keys (GrlData *data)
   registry = grl_plugin_registry_get_default ();
 
   for (key = keylist; key; key = g_list_next (key)) {
-    relkeys = grl_plugin_registry_lookup_metadata_key_relation (registry,
-                                                                key->data);
+    GrlKeyID key_id = GRLPOINTER_TO_KEYID (key->data);
+    relkeys =
+        grl_plugin_registry_lookup_metadata_key_relation (registry, key_id);
     while (relkeys) {
-      if (grl_data_has_key (data, relkeys->data)) {
+      if (grl_data_has_key (data, GRLPOINTER_TO_KEYID (relkeys->data))) {
         allkeys = g_list_prepend (allkeys, relkeys->data);
       }
       relkeys = g_list_next (relkeys);
@@ -782,7 +783,8 @@ grl_data_length (GrlData *data,
     return 0;
   }
 
-  return g_list_length (g_hash_table_lookup (data->priv->data, sample_key));
+  return g_list_length (g_hash_table_lookup (data->priv->data,
+                                             GRLKEYID_TO_POINTER (sample_key)));
 }
 
 /**
@@ -818,7 +820,8 @@ grl_data_get_related_keys (GrlData *data,
     return NULL;
   }
 
-  relkeys_list = g_hash_table_lookup (data->priv->data, sample_key);
+  relkeys_list = g_hash_table_lookup (data->priv->data,
+                                      GRLKEYID_TO_POINTER (sample_key));
   relkeys = g_list_nth_data (relkeys_list, index);
 
   if (!relkeys) {
@@ -881,7 +884,8 @@ grl_data_get_single_values_for_key (GrlData *data,
     return NULL;
   }
 
-  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) {
     v = grl_related_keys_get (related_keys->data, key);
     if (v) {
@@ -990,7 +994,8 @@ grl_data_remove_nth (GrlData *data,
     return;
   }
 
-  relkeys_list = g_hash_table_lookup (data->priv->data, sample_key);
+  relkeys_list = g_hash_table_lookup (data->priv->data,
+                                      GRLKEYID_TO_POINTER (sample_key));
   relkeys_element = g_list_nth (relkeys_list, index);
   if (!relkeys_element) {
     GRL_WARNING ("%s: index %u out of range", __FUNCTION__, index);
@@ -999,7 +1004,9 @@ grl_data_remove_nth (GrlData *data,
 
   g_object_unref (relkeys_element->data);
   relkeys_list = g_list_delete_link (relkeys_list, relkeys_element);
-  g_hash_table_insert (data->priv->data, sample_key, relkeys_list);
+  g_hash_table_insert (data->priv->data,
+                       GRLKEYID_TO_POINTER (sample_key),
+                       relkeys_list);
 }
 
 /**
@@ -1035,13 +1042,14 @@ grl_data_set_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) {
     return;
   }
 
-  relkeys_list = g_hash_table_lookup (data->priv->data, sample_key);
+  relkeys_list = g_hash_table_lookup (data->priv->data,
+                                      GRLKEYID_TO_POINTER (sample_key));
   relkeys_element = g_list_nth (relkeys_list, index);
   if (!relkeys_element) {
     GRL_WARNING ("%s: index %u out of range", __FUNCTION__, index);
diff --git a/src/data/grl-related-keys.c b/src/data/grl-related-keys.c
index 2f409cf..40f2edd 100644
--- a/src/data/grl-related-keys.c
+++ b/src/data/grl-related-keys.c
@@ -41,6 +41,7 @@
 
 #include "grl-related-keys.h"
 #include "grl-log.h"
+#include "grl-plugin-registry.h"
 
 struct _GrlRelatedKeysPrivate {
   GHashTable *data;
@@ -212,7 +213,7 @@ grl_related_keys_get (GrlRelatedKeys *relkeys,
   g_return_val_if_fail (GRL_IS_RELATED_KEYS (relkeys), NULL);
   g_return_val_if_fail (key, NULL);
 
-  return g_hash_table_lookup (relkeys->priv->data, key);
+  return g_hash_table_lookup (relkeys->priv->data, GRLKEYID_TO_POINTER (key));
 }
 
 /**
@@ -236,6 +237,7 @@ grl_related_keys_set (GrlRelatedKeys *relkeys,
                       const GValue *value)
 {
   GValue *copy = NULL;
+  GrlPluginRegistry *registry;
 
   g_return_if_fail (GRL_IS_RELATED_KEYS (relkeys));
   g_return_if_fail (key);
@@ -256,11 +258,13 @@ grl_related_keys_set (GrlRelatedKeys *relkeys,
   g_value_init (copy, G_VALUE_TYPE (value));
   g_value_copy (value, copy);
 
-  if (g_param_value_validate (key, copy)) {
+  registry = grl_plugin_registry_get_default ();
+
+  if (!grl_plugin_registry_metadata_key_validate (registry, key, copy)) {
     GRL_WARNING ("'%s' value invalid, adjusting",
                  GRL_METADATA_KEY_GET_NAME (key));
   }
-  g_hash_table_insert (relkeys->priv->data, key, copy);
+  g_hash_table_insert (relkeys->priv->data, GRLKEYID_TO_POINTER (key), copy);
 }
 
 /**
@@ -514,7 +518,9 @@ grl_related_keys_has_key (GrlRelatedKeys *relkeys,
 {
   g_return_val_if_fail (GRL_IS_RELATED_KEYS (relkeys), FALSE);
 
-  return g_hash_table_lookup_extended (relkeys->priv->data, key, NULL, NULL);
+  return g_hash_table_lookup_extended (relkeys->priv->data,
+                                       GRLKEYID_TO_POINTER (key),
+                                       NULL, NULL);
 }
 
 /**
@@ -584,7 +590,7 @@ grl_related_keys_dup (GrlRelatedKeys *relkeys)
 
   keys = grl_related_keys_get_keys (relkeys);
   for (key = keys; key; key = g_list_next (key)) {
-    value = grl_related_keys_get (relkeys, key->data);
+    value = grl_related_keys_get (relkeys, GRLPOINTER_TO_KEYID (key->data));
     value_copy = g_new0 (GValue, 1);
     g_value_init (value_copy, G_VALUE_TYPE (value));
     g_value_copy (value, value_copy);
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index e561a04..0096811 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -61,17 +61,17 @@ 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;
-GrlKeyID GRL_METADATA_KEY_SHOW = NULL;
+GrlKeyID GRL_METADATA_KEY_SEASON = 0;
+GrlKeyID GRL_METADATA_KEY_EPISODE = 0;
+GrlKeyID GRL_METADATA_KEY_SHOW = 0;
 
-GrlKeyID GRL_METADATA_KEY_CREATION_DATE = NULL;
+GrlKeyID GRL_METADATA_KEY_CREATION_DATE = 0;
 
-GrlKeyID GRL_METADATA_KEY_CAMERA_MODEL = NULL;
-GrlKeyID GRL_METADATA_KEY_ORIENTATION = NULL;
-GrlKeyID GRL_METADATA_KEY_FLASH_USED = NULL;
-GrlKeyID GRL_METADATA_KEY_EXPOSURE_TIME = NULL;
-GrlKeyID GRL_METADATA_KEY_ISO_SPEED = NULL;
+GrlKeyID GRL_METADATA_KEY_CAMERA_MODEL = 0;
+GrlKeyID GRL_METADATA_KEY_ORIENTATION = 0;
+GrlKeyID GRL_METADATA_KEY_FLASH_USED = 0;
+GrlKeyID GRL_METADATA_KEY_EXPOSURE_TIME = 0;
+GrlKeyID GRL_METADATA_KEY_ISO_SPEED = 0;
 
 void
 grl_metadata_key_setup_system_keys (GrlPluginRegistry *registry)
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index fee2ee1..a7d62ea 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -1032,8 +1032,8 @@ grl_plugin_registry_register_metadata_key_relation (GrlPluginRegistry *registry,
   }
 
   /* Search for keys related with each key */
-  key1_partners = g_hash_table_lookup (registry->priv->related_keys, key1);
-  key2_partners = g_hash_table_lookup (registry->priv->related_keys, key2);
+  key1_partners = g_hash_table_lookup (registry->priv->related_keys, GRLKEYID_TO_POINTER (key1));
+  key2_partners = g_hash_table_lookup (registry->priv->related_keys, GRLKEYID_TO_POINTER (key2));
 
   /* Check if they are already related */
   if (!key1_partners || !key2_partners || key1_partners == key2_partners) {
@@ -1235,7 +1235,7 @@ grl_plugin_registry_lookup_metadata_key_relation (GrlPluginRegistry *registry,
 {
   g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), NULL);
 
-  return g_hash_table_lookup (registry->priv->related_keys, key);
+  return g_hash_table_lookup (registry->priv->related_keys, GRLKEYID_TO_POINTER (key));
 }
 
 /**
-- 
1.7.1



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