[grilo-plugins] tracker: Add support for new picture keys



commit 3093dd939ba1a99171262184ca83600e15bb0bbf
Author: Lionel Landwerlin <lionel g landwerlin linux intel com>
Date:   Fri Mar 25 15:44:29 2011 +0100

    tracker: Add support for new picture keys
    
    Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>

 src/media/tracker/grl-tracker-media-api.c |   56 ++++++++++++++------------
 src/media/tracker/grl-tracker-metadata.c  |   50 ++++++++++++-----------
 src/media/tracker/grl-tracker-utils.c     |   60 +++++++++++++++++++++++++++++
 src/media/tracker/grl-tracker-utils.h     |    7 +++
 4 files changed, 123 insertions(+), 50 deletions(-)
---
diff --git a/src/media/tracker/grl-tracker-media-api.c b/src/media/tracker/grl-tracker-media-api.c
index bdef8da..0e11f69 100644
--- a/src/media/tracker/grl-tracker-media-api.c
+++ b/src/media/tracker/grl-tracker-media-api.c
@@ -221,33 +221,37 @@ fill_grilo_media_from_sparql (GrlTrackerMedia    *source,
     return;
   }
 
-  switch (G_PARAM_SPEC (assoc->grl_key)->value_type) {
-  case G_TYPE_STRING:
-    /* Cache the source associated to this result. */
-    if (assoc->grl_key == GRL_METADATA_KEY_ID) {
-      grl_tracker_media_cache_add_item (grl_tracker_item_cache,
-                                        tracker_sparql_cursor_get_integer (cursor,
-                                                                           column),
-                                        source);
+  if (assoc->set_value) {
+    assoc->set_value (cursor, column, media, assoc->grl_key);
+  } else {
+    switch (G_PARAM_SPEC (assoc->grl_key)->value_type) {
+      case G_TYPE_STRING:
+        /* Cache the source associated to this result. */
+        if (assoc->grl_key == GRL_METADATA_KEY_ID) {
+          grl_tracker_media_cache_add_item (grl_tracker_item_cache,
+                                            tracker_sparql_cursor_get_integer (cursor,
+                                                                               column),
+                                            source);
+        }
+        val.str_val = tracker_sparql_cursor_get_string (cursor, column, NULL);
+        if (val.str_val != NULL)
+          grl_data_set_string (GRL_DATA (media), assoc->grl_key, val.str_val);
+        break;
+
+      case G_TYPE_INT:
+        val.int_val = tracker_sparql_cursor_get_integer (cursor, column);
+        grl_data_set_int (GRL_DATA (media), assoc->grl_key, val.int_val);
+        break;
+
+      case G_TYPE_FLOAT:
+        val.double_val = tracker_sparql_cursor_get_double (cursor, column);
+        grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) val.double_val);
+        break;
+
+      default:
+        GRL_ODEBUG ("\t\tUnexpected data type");
+        break;
     }
-    val.str_val = tracker_sparql_cursor_get_string (cursor, column, NULL);
-    if (val.str_val != NULL)
-      grl_data_set_string (GRL_DATA (media), assoc->grl_key, val.str_val);
-    break;
-
-  case G_TYPE_INT:
-    val.int_val = tracker_sparql_cursor_get_integer (cursor, column);
-    grl_data_set_int (GRL_DATA (media), assoc->grl_key, val.int_val);
-    break;
-
-  case G_TYPE_FLOAT:
-    val.double_val = tracker_sparql_cursor_get_double (cursor, column);
-    grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) val.double_val);
-    break;
-
-  default:
-    GRL_ODEBUG ("\t\tUnexpected data type");
-    break;
   }
 }
 
diff --git a/src/media/tracker/grl-tracker-metadata.c b/src/media/tracker/grl-tracker-metadata.c
index 08eaee0..8f09ad0 100644
--- a/src/media/tracker/grl-tracker-metadata.c
+++ b/src/media/tracker/grl-tracker-metadata.c
@@ -180,8 +180,7 @@ grl_tracker_metadata_set_property (GObject      *object,
 /**/
 
 static void
-fill_grilo_media_from_sparql (GrlTrackerMetadata  *source,
-                              GrlMedia            *media,
+fill_grilo_media_from_sparql (GrlMedia            *media,
                               TrackerSparqlCursor *cursor,
                               gint                 column)
 {
@@ -214,26 +213,30 @@ fill_grilo_media_from_sparql (GrlTrackerMetadata  *source,
     return;
   }
 
-  switch (G_PARAM_SPEC (assoc->grl_key)->value_type) {
-  case G_TYPE_STRING:
-    val.str_val = tracker_sparql_cursor_get_string (cursor, column, NULL);
-    if (val.str_val != NULL)
-      grl_data_set_string (GRL_DATA (media), assoc->grl_key, val.str_val);
-    break;
-
-  case G_TYPE_INT:
-    val.int_val = tracker_sparql_cursor_get_integer (cursor, column);
-    grl_data_set_int (GRL_DATA (media), assoc->grl_key, val.int_val);
-    break;
-
-  case G_TYPE_FLOAT:
-    val.double_val = tracker_sparql_cursor_get_double (cursor, column);
-    grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) val.double_val);
-    break;
-
-  default:
-    GRL_ODEBUG ("\t\tUnexpected data type");
-    break;
+  if (assoc->set_value) {
+    assoc->set_value (cursor, column, media, assoc->grl_key);
+  } else {
+    switch (G_PARAM_SPEC (assoc->grl_key)->value_type) {
+      case G_TYPE_STRING:
+        val.str_val = tracker_sparql_cursor_get_string (cursor, column, NULL);
+        if (val.str_val != NULL)
+          grl_data_set_string (GRL_DATA (media), assoc->grl_key, val.str_val);
+        break;
+
+      case G_TYPE_INT:
+        val.int_val = tracker_sparql_cursor_get_integer (cursor, column);
+        grl_data_set_int (GRL_DATA (media), assoc->grl_key, val.int_val);
+        break;
+
+      case G_TYPE_FLOAT:
+        val.double_val = tracker_sparql_cursor_get_double (cursor, column);
+        grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) val.double_val);
+        break;
+
+      default:
+        GRL_ODEBUG ("\t\tUnexpected data type");
+        break;
+    }
   }
 }
 
