[PATCH 2/2] tracker: add support for pictures orientation
- From: lionel g landwerlin linux intel com
- To: grilo-list gnome org
- Subject: [PATCH 2/2] tracker: add support for pictures orientation
- Date: Mon, 14 Mar 2011 18:19:15 +0000
From: Lionel Landwerlin <lionel g landwerlin linux intel com>
Signed-off-by: Lionel Landwerlin <lionel g landwerlin linux intel 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 | 40 ++++++++++++++++++++
src/media/tracker/grl-tracker-utils.h | 7 ++++
4 files changed, 103 insertions(+), 50 deletions(-)
diff --git a/src/media/tracker/grl-tracker-media-api.c b/src/media/tracker/grl-tracker-media-api.c
index b61fdd6..b1dfccf 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 f07a50d..23990af 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 d2db7df..606b654 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
@@ -182,6 +217,11 @@ grl_tracker_setup_key_mappings (void)
insert_key_mapping (GRL_METADATA_KEY_ORIGINAL_HEIGHT,
"nfo:verticalResolution(?urn)",
"image");
+
+ insert_key_mapping_with_setter (GRL_METADATA_KEY_ORENTATION,
+ "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);
--
1.7.4.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]