[gnome-photos/wip/rishi/item-manager: 11/11] WIP



commit 963a55f2431cef84239438c75dd91cbbc521fa68
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Aug 15 22:17:21 2016 +0200

    WIP
    
    Some changes by Debarshi Ray.

 src/photos-item-manager.c       |  170 +++++++++++++++++++++++++++------------
 src/photos-item-manager.h       |    8 ++-
 src/photos-tracker-controller.c |    2 +-
 3 files changed, 125 insertions(+), 55 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 6042726..f4a18ab 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -46,6 +46,7 @@
 struct _PhotosItemManager
 {
   PhotosBaseManager parent_instance;
+  GObject *active_object;
   GCancellable *loader_cancellable;
   GHashTable *collections;
   GHashTable *hidden_items;
@@ -94,30 +95,7 @@ EGG_DEFINE_COUNTER (instances, "PhotosItemManager", "Instances", "Number of Phot
 static void
 photos_item_manager_add_object (PhotosBaseManager *mngr, GObject *object)
 {
-  PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
-  PhotosBaseItem *item;
-  const gchar *id;
-  gpointer *old_collection;
-
-  g_return_if_fail (PHOTOS_IS_BASE_ITEM (object));
-
-  item = PHOTOS_BASE_ITEM (object);
-
-  if (!photos_base_item_is_collection (item))
-    goto end;
-
-  id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
-  if (id == NULL)
-    goto end;
-
-  old_collection = g_hash_table_lookup (self->collections, id);
-  if (old_collection != NULL)
-    goto end;
-
-  g_hash_table_insert (self->collections, g_strdup (id), g_object_ref (item));
-
- end:
-  PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)->add_object (mngr, object);
+  g_assert_not_reached ();
 }
 
 
@@ -244,6 +222,47 @@ photos_item_manager_collection_path_free (PhotosItemManager *self)
 }
 
 
+static GObject *
+photos_item_manager_get_active_object (PhotosBaseManager *mngr)
+{
+  PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
+  return self->active_object;
+}
+
+
+static PhotosBaseItem *
+photos_item_manager_get_object_by_id_from_children (PhotosItemManager *self, const gchar *id)
+{
+  PhotosBaseItem *ret_val = NULL;
+  guint i;
+
+  for (i = 0; self->item_mngr_chldrn[i] != NULL; i++)
+    {
+      PhotosBaseItem *item;
+
+      item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr_chldrn[i], id));
+      if (item != NULL)
+        {
+          ret_val = item;
+          break;
+        }
+    }
+
+  return ret_val;
+}
+
+
+static GObject *
+photos_item_manager_get_object_by_id (PhotosBaseManager *mngr, const gchar *id)
+{
+  PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
+  GObject *ret_val;
+
+  ret_val = G_OBJECT (photos_item_manager_get_object_by_id_from_children (self, id));
+  return ret_val;
+}
+
+
 static gchar *
 photos_item_manager_get_where (PhotosBaseManager *mngr, gint flags)
 {
@@ -293,6 +312,7 @@ photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *i
 {
   PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
   gpointer *collection;
+  guint i;
 
   if (id == NULL)
     goto end;
@@ -304,7 +324,16 @@ photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *i
   g_hash_table_remove (self->collections, id);
 
  end:
-  PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)->remove_object_by_id (mngr, id);
+  for (i = 0; self->item_mngr_chldrn[i] != NULL; i++)
+    {
+      PhotosBaseItem *item;
+
+      item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr_chldrn[i], id));
+      if (item != NULL)
+        break;
+    }
+
+  PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)->remove_object_by_id 
(self->item_mngr_chldrn[i], id);
 }
 
 
@@ -350,7 +379,6 @@ static gboolean
 photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *object)
 {
   PhotosItemManager *self = PHOTOS_ITEM_MANAGER (manager);
-  GObject *active_item;
   PhotosWindowMode old_mode;
   gboolean active_collection_changed = FALSE;
   gboolean ret_val = FALSE;
@@ -360,8 +388,7 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
   g_return_val_if_fail (object != NULL, FALSE);
   g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (object), FALSE);
 
