[gnome-photos/wip/rishi/collection: 1/10] item-manager: collection_view



commit 053ef04cd542859247e4a4938a14db1e6771b8ba
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Jul 27 15:11:41 2017 +0200

    item-manager: collection_view

 src/photos-embed.c             |  123 +++++++++++++++++++---------------------
 src/photos-empty-results-box.c |    8 +++
 src/photos-item-manager.c      |   59 +++++++++++--------
 src/photos-item-manager.h      |    3 +-
 src/photos-main-window.c       |   14 ++---
 src/photos-preview-view.c      |    1 +
 6 files changed, 107 insertions(+), 101 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index db37edc..ef09657 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -68,6 +68,7 @@ struct _PhotosEmbed
   GAction *search_action;
   GHashTable *notifications;
   GIOExtensionPoint *extension_point;
+  GtkWidget *collection_view;
   GtkWidget *collections;
   GtkWidget *favorites;
   GtkWidget *no_results;
@@ -141,6 +142,10 @@ photos_embed_get_view_container_from_mode (PhotosEmbed *self, PhotosWindowMode m
 
   switch (mode)
     {
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+      view_container = self->collection_view;
+      break;
+
     case PHOTOS_WINDOW_MODE_COLLECTIONS:
       view_container = self->collections;
       break;
@@ -251,7 +256,6 @@ photos_embed_tracker_controllers_set_frozen (PhotosEmbed *self, gboolean frozen)
 static void
 photos_embed_prepare_for_preview (PhotosEmbed *self, PhotosWindowMode old_mode)
 {
-  PhotosBaseItem *active_collection;
   PhotosBaseItem *item;
 
   /* TODO: SearchController,
@@ -269,11 +273,9 @@ photos_embed_prepare_for_preview (PhotosEmbed *self, PhotosWindowMode old_mode)
    */
   photos_embed_tracker_controllers_set_frozen (self, TRUE);
 
-  active_collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
   if (old_mode == PHOTOS_WINDOW_MODE_SEARCH)
     {
-      if (active_collection == NULL)
-        photos_embed_save_search (self);
+      photos_embed_save_search (self);
     }
   else
     {
@@ -335,41 +337,6 @@ photos_embed_load_started (PhotosEmbed *self, PhotosBaseItem *item)
 
 
 static void
-photos_embed_active_collection_changed (PhotosBaseManager *manager, PhotosBaseItem *collection, gpointer 
user_data)
-{
-  PhotosEmbed *self = PHOTOS_EMBED (user_data);
-  PhotosWindowMode mode;
-
-  mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
-  if (mode != PHOTOS_WINDOW_MODE_SEARCH)
-    return;
-
-  if (collection == NULL)
-    {
-      photos_embed_restore_search (self);
-    }
-  else
-    {
-      PhotosSearchType *search_type;
-      const gchar *str;
-      const gchar *id;
-
-      photos_embed_save_search (self);
-
-      search_type = PHOTOS_SEARCH_TYPE (photos_base_manager_get_active_object (self->srch_mngr));
-      str = photos_search_controller_get_string (self->srch_cntrlr);
-      id = photos_filterable_get_id (PHOTOS_FILTERABLE (search_type));
-
-      if (g_strcmp0 (str, "") != 0 || g_strcmp0 (id, "all") != 0)
-        {
-          photos_base_manager_set_active_object_by_id (self->srch_mngr, "all");
-          photos_search_controller_set_string (self->srch_cntrlr, "");
-        }
-    }
-}
-
-
-static void
 photos_embed_fullscreen_changed (PhotosModeController *mode_cntrlr, gboolean fullscreen, gpointer user_data)
 {
 }
@@ -406,6 +373,37 @@ photos_embed_notify_visible_child (PhotosEmbed *self)
 
 
 static void
+photos_embed_prepare_for_collection_view (PhotosEmbed *self, PhotosWindowMode old_mode)
+{
+  switch (old_mode)
+    {
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+      photos_embed_tracker_controllers_set_frozen (self, FALSE);
+      break;
+
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      photos_embed_save_search (self);
+      break;
+
+    case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+      break;
+
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  photos_spinner_box_stop (PHOTOS_SPINNER_BOX (self->spinner_box));
+  gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "collection-view");
+}
+
+
+static void
 photos_embed_prepare_for_collections (PhotosEmbed *self, PhotosWindowMode old_mode)
 {
   if (old_mode == PHOTOS_WINDOW_MODE_PREVIEW)
@@ -441,16 +439,10 @@ photos_embed_prepare_for_overview (PhotosEmbed *self, PhotosWindowMode old_mode)
 static void
 photos_embed_prepare_for_search (PhotosEmbed *self, PhotosWindowMode old_mode)
 {
-  if (old_mode == PHOTOS_WINDOW_MODE_PREVIEW)
-    {
-      PhotosBaseItem *active_collection;
+  photos_embed_restore_search (self);
 
-      active_collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
-      if (active_collection == NULL)
-        photos_embed_restore_search (self);
-
-      photos_embed_tracker_controllers_set_frozen (self, FALSE);
-    }
+  if (old_mode == PHOTOS_WINDOW_MODE_PREVIEW)
+    photos_embed_tracker_controllers_set_frozen (self, FALSE);
 
   photos_spinner_box_stop (PHOTOS_SPINNER_BOX (self->spinner_box));
   gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "search");
@@ -476,20 +468,21 @@ photos_embed_search_changed (PhotosEmbed *self)
   const gchar *source_id;
   const gchar *str;
 
-  /* Whenever a search constraint is specified we want to switch to
-   * the search mode, and when all constraints have been lifted we
-   * want to go back to the previous mode which can be either
-   * collections, favorites or overview.
+  /* Whenever a search constraint is specified, we want to switch to
+   * the search mode. Search is always global. If we are in
+   * collection-view, we go back to the previous top-level mode and
+   * then enter the search mode. This is taken care of by
+   * photos_mode_controller_set_window_mode.
+   *
+   * When all constraints have been lifted we want to go back to the
+   * previous top-level mode which can be either collections,
+   * favorites or overview.
    *
-   * However there are some exceptions, which are taken care of
-   * elsewhere:
-   *  - when moving from search to preview or collection view
-   *  - when in preview
+   * The constraints are saved when entering collection-view or
+   * preview from the search mode. They are restored when going back.
    */
-  object = photos_base_manager_get_active_object (self->item_mngr);
+
   mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
-  if (mode == PHOTOS_WINDOW_MODE_SEARCH && object != NULL)
-    return;
   if (mode == PHOTOS_WINDOW_MODE_PREVIEW)
     return;
 
@@ -590,6 +583,10 @@ photos_embed_window_mode_changed (PhotosModeController *mode_cntrlr,
     case PHOTOS_WINDOW_MODE_EDIT:
       break;
 
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+      photos_embed_prepare_for_collection_view (self, old_mode);
+      break;
+
     case PHOTOS_WINDOW_MODE_COLLECTIONS:
       photos_embed_prepare_for_collections (self, old_mode);
       break;
@@ -675,6 +672,9 @@ photos_embed_init (PhotosEmbed *self)
   name = photos_view_container_get_name (PHOTOS_VIEW_CONTAINER (self->overview));
   gtk_stack_add_titled (GTK_STACK (self->stack), self->overview, "overview", name);
 
+  self->collection_view = photos_view_container_new (PHOTOS_WINDOW_MODE_COLLECTION_VIEW, _("Collection 
View"));
+  gtk_stack_add_named (GTK_STACK (self->stack), self->collection_view, "collection-view");
+
   self->collections = photos_view_container_new (PHOTOS_WINDOW_MODE_COLLECTIONS, _("Albums"));
   name = photos_view_container_get_name (PHOTOS_VIEW_CONTAINER (self->collections));
   gtk_stack_add_titled (GTK_STACK (self->stack), self->collections, "collections", name);
@@ -719,11 +719,6 @@ photos_embed_init (PhotosEmbed *self)
 
   self->item_mngr = g_object_ref (state->item_mngr);
   g_signal_connect_object (self->item_mngr,
-                           "active-collection-changed",
-                           G_CALLBACK (photos_embed_active_collection_changed),
-                           self,
-                           0);
-  g_signal_connect_object (self->item_mngr,
                            "load-finished",
                            G_CALLBACK (photos_embed_load_finished),
                            self,
diff --git a/src/photos-empty-results-box.c b/src/photos-empty-results-box.c
index ee9ed8a..d2c9451 100644
--- a/src/photos-empty-results-box.c
+++ b/src/photos-empty-results-box.c
@@ -186,6 +186,10 @@ photos_empty_results_box_constructed (GObject *object)
       label = g_strconcat ("<b><span size=\"large\">", _("Starred photos will appear here"), "</span></b>", 
NULL);
       break;
 
+    /* TODO: Don't show a collection if there are no screenshots in
+     * the relevant locations.
+     */
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
     case PHOTOS_WINDOW_MODE_OVERVIEW:
     case PHOTOS_WINDOW_MODE_SEARCH:
       image = gtk_image_new_from_icon_name (PHOTOS_ICON_PHOTOS_SYMBOLIC, GTK_ICON_SIZE_INVALID);
@@ -222,6 +226,10 @@ photos_empty_results_box_constructed (GObject *object)
       photos_empty_results_box_add_collections_label (self);
       break;
 
+    /* TODO: Don't show a collection if there are no screenshots in
+     * the relevant locations.
+     */
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
     case PHOTOS_WINDOW_MODE_FAVORITES:
     case PHOTOS_WINDOW_MODE_SEARCH:
       gtk_widget_set_valign (title_label, GTK_ALIGN_CENTER);
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 7d896fe..ab7bf63 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -245,8 +245,7 @@ photos_item_manager_info_updated (PhotosBaseItem *item, gpointer user_data)
 
   if (is_collection)
     {
-      if (self->active_collection == NULL)
-        photos_item_manager_try_to_add_item_for_mode (self, item, PHOTOS_WINDOW_MODE_COLLECTIONS);
+      photos_item_manager_try_to_add_item_for_mode (self, item, PHOTOS_WINDOW_MODE_COLLECTIONS);
     }
   else
     {
@@ -258,13 +257,14 @@ photos_item_manager_info_updated (PhotosBaseItem *item, gpointer user_data)
 
   if (is_collection)
     {
+      photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_COLLECTION_VIEW],
+                                         G_OBJECT (item));
       photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_FAVORITES], G_OBJECT 
(item));
       photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_OVERVIEW], G_OBJECT 
(item));
     }
   else
     {
-      if (self->active_collection == NULL)
-        photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_COLLECTIONS], G_OBJECT 
(item));
+      photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_COLLECTIONS], G_OBJECT 
(item));
 
       if (!is_favorite)
         photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_FAVORITES], G_OBJECT 
