[gnome-photos/wip/rishi/manager-model: 2/6] base-manager: Consolidate the removal logic in one place



commit 2ad9105f87ddd5d52a22ade9a8d7e77a9fbca8eb
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Nov 5 17:15:17 2016 +0100

    base-manager: Consolidate the removal logic in one place
    
    The code to remove an object will get slightly lengthier when we
    implement the GListModel interface. Hence, there is value in removing
    the duplication.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774191

 src/photos-base-manager.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 08220b3..31ce0be 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -481,6 +481,8 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
 {
   PhotosBaseManagerPrivate *priv;
   GHashTableIter iter;
+  GList *l;
+  GList *removed_ids = NULL;
   GObject *object;
   const gchar *id;
 
@@ -498,12 +500,16 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
        */
       builtin = photos_filterable_get_builtin (PHOTOS_FILTERABLE (object));
       if (g_hash_table_lookup (new_objects, id) == NULL && !builtin)
-        {
-          g_object_ref (object);
-          g_hash_table_iter_remove (&iter);
-          g_signal_emit (self, signals[OBJECT_REMOVED], 0, object);
-          g_object_unref (object);
-        }
+        removed_ids = g_list_prepend (removed_ids, g_strdup (id));
+    }
+
+  /* Calling photos_base_manager_remove_object_by_id invalidates the
+   * GHashTableIter, so we can't use it while iterating the GHashTable.
+   */
+  for (l = removed_ids; l != NULL; l = l->next)
+    {
+      id = (gchar *) l->data;
+      photos_base_manager_remove_object_by_id (self, id);
     }
 
   g_hash_table_iter_init (&iter, new_objects);
@@ -517,6 +523,8 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
     }
 
   /* TODO: merge existing item properties with new values. */
+
+  g_list_free_full (removed_ids, g_free);
 }
 
 


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