[gtk+/wip/gbsneto/placessidebar-locations] placesview: better check if device is removable



commit 203481116a7e4250cf333ff4ea3a5ab7a43f564e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Jun 8 10:33:48 2015 -0300

    placesview: better check if device is removable

 gtk/gtkplacesview.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 0ba95c3..33107a6 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -363,6 +363,42 @@ gtk_places_view_set_property (GObject      *object,
     }
 }
 
+static gboolean
+is_external_device (GVolume *volume)
+{
+  gboolean external;
+  GDrive *drive;
+  GMount *mount;
+
+  external = FALSE;
+  drive = g_volume_get_drive (volume);
+  mount = g_volume_get_mount (volume);
+
+  if (drive)
+    {
+      external = g_drive_can_eject (drive);
+
+      if (volume)
+        external |= g_volume_can_eject (volume);
+
+      if (mount)
+        external |= g_mount_can_eject (mount) && g_mount_can_unmount (mount);
+    }
+  else
+    {
+      /*
+       * If no GDrive is associated with the given volume, it is assured
+       * this is not an external device (e.g. USB sticks or external hard
+       * drives).
+       */
+      external = FALSE;
+    }
+
+  g_clear_object (&drive);
+  g_clear_object (&mount);
+
+  return external;
+}
 
 static void
 populate_servers (GtkPlacesView *view)
@@ -434,6 +470,9 @@ add_volume (GtkPlacesView *view,
 
   priv = view->priv;
 
+  if (is_external_device (volume))
+    return;
+
   drive = g_volume_get_drive (volume);
 
   if (drive)
@@ -454,7 +493,11 @@ add_volume (GtkPlacesView *view,
   root = mount ? g_mount_get_root (mount) : NULL;
   icon = g_volume_get_icon (volume);
   name = g_volume_get_name (volume);
-  path = root ? g_file_get_path (root) : NULL;
+
+  if (root)
+    path = is_network ? g_file_get_uri (root) : g_file_get_path (root);
+  else
+    path = NULL;
 
   if (!mount ||
       (mount && !g_mount_is_shadowed (mount)))
@@ -524,9 +567,13 @@ add_mount (GtkPlacesView *view,
   icon = g_mount_get_icon (mount);
   name = g_mount_get_name (mount);
   root = g_mount_get_root (mount);
-  path = root ? g_file_get_path (root) : NULL;
   is_network = root ? g_file_is_native (root) : FALSE;
 
+  if (root)
+    path = is_network ? g_file_get_uri (root) : g_file_get_path (root);
+  else
+    path = NULL;
+
   if (!g_mount_is_shadowed (mount))
     {
       GtkWidget *row;
@@ -562,7 +609,7 @@ add_drive (GtkPlacesView *view,
   g_return_if_fail (G_IS_DRIVE (drive));
 
   /* Removable devices won't appear here */
-  if (g_drive_is_media_removable (drive))
+  if (g_drive_can_eject (drive))
     return;
 
   volumes = g_drive_get_volumes (drive);


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