[gnome-photos] item-manager: Add photos_item_manager_clear



commit 8d1d00232a9e62deb93ae4d4f498d0b51b3dad2e
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Aug 30 10:49:25 2016 +0200

    item-manager: Add photos_item_manager_clear
    
    Encouraging the TrackerControllers to take a peek at the child
    BaseManagers doesn't sound like a good idea. Plus, it is slightly more
    efficient to update the 0th child if the ItemManager is in control of
    the operation - we can iterate over the, hopefully, smaller child
    BaseManager instead of the union of all children.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770342

 src/photos-item-manager.c |   47 +++++++++++++++++++++++++++++++++++++++++++++
 src/photos-item-manager.h |    3 ++
 2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index c6d7cd1..50caa05 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -779,6 +779,53 @@ photos_item_manager_add_item_for_mode (PhotosItemManager *self, PhotosWindowMode
 }
 
 
+void
+photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
+{
+  GHashTable *items;
+  GHashTableIter iter;
+  PhotosBaseManager *item_mngr_chld;
+  const gchar *id;
+
+  g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_NONE);
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_EDIT);
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
+
+  item_mngr_chld = self->item_mngr_chldrn[mode];
+  items = photos_base_manager_get_objects (item_mngr_chld);
+
+  g_hash_table_iter_init (&iter, items);
+  while (g_hash_table_iter_next (&iter, (gpointer *) &id, NULL))
+    {
+      PhotosBaseItem *item = NULL;
+      guint i;
+
+      for (i = 1; self->item_mngr_chldrn[i] != NULL; i++)
+        {
+          if (item_mngr_chld == self->item_mngr_chldrn[i])
+            continue;
+
+          item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr_chldrn[i], id));
+          if (item != NULL)
+            break;
+        }
+
+      if (item != NULL)
+        {
+          const gchar *id1;
+
+          id1 = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+          g_assert_cmpstr (id, ==, id1);
+
+          photos_base_manager_remove_object_by_id (self->item_mngr_chldrn[0], id);
+        }
+    }
+
+  photos_base_manager_clear (item_mngr_chld);
+}
+
+
 PhotosBaseItem *
 photos_item_manager_create_item (PhotosItemManager *self, TrackerSparqlCursor *cursor)
 {
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index 367d9d3..83b90ee 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -93,6 +93,9 @@ void                      photos_item_manager_add_item_for_mode            (Phot
                                                                             PhotosWindowMode mode,
                                                                             TrackerSparqlCursor *cursor);
 
+void                      photos_item_manager_clear                        (PhotosItemManager *self,
+                                                                            PhotosWindowMode mode);
+
 PhotosBaseItem           *photos_item_manager_create_item                  (PhotosItemManager *self,
                                                                             TrackerSparqlCursor *cursor);
 


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