filechooserwidget: use places view to manage fixed devices
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 14 Jul 2015 17:48:49 +0000 (14:48 -0300)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 16 Jul 2015 02:11:52 +0000 (23:11 -0300)
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
gtk/ui/gtkfilechooserwidget.ui

index 84f860a5ed4fcaa53bd769efd7c31ce6a18dc1fb..ddadbab0387259f4bfb04e9a7560b6b0ab2d1c32 100644 (file)
@@ -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);
@@ -3064,6 +3094,23 @@ operation_mode_set_recent (GtkFileChooserWidget *impl)
   gtk_widget_set_sensitive (priv->filter_combo, TRUE);
 }
 
+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)
 {
@@ -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;
@@ -3218,11 +3269,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;
 
@@ -7108,6 +7167,9 @@ search_start_query (GtkFileChooserWidget *impl,
   GtkFileChooserWidgetPrivate *priv = impl->priv;
   GFile *file;
 
+  if (gtk_stack_get_visible_child (GTK_STACK (priv->browse_files_stack)) == priv->places_view)
+    return;
+
   stop_loading_and_clear_list_model (impl, TRUE);
   recent_stop_loading (impl);
   recent_clear_model (impl, TRUE);
@@ -7178,6 +7240,8 @@ search_entry_activate_cb (GtkFileChooserWidget *impl)
   /* reset any existing query object */
   g_set_object (&priv->search_query, NULL);
 
+  gtk_places_view_set_search_query (GTK_PLACES_VIEW (priv->places_view), text);
+
   if (text[0] != '\0')
     search_start_query (impl, text);
   else
@@ -8253,7 +8317,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);
@@ -8303,6 +8369,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);
index 43e1e17b4bf54e910e234074c68e536ebc824f4f..9718ce581b08bd6265ac3b0e3252fd4a626a36e8 100644 (file)
                 <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>
                             <property name="name">list</property>
                           </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>