[Xfce4-commits] <thunar:master> Propely leave unmounted mounts and volumes.

Nick Schermer noreply at xfce.org
Sat Oct 13 16:12:26 CEST 2012


Updating branch refs/heads/master
         to bdf2740c11aa707576b84626f3f52d996c764f24 (commit)
       from 67578cbf9caead21d9fe137ba25862fe39455ef7 (commit)

commit bdf2740c11aa707576b84626f3f52d996c764f24
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Oct 7 13:46:21 2012 +0200

    Propely leave unmounted mounts and volumes.

 thunar/thunar-device-monitor.c |   33 +++++++++++++++++++++++++++++----
 thunar/thunar-marshal.list     |    1 +
 thunar/thunar-tree-model.c     |    3 +++
 thunar/thunar-window.c         |   34 ++++++++++++++++++++++++++++------
 4 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/thunar/thunar-device-monitor.c b/thunar/thunar-device-monitor.c
index a275e92..4f5798a 100644
--- a/thunar/thunar-device-monitor.c
+++ b/thunar/thunar-device-monitor.c
@@ -28,6 +28,7 @@
 
 #include <thunar/thunar-device-monitor.h>
 #include <thunar/thunar-private.h>
+#include <thunar/thunar-marshal.h>
 
 
 
@@ -80,7 +81,8 @@ struct _ThunarDeviceMonitorClass
   void (*device_changed)     (ThunarDeviceMonitor *monitor,
                               ThunarDevice        *device);
   void (*device_pre_unmount) (ThunarDeviceMonitor *monitor,
-                              ThunarDevice        *device);
+                              ThunarDevice        *device,
+                              GFile               *root_file);
 };
 
 struct _ThunarDeviceMonitor
@@ -146,8 +148,9 @@ thunar_device_monitor_class_init (ThunarDeviceMonitorClass *klass)
                     G_SIGNAL_RUN_LAST,
                     G_STRUCT_OFFSET (ThunarDeviceMonitorClass, device_pre_unmount),
                     NULL, NULL,
-                    g_cclosure_marshal_VOID__OBJECT,
-                    G_TYPE_NONE, 1, G_TYPE_OBJECT);
+                    _thunar_marshal_VOID__OBJECT_OBJECT,
+                    G_TYPE_NONE, 2,
+                    G_TYPE_OBJECT, G_TYPE_OBJECT);
 }
 
 
@@ -536,6 +539,8 @@ thunar_device_monitor_mount_removed (GVolumeMonitor      *volume_monitor,
                                      ThunarDeviceMonitor *monitor)
 {
   ThunarDevice *device;
+  GVolume      *volume;
+  GFile        *root_file;
 
   _thunar_return_if_fail (G_IS_VOLUME_MONITOR (volume_monitor));
   _thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (monitor));
@@ -547,11 +552,31 @@ thunar_device_monitor_mount_removed (GVolumeMonitor      *volume_monitor,
   if (device != NULL)
     {
       /* notify */
-      g_signal_emit (G_OBJECT (monitor), device_monitor_signals[DEVICE_REMOVED], 0, device);
+      g_signal_emit (G_OBJECT (monitor),device_monitor_signals[DEVICE_REMOVED], 0, device);
 
       /* drop it */
       g_hash_table_remove (monitor->devices, mount);
     }
+  else
+    {
+      /* maybe a mount was removed from a known volume, gphoto2 does this */
+      volume = g_mount_get_volume (mount);
+      if (volume != NULL)
+        {
+          device = g_hash_table_lookup (monitor->devices, volume);
+          if (device != NULL)
+            {
+              /* we can't get the file from the volume at this point so provide it */
+              root_file = g_mount_get_root (mount);
+              g_signal_emit (G_OBJECT (monitor),
+                             device_monitor_signals[DEVICE_PRE_UNMOUNT], 0,
+                             device, root_file);
+              g_object_unref (root_file);
+            }
+
+          g_object_unref (volume);
+        }
+    }
 }
 
 
diff --git a/thunar/thunar-marshal.list b/thunar/thunar-marshal.list
index 59a4e91..24d26e0 100644
--- a/thunar/thunar-marshal.list
+++ b/thunar/thunar-marshal.list
@@ -6,3 +6,4 @@ VOID:STRING,STRING
 VOID:UINT64,UINT,UINT,UINT
 VOID:UINT,BOXED,UINT,STRING
 VOID:UINT,BOXED
