[gnome-photos/wip/rishi/collection: 31/33] new mode



commit 792bc90ee8b85058ed98768616f730cf6e1b4603
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Jan 22 00:37:06 2018 +0100

    new mode

 src/photos-embed.c                     | 123 ++++++++++++++++++++++-----------
 src/photos-item-manager.c              |  31 ++++++---
 src/photos-main-toolbar.c              |   8 +--
 src/photos-offset-import-controller.c  |  16 ++++-
 src/photos-tracker-import-controller.c |   2 +-
 5 files changed, 122 insertions(+), 58 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 500fd697..40d27ea6 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -500,58 +500,101 @@ photos_embed_query_status_changed (PhotosEmbed *self, gboolean querying)
 static void
 photos_embed_search_changed (PhotosEmbed *self)
 {
-  GObject *object;
-  const gchar *search_match_id;
-  const gchar *search_type_id;
-  const gchar *source_id;
-  const gchar *str;
-
-  /* Whenever a search constraint is specified, we 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.
-   *
-   * 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.
-   *
-   * The constraints are saved when entering collection-view or
-   * preview from the search mode. They are restored when going back.
-   * Saving and restoring doesn't cause any further mode changes.
-   */
+  GMount *mount;
+  PhotosSource *source;
 
-  self->search_changed = TRUE;
+  source = PHOTOS_SOURCE (photos_base_manager_get_active_object (self->src_mngr));
 
-  object = photos_base_manager_get_active_object (self->src_mngr);
-  source_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+  mount = photos_source_get_mount (source);
+  if (mount != NULL)
+    {
+      GObject *object;
+      PhotosWindowMode mode;
+      const gchar *search_match_id;
+      const gchar *search_type_id;
 
-  object = photos_base_manager_get_active_object (self->srch_mtch_mngr);
-  search_match_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+      photos_embed_block_search_changed (self);
 
-  object = photos_base_manager_get_active_object (self->srch_typ_mngr);
-  search_type_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+      mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
+      if (mode == PHOTOS_WINDOW_MODE_PREVIEW)
+        photos_mode_controller_go_back (self->mode_cntrlr);
 
-  str = photos_search_controller_get_string (self->srch_cntrlr);
+      mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
+      if (mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW)
+        photos_mode_controller_go_back (self->mode_cntrlr);
 
-  if (g_strcmp0 (search_match_id, PHOTOS_SEARCH_MATCH_STOCK_ALL) == 0
-      && g_strcmp0 (search_type_id, PHOTOS_SEARCH_TYPE_STOCK_ALL) == 0
-      && g_strcmp0 (source_id, PHOTOS_SOURCE_STOCK_ALL) == 0
-      && (str == NULL || str [0] == '\0'))
-    {
-      photos_mode_controller_go_back (self->mode_cntrlr);
+      mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
+      if (mode == PHOTOS_WINDOW_MODE_SEARCH)
+        photos_mode_controller_go_back (self->mode_cntrlr);
+
+      photos_base_manager_set_active_object (self->src_mngr, G_OBJECT (source));
+
+      object = photos_base_manager_get_active_object (self->srch_mtch_mngr);
+      search_match_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+      g_assert_cmpstr (search_match_id, ==, PHOTOS_SEARCH_MATCH_STOCK_ALL);
+
+      object = photos_base_manager_get_active_object (self->srch_typ_mngr);
+      search_type_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+      g_assert_cmpstr (search_type_id, ==, PHOTOS_SEARCH_TYPE_STOCK_ALL);
+
+      photos_mode_controller_set_window_mode (self->mode_cntrlr, PHOTOS_WINDOW_MODE_IMPORT);
+
+      photos_embed_unblock_search_changed (self);
     }
   else
     {
-      PhotosWindowMode mode;
+      GObject *object;
+      const gchar *search_match_id;
+      const gchar *search_type_id;
+      const gchar *source_id;
+      const gchar *str;
+
+      /* Whenever a search constraint is specified, we 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.
+       *
+       * 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.
+       *
+       * The constraints are saved when entering collection-view or
+       * preview from the search mode. They are restored when going back.
+       * Saving and restoring doesn't cause any further mode changes.
+       */
 
-      mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
-      if (mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW)
-        photos_mode_controller_go_back (self->mode_cntrlr);
+      self->search_changed = TRUE;
 
-      photos_mode_controller_set_window_mode (self->mode_cntrlr, PHOTOS_WINDOW_MODE_SEARCH);
-    }
+      source_id = photos_filterable_get_id (PHOTOS_FILTERABLE (source));
+
+      object = photos_base_manager_get_active_object (self->srch_mtch_mngr);
+      search_match_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+
+      object = photos_base_manager_get_active_object (self->srch_typ_mngr);
+      search_type_id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
+
+      str = photos_search_controller_get_string (self->srch_cntrlr);
 
-  self->search_changed = FALSE;
+      if (g_strcmp0 (search_match_id, PHOTOS_SEARCH_MATCH_STOCK_ALL) == 0
+          && g_strcmp0 (search_type_id, PHOTOS_SEARCH_TYPE_STOCK_ALL) == 0
+          && g_strcmp0 (source_id, PHOTOS_SOURCE_STOCK_ALL) == 0
+          && (str == NULL || str [0] == '\0'))
+        {
+          photos_mode_controller_go_back (self->mode_cntrlr);
+        }
+      else
+        {
+          PhotosWindowMode mode;
+
+          mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
+          if (mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW)
+            photos_mode_controller_go_back (self->mode_cntrlr);
+
+          photos_mode_controller_set_window_mode (self->mode_cntrlr, PHOTOS_WINDOW_MODE_SEARCH);
+        }
+
+      self->search_changed = FALSE;
+    }
 }
 
 
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index d4b60da2..70d914c3 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -47,7 +47,6 @@
 struct _PhotosItemManager
 {
   PhotosBaseManager parent_instance;
-  GAction *selection_mode_action;
   GObject *active_object;
   GCancellable *loader_cancellable;
   GHashTable *collections;
@@ -830,15 +829,11 @@ photos_item_manager_finalize (GObject *object)
 static void
 photos_item_manager_init (PhotosItemManager *self)
 {
-  GApplication *app;
   GEnumClass *window_mode_class;
   guint i;
 
   EGG_COUNTER_INC (instances);
 
-  app = g_application_get_default ();
-  self->selection_mode_action = g_action_map_lookup_action (G_ACTION_MAP (app), "selection-mode");
-
   self->collections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
   self->hidden_items = g_hash_table_new_full (g_str_hash,
                                               g_str_equal,
@@ -1344,6 +1339,8 @@ photos_mode_controller_get_window_mode (PhotosModeController *self)
 void
 photos_mode_controller_go_back (PhotosModeController *self)
 {
+  GAction *selection_mode_action;
+  GApplication *app;
   PhotosWindowMode old_mode;
   PhotosWindowMode tmp;
   gboolean active_changed = FALSE;
@@ -1353,6 +1350,9 @@ photos_mode_controller_go_back (PhotosModeController *self)
   g_return_if_fail (PHOTOS_IS_MODE_CONTROLLER (self));
   g_return_if_fail (!g_queue_is_empty (self->history));
 
+  app = g_application_get_default ();
+  selection_mode_action = g_action_map_lookup_action (G_ACTION_MAP (app), "selection-mode");
+
   old_mode = (PhotosWindowMode) GPOINTER_TO_INT (g_queue_peek_head (self->history));
   g_return_if_fail (old_mode != PHOTOS_WINDOW_MODE_NONE);
 
@@ -1381,9 +1381,11 @@ photos_mode_controller_go_back (PhotosModeController *self)
       {
         g_autoptr (GVariant) state = NULL;
 
-        g_return_if_fail (old_mode == PHOTOS_WINDOW_MODE_COLLECTIONS || old_mode == 
PHOTOS_WINDOW_MODE_OVERVIEW);
+        g_return_if_fail (old_mode == PHOTOS_WINDOW_MODE_COLLECTIONS
+                          || old_mode == PHOTOS_WINDOW_MODE_FAVORITES
+                          || old_mode == PHOTOS_WINDOW_MODE_OVERVIEW);
 
-        state = g_action_get_state (self->selection_mode_action);
+        state = g_action_get_state (selection_mode_action);
         g_return_if_fail (state != NULL);
         g_return_if_fail (g_variant_get_boolean (state));
         break;
@@ -1462,7 +1464,7 @@ photos_mode_controller_go_back (PhotosModeController *self)
       GVariant *state;
 
       state = g_variant_new_boolean (FALSE);
-      g_action_change_state (self->selection_mode_action, state);
+      g_action_change_state (selection_mode_action, state);
     }
 
   if (active_changed)
@@ -1499,6 +1501,8 @@ photos_mode_controller_set_fullscreen (PhotosModeController *self, gboolean full
 void
 photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindowMode mode)
 {
+  GAction *selection_mode_action;
+  GApplication *app;
   PhotosWindowMode old_mode;
   gboolean active_changed = FALSE;
   gboolean active_collection_changed = FALSE;
@@ -1509,6 +1513,9 @@ photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindow
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_COLLECTION_VIEW);
   g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
 
+  app = g_application_get_default ();
+  selection_mode_action = g_action_map_lookup_action (G_ACTION_MAP (app), "selection-mode");
+
   if (mode == PHOTOS_WINDOW_MODE_EDIT)
     {
       g_return_if_fail (self->load_state == PHOTOS_LOAD_STATE_FINISHED);
@@ -1518,9 +1525,11 @@ photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindow
     {
       g_autoptr (GVariant) state = NULL;
 
-      g_return_if_fail (self->mode == PHOTOS_WINDOW_MODE_COLLECTIONS || self->mode == 
PHOTOS_WINDOW_MODE_OVERVIEW);
+      g_return_if_fail (self->mode == PHOTOS_WINDOW_MODE_COLLECTIONS
+                        || self->mode == PHOTOS_WINDOW_MODE_FAVORITES
+                        || self->mode == PHOTOS_WINDOW_MODE_OVERVIEW);
 
-      state = g_action_get_state (self->selection_mode_action);
+      state = g_action_get_state (selection_mode_action);
       g_return_if_fail (state != NULL);
       g_return_if_fail (!g_variant_get_boolean (state));
     }
@@ -1558,7 +1567,7 @@ photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindow
       GVariant *state;
 
       state = g_variant_new_boolean (TRUE);
-      g_action_change_state (self->selection_mode_action, state);
+      g_action_change_state (selection_mode_action, state);
     }
 
   if (active_changed)
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 0ff23ab7..a541be02 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -486,16 +486,16 @@ photos_main_toolbar_populate_for_favorites (PhotosMainToolbar *self)
 static void
 photos_main_toolbar_populate_for_import (PhotosMainToolbar *self)
 {
-  GtkWidget *back_button;
   GtkStyleContext *context;
+  GtkWidget *cancel_button;
 
   gtk_header_bar_set_custom_title (GTK_HEADER_BAR (self->header_bar), self->selection_menu);
   context = gtk_widget_get_style_context (self->header_bar);
   gtk_style_context_add_class (context, "selection-mode");
 
-  back_button = gtk_button_new_with_label (_("Cancel"));
-  gtk_header_bar_pack_end (GTK_HEADER_BAR (self->header_bar), back_button);
-  g_signal_connect_swapped (back_button, "clicked", G_CALLBACK (photos_main_toolbar_back_button_clicked), 
self);
+  cancel_button = gtk_button_new_with_label (_("Cancel"));
+  gtk_actionable_set_action_name (GTK_ACTIONABLE (cancel_button), "app.import-cancel");
+  gtk_header_bar_pack_end (GTK_HEADER_BAR (self->header_bar), cancel_button);
 
   g_signal_connect_object (self->sel_cntrlr,
                            "selection-changed",
diff --git a/src/photos-offset-import-controller.c b/src/photos-offset-import-controller.c
index c45be4a9..37d58c1c 100644
--- a/src/photos-offset-import-controller.c
+++ b/src/photos-offset-import-controller.c
@@ -26,7 +26,9 @@
 #include <gio/gio.h>
 
 #include "photos-base-manager.h"
+#include "photos-filterable.h"
 #include "photos-offset-import-controller.h"
+#include "photos-query.h"
 #include "photos-query-builder.h"
 #include "photos-search-context.h"
 #include "photos-source.h"
@@ -48,19 +50,29 @@ photos_offset_import_controller_get_query (PhotosOffsetController *offset_cntrlr
   PhotosOffsetImportController *self = PHOTOS_OFFSET_IMPORT_CONTROLLER (offset_cntrlr);
   GApplication *app;
   GMount *mount;
+  g_autoptr (PhotosQuery) query = NULL;
+  PhotosQuery *ret_val = NULL;
   PhotosSearchContextState *state;
   PhotosSource *source;
+  const gchar *id;
 
   source = PHOTOS_SOURCE (photos_base_manager_get_active_object (self->src_mngr));
   g_return_val_if_fail (PHOTOS_IS_SOURCE (source), NULL);
 
+  id = photos_filterable_get_id (PHOTOS_FILTERABLE (source));
   mount = photos_source_get_mount (source);
-  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
+  g_return_val_if_fail (g_strcmp0 (id, PHOTOS_SOURCE_STOCK_ALL) == 0 || G_IS_MOUNT (mount), NULL);
 
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  return photos_query_builder_count_query (state, PHOTOS_QUERY_FLAGS_IMPORT);
+  if (mount != NULL)
+    query = photos_query_builder_count_query (state, PHOTOS_QUERY_FLAGS_IMPORT);
+  else
+    query = photos_query_new (state, "SELECT DISTINCT COUNT (?urn) WHERE { ?urn a rdfs:Resource FILTER 
(false) }");
+
+  ret_val = g_steal_pointer (&query);
+  return ret_val;
 }
 
 
diff --git a/src/photos-tracker-import-controller.c b/src/photos-tracker-import-controller.c
index 63f3e6c8..8b9dfa05 100644
--- a/src/photos-tracker-import-controller.c
+++ b/src/photos-tracker-import-controller.c
@@ -181,6 +181,6 @@ photos_tracker_import_controller_dup_singleton (void)
 {
   return g_object_new (PHOTOS_TYPE_TRACKER_IMPORT_CONTROLLER,
                        "delay-start", TRUE,
-                       "mode", PHOTOS_WINDOW_MODE_SEARCH,
+                       "mode", PHOTOS_WINDOW_MODE_IMPORT,
                        NULL);
 }


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