[gnome-photos/wip/halfline/album-refresh: 1/2] wip! item-manager: Handle collection COLUMNS_URNs with stripped prefix




commit 8ab02ff50f91b1572c8b65447de94a4f2340a98f
Author: Ray Strode <rstrode redhat com>
Date:   Tue May 3 12:50:21 2022 -0400

    wip! item-manager: Handle collection COLUMNS_URNs with stripped prefix
    
    For reasons I don't understand, tracker sometimes returns
    blank node urns without their qualifiers (so "82" instead of "urn:bnode:82")
    
    That causes duplicate entries to get added to the collection model, and
    makes the album view get confused.
    
    This commit tries to accomodate the oddity by manually adding the
    prefix back.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/-/issues/197

 src/photos-base-item.c    | 16 ++++++++++++----
 src/photos-item-manager.c | 15 +++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 3b20bc2e..eef0bf66 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -2807,6 +2807,7 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
   gchar *name_fallback;
   gint64 height;
   gint64 width;
+  g_autofree char *bnode_id = NULL;
 
   priv = photos_base_item_get_instance_private (self);
 
@@ -2816,7 +2817,18 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
   photos_utils_set_string (&priv->uri, uri);
   g_object_notify (G_OBJECT (self), "uri");
 
+  rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
+  photos_utils_set_string (&priv->rdf_type, rdf_type);
+
+  photos_base_item_update_info_from_type (self);
+
   id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+
+  if (priv->collection && !g_str_has_prefix (id, "urn:bnode:"))
+    {
+      bnode_id = g_strdup_printf ("urn:bnode:%s", id);
+      id = bnode_id;
+    }
   photos_utils_set_string (&priv->id, id);
   g_object_notify (G_OBJECT (self), "id");
 
@@ -2841,10 +2853,6 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
   mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL);
   photos_utils_set_string (&priv->mime_type, mime_type);
 
-  rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
-  photos_utils_set_string (&priv->rdf_type, rdf_type);
-
-  photos_base_item_update_info_from_type (self);
   priv->favorite = favorite && !priv->collection;
 
   priv->ctime = -1;
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 73ccaaa6..30a31769 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -305,6 +305,7 @@ photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
   PhotosBaseManager *item_mngr_chld;
   gboolean is_collection;
   const gchar *id;
+  g_autofree char *bnode_id = NULL;
 
   g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
   g_return_if_fail (base_item_type == G_TYPE_NONE
@@ -326,6 +327,12 @@ photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
   item_mngr_chld = self->item_mngr_chldrn[mode];
   id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
 
+  if (mode == PHOTOS_WINDOW_MODE_COLLECTIONS && !g_str_has_prefix (id, "urn:bnode:"))
+    {
+      bnode_id = g_strdup_printf ("urn:bnode:%s", id);
+      id = bnode_id;
+    }
+
   item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (item_mngr_chld, id));
   if (item != NULL)
     {
@@ -1378,6 +1385,7 @@ photos_item_manager_create_item (PhotosItemManager *self,
   PhotosBaseItem *item;
   PhotosBaseItem *ret_val = NULL;
   const gchar *id;
+  g_autofree char *bnode_id = NULL;
 
   g_return_val_if_fail (PHOTOS_IS_ITEM_MANAGER (self), NULL);
   g_return_val_if_fail (base_item_type == G_TYPE_NONE
@@ -1386,6 +1394,13 @@ photos_item_manager_create_item (PhotosItemManager *self,
   g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), NULL);
 
   id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+
+  if (photos_item_manager_cursor_is_collection (cursor) && !g_str_has_prefix (id, "urn:bnode:"))
+    {
+      bnode_id = g_strdup_printf ("urn:bnode:%s", id);
+      id = bnode_id;
+    }
+
   item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id));
   if (item != NULL)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]