[gnome-photos/wip/rishi/collection: 12/28] base-manager, item-manager: Log additions and removals



commit 295588ddaaf163747df6aed664735d5e5c66a8ce
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Sep 4 18:42:43 2017 +0200

    base-manager, item-manager: Log additions and removals

 src/photos-base-manager.c | 55 +++++++++++++++++++++++++++++++++++++++++++----
 src/photos-item-manager.c | 37 +++++++++++++++++++++++++++----
 2 files changed, 84 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 2f8f9e39..13ee5c37 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -28,6 +28,7 @@
 #include <glib.h>
 
 #include "photos-base-manager.h"
+#include "photos-debug.h"
 #include "photos-filterable.h"
 
 
@@ -126,6 +127,7 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
   GSequenceIter *iter;
   PhotosBaseManagerObjectData *object_data;
   const gchar *id;
+  const gchar *type_name;
   guint position;
 
   priv = photos_base_manager_get_instance_private (self);
@@ -133,7 +135,7 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
   id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
   old_object = photos_base_manager_get_object_by_id (self, id);
   if (old_object != NULL)
-    return;
+    goto out;
 
   if (priv->sort_func == NULL)
     {
@@ -151,6 +153,29 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
 
   photos_base_manager_objects_changed (self, position, 0, 1);
   g_signal_emit (self, signals[OBJECT_ADDED], 0, object);
+
+ out:
+  type_name = G_OBJECT_TYPE_NAME (self);
+  if (old_object == NULL)
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) added for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    object,
+                    id);
+    }
+  else
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) already exists for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    old_object,
+                    id);
+    }
 }
 
 
@@ -254,15 +279,16 @@ static void
 photos_base_manager_default_remove_object_by_id (PhotosBaseManager *self, const gchar *id)
 {
   PhotosBaseManagerPrivate *priv;
-  GObject *object;
+  GObject *object = NULL;
   PhotosBaseManagerObjectData *object_data;
+  const gchar *type_name;
   guint position;
 
   priv = photos_base_manager_get_instance_private (self);
 
   object_data = g_hash_table_lookup (priv->objects, id);
   if (object_data == NULL)
-    return;
+    goto out;
 
   position = g_sequence_iter_get_position (object_data->iter);
   g_sequence_remove (object_data->iter);
@@ -273,7 +299,24 @@ photos_base_manager_default_remove_object_by_id (PhotosBaseManager *self, const
   photos_base_manager_objects_changed (self, position, 1, 0);
   g_signal_emit (self, signals[OBJECT_REMOVED], 0, object);
 
-  g_object_unref (object);
+ out:
+  type_name = G_OBJECT_TYPE_NAME (self);
+  if (object_data == NULL)
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: object not found for %s", type_name, self, 
G_STRFUNC, id);
+    }
+  else
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) removed for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    object,
+                    id);
+    }
+
+  g_clear_object (&object);
 }
 
 
@@ -555,6 +598,7 @@ photos_base_manager_clear (PhotosBaseManager *self)
   PhotosBaseManagerPrivate *priv;
   GSequenceIter *begin_iter;
   GSequenceIter *end_iter;
+  const gchar *type_name;
   guint count;
 
   g_return_if_fail (PHOTOS_IS_BASE_MANAGER (self));
@@ -572,6 +616,9 @@ photos_base_manager_clear (PhotosBaseManager *self)
 
   photos_base_manager_objects_changed (self, 0, count, 0);
   g_signal_emit (self, signals[CLEAR], 0);
+
+  type_name = G_OBJECT_TYPE_NAME (self);
+  photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: cleared", type_name, self, G_STRFUNC);
 }
 
 
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index b7dc3b2f..0832e5a8 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -30,6 +30,7 @@
 #include <tracker-sparql.h>
 
 #include "egg-counter.h"
+#include "photos-debug.h"
 #include "photos-enums.h"
 #include "photos-filterable.h"
 #include "photos-item-manager.h"
@@ -597,14 +598,15 @@ static void
 photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *id)
 {
   PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
-  PhotosBaseItem *item;
+  PhotosBaseItem *item = NULL;
+  const gchar *type_name;
   guint i;
 
   g_hash_table_remove (self->collections, id);
 
   item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id));
   if (item == NULL)
-    return;
+    goto out;
 
   g_signal_handlers_disconnect_by_func (item, photos_item_manager_info_updated, self);
   g_object_ref (item);
@@ -613,7 +615,25 @@ photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *i
     photos_base_manager_remove_object_by_id (self->item_mngr_chldrn[i], id);
 
   g_signal_emit_by_name (self, "object-removed", G_OBJECT (item));
-  g_object_unref (item);
+
+ out:
+  type_name = G_OBJECT_TYPE_NAME (self);
+  if (item == NULL)
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: object not found for %s", type_name, self, 
G_STRFUNC, id);
+    }
+  else
+    {
+      photos_debug (PHOTOS_DEBUG_MANAGER,
+                    "%s (%p), %s: object (%p) removed for %s",
+                    type_name,
+                    self,
+                    G_STRFUNC,
+                    item,
+                    id);
+    }
+
+  g_clear_object (&item);
 }
 
 
@@ -1011,6 +1031,7 @@ void
 photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 {
   PhotosBaseManager *item_mngr_chld;
+  const gchar *type_name;
   guint i;
   guint n_items;
 
@@ -1019,6 +1040,9 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_EDIT);
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
 
+  type_name = G_OBJECT_TYPE_NAME (self);
+  photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: clearing mode %d", type_name, self, G_STRFUNC, mode);
+
   item_mngr_chld = self->item_mngr_chldrn[mode];
   n_items = g_list_model_get_n_items (G_LIST_MODEL (item_mngr_chld));
   for (i = 0; i < n_items; i++)
@@ -1038,7 +1062,10 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 
           item1 = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr_chldrn[j], id));
           if (item1 != NULL)
-            break;
+            {
+              photos_debug (PHOTOS_DEBUG_MANAGER, "Object (%p, %s) also exists in mode %d", item, id, j);
+              break;
+            }
         }
 
       if (item1 == NULL)
@@ -1048,12 +1075,14 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
 
           g_signal_handlers_disconnect_by_func (item, photos_item_manager_info_updated, self);
           photos_base_manager_remove_object_by_id (self->item_mngr_chldrn[0], id);
+          photos_debug (PHOTOS_DEBUG_MANAGER, "Object (%p, %s) removed from mode 0", item, id);
         }
 
       g_object_unref (item);
     }
 
   photos_base_manager_clear (item_mngr_chld);
+  photos_debug (PHOTOS_DEBUG_MANAGER, "%s (%p), %s: clearing mode %d: done", type_name, self, G_STRFUNC, 
mode);
 }
 
 


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