[gnome-photos/wip/rishi/manager-model: 2/5] base-manager: Simplify code



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

    base-manager: Simplify code

 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 190cbc2..fb3d30a 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -486,6 +486,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;
 
@@ -503,12 +505,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);
@@ -522,6 +528,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]