[gtk+/wip/gbsneto/other-locations: 3/3] filechooserwidget: use places view to manage fixed devices



commit 0a66daed213b3b05a55c0176a2d76d3ac2c3f054
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jul 14 14:48:49 2015 -0300

    filechooserwidget: use places view to manage fixed devices
    
    Previous patch modified places sidebar widget to stop handling
    fixed devices by adding an "Other Locations..." item. Up to now,
    however, these changes are isolated from each other since the
    bundled file manager widgets ignore the sidebar requests for
    external management of fixed devices and networks.
    
    To fix that, make the file chooser widget be aware of the
    GtkPlacesSidebar::show-other-locations signal and, when requested,
    show places view to manage the fixed devices and networks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752034

 gtk/gtkfilechooserwidget.c     |  173 ++++++++++++++++++++++++++++------------
 gtk/ui/gtkfilechooserwidget.ui |   13 +++
 2 files changed, 134 insertions(+), 52 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index ca414ad..2bc8e56 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -51,6 +51,7 @@
 #include "gtkpathbar.h"
 #include "gtkplacessidebar.h"
 #include "gtkplacessidebarprivate.h"
+#include "gtkplacesviewprivate.h"
 #include "gtkprivate.h"
 #include "gtkrecentmanager.h"
 #include "gtksearchentry.h"
@@ -177,6 +178,7 @@ typedef enum {
   OPERATION_MODE_BROWSE,
   OPERATION_MODE_SEARCH,
   OPERATION_MODE_ENTER_LOCATION,
+  OPERATION_MODE_OTHER_LOCATIONS,
   OPERATION_MODE_RECENT
 } OperationMode;
 
@@ -209,6 +211,7 @@ struct _GtkFileChooserWidgetPrivate {
   GtkWidget *browse_header_revealer;
   GtkWidget *browse_header_stack;
   GtkWidget *browse_files_stack;
+  GtkWidget *browse_files_swin;
   GtkWidget *browse_files_tree_view;
   GtkWidget *browse_files_popup_menu;
   GtkWidget *add_shortcut_item;
@@ -239,6 +242,7 @@ struct _GtkFileChooserWidgetPrivate {
   char *browse_files_last_selected_name;
 
   GtkWidget *places_sidebar;
+  GtkWidget *places_view;
   StartupMode startup_mode;
 
   /* OPERATION_MODE_SEARCH */
@@ -2565,6 +2569,8 @@ save_widgets_create (GtkFileChooserWidget *impl)
 
   location_switch_to_path_bar (impl);
 
+  gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (priv->places_sidebar), priv->current_folder);
+
   if (priv->external_entry)
     {
       location_entry_disconnect (impl);
@@ -2643,8 +2649,6 @@ location_switch_to_path_bar (GtkFileChooserWidget *impl)
     }
 
   gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "pathbar");
-
-  gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (priv->places_sidebar), priv->current_folder);
 }
 
 /* Turns on the location entry.  Can be called even if we are already in that
@@ -2733,6 +2737,20 @@ location_mode_set (GtkFileChooserWidget *impl,
   g_object_notify (G_OBJECT (impl), "subtitle");
 }
 
+/* Callback used when the places sidebar asks us to show other locations */
+static void
+places_sidebar_show_other_locations_cb (GtkPlacesSidebar     *sidebar,
+                                        GtkFileChooserWidget *impl)
+{
+  GtkFileChooserWidgetPrivate *priv = impl->priv;
+
+  priv->preview_widget_active = FALSE;
+
+  update_preview_widget_visibility (impl);
+
+  operation_mode_set (impl, OPERATION_MODE_OTHER_LOCATIONS);
+}
+
 static void
 location_toggle_popup_handler (GtkFileChooserWidget *impl)
 {
@@ -2952,6 +2970,9 @@ location_bar_update (GtkFileChooserWidget *impl)
     case OPERATION_MODE_ENTER_LOCATION:
       break;
 
+    case OPERATION_MODE_OTHER_LOCATIONS:
+      break;
+
     case OPERATION_MODE_BROWSE:
       break;
 
@@ -3022,6 +3043,7 @@ operation_mode_set_browse (GtkFileChooserWidget *impl)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
 
+  gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (priv->places_sidebar), priv->current_folder);
   gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list");
   location_mode_set (impl, LOCATION_MODE_PATH_BAR);
   gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "pathbar");
@@ -3034,10 +3056,18 @@ static void
 operation_mode_set_search (GtkFileChooserWidget *impl)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
+  GtkWidget *visible_widget;
 
   g_assert (priv->search_model == NULL);
 
-  gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list");
+  visible_widget = gtk_stack_get_visible_child (GTK_STACK (priv->browse_files_stack));
+
+  if (visible_widget != priv->places_view &&
+      visible_widget != priv->browse_files_swin)
+    {
+      gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list");
+    }
+
   gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "search");
   gtk_revealer_set_reveal_child (GTK_REVEALER (priv->browse_header_revealer), TRUE);
   location_bar_update (impl);
