[grilo-plugins] tracker: Support favorite read/write
- From: Victor Toso de Carvalho <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] tracker: Support favorite read/write
- Date: Fri, 2 Dec 2016 21:24:21 +0000 (UTC)
commit bb3a85d9ed53335e7f64ce3ecd562ebc1bc27d11
Author: Marinus Schraal <mschraal scr gnome org>
Date: Sun Nov 20 14:51:28 2016 +0100
tracker: Support favorite read/write
Support GRL_METADATA_KEY_FAVOURITE reading & writing in the tracker
backend. The tracker ontology for this uses hasTag in combination with
the nao:predefined-tag-favorite property, which doesn't line up directly
with the boolean format Grilo uses. So either set the key with the given
property or delete the tag completely.
https://bugzilla.gnome.org/show_bug.cgi?id=774748
src/tracker/grl-tracker-source-api.c | 19 +++++++++++++---
src/tracker/grl-tracker-utils.c | 39 ++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/src/tracker/grl-tracker-source-api.c b/src/tracker/grl-tracker-source-api.c
index 9df1a73..31faabe 100644
--- a/src/tracker/grl-tracker-source-api.c
+++ b/src/tracker/grl-tracker-source-api.c
@@ -156,6 +156,9 @@ GRL_LOG_DOMAIN_STATIC(tracker_source_result_log_domain);
"?urn nie:url \"%s\" " \
"}"
+#define TRACKER_DELETE_REQUEST \
+ "DELETE { <%s> %s } WHERE { <%s> a nfo:Media . %s }"
+
#define TRACKER_SAVE_REQUEST \
"DELETE { <%s> %s } WHERE { <%s> a nfo:Media . %s } " \
"INSERT { <%s> a nfo:Media ; %s . }"
@@ -658,6 +661,7 @@ grl_tracker_source_writable_keys (GrlSource *source)
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_PLAY_COUNT,
GRL_METADATA_KEY_LAST_PLAYED,
GRL_METADATA_KEY_LAST_POSITION,
+ GRL_METADATA_KEY_FAVOURITE,
NULL);
}
return keys;
@@ -951,10 +955,17 @@ grl_tracker_source_store_metadata (GrlSource *source,
sparql_delete = grl_tracker_get_delete_string (sms->keys);
sparql_cdelete = grl_tracker_get_delete_conditional_string (urn, sms->keys);
sparql_insert = grl_tracker_tracker_get_insert_string (sms->media, sms->keys);
- sparql_final = g_strdup_printf (TRACKER_SAVE_REQUEST,
- urn, sparql_delete,
- urn, sparql_cdelete,
- urn, sparql_insert);
+
+ if (g_strcmp0 (sparql_insert, "") == 0) {
+ sparql_final = g_strdup_printf (TRACKER_DELETE_REQUEST,
+ urn, sparql_delete,
+ urn, sparql_cdelete);
+ } else {
+ sparql_final = g_strdup_printf (TRACKER_SAVE_REQUEST,
+ urn, sparql_delete,
+ urn, sparql_cdelete,
+ urn, sparql_insert);
+ }
os = grl_tracker_op_initiate_set_metadata (sparql_final,
(GAsyncReadyCallback) tracker_store_metadata_cb,
diff --git a/src/tracker/grl-tracker-utils.c b/src/tracker/grl-tracker-utils.c
index fd13041..4c296bc 100644
--- a/src/tracker/grl-tracker-utils.c
+++ b/src/tracker/grl-tracker-utils.c
@@ -92,6 +92,21 @@ set_date (TrackerSparqlCursor *cursor,
}
static void
+set_favourite (TrackerSparqlCursor *cursor,
+ gint column,
+ GrlMedia *media,
+ GrlKeyID key)
+{
+ const gchar *str = tracker_sparql_cursor_get_string (cursor, column, NULL);
+ gboolean is_favourite = FALSE;
+
+ if (str != NULL && g_str_has_suffix (str, "predefined-tag-favorite"))
+ is_favourite = TRUE;
+
+ grl_data_set_boolean (GRL_DATA (media), key, is_favourite);
+}
+
+static void
set_title_from_filename (TrackerSparqlCursor *cursor,
gint column,
GrlMedia *media,
@@ -386,6 +401,12 @@ grl_tracker_setup_key_mappings (void)
"nmm:trackNumber",
"nmm:trackNumber(?urn)",
"audio");
+
+ insert_key_mapping_with_setter (GRL_METADATA_KEY_FAVOURITE,
+ "nao:hasTag",
+ "nao:hasTag(?urn)",
+ "audio",
+ set_favourite);
}
tracker_grl_sparql_t *
@@ -480,6 +501,16 @@ gen_prop_insert_string (GString *gstr,
grl_data_get_float (data, assoc->grl_key));
break;
+ case G_TYPE_BOOLEAN:
+ /* Special case for favourite tag, see comment in
+ * grl_tracker_tracker_get_insert_string for more details.
+ */
+ if (assoc->grl_key == GRL_METADATA_KEY_FAVOURITE) {
+ g_string_append_printf (gstr, "%s nao:predefined-tag-favorite",
+ assoc->sparql_key_attr);
+ }
+ break;
+
default:
break;
}
@@ -504,6 +535,14 @@ grl_tracker_tracker_get_insert_string (GrlMedia *media, const GList *keys)
if (assoc == NULL)
continue;
+ /* The favourite key is really setting or deleting a tag
+ * in tracker, so in the case of setting it to false skip
+ * the insert string creation step for this key completely.
+ */
+ if (assoc->grl_key == GRL_METADATA_KEY_FAVOURITE &&
+ !grl_media_get_favourite (media))
+ continue;
+
if (!grl_data_has_key (GRL_DATA (media), key_id))
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]