[PATCH 05/14] tracker: add metadata support
- From: llandwerlin gmail com
- To: grilo-list gnome org
- Subject: [PATCH 05/14] tracker: add metadata support
- Date: Mon, 17 Jan 2011 10:18:02 +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 | 110 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 98 insertions(+), 12 deletions(-)
diff --git a/src/tracker/grl-tracker.c b/src/tracker/grl-tracker.c
index 8d93c85..d997446 100644
--- a/src/tracker/grl-tracker.c
+++ b/src/tracker/grl-tracker.c
@@ -81,6 +81,12 @@ enum {
ORDER BY DESC(nfo:fileLastModified(?urn)) \
OFFSET %i LIMIT %i"
+#define TRACKER_METADATA_REQUEST " \
+ SELECT %s \
+ WHERE { \
+ ?urn nie:isStoredAs <%s> \
+ }"
+
typedef enum {
MEDIA_PROP_NONE = 0,
MEDIA_PROP_STRING,
@@ -97,14 +103,14 @@ typedef struct {
} tracker_grl_sparql_t;
struct OperationSpec {
- GrlMediaSource *source;
- GrlTrackerSourcePriv *priv;
- guint operation_id;
- const GList *keys;
- guint skip;
- guint count;
- GrlMediaSourceResultCb callback;
- gpointer user_data;
+ GrlMediaSource *source;
+ GrlTrackerSourcePriv *priv;
+ guint operation_id;
+ const GList *keys;
+ guint skip;
+ guint count;
+ GrlMediaSourceResultCb callback;
+ gpointer user_data;
};
struct _GrlTrackerSourcePriv {
@@ -133,6 +139,9 @@ static void grl_tracker_source_query (GrlMediaSource *source,
static void grl_tracker_source_search (GrlMediaSource *source,
GrlMediaSourceSearchSpec *ss);
+static void grl_tracker_source_metadata (GrlMediaSource *source,
+ GrlMediaSourceMetadataSpec *ms);
+
static void setup_key_mappings (void);
/* ===================== Globals ================= */
@@ -212,8 +221,9 @@ grl_tracker_source_class_init (GrlTrackerSourceClass * klass)
GrlMetadataSourceClass *metadata_class = GRL_METADATA_SOURCE_CLASS (klass);
GObjectClass *g_class = G_OBJECT_CLASS (klass);
- source_class->query = grl_tracker_source_query;
- source_class->search = grl_tracker_source_search;
+ source_class->query = grl_tracker_source_query;
+ source_class->search = grl_tracker_source_search;
+ 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;
@@ -463,6 +473,10 @@ fill_grilo_media_from_sparql (GrlMedia *media,
assoc->grl_key_type,
tracker_sparql_cursor_get_string (cursor, column, NULL));
+ if (grl_data_has_key (GRL_DATA (media), assoc->grl_key)) {
+ GRL_DEBUG ("\t\tDropping, already here");
+ }
+
switch (assoc->grl_key_type) {
case MEDIA_PROP_STRING:
val.str_val = tracker_sparql_cursor_get_string (cursor, column, NULL);
@@ -546,10 +560,54 @@ tracker_query_cb (GObject *source_object,
end_operation:
if (cursor)
g_object_unref (G_OBJECT (cursor));
-
g_slice_free (struct OperationSpec, 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 = 1 ; 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
@@ -559,7 +617,7 @@ grl_tracker_source_supported_operations (GrlMetadataSource *metadata_source)
GrlTrackerSource *source;
source = GRL_TRACKER_SOURCE (metadata_source);
- caps = GRL_OP_QUERY | GRL_OP_SEARCH;
+ caps = GRL_OP_QUERY | GRL_OP_SEARCH | GRL_OP_METADATA;
return caps;
}
@@ -731,3 +789,31 @@ grl_tracker_source_search (GrlMediaSource *source, GrlMediaSourceSearchSpec *ss)
ss->callback (ss->source, ss->search_id, NULL, 0, ss->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 ("grl_tracker_source_metadata");
+
+ 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]