(item));
@@ -292,8 +292,7 @@ photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
   is_collection = photos_item_manager_cursor_is_collection (cursor);
   g_return_if_fail ((is_collection
                      && (mode == PHOTOS_WINDOW_MODE_COLLECTIONS || mode == PHOTOS_WINDOW_MODE_SEARCH))
-                    || (!is_collection
-                        && (mode != PHOTOS_WINDOW_MODE_COLLECTIONS || self->active_collection != NULL)));
+                    || (!is_collection && mode != PHOTOS_WINDOW_MODE_COLLECTIONS));
 
   if (!force && !photos_item_manager_can_add_cursor_for_mode (self, cursor, mode))
     goto out;
@@ -686,6 +685,11 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
 
   if (is_collection)
     {
+      window_mode_changed = photos_item_manager_set_window_mode_internal (self,
+                                                                          PHOTOS_WINDOW_MODE_COLLECTION_VIEW,
+                                                                          &old_mode);
+      g_assert_true (window_mode_changed);
+
       g_assert_null (self->active_collection);
       self->active_collection = g_object_ref (PHOTOS_BASE_ITEM (object));
       self->load_state = PHOTOS_LOAD_STATE_NONE;
@@ -729,12 +733,12 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
 
       g_signal_emit (self, signals[LOAD_STARTED], 0, PHOTOS_BASE_ITEM (object));
 
-      if (window_mode_changed)
-        g_signal_emit (self, signals[WINDOW_MODE_CHANGED], 0, PHOTOS_WINDOW_MODE_PREVIEW, old_mode);
-
       g_assert (self->active_object != (GObject *) self->active_collection);
     }
 