@@ -273,8 +276,7 @@ tracker_resolve_cb (GObject                      *source_object,
   if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
     /* Translate Sparql result into Grilo result */
     for (col = 0 ; col < tracker_sparql_cursor_get_n_columns (cursor) ; col++) {
-      fill_grilo_media_from_sparql (GRL_TRACKER_METADATA (rs->source),
-                                    rs->media, cursor, col);
+      fill_grilo_media_from_sparql (rs->media, cursor, col);
     }
 
     rs->callback (rs->source, rs->media, rs->user_data, NULL);
diff --git a/src/media/tracker/grl-tracker-utils.c b/src/media/tracker/grl-tracker-utils.c
index f58832b..d69af50 100644
--- a/src/media/tracker/grl-tracker-utils.c
+++ b/src/media/tracker/grl-tracker-utils.c
@@ -47,6 +47,24 @@ build_flavored_key (gchar *key, const gchar *flavor)
 }
 
 static void
+set_orientation (TrackerSparqlCursor *cursor,
+                 gint                 column,
+                 GrlMedia            *media,
+                 GrlKeyID             key)
+{
+  const gchar *str = tracker_sparql_cursor_get_string (cursor, column, NULL);
+
+  if (g_str_has_suffix (str, "nfo#orientation-top"))
+    grl_data_set_int (GRL_DATA (media), key, 0);
+  else if (g_str_has_suffix (str, "nfo#orientation-right"))
+    grl_data_set_int (GRL_DATA (media), key, 90);
+  else if (g_str_has_suffix (str, "nfo#orientation-bottom"))
+    grl_data_set_int (GRL_DATA (media), key, 180);
+  else if (g_str_has_suffix (str, "nfo#orientation-left"))
+    grl_data_set_int (GRL_DATA (media), key, 270);
+}
+
+static tracker_grl_sparql_t *
 insert_key_mapping (GrlKeyID     grl_key,
                     const gchar *sparql_key_attr,
                     const gchar *sparql_key_flavor)
@@ -71,6 +89,23 @@ insert_key_mapping (GrlKeyID     grl_key,
                        assoc);
 
   g_free (canon_name);
+
+  return assoc;
+}
+
+static tracker_grl_sparql_t *
+insert_key_mapping_with_setter (GrlKeyID                       grl_key,
+                                const gchar                   *sparql_key_attr,
+                                const gchar                   *sparql_key_flavor,
+                                tracker_grl_sparql_setter_cb_t setter)
+{
+  tracker_grl_sparql_t *assoc;
+
+  assoc = insert_key_mapping (grl_key, sparql_key_attr, sparql_key_flavor);
+
+  assoc->set_value = setter;
+
+  return assoc;
 }
 
 void
@@ -154,6 +189,31 @@ grl_tracker_setup_key_mappings (void)
   insert_key_mapping (GRL_METADATA_KEY_EPISODE,
                       "nmm:episodeNumber(?urn)",
                       "video");
+
+  insert_key_mapping (GRL_METADATA_KEY_CREATION_DATE,
+                      "nie:contentCreated(?urn)",
+                      "image");
+
+  insert_key_mapping (GRL_METADATA_KEY_CAMERA_MODEL,
+                      "nfo:model(nfo:equipment(?urn))",
+                      "image");
+
+  insert_key_mapping (GRL_METADATA_KEY_FLASH_USED,
+                      "nmm:flash(?urn)",
+                      "image");
+
+  insert_key_mapping (GRL_METADATA_KEY_EXPOSURE_TIME,
+                      "nmm:exposureTime(?urn)",
+                      "image");
+
+  insert_key_mapping (GRL_METADATA_KEY_ISO_SPEED,
+                      "nmm:isoSpeed(?urn)",
+                      "image");
+
+  insert_key_mapping_with_setter (GRL_METADATA_KEY_ORIENTATION,
+                                  "nfo:orientation(?urn)",
+                                  "image",
+                                  set_orientation);
 }
 
 tracker_grl_sparql_t *
diff --git a/src/media/tracker/grl-tracker-utils.h b/src/media/tracker/grl-tracker-utils.h
index 2c3e835..b0e1945 100644
--- a/src/media/tracker/grl-tracker-utils.h
+++ b/src/media/tracker/grl-tracker-utils.h
@@ -44,11 +44,18 @@
 
 /**/
 
+typedef void (*tracker_grl_sparql_setter_cb_t) (TrackerSparqlCursor *cursor,
+                                                gint                 column,
+                                                GrlMedia            *media,
+                                                GrlKeyID             key);
+
 typedef struct {
   GrlKeyID     grl_key;
   const gchar *sparql_key_name;
   const gchar *sparql_key_attr;
   const gchar *sparql_key_flavor;
+
+  tracker_grl_sparql_setter_cb_t set_value;
 } tracker_grl_sparql_t;
 
 const GList *grl_tracker_supported_keys (GrlMetadataSource *source);



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