-  active_item = photos_base_manager_get_active_object (manager);
-  if (object == active_item)
+  if (object == self->active_object)
     goto out;
 
   photos_item_manager_clear_active_item_load (self);
@@ -385,17 +412,15 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
       start_loading = TRUE;
     }
 
-  ret_val = PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)->set_active_object (manager, 
object);
+  g_set_object (&self->active_object, object);
+  g_signal_emit_by_name (self, "active-changed", self->active_object);
   /* We have already eliminated the possibility of failure. */
-  g_assert (ret_val == TRUE);
-
-  active_item = photos_base_manager_get_active_object (manager);
-  g_assert (active_item == object);
+  ret_val = TRUE;
 
   if (active_collection_changed)
     {
       g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
-      g_assert (active_item == (GObject *) self->active_collection);
+      g_assert (self->active_object == (GObject *) self->active_collection);
     }
 
   if (start_loading)
@@ -418,7 +443,7 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
       if (window_mode_changed)
         g_signal_emit (self, signals[WINDOW_MODE_CHANGED], 0, PHOTOS_WINDOW_MODE_PREVIEW, old_mode);
 
-      g_assert (active_item != (GObject *) self->active_collection);
+      g_assert (self->active_object != (GObject *) self->active_collection);
     }
 
  out:
@@ -516,7 +541,9 @@ photos_item_manager_class_init (PhotosItemManagerClass *class)
   object_class->dispose = photos_item_manager_dispose;
   object_class->finalize = photos_item_manager_finalize;
   base_manager_class->add_object = photos_item_manager_add_object;
+  base_manager_class->get_active_object = photos_item_manager_get_active_object;
   base_manager_class->get_where = photos_item_manager_get_where;
+  base_manager_class->get_object_by_id = photos_item_manager_get_object_by_id;
   base_manager_class->set_active_object = photos_item_manager_set_active_object;
   base_manager_class->remove_object_by_id = photos_item_manager_remove_object_by_id;
 
@@ -613,10 +640,9 @@ photos_item_manager_activate_previous_collection (PhotosItemManager *self)
   g_assert (collection == NULL || PHOTOS_IS_BASE_ITEM (collection));
 
   g_set_object (&self->active_collection, PHOTOS_BASE_ITEM (collection));
+  g_set_object (&self->active_object, G_OBJECT (collection));
 
-  PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)
-    ->set_active_object (PHOTOS_BASE_MANAGER (self), (GObject *) collection);
-
+  g_signal_emit_by_name (self, "active-changed", self->active_object);
   g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
 
   g_clear_object (&collection);
@@ -627,19 +653,60 @@ void
 photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *cursor)
 {
   PhotosBaseItem *item = NULL;
-  GObject *object;
+  PhotosBaseManager *item_mngr_chld;
+  PhotosWindowMode mode;
   const gchar *id;
 
   id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
-  object = photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id);
-  if (object != NULL)
+  if (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id))
+    goto out;
+
+  item = photos_item_manager_create_item (self, cursor);
+  if (photos_base_item_is_collection (item))
     {
-      g_signal_emit_by_name (self, "object-added", object);
-      goto out;
+      g_hash_table_insert (self->collections, g_strdup (id), g_object_ref (item));
+      mode = PHOTOS_WINDOW_MODE_COLLECTIONS;
+    }
+  else
+    {
+      mode = PHOTOS_WINDOW_MODE_OVERVIEW;
     }
 