+  if (window_mode_changed)
+    g_signal_emit (self, signals[WINDOW_MODE_CHANGED], 0, self->mode, old_mode);
+
  out:
   return ret_val;
 }
@@ -955,22 +959,6 @@ photos_item_manager_new (void)
 
 
 void
-photos_item_manager_activate_previous_collection (PhotosItemManager *self)
-{
-  g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
-  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self->active_collection));
-
-  photos_item_manager_clear_active_item_load (self);
-
-  g_clear_object (&self->active_collection);
-  g_clear_object (&self->active_object);
-
-  g_signal_emit_by_name (self, "active-changed", self->active_object);
-  g_signal_emit (self, signals[ACTIVE_COLLECTION_CHANGED], 0, self->active_collection);
-}
-
-
-void
 photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *cursor, gboolean force)
 {
   g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
@@ -979,7 +967,7 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
   if (photos_item_manager_cursor_is_collection (cursor))
     {
       if (self->active_collection != NULL && force)
-        photos_item_manager_activate_previous_collection (self);
+        photos_mode_controller_go_back (self);
 
       if (self->active_collection == NULL)
         photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_COLLECTIONS, force);
@@ -1328,6 +1316,13 @@ photos_mode_controller_go_back (PhotosModeController *self)
       g_return_if_fail (old_mode == PHOTOS_WINDOW_MODE_PREVIEW);
       break;
 
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+      g_return_if_fail (self->load_state == PHOTOS_LOAD_STATE_NONE);
+      g_return_if_fail (PHOTOS_IS_BASE_ITEM (self->active_collection));
+      g_return_if_fail (self->active_object == (GObject *) self->active_collection);
+      g_return_if_fail (old_mode == PHOTOS_WINDOW_MODE_COLLECTIONS || old_mode == PHOTOS_WINDOW_MODE_SEARCH);
+      break;
+
     case PHOTOS_WINDOW_MODE_COLLECTIONS:
     case PHOTOS_WINDOW_MODE_FAVORITES:
     case PHOTOS_WINDOW_MODE_OVERVIEW:
@@ -1339,6 +1334,10 @@ photos_mode_controller_go_back (PhotosModeController *self)
       g_return_if_fail (PHOTOS_IS_BASE_ITEM (self->active_object));
       g_return_if_fail (self->active_object != (GObject *) self->active_collection);
       g_return_if_fail (old_mode != PHOTOS_WINDOW_MODE_PREVIEW);
+      g_return_if_fail ((old_mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW
+                         && PHOTOS_IS_BASE_ITEM (self->active_collection))
+                        || (old_mode != PHOTOS_WINDOW_MODE_COLLECTION_VIEW
+                            && !PHOTOS_IS_BASE_ITEM (self->active_collection)));
       break;
 
     case PHOTOS_WINDOW_MODE_NONE:
@@ -1359,6 +1358,13 @@ photos_mode_controller_go_back (PhotosModeController *self)
 
   switch (old_mode)
     {
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+      g_clear_object (&self->active_collection);
+      g_clear_object (&self->active_object);
+      active_changed = TRUE;
+      active_collection_changed = TRUE;
+      break;
+
     case PHOTOS_WINDOW_MODE_EDIT:
       break;
 
@@ -1429,6 +1435,7 @@ photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindow
 
   g_return_if_fail (PHOTOS_IS_MODE_CONTROLLER (self));
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_NONE);
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_COLLECTION_VIEW);
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
 
   if (mode == PHOTOS_WINDOW_MODE_EDIT)
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index e95314e..22fa342 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -58,6 +58,7 @@ typedef enum
 typedef enum
 {
   PHOTOS_WINDOW_MODE_NONE,
+  PHOTOS_WINDOW_MODE_COLLECTION_VIEW,
   PHOTOS_WINDOW_MODE_COLLECTIONS,
   PHOTOS_WINDOW_MODE_EDIT,
   PHOTOS_WINDOW_MODE_FAVORITES,
@@ -71,8 +72,6 @@ typedef struct _PhotosItemManagerClass PhotosModeControllerClass;
 
 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,
                                                                             gboolean force);