@@ -3065,6 +3095,23 @@ operation_mode_set_recent (GtkFileChooserWidget *impl)
 }
 
 static void
+operation_mode_set_other_locations (GtkFileChooserWidget *impl)
+{
+  GtkFileChooserWidgetPrivate *priv = impl->priv;
+
+  gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "other_locations");
+  gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_header_stack), "pathbar");
+  gtk_revealer_set_reveal_child (GTK_REVEALER (priv->browse_header_revealer), FALSE);
+  location_bar_update (impl);
+  stop_loading_and_clear_list_model (impl, TRUE);
+  recent_stop_loading (impl);
+  search_stop_searching (impl, TRUE);
+  recent_clear_model (impl, TRUE);
+  search_clear_model (impl, TRUE);
+  gtk_widget_set_sensitive (priv->filter_combo, FALSE);
+}
+
+static void
 operation_mode_set (GtkFileChooserWidget *impl, OperationMode mode)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
@@ -3081,6 +3128,10 @@ operation_mode_set (GtkFileChooserWidget *impl, OperationMode mode)
       operation_mode_set_enter_location (impl);
       break;
 
+    case OPERATION_MODE_OTHER_LOCATIONS:
+      operation_mode_set_other_locations (impl);
+      break;
+
     case OPERATION_MODE_BROWSE:
       operation_mode_set_browse (impl);
       break;
@@ -3198,11 +3249,19 @@ gtk_file_chooser_widget_set_property (GObject      *object,
         operation_mode_set (impl, OPERATION_MODE_SEARCH);
       else
         {
-          operation_mode_set (impl, OPERATION_MODE_BROWSE);
-          if (priv->current_folder)
-            change_folder_and_display_error (impl, priv->current_folder, FALSE);
+          if (gtk_stack_get_visible_child (GTK_STACK (priv->browse_files_stack)) != priv->places_view)
+            {
+              operation_mode_set (impl, OPERATION_MODE_BROWSE);
+
+              if (priv->current_folder)
+                change_folder_and_display_error (impl, priv->current_folder, FALSE);
+               else
+                switch_to_home_dir (impl);
+            }
           else
-            switch_to_home_dir (impl);
+            {
+              operation_mode_set (impl, OPERATION_MODE_OTHER_LOCATIONS);
+            }
         }
       break;
 
@@ -7093,60 +7152,68 @@ search_start_query (GtkFileChooserWidget *impl,
                     const gchar          *query_text)
 {
   GtkFileChooserWidgetPrivate *priv = impl->priv;
-  GFile *file;
 
-  stop_loading_and_clear_list_model (impl, TRUE);
-  recent_stop_loading (impl);
-  recent_clear_model (impl, TRUE);
+  if (gtk_stack_get_visible_child (GTK_STACK (priv->browse_files_stack)) == priv->places_view)
+    {
+      gtk_places_view_set_search_query (GTK_PLACES_VIEW (priv->places_view), query_text);
+    }
+  else if (query_text[0] != '\0')
+    {
+      GFile *file;
 
-  search_stop_searching (impl, FALSE);
-  search_clear_model (impl, TRUE);
-  search_setup_model (impl);
+      stop_loading_and_clear_list_model (impl, TRUE);
+      recent_stop_loading (impl);
+      recent_clear_model (impl, TRUE);
 
-  set_busy_cursor (impl, TRUE);
-  gtk_spinner_start (GTK_SPINNER (priv->search_spinner));
-  priv->show_progress_timeout = g_timeout_add (1000, show_spinner, impl);
+      search_stop_searching (impl, FALSE);
+      search_clear_model (impl, TRUE);
+      search_setup_model (impl);
 
-  gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list");
+      set_busy_cursor (impl, TRUE);
+      gtk_spinner_start (GTK_SPINNER (priv->search_spinner));
+      priv->show_progress_timeout = g_timeout_add (1000, show_spinner, impl);
 
-  if (priv->search_engine == NULL)
-    priv->search_engine = _gtk_search_engine_new ();
+      gtk_stack_set_visible_child_name (GTK_STACK (priv->browse_files_stack), "list");
 
-  if (!priv->search_engine)
-    {
-      set_busy_cursor (impl, FALSE);
-      gtk_spinner_stop (GTK_SPINNER (priv->search_spinner));
-      search_error_could_not_create_client (impl); /* lame; we don't get an error code or anything */
-      return;
-    }
+      if (priv->search_engine == NULL)
+        priv->search_engine = _gtk_search_engine_new ();
 
-  if (!priv->search_query)
-    {
-      priv->search_query = gtk_query_new ();
-      gtk_query_set_text (priv->search_query, query_text);
-    }
+      if (!priv->search_engine)
+        {
+          set_busy_cursor (impl, FALSE);
+          gtk_spinner_stop (GTK_SPINNER (priv->search_spinner));
+          search_error_could_not_create_client (impl); /* lame; we don't get an error code or anything */
+          return;
+        }
 
-  file = gtk_places_sidebar_get_location (GTK_PLACES_SIDEBAR (priv->places_sidebar));
-  if (file)
-    {
-      gchar *location;
-      location = g_file_get_uri (file);
-      gtk_query_set_location (priv->search_query, location);
-      g_free (location);
-      g_object_unref (file);
-    }
+      if (!priv->search_query)
+        {
+          priv->search_query = gtk_query_new ();
+          gtk_query_set_text (priv->search_query, query_text);
+        }
+
+      file = gtk_places_sidebar_get_location (GTK_PLACES_SIDEBAR (priv->places_sidebar));
+      if (file)
+        {
+          gchar *location;
+          location = g_file_get_uri (file);
+          gtk_query_set_location (priv->search_query, location);
+          g_free (location);
+          g_object_unref (file);
+        }
 
-  _gtk_search_engine_set_model (priv->search_engine, priv->model_for_search);
-  _gtk_search_engine_set_query (priv->search_engine, priv->search_query);
+      _gtk_search_engine_set_model (priv->search_engine, priv->model_for_search);
+      _gtk_search_engine_set_query (priv->search_engine, priv->search_query);
 
-  g_signal_connect (priv->search_engine, "hits-added",
-                    G_CALLBACK (search_engine_hits_added_cb), impl);
-  g_signal_connect (priv->search_engine, "finished",
-                    G_CALLBACK (search_engine_finished_cb), impl);
-  g_signal_connect (priv->search_engine, "error",
-                    G_CALLBACK (search_engine_error_cb), impl);
+      g_signal_connect (priv->search_engine, "hits-added",
+                        G_CALLBACK (search_engine_hits_added_cb), impl);
+      g_signal_connect (priv->search_engine, "finished",
+                        G_CALLBACK (search_engine_finished_cb), impl);
+      g_signal_connect (priv->search_engine, "error",
+                        G_CALLBACK (search_engine_error_cb), impl);
 
-  _gtk_search_engine_start (priv->search_engine);
+      _gtk_search_engine_start (priv->search_engine);
+    }
 }
 
 /* Callback used when the user presses Enter while typing on the search
@@ -7166,8 +7233,7 @@ search_entry_activate_cb (GtkFileChooserWidget *impl)
   /* reset any existing query object */
   g_set_object (&priv->search_query, NULL);
 
-  if (text[0] != '\0')
-    search_start_query (impl, text);
+  search_start_query (impl, text);
 }
 
 static void
