[gtk+/wip/gbsneto/placessidebar-locations] placessidebar: hide fixed volumes



commit b32c2a55a91bf635e84f9652196d117079c85bb7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Jun 7 18:40:44 2015 -0300

    placessidebar: hide fixed volumes
    
    GtkPlacesSidebar shows every mountable volume
    available, and mounts them when it's needed, i.e.
    the user selects them.
    
    In order to implement the new proposed interaction
    flow, fixed devices (like hard drives' partitions)
    should not be shown here. Mounted networks, however,
    should still be shown.
    
    This commit makes GtkPlacesSidebar be more strict on
    which drives, volumes and mounts are added.

 gtk/gtkplacessidebar.c |  268 ++++++++++++++++++++++++++++--------------------
 gtk/gtkplacessidebar.h |   10 ++-
 2 files changed, 165 insertions(+), 113 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 31f8eb3..9ee18d6 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -178,6 +178,7 @@ struct _GtkPlacesSidebar {
   guint show_desktop_set       : 1;
   guint show_desktop           : 1;
   guint show_connect_to_server : 1;
+  guint show_other_locations   : 1;
   guint show_enter_location    : 1;
   guint local_only             : 1;
 };
@@ -207,6 +208,8 @@ struct _GtkPlacesSidebarClass {
                                       GList              *source_file_list,
                                       GdkDragAction       action);
   void    (* show_enter_location)    (GtkPlacesSidebar   *sidebar);
+
+  void    (* show_other_locations)   (GtkPlacesSidebar   *sidebar);
 };
 
 enum {
@@ -235,14 +238,15 @@ typedef enum {
   PLACES_HEADING,
   PLACES_CONNECT_TO_SERVER,
   PLACES_ENTER_LOCATION,
-  PLACES_DROP_FEEDBACK
+  PLACES_DROP_FEEDBACK,
+  PLACES_OTHER_LOCATIONS
 } PlaceType;
 
 typedef enum {
-  SECTION_DEVICES,
   SECTION_BOOKMARKS,
   SECTION_COMPUTER,
-  SECTION_NETWORK
+  SECTION_MOUNTS,
+  SECTION_OTHER_LOCATIONS
 } SectionType;
 
 enum {
@@ -254,6 +258,7 @@ enum {
   DRAG_ACTION_REQUESTED,
   DRAG_ACTION_ASK,
   DRAG_PERFORM_DROP,
+  SHOW_OTHER_LOCATIONS,
   LAST_SIGNAL
 };
 
@@ -264,6 +269,7 @@ enum {
   PROP_SHOW_CONNECT_TO_SERVER,
   PROP_SHOW_ENTER_LOCATION,
   PROP_LOCAL_ONLY,
+  PROP_SHOW_OTHER_LOCATIONS,
   NUM_PROPERTIES
 };
 
@@ -275,6 +281,7 @@ enum {
 #define ICON_NAME_NETWORK  "network-workgroup-symbolic"
 #define ICON_NAME_NETWORK_SERVER "network-server-symbolic"
 #define ICON_NAME_FOLDER_NETWORK "folder-remote-symbolic"
+#define ICON_NAME_OTHER_LOCATIONS "list-add-symbolic"
 
 #define ICON_NAME_FOLDER                "folder-symbolic"
 #define ICON_NAME_FOLDER_DESKTOP  "user-desktop-symbolic"
@@ -387,6 +394,12 @@ emit_show_enter_location (GtkPlacesSidebar *sidebar)
   g_signal_emit (sidebar, places_sidebar_signals[SHOW_ENTER_LOCATION], 0);
 }
 
+static void
+emit_show_other_locations (GtkPlacesSidebar *sidebar)
+{
+  g_signal_emit (sidebar, places_sidebar_signals[SHOW_OTHER_LOCATIONS], 0);
+}
+
 static GdkDragAction
 emit_drag_action_requested (GtkPlacesSidebar *sidebar,
                             GdkDragContext   *context,
@@ -459,10 +472,10 @@ check_heading_for_section (GtkPlacesSidebar *sidebar,
 {
   switch (section_type)
     {
-    case SECTION_DEVICES:
+    case SECTION_MOUNTS:
       if (!sidebar->devices_header_added)
         {
-          add_heading (sidebar, SECTION_DEVICES, _("Devices"));
+          add_heading (sidebar, SECTION_MOUNTS, _("Mount Points"));
           sidebar->devices_header_added = TRUE;
         }
       break;
@@ -1029,6 +1042,9 @@ update_places (GtkPlacesSidebar *sidebar)
     {
       drive = l->data;
 
+      if (!g_drive_is_media_removable (drive))
+        continue;
+
       volumes = g_drive_get_volumes (drive);
       if (volumes != NULL)
         {
@@ -1056,7 +1072,7 @@ update_places (GtkPlacesSidebar *sidebar)
                   tooltip = g_file_get_parse_name (root);
 
                   add_place (sidebar, PLACES_MOUNTED_VOLUME,
-                             SECTION_DEVICES,
+                             SECTION_MOUNTS,
                              name, icon, mount_uri,
                              drive, volume, mount, 0, tooltip);
                   g_object_unref (root);
@@ -1081,16 +1097,15 @@ update_places (GtkPlacesSidebar *sidebar)
                   tooltip = g_strdup_printf (_("Mount and open “%s”"), name);
 
                   add_place (sidebar, PLACES_MOUNTED_VOLUME,
-                             SECTION_DEVICES,
+                             SECTION_MOUNTS,
                              name, icon, NULL,
                              drive, volume, NULL, 0, tooltip);
                   g_object_unref (icon);
                   g_free (name);
                   g_free (tooltip);
                 }
-              g_object_unref (volume);
             }
-          g_list_free (volumes);
+          g_list_free_full (volumes, g_object_unref);
         }
       else
         {
@@ -1109,7 +1124,7 @@ update_places (GtkPlacesSidebar *sidebar)
               tooltip = g_strdup_printf (_("Mount and open “%s”"), name);
 
               add_place (sidebar, PLACES_BUILT_IN,
-                         SECTION_DEVICES,
+                         SECTION_MOUNTS,
                          name, icon, NULL,
                          drive, NULL, NULL, 0, tooltip);
               g_object_unref (icon);
@@ -1117,78 +1132,8 @@ update_places (GtkPlacesSidebar *sidebar)
               g_free (name);
             }
         }
-      g_object_unref (drive);
-    }
-  g_list_free (drives);
-
-  /* add all volumes that is not associated with a drive */
-  volumes = g_volume_monitor_get_volumes (volume_monitor);
-  for (l = volumes; l != NULL; l = l->next)
-    {
-      volume = l->data;
-      drive = g_volume_get_drive (volume);
-      if (drive != NULL)
-        {
-          g_object_unref (volume);
-          g_object_unref (drive);
-          continue;
-        }
-
-      identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
-
-      if (g_strcmp0 (identifier, "network") == 0)
-        {
-          g_free (identifier);
-          network_volumes = g_list_prepend (network_volumes, volume);
-          continue;
-        }
-      g_free (identifier);
-
-      mount = g_volume_get_mount (volume);
-      if (mount != NULL)
-        {
-          icon = g_mount_get_symbolic_icon (mount);
-          root = g_mount_get_default_location (mount);
-          mount_uri = g_file_get_uri (root);
-          tooltip = g_file_get_parse_name (root);
-          name = g_mount_get_name (mount);
-          add_place (sidebar, PLACES_MOUNTED_VOLUME,
-                     SECTION_DEVICES,
-                     name, icon, mount_uri,
-                     NULL, volume, mount, 0, tooltip);
-          g_object_unref (mount);
-          g_object_unref (root);
-          g_object_unref (icon);
-          g_free (name);
-          g_free (tooltip);
-          g_free (mount_uri);
-        }
-      else
-        {
-          /* see comment above in why we add an icon for an unmounted mountable volume */
-          icon = g_volume_get_symbolic_icon (volume);
-          name = g_volume_get_name (volume);
-          add_place (sidebar, PLACES_MOUNTED_VOLUME,
-                     SECTION_DEVICES,
-                     name, icon, NULL,
-                     NULL, volume, NULL, 0, name);
-          g_object_unref (icon);
-          g_free (name);
-        } 
-      g_object_unref (volume);
     }
-  g_list_free (volumes);
-
-  /* file system root */
-
-  mount_uri = "file:///"; /* No need to strdup */
-  icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_FILESYSTEM);
-  add_place (sidebar, PLACES_BUILT_IN,
-             SECTION_DEVICES,
-             sidebar->hostname, icon, mount_uri,
-             NULL, NULL, NULL, 0,
-             _("Open the contents of the file system"));
-  g_object_unref (icon);
+  g_list_free_full (drives, g_object_unref);
 
   /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
   mounts = g_volume_monitor_get_mounts (volume_monitor);
@@ -1277,28 +1222,6 @@ update_places (GtkPlacesSidebar *sidebar)
   /* network */
   if (!sidebar->local_only)
     {
-      add_heading (sidebar, SECTION_NETWORK, _("Network"));
-
-      mount_uri = "network:///";
-      icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK);
-      add_place (sidebar, PLACES_BUILT_IN,
-                 SECTION_NETWORK,
-                 _("Browse Network"), icon, mount_uri,
-                 NULL, NULL, NULL, 0,
-                 _("Browse the contents of the network"));
-      g_object_unref (icon);
-
-      if (sidebar->show_connect_to_server)
-        {
-          icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
-          add_place (sidebar, PLACES_CONNECT_TO_SERVER,
-                     SECTION_NETWORK,
-                     _("Connect to Server"), icon, NULL,
-                     NULL, NULL, NULL, 0,
-                     _("Connect to a network server address"));
-          g_object_unref (icon);
-        }
-
       network_volumes = g_list_reverse (network_volumes);
       for (l = network_volumes; l != NULL; l = l->next)
         {
@@ -1317,7 +1240,7 @@ update_places (GtkPlacesSidebar *sidebar)
               tooltip = g_strdup_printf (_("Mount and open “%s”"), name);
 
               add_place (sidebar, PLACES_MOUNTED_VOLUME,
-                         SECTION_NETWORK,
+                         SECTION_MOUNTS,
                          name, icon, NULL,
                          NULL, volume, NULL, 0, tooltip);
               g_object_unref (icon);
@@ -1336,7 +1259,7 @@ update_places (GtkPlacesSidebar *sidebar)
           name = g_mount_get_name (mount);
           tooltip = g_file_get_parse_name (root);
           add_place (sidebar, PLACES_MOUNTED_VOLUME,
-                     SECTION_NETWORK,
+                     SECTION_MOUNTS,
                      name, icon, mount_uri,
                      NULL, NULL, mount, 0, tooltip);
           g_object_unref (root);
@@ -1345,11 +1268,37 @@ update_places (GtkPlacesSidebar *sidebar)
           g_free (mount_uri);
           g_free (tooltip);
         }
+
+      if (sidebar->show_connect_to_server)
+        {
+          icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
+          add_place (sidebar, PLACES_CONNECT_TO_SERVER,
+                     SECTION_MOUNTS,
+                     _("Connect to Server"), icon, NULL,
+                     NULL, NULL, NULL, 0,
+                     _("Connect to a network server address"));
+          g_object_unref (icon);
+        }
     }
 
   g_list_free_full (network_volumes, g_object_unref);
   g_list_free_full (network_mounts, g_object_unref);
 
+  /* Other locations */
+  if (sidebar->show_other_locations)
+    {
+      add_heading (sidebar, SECTION_OTHER_LOCATIONS, _("Other Locations"));
+
+      icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_OTHER_LOCATIONS);
+
+      add_place (sidebar, PLACES_OTHER_LOCATIONS,
+                 SECTION_OTHER_LOCATIONS,
+                 _("Other Locations"), icon, NULL,
+                 NULL, NULL, NULL, 0, _("Show other locations"));
+
+      g_object_unref (icon);
+    }
+
   /* restore original selection */
   if (original_uri)
     {
@@ -2476,6 +2425,10 @@ open_selected_bookmark (GtkPlacesSidebar   *sidebar,
     {
       emit_show_enter_location (sidebar);
     }
+  else if (place_type == PLACES_OTHER_LOCATIONS)
+    {
+      emit_show_other_locations (sidebar);
+    }
   else
     {
       open_selected_volume (sidebar, model, iter, open_flags);
@@ -3952,11 +3905,19 @@ places_sidebar_sort_func (GtkTreeModel *model,
 
       retval = pos_a - pos_b;
     }
-  else if (place_type_a == PLACES_CONNECT_TO_SERVER)
+  else if (place_type_a == PLACES_OTHER_LOCATIONS)
+    {
+      retval = 1;
+    }
+  else if (place_type_b == PLACES_OTHER_LOCATIONS)
+    {
+      retval = -1;
+    }
+  else if (section_type_a == SECTION_OTHER_LOCATIONS)
     {
       retval = 1;
     }
-  else if (place_type_b == PLACES_CONNECT_TO_SERVER)
+  else if (section_type_b == SECTION_OTHER_LOCATIONS)
     {
       retval = -1;
     }
@@ -4314,7 +4275,9 @@ gtk_places_sidebar_set_property (GObject      *obj,
       break;
 
     case PROP_SHOW_CONNECT_TO_SERVER:
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
       gtk_places_sidebar_set_show_connect_to_server (sidebar, g_value_get_boolean (value));
+G_GNUC_END_IGNORE_DEPRECATIONS
       break;
 
     case PROP_SHOW_ENTER_LOCATION:
@@ -4325,6 +4288,10 @@ gtk_places_sidebar_set_property (GObject      *obj,
       gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
       break;
 
+    case PROP_SHOW_OTHER_LOCATIONS:
+      gtk_places_sidebar_set_show_other_locations (sidebar, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
       break;
@@ -4354,7 +4321,9 @@ gtk_places_sidebar_get_property (GObject    *obj,
       break;
 
     case PROP_SHOW_CONNECT_TO_SERVER:
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
       g_value_set_boolean (value, gtk_places_sidebar_get_show_connect_to_server (sidebar));
+G_GNUC_END_IGNORE_DEPRECATIONS
       break;
 
     case PROP_SHOW_ENTER_LOCATION:
@@ -4365,6 +4334,10 @@ gtk_places_sidebar_get_property (GObject    *obj,
       g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
       break;
 
+    case PROP_SHOW_OTHER_LOCATIONS:
+      g_value_set_boolean (value, gtk_places_sidebar_get_show_other_locations (sidebar));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
       break;
@@ -4559,7 +4532,8 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
    * a URL like "sftp://ftp.example.com";.  It is up to the application to create
    * the corresponding mount by using, for example, g_file_mount_enclosing_volume().
    *
-   * Since: 3.10
+   * Deprecated: 3.18: use #GtkPlacesSidebar::show-other-locations property to
+   * connect to network servers.
    */
   places_sidebar_signals [SHOW_CONNECT_TO_SERVER] =
           g_signal_new (I_("show-connect-to-server"),
@@ -4677,6 +4651,27 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
                         G_TYPE_POINTER, /* GList of GFile */
                         G_TYPE_INT);
 
+  /**
+   * GtkPlacesSidebar::show-other-locations:
+   * @sidebar: the object which received the signal.
+   *
+   * The places sidebar emits this signal when it needs the calling
+   * application to present an way to show other locations e.g. drives
+   * and network access points.
+   * For example, the application may bring up a page showing the volumes
+   * and discovered network addresses.
+   *
+   * Since: 3.18
+   */
+  places_sidebar_signals [SHOW_OTHER_LOCATIONS] =
+          g_signal_new (I_("show-other-locations"),
+                        G_OBJECT_CLASS_TYPE (gobject_class),
+                        G_SIGNAL_RUN_FIRST,
+                        G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_other_locations),
+                        NULL, NULL,
+                        _gtk_marshal_VOID__VOID,
+                        G_TYPE_NONE, 0);
+
   properties[PROP_LOCATION] =
           g_param_spec_object ("location",
                                P_("Location to Select"),
@@ -4701,7 +4696,7 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
                                 P_("Show 'Connect to Server'"),
                                 P_("Whether the sidebar includes a builtin shortcut to a 'Connect to server' 
dialog"),
                                 FALSE,
-                                G_PARAM_READWRITE);
+                                G_PARAM_READWRITE | G_PARAM_DEPRECATED);
   properties[PROP_SHOW_ENTER_LOCATION] =
           g_param_spec_boolean ("show-enter-location",
                                 P_("Show 'Enter Location'"),
@@ -4714,6 +4709,12 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
                                 P_("Whether the sidebar only includes local files"),
                                 FALSE,
                                 G_PARAM_READWRITE);
+  properties[PROP_SHOW_OTHER_LOCATIONS] =
+          g_param_spec_boolean ("show-other-locations",
+                                P_("Show 'Other locations'"),
+                                P_("Whether the sidebar includes an item to show customly external 
locations"),
+                                FALSE,
+                                G_PARAM_READWRITE);
 
   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
 }
@@ -5040,7 +5041,7 @@ gtk_places_sidebar_get_show_desktop (GtkPlacesSidebar *sidebar)
  * An application may want to turn this on if it implements a way for the user to connect
  * to network servers directly.
  *
- * Since: 3.10
+ * Deprecated: 3.18: use gtk_places_sidebar_set_show_other_locations() instead.
  */
 void
 gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar *sidebar,
@@ -5065,7 +5066,7 @@ gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar *sidebar,
  *
  * Returns: %TRUE if the sidebar will display a “Connect to Server” item.
  *
- * Since: 3.10
+ * Deprecated: 3.18: use gtk_places_sidebar_get_show_other_locations() instead.
  */
 gboolean
 gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSidebar *sidebar)
@@ -5324,3 +5325,48 @@ gtk_places_sidebar_get_nth_bookmark (GtkPlacesSidebar *sidebar,
 
   return file;
 }
+
+/**
+ * gtk_places_sidebar_set_show_other_locations:
+ * @sidebar: a places sidebar
+ * @show_other_locations: whether to show an item for the Other Locations view
+ *
+ * Sets whether the @sidebar should show an item for the application to show an Other Locations
+ * view; this is off by default.
+ * An application may want to turn this on if it implements a way for the user to see and interact
+ * to drives and network servers directly.
+ *
+ * Since: 3.18
+ */
+void
+gtk_places_sidebar_set_show_other_locations (GtkPlacesSidebar *sidebar,
+                                             gboolean          show_other_locations)
+{
+  g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
+
+  show_other_locations = !!show_other_locations;
+  if (sidebar->show_other_locations != show_other_locations)
+    {
+      sidebar->show_other_locations = show_other_locations;
+      update_places (sidebar);
+      g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_OTHER_LOCATIONS]);
+    }
+}
+
+/**
+ * gtk_places_sidebar_get_show_other_locations:
+ * @sidebar: a places sidebar
+ *
+ * Returns the value previously set with gtk_places_sidebar_set_show_other_locations()
+ *
+ * Returns: %TRUE if the sidebar will display an “Other Locations” item.
+ *
+ * Since: 3.18
+ */
+gboolean
+gtk_places_sidebar_get_show_other_locations (GtkPlacesSidebar *sidebar)
+{
+  g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
+
+  return sidebar->show_other_locations;
+}
diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h
index f703cf8..d8657cb 100644
--- a/gtk/gtkplacessidebar.h
+++ b/gtk/gtkplacessidebar.h
@@ -101,9 +101,9 @@ GDK_AVAILABLE_IN_3_10
 void               gtk_places_sidebar_set_show_desktop           (GtkPlacesSidebar   *sidebar,
                                                                   gboolean            show_desktop);
 
-GDK_AVAILABLE_IN_3_10
+GDK_DEPRECATED_IN_3_18
 gboolean           gtk_places_sidebar_get_show_connect_to_server (GtkPlacesSidebar   *sidebar);
-GDK_AVAILABLE_IN_3_10
+GDK_DEPRECATED_IN_3_18
 void               gtk_places_sidebar_set_show_connect_to_server (GtkPlacesSidebar   *sidebar,
                                                                   gboolean            
show_connect_to_server);
 GDK_AVAILABLE_IN_3_14
@@ -132,6 +132,12 @@ GDK_AVAILABLE_IN_3_10
 GFile *            gtk_places_sidebar_get_nth_bookmark           (GtkPlacesSidebar   *sidebar,
                                                                   gint                n);
 
+GDK_AVAILABLE_IN_3_18
+void                 gtk_places_sidebar_set_show_other_locations (GtkPlacesSidebar   *sidebar,
+                                                                  gboolean            show_other_locations);
+GDK_AVAILABLE_IN_3_18
+gboolean             gtk_places_sidebar_get_show_other_locations (GtkPlacesSidebar   *sidebar);
+
 G_END_DECLS
 
 #endif /* __GTK_PLACES_SIDEBAR_H__ */


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