-  item = photos_item_manager_create_item (self, cursor);
-  photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (item));
+  item_mngr_chld = self->item_mngr_chldrn[mode];
+  photos_base_manager_add_object (item_mngr_chld, G_OBJECT (item));
+  g_signal_emit_by_name (self, "object-added", G_OBJECT (item));
+
+ out:
+  g_clear_object (&item);
+}
+
+
+void
+photos_item_manager_add_item_from_cursor (PhotosItemManager *self, PhotosWindowMode mode, 
TrackerSparqlCursor *cursor)
+{
+  PhotosBaseItem *item = NULL;
+  PhotosBaseManager *item_mngr_chld;
+  const gchar *id;
+
+  item_mngr_chld = self->item_mngr_chldrn[mode];
+  id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+  if (photos_base_manager_get_object_by_id (item_mngr_chld, id) != NULL)
+    goto out;
+
+  item = photos_item_manager_get_object_by_id_from_children (self, id);
+  if (item != NULL)
+    {
+      g_object_ref (item);
+    }
+  else
+    {
+      item = photos_item_manager_create_item (self, cursor);
+      if (photos_base_item_is_collection (item))
+        g_hash_table_insert (self->collections, g_strdup (id), g_object_ref (item));
+    }
+
+  photos_base_manager_add_object (item_mngr_chld, G_OBJECT (item));
+  g_signal_emit_by_name (self, "object-added", G_OBJECT (item));
 
  out:
   g_clear_object (&item);
@@ -819,8 +886,8 @@ photos_mode_controller_go_back (PhotosModeController *self)
   if (old_mode == PHOTOS_WINDOW_MODE_PREVIEW)
     {
       self->load_state = PHOTOS_LOAD_STATE_NONE;
-      PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)
-        ->set_active_object (PHOTOS_BASE_MANAGER (self), (GObject *) self->active_collection);
+      g_set_object (&self->active_object, G_OBJECT (self->active_collection));
+      g_signal_emit_by_name (self, "active-changed", self->active_object);
     }
   else if (old_mode != PHOTOS_WINDOW_MODE_EDIT)
     {
@@ -828,11 +895,10 @@ photos_mode_controller_go_back (PhotosModeController *self)
       self->collection_path = g_queue_new ();
 
       g_clear_object (&self->active_collection);
+      g_clear_object (&self->active_object);
       self->load_state = PHOTOS_LOAD_STATE_NONE;
 
-      PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)
-        ->set_active_object (PHOTOS_BASE_MANAGER (self), NULL);
-
+      g_signal_emit_by_name (self, "active-changed", self->active_object);
       g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
     }
 
@@ -895,8 +961,8 @@ photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindow
           active_collection_changed = TRUE;
         }
 
-      PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)
-        ->set_active_object (PHOTOS_BASE_MANAGER (self), NULL);
+      g_clear_object (&self->active_object);
+      g_signal_emit_by_name (self, "active-changed", self->active_object);
 
       if (active_collection_changed)
         g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index 726cc41..5977153 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -85,8 +85,12 @@ PhotosBaseManager        *photos_item_manager_new                (void);
 
 void                      photos_item_manager_activate_previous_collection (PhotosItemManager *self);
 
-void                      photos_item_manager_add_item           (PhotosItemManager *self,
-                                                                  TrackerSparqlCursor *cursor);
+void                      photos_item_manager_add_item              (PhotosItemManager *self,
+                                                                     TrackerSparqlCursor *cursor);
+
+void                      photos_item_manager_add_item_from_cursor  (PhotosItemManager *self,
+                                                                     PhotosWindowMode mode,
+                                                                     TrackerSparqlCursor *cursor);
 
 PhotosBaseItem           *photos_item_manager_create_item        (PhotosItemManager *self,
                                                                   TrackerSparqlCursor *cursor);
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index 9e0cdbe..31d9d60 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -156,7 +156,7 @@ photos_tracker_controller_cursor_next (GObject *source_object, GAsyncResult *res
   now = g_get_monotonic_time ();
   photos_debug (PHOTOS_DEBUG_TRACKER, "Query Cursor: %" G_GINT64_FORMAT, (now - priv->last_query_time) / 
1000000);
 
-  photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (priv->item_mngr), cursor);
+  photos_item_manager_add_item_from_cursor (PHOTOS_ITEM_MANAGER (priv->item_mngr), priv->mode, cursor);
   tracker_sparql_cursor_next_async (cursor,
                                     priv->cancellable,
                                     photos_tracker_controller_cursor_next,


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