[grilo-plugins/0.1.x] tracker: Check if keys are already registered



commit 7d330dd28447f78d81b0fd9b2820a2c01b696911
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Tue May 17 08:01:17 2011 +0000

    tracker: Check if keys are already registered
    
    When registering a new key, check first if the key is already registered.
    
    This situation happens when a plugin is re-loaded for second time.
    
    Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>

 src/media/tracker/grl-tracker-media-api.c |   24 ++++++++++++++++--------
 src/media/tracker/grl-tracker-utils.c     |   25 ++++++++++++++++---------
 2 files changed, 32 insertions(+), 17 deletions(-)
---
diff --git a/src/media/tracker/grl-tracker-media-api.c b/src/media/tracker/grl-tracker-media-api.c
index 3aeba2f..be5a892 100644
--- a/src/media/tracker/grl-tracker-media-api.c
+++ b/src/media/tracker/grl-tracker-media-api.c
@@ -883,15 +883,23 @@ grl_tracker_media_change_stop (GrlMediaSource *source, GError **error)
 void
 grl_tracker_media_init_requests (void)
 {
+  GrlPluginRegistry *registry = grl_plugin_registry_get_default ();
+
+  /* Check if "tracker-category" is registered; if not, the register it */
   grl_metadata_key_tracker_category =
-    grl_plugin_registry_register_metadata_key (grl_plugin_registry_get_default (),
-                                               g_param_spec_string ("tracker-category",
-                                                                    "Tracker category",
-                                                                    "Category a media belongs to",
-                                                                    NULL,
-                                                                    G_PARAM_STATIC_STRINGS |
-                                                                    G_PARAM_READWRITE),
-                                               NULL);
+    grl_plugin_registry_lookup_metadata_key (registry, "tracker-category");
+
+  if (grl_metadata_key_tracker_category == GRL_METADATA_KEY_INVALID) {
+    grl_metadata_key_tracker_category =
+      grl_plugin_registry_register_metadata_key (grl_plugin_registry_get_default (),
+                                                 g_param_spec_string ("tracker-category",
+                                                                      "Tracker category",
+                                                                      "Category a media belongs to",
+                                                                      NULL,
+                                                                      G_PARAM_STATIC_STRINGS |
+                                                                      G_PARAM_READWRITE),
+                                                 NULL);
+  }
 
   grl_tracker_operations = g_hash_table_new (g_direct_hash, g_direct_equal);
 
diff --git a/src/media/tracker/grl-tracker-utils.c b/src/media/tracker/grl-tracker-utils.c
index a038941..bbfdfe3 100644
--- a/src/media/tracker/grl-tracker-utils.c
+++ b/src/media/tracker/grl-tracker-utils.c
@@ -125,16 +125,23 @@ insert_key_mapping_with_setter (GrlKeyID                       grl_key,
 void
 grl_tracker_setup_key_mappings (void)
 {
-  grl_metadata_key_tracker_urn =
-    grl_plugin_registry_register_metadata_key (grl_plugin_registry_get_default (),
-                                               g_param_spec_string ("tracker-urn",
-                                                                    "Tracker URN",
-                                                                    "Universal resource number in Tracker's store",
-                                                                    NULL,
-                                                                    G_PARAM_STATIC_STRINGS |
-                                                                    G_PARAM_READWRITE),
-                                               NULL);
+  GrlPluginRegistry *registry = grl_plugin_registry_get_default ();
 
+  /* Check if "tracker-urn" is registered; if not, then register it */
+  grl_metadata_key_tracker_urn =
+    grl_plugin_registry_lookup_metadata_key (registry, "tracker-urn");
+
+  if (grl_metadata_key_tracker_urn == GRL_METADATA_KEY_INVALID) {
+    grl_metadata_key_tracker_urn =
+      grl_plugin_registry_register_metadata_key (grl_plugin_registry_get_default (),
+                                                 g_param_spec_string ("tracker-urn",
+                                                                      "Tracker URN",
+                                                                      "Universal resource number in Tracker's store",
+                                                                      NULL,
+                                                                      G_PARAM_STATIC_STRINGS |
+                                                                      G_PARAM_READWRITE),
+                                                 NULL);
+  }
 
   grl_to_sparql_mapping = g_hash_table_new (g_direct_hash, g_direct_equal);
   sparql_to_grl_mapping = g_hash_table_new (g_str_hash, g_str_equal);



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