[PATCH 5/7] tracker: add metadata support
- From: llandwerlin gmail com
- To: grilo-list gnome org
- Subject: [PATCH 5/7] tracker: add metadata support
- Date: Tue, 18 Jan 2011 18:31:59 +0000
From: Lionel Landwerlin <lionel g landwerlin linux intel com>
Signed-off-by: Lionel Landwerlin <lionel g landwerlin linux intel com>
---
src/tracker/grl-tracker.c | 118 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 116 insertions(+), 2 deletions(-)
diff --git a/src/tracker/grl-tracker.c b/src/tracker/grl-tracker.c
index 6f60cc1..d4eaaa7 100644
--- a/src/tracker/grl-tracker.c
+++ b/src/tracker/grl-tracker.c
@@ -70,6 +70,12 @@ enum {
/* --- Other --- */
+#define TRACKER_METADATA_REQUEST " \
+ SELECT %s \
+ WHERE { \
+ ?urn nie:isStoredAs <%s> \
+ }"
+
typedef struct {
GrlKeyID grl_key;
const gchar *sparql_key_name;
@@ -121,10 +127,12 @@ static GrlSupportedOps grl_tracker_source_supported_operations (GrlMetadataSourc
static const GList *grl_tracker_source_supported_keys (GrlMetadataSource *source);
-
static void grl_tracker_source_query (GrlMediaSource *source,
GrlMediaSourceQuerySpec *qs);
+static void grl_tracker_source_metadata (GrlMediaSource *source,
+ GrlMediaSourceMetadataSpec *ms);
+
static void setup_key_mappings (void);
/* ===================== Globals ================= */
@@ -198,6 +206,7 @@ grl_tracker_source_class_init (GrlTrackerSourceClass * klass)
GObjectClass *g_class = G_OBJECT_CLASS (klass);
source_class->query = grl_tracker_source_query;
+ source_class->metadata = grl_tracker_source_metadata;
metadata_class->supported_keys = grl_tracker_source_supported_keys;
metadata_class->supported_operations = grl_tracker_source_supported_operations;
@@ -385,6 +394,38 @@ get_mapping_from_sparql (const gchar *key)
key);
}
+static GList *
+get_mapping_from_grl (const GrlKeyID key)
+{
+ return (GList *) g_hash_table_lookup (grl_to_sparql_mapping, key);
+}
+
+static gchar *
+get_select_string (GrlMediaSource *source, const GList *keys)
+{
+ const GList *key = keys;
+ GString *gstr = g_string_new ("");
+ GList *assoc_list;
+ tracker_grl_sparql_t *assoc;
+
+ while (key != NULL) {
+ assoc_list = get_mapping_from_grl ((GrlKeyID) key->data);
+ while (assoc_list != NULL) {
+ assoc = (tracker_grl_sparql_t *) assoc_list->data;
+ if (assoc != NULL) {
+ g_string_append_printf (gstr, "%s AS %s",
+ assoc->sparql_key_attr,
+ assoc->sparql_key_name);
+ g_string_append (gstr, " ");
+ }
+ assoc_list = assoc_list->next;
+ }
+ key = key->next;
+ }
+
+ return g_string_free (gstr, FALSE);
+}
+
/* Builds an appropriate GrlMedia based on ontology type returned by tracker, or
NULL if unknown */
static GrlMedia *
@@ -592,6 +633,52 @@ tracker_query_cb (GObject *source_object,
(gpointer) operation);
}
+static void
+tracker_metadata_cb (GObject *source_object,
+ GAsyncResult *result,
+ GrlMediaSourceMetadataSpec *ms)
+{
+ GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (ms->source);
+ gint col;
+ GError *tracker_error = NULL, *error = NULL;
+ TrackerSparqlCursor *cursor;
+
+ GRL_DEBUG ("%s", __FUNCTION__);
+
+ cursor = tracker_sparql_connection_query_finish (priv->tracker_connection,
+ result, &tracker_error);
+
+ if (tracker_error) {
+ GRL_WARNING ("Could not execute sparql query: %s", tracker_error->message);
+
+ error = g_error_new (GRL_CORE_ERROR,
+ GRL_CORE_ERROR_BROWSE_FAILED,
+ "Failed to start browse action : %s",
+ tracker_error->message);
+
+ ms->callback (ms->source, NULL, ms->user_data, error);
+
+ g_error_free (tracker_error);
+ g_error_free (error);
+
+ goto end_operation;
+ }
+
+
+ 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 (ms->media, cursor, col);
+ }
+
+ ms->callback (ms->source, ms->media, ms->user_data, NULL);
+
+ end_operation:
+ if (cursor)
+ g_object_unref (G_OBJECT (cursor));
+}
+
/* ================== API Implementation ================ */
static GrlSupportedOps
@@ -601,7 +688,7 @@ grl_tracker_source_supported_operations (GrlMetadataSource *metadata_source)
GrlTrackerSource *source;
source = GRL_TRACKER_SOURCE (metadata_source);
- caps = GRL_OP_QUERY;
+ caps = GRL_OP_METADATA | GRL_OP_QUERY;
return caps;
}
@@ -708,3 +795,30 @@ grl_tracker_source_query (GrlMediaSource *source,
qs->callback (qs->source, qs->query_id, NULL, 0, qs->user_data, error);
g_error_free (error);
}
+
+static void
+grl_tracker_source_metadata (GrlMediaSource *source,
+ GrlMediaSourceMetadataSpec *ms)
+{
+ GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
+ gchar *sparql_select, *sparql_final;
+
+ GRL_DEBUG ("%s", __FUNCTION__);
+
+ sparql_select = get_select_string (source, ms->keys);
+ sparql_final = g_strdup_printf (TRACKER_METADATA_REQUEST, sparql_select,
+ grl_media_get_id (ms->media));
+
+ GRL_DEBUG ("select: '%s'", sparql_final);
+
+ tracker_sparql_connection_query_async (priv->tracker_connection,
+ sparql_final,
+ NULL,
+ (GAsyncReadyCallback) tracker_metadata_cb,
+ ms);
+
+ if (sparql_select != NULL)
+ g_free (sparql_select);
+ if (sparql_final != NULL)
+ g_free (sparql_final);
+}
--
1.7.2.3
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]