[grilo-plugins] tracker: Fix type of media when it has multiple types
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] tracker: Fix type of media when it has multiple types
- Date: Mon, 21 Mar 2016 22:56:00 +0000 (UTC)
commit cacc7c4ca0fedf507d8f8328b2cfead3ebcfdd1f
Author: Bastien Nocera <hadess hadess net>
Date: Tue Mar 15 14:33:06 2016 +0100
tracker: Fix type of media when it has multiple types
To avoid a Video application receiving an audio file, when a file is
tagged in Tracker as having both types, and possibly shifting the
problem to another type if we were to have a simple "priority" list,
check what the application wants through the GrlTypeFilter it sets, and
prefer creating a video file if the app prefers videos.
This should stop totem receiving GrlMediaAudios when it only ever
expects GrlMediaVideo or containers.
https://bugzilla.gnome.org/show_bug.cgi?id=730028
src/tracker/grl-tracker-request-queue.h | 1 +
src/tracker/grl-tracker-source-api.c | 8 ++++-
src/tracker/grl-tracker-source-notif.c | 2 +-
src/tracker/grl-tracker-utils.c | 47 +++++++++++++++++++++++--------
src/tracker/grl-tracker-utils.h | 3 +-
5 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/src/tracker/grl-tracker-request-queue.h b/src/tracker/grl-tracker-request-queue.h
index ee61908..8805b9c 100644
--- a/src/tracker/grl-tracker-request-queue.h
+++ b/src/tracker/grl-tracker-request-queue.h
@@ -51,6 +51,7 @@ typedef struct {
guint skip;
guint count;
guint current;
+ GrlTypeFilter type_filter;
} GrlTrackerOp;
typedef struct _GrlTrackerQueue GrlTrackerQueue;
diff --git a/src/tracker/grl-tracker-source-api.c b/src/tracker/grl-tracker-source-api.c
index c7e01b9..9df1a73 100644
--- a/src/tracker/grl-tracker-source-api.c
+++ b/src/tracker/grl-tracker-source-api.c
@@ -427,7 +427,7 @@ get_sparql_type_filter (GrlOperationOptions *options,
GRL_ODEBUG ("\tParsing line %i of type %s", \
os->current, sparql_type); \
\
- media = grl_tracker_build_grilo_media (sparql_type); \
+ media = grl_tracker_build_grilo_media (sparql_type, os->type_filter);\
\
if (media != NULL) { \
for (col = 1 ; \
@@ -594,7 +594,7 @@ tracker_media_from_uri_cb (GObject *source_object,
if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
/* Build grilo media */
sparql_type = tracker_sparql_cursor_get_string (cursor, 0, NULL);
- media = grl_tracker_build_grilo_media (sparql_type);
+ media = grl_tracker_build_grilo_media (sparql_type, GRL_TYPE_FILTER_NONE);
/* Translate Sparql result into Grilo result */
for (col = 0 ; col < tracker_sparql_cursor_get_n_columns (cursor) ; col++) {
@@ -835,6 +835,7 @@ grl_tracker_source_query (GrlSource *source,
os->keys = qs->keys;
os->skip = skip;
os->count = count;
+ os->type_filter = grl_operation_options_get_type_filter (qs->options);
os->data = qs;
/* os->cb.sr = qs->callback; */
/* os->user_data = qs->user_data; */
@@ -1012,6 +1013,7 @@ grl_tracker_source_search (GrlSource *source, GrlSourceSearchSpec *ss)
os->keys = ss->keys;
os->skip = skip;
os->count = count;
+ os->type_filter = grl_operation_options_get_type_filter (ss->options);
grl_tracker_queue_push (grl_tracker_queue, os);
@@ -1196,6 +1198,7 @@ grl_tracker_source_browse_category (GrlSource *source,
os->keys = bs->keys;
os->skip = skip;
os->count = count;
+ os->type_filter = grl_operation_options_get_type_filter (bs->options);
grl_tracker_queue_push (grl_tracker_queue, os);
@@ -1255,6 +1258,7 @@ grl_tracker_source_browse_filesystem (GrlSource *source,
os->keys = bs->keys;
os->skip = skip;
os->count = count;
+ os->type_filter = grl_operation_options_get_type_filter (bs->options);
grl_tracker_queue_push (grl_tracker_queue, os);
diff --git a/src/tracker/grl-tracker-source-notif.c b/src/tracker/grl-tracker-source-notif.c
index 4b35e0e..027174e 100644
--- a/src/tracker/grl-tracker-source-notif.c
+++ b/src/tracker/grl-tracker-source-notif.c
@@ -122,7 +122,7 @@ notify_change (GrlTrackerSourceNotify *self,
goto out;
id_str = g_strdup_printf ("%i", id);
- media = grl_tracker_build_grilo_media (info->type);
+ media = grl_tracker_build_grilo_media (info->type, GRL_TYPE_FILTER_NONE);
grl_media_set_id (media, id_str);
grl_media_set_url (media, info->url);
diff --git a/src/tracker/grl-tracker-utils.c b/src/tracker/grl-tracker-utils.c
index 47dff05..be3b36d 100644
--- a/src/tracker/grl-tracker-utils.c
+++ b/src/tracker/grl-tracker-utils.c
@@ -579,12 +579,35 @@ grl_tracker_get_delete_conditional_string (const gchar *urn,
return ret;
}
+static GrlMedia *
+grl_tracker_build_grilo_media_default (GHashTable *ht)
+{
+ if (g_hash_table_lookup (ht, RDF_TYPE_MUSIC)) {
+ return grl_media_audio_new ();
+ } else if (g_hash_table_lookup (ht, RDF_TYPE_VIDEO)) {
+ return grl_media_video_new ();
+ } else if (g_hash_table_lookup (ht, RDF_TYPE_IMAGE)) {
+ return grl_media_image_new ();
+ } else if (g_hash_table_lookup (ht, RDF_TYPE_ARTIST)) {
+ return grl_media_container_new ();
+ } else if (g_hash_table_lookup (ht, RDF_TYPE_ALBUM)) {
+ return grl_media_container_new ();
+ } else if (g_hash_table_lookup (ht, RDF_TYPE_CONTAINER)) {
+ return grl_media_container_new ();
+ } else if (g_hash_table_lookup (ht, RDF_TYPE_FOLDER)) {
+ return grl_media_container_new ();
+ }
+
+ return NULL;
+}
+
/**/
/* Builds an appropriate GrlMedia based on ontology type returned by
tracker, or NULL if unknown */
GrlMedia *
-grl_tracker_build_grilo_media (const gchar *rdf_type)
+grl_tracker_build_grilo_media (const gchar *rdf_type,
+ GrlTypeFilter type_filter)
{
GrlMedia *media = NULL;
gchar **rdf_single_type;
@@ -602,20 +625,20 @@ grl_tracker_build_grilo_media (const gchar *rdf_type)
for (; i>= 0; i--)
g_hash_table_insert (ht, g_path_get_basename (rdf_single_type[i]), GINT_TO_POINTER(TRUE));
- if (g_hash_table_lookup (ht, RDF_TYPE_MUSIC)) {
+ if (type_filter == GRL_TYPE_FILTER_NONE ||
+ type_filter == GRL_TYPE_FILTER_ALL) {
+ media = grl_tracker_build_grilo_media_default (ht);
+ } else if ((type_filter & GRL_TYPE_FILTER_AUDIO) &&
+ g_hash_table_lookup (ht, RDF_TYPE_MUSIC)) {
media = grl_media_audio_new ();
- } else if (g_hash_table_lookup (ht, RDF_TYPE_VIDEO)) {
+ } else if ((type_filter & GRL_TYPE_FILTER_VIDEO) &&
+ g_hash_table_lookup (ht, RDF_TYPE_VIDEO)) {
media = grl_media_video_new ();
- } else if (g_hash_table_lookup (ht, RDF_TYPE_IMAGE)) {
+ } else if ((type_filter & GRL_TYPE_FILTER_IMAGE) &&
+ g_hash_table_lookup (ht, RDF_TYPE_IMAGE)) {
media = grl_media_image_new ();
- } else if (g_hash_table_lookup (ht, RDF_TYPE_ARTIST)) {
- media = grl_media_container_new ();
- } else if (g_hash_table_lookup (ht, RDF_TYPE_ALBUM)) {
- media = grl_media_container_new ();
- } else if (g_hash_table_lookup (ht, RDF_TYPE_CONTAINER)) {
- media = grl_media_container_new ();
- } else if (g_hash_table_lookup (ht, RDF_TYPE_FOLDER)) {
- media = grl_media_container_new ();
+ } else {
+ media = grl_tracker_build_grilo_media_default (ht);
}
g_hash_table_destroy (ht);
diff --git a/src/tracker/grl-tracker-utils.h b/src/tracker/grl-tracker-utils.h
index 41bd232..6a8dddc 100644
--- a/src/tracker/grl-tracker-utils.h
+++ b/src/tracker/grl-tracker-utils.h
@@ -71,7 +71,8 @@ void grl_tracker_setup_key_mappings (void);
tracker_grl_sparql_t *grl_tracker_get_mapping_from_sparql (const gchar *key);
-GrlMedia *grl_tracker_build_grilo_media (const gchar *rdf_type);
+GrlMedia *grl_tracker_build_grilo_media (const gchar *rdf_type,
+ GrlTypeFilter type_filter);
gchar *grl_tracker_source_get_device_constraint (GrlTrackerSourcePriv *priv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]