+VOID:OBJECT,OBJECT
diff --git a/thunar/thunar-tree-model.c b/thunar/thunar-tree-model.c
index ecd15cb..e2bbabf 100644
--- a/thunar/thunar-tree-model.c
+++ b/thunar/thunar-tree-model.c
@@ -120,6 +120,7 @@ static void                 thunar_tree_model_device_added            (ThunarDev
                                                                        ThunarTreeModel        *model);
 static void                 thunar_tree_model_device_pre_unmount      (ThunarDeviceMonitor    *device_monitor,
                                                                        ThunarDevice           *device,
+                                                                       GFile                  *root_file,
                                                                        ThunarTreeModel        *model);
 static void                 thunar_tree_model_device_removed          (ThunarDeviceMonitor    *device_monitor,
                                                                        ThunarDevice           *device,
@@ -1025,6 +1026,7 @@ thunar_tree_model_device_changed (ThunarDeviceMonitor *device_monitor,
 static void
 thunar_tree_model_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
                                       ThunarDevice        *device,
+                                      GFile               *root_file,
                                       ThunarTreeModel     *model)
 {
   GNode *node;
@@ -1032,6 +1034,7 @@ thunar_tree_model_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
   _thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (device_monitor));
   _thunar_return_if_fail (model->device_monitor == device_monitor);
   _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
+  _thunar_return_if_fail (G_IS_FILE (root_file));
   _thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model));
 
   /* lookup the node for the volume (if visible) */
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index e6f8536..ccb60d1 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -210,6 +210,10 @@ static void     thunar_window_notify_loading              (ThunarView
                                                            ThunarWindow           *window);
 static void     thunar_window_device_pre_unmount          (ThunarDeviceMonitor    *device_monitor,
                                                            ThunarDevice           *device,
+                                                           GFile                  *root_file,
+                                                           ThunarWindow           *window);
+static void     thunar_window_device_removed              (ThunarDeviceMonitor    *device_monitor,
+                                                           ThunarDevice           *device,
                                                            ThunarWindow           *window);
 static gboolean thunar_window_merge_idle                  (gpointer                user_data);
 static void     thunar_window_merge_idle_destroy          (gpointer                user_data);
@@ -760,6 +764,7 @@ thunar_window_init (ThunarWindow *window)
   /* connect to the volume monitor */
   window->device_monitor = thunar_device_monitor_get ();
   g_signal_connect (window->device_monitor, "device-pre-unmount", G_CALLBACK (thunar_window_device_pre_unmount), window);
+  g_signal_connect (window->device_monitor, "device-removed", G_CALLBACK (thunar_window_device_removed), window);
 
   /* allocate a closure for the menu_item_selected() callback */
   window->menu_item_selected_closure = g_cclosure_new_object (G_CALLBACK (thunar_window_menu_item_selected), G_OBJECT (window));
@@ -2768,21 +2773,22 @@ thunar_window_notify_loading (ThunarView   *view,
         }
     }
 }
-  
+
 
 
 static void
 thunar_window_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
                                   ThunarDevice        *device,
+                                  GFile               *root_file,
                                   ThunarWindow        *window)
 {
   ThunarFile *file;
   GtkAction  *action;
-  GFile      *mount_point;
 
   _thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (device_monitor));
   _thunar_return_if_fail (window->device_monitor == device_monitor);
   _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
+  _thunar_return_if_fail (G_IS_FILE (root_file));
   _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
 
   /* nothing to do if we don't have a current directory */
@@ -2790,10 +2796,7 @@ thunar_window_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
     return;
 
   /* try to get the ThunarFile for the mount point from the file cache */
-  mount_point = thunar_device_get_root (device);
-  file = thunar_file_cache_lookup (mount_point);
-  g_object_unref (mount_point);
-
+  file = thunar_file_cache_lookup (root_file);
   if (G_UNLIKELY (file == NULL))
     return;
 
@@ -2809,6 +2812,25 @@ thunar_window_device_pre_unmount (ThunarDeviceMonitor *device_monitor,
 
 
 
+static void
+thunar_window_device_removed (ThunarDeviceMonitor *device_monitor,
+                              ThunarDevice        *device,
+                              ThunarWindow        *window)
+{
+  GFile *root_file;
+
+  _thunar_return_if_fail (THUNAR_IS_DEVICE_MONITOR (device_monitor));
+  _thunar_return_if_fail (window->device_monitor == device_monitor);
+  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
+  _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
+
+  root_file = thunar_device_get_root (device);
+  thunar_window_device_pre_unmount (device_monitor, device, root_file, window);
+  g_object_unref (root_file);
+}
+
+
+
 static gboolean
 thunar_window_merge_idle (gpointer user_data)
 {


More information about the Xfce4-commits mailing list