[gnome-photos] base-manager: Consolidate the removal logic in one place
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] base-manager: Consolidate the removal logic in one place
- Date: Fri, 18 Nov 2016 08:07:31 +0000 (UTC)
commit 09384965650fab3eebad859ef9353f5e3544ce0f
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 777ce67..b59a0cc 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -482,6 +482,8 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
PhotosBaseManagerPrivate *priv;
GHashTableIter iter;
GObject *object;
+ GSList *l;
+ GSList *removed_ids = NULL;
const gchar *id;
g_return_if_fail (PHOTOS_IS_BASE_MANAGER (self));
@@ -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_slist_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_slist_free_full (removed_ids, g_free);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]