diff --git a/src/photos-main-window.c b/src/photos-main-window.c
index c789763..9153b4d 100644
--- a/src/photos-main-window.c
+++ b/src/photos-main-window.c
@@ -152,29 +152,24 @@ photos_main_window_fullscreen_changed (PhotosMainWindow *self, gboolean fullscre
 static gboolean
 photos_main_window_go_back (PhotosMainWindow *self)
 {
-  PhotosBaseItem *active_collection;
   PhotosWindowMode mode;
   gboolean handled = TRUE;
 
   mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
-  active_collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
 
   switch (mode)
     {
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
     case PHOTOS_WINDOW_MODE_PREVIEW:
       photos_mode_controller_go_back (self->mode_cntrlr);
       break;
 
-    case PHOTOS_WINDOW_MODE_COLLECTIONS:
-    case PHOTOS_WINDOW_MODE_FAVORITES:
-    case PHOTOS_WINDOW_MODE_SEARCH:
-      if (active_collection != NULL)
-        photos_item_manager_activate_previous_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
-      break;
-
     case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
     case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
     case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
     default:
       handled = FALSE;
       break;
@@ -280,6 +275,7 @@ photos_main_window_key_press_event (GtkWidget *widget, GdkEventKey *event)
   switch (mode)
     {
     case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
     case PHOTOS_WINDOW_MODE_COLLECTIONS:
     case PHOTOS_WINDOW_MODE_FAVORITES:
     case PHOTOS_WINDOW_MODE_OVERVIEW:
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 5c862af..a12dd70 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -807,6 +807,7 @@ photos_preview_view_window_mode_changed (PhotosPreviewView *self, PhotosWindowMo
 {
   switch (mode)
     {
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
     case PHOTOS_WINDOW_MODE_COLLECTIONS:
     case PHOTOS_WINDOW_MODE_FAVORITES:
     case PHOTOS_WINDOW_MODE_OVERVIEW:


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