@@ -8239,7 +8305,9 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_widgets_hpaned);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_files_stack);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, places_sidebar);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, places_view);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_files_tree_view);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_files_swin);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_header_revealer);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, browse_header_stack);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserWidget, 
browse_new_folder_button);
@@ -8289,6 +8357,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_callback (widget_class, path_bar_clicked);
   gtk_widget_class_bind_template_callback (widget_class, places_sidebar_open_location_cb);
   gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_error_message_cb);
+  gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_other_locations_cb);
   gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb);
   gtk_widget_class_bind_template_callback (widget_class, search_entry_stop_cb);
   gtk_widget_class_bind_template_callback (widget_class, new_folder_popover_active);
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 8389bff..bdebc9e 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -17,11 +17,13 @@
                 <property name="can_focus">False</property>
                 <property name="hscrollbar_policy">never</property>
                 <property name="local_only">True</property>
+                <property name="show_other_locations">True</property>
                 <style>
                   <class name="sidebar"/>
                 </style>
                 <signal name="open-location" handler="places_sidebar_open_location_cb" swapped="no"/>
                 <signal name="show-error-message" handler="places_sidebar_show_error_message_cb" 
swapped="no"/>
+                <signal name="show-other-locations" handler="places_sidebar_show_other_locations_cb" 
swapped="no"/>
               </object>
               <packing>
                 <property name="resize">False</property>
@@ -240,6 +242,17 @@
                           </packing>
                         </child>
                         <child>
+                          <object class="GtkPlacesView" id="places_view">
+                            <property name="visible">True</property>
+                            <property name="local_only" bind-source="GtkFileChooserWidget" 
bind-property="local-only" bind-flags="default|sync-create" />
+                            <signal name="open-location" handler="places_sidebar_open_location_cb" 
swapped="no"/>
+                            <signal name="show-error-message" handler="places_sidebar_show_error_message_cb" 
swapped="no"/>
+                          </object>
+                          <packing>
+                            <property name="name">other_locations</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkGrid">
                             <property name="visible">True</property>
                             <property name="row_spacing">12</property>


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