[gnome-photos/wip/rishi/manager-model: 1/5] 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/wip/rishi/manager-model: 1/5] base-manager: Consolidate the removal logic in one place
- Date: Tue, 15 Nov 2016 11:08:50 +0000 (UTC)
commit 80e9bab2a0c4dcce710e2179db6b33fe683134e5
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]