[gnome-shell/hotplug: 10/14] autorun: prefer Safe Removal over eject/unmount if possible



commit 8e332b0946e70d5655638b40be4e8cdcffd9d188
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Jun 23 10:08:17 2011 -0400

    autorun: prefer Safe Removal over eject/unmount if possible
    
    Basically do what NautilusPlacesSidebar does with the drive/volume/mount
    eject/unmount/stop priorities.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653520

 js/ui/autorunManager.js |   61 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/js/ui/autorunManager.js b/js/ui/autorunManager.js
index f1ecf5d..6bf1d39 100644
--- a/js/ui/autorunManager.js
+++ b/js/ui/autorunManager.js
@@ -204,20 +204,35 @@ AutorunManager.prototype = {
     ejectMount: function(mount) {
         let mountOp = new ShellMountOperation.ShellMountOperation(mount);
 
-        if (mount.can_eject())
-            mount.eject_with_operation(0, mountOp.mountOp, null,
-                                       Lang.bind(this, this._onMountEject));
-        else
-            mount.unmount_with_operation(0, mountOp.mountOp, null,
-                                         Lang.bind(this, this._onMountEject));
+        // first, see if we have a drive
+        let drive = mount.get_drive();
+        let volume = mount.get_volume();
+
+        if (drive &&
+            drive.get_start_stop_type() == Gio.DriveStartStopType.SHUTDOWN &&
+            drive.can_stop()) {
+            drive.stop(0, mountOp.mountOp, null,
+                       Lang.bind(this, this._onStop));
+        } else {
+            if (mount.can_eject()) {
+                mount.eject_with_operation(0, mountOp.mountOp, null,
+                                           Lang.bind(this, this._onEject));
+            } else if (volume && volume.can_eject()) {
+                volume.eject_with_operation(0, mountOp.mountOp, null,
+                                            Lang.bind(this, this._onEject));
+            } else if (drive && drive.can_eject()) {
+                drive.eject_with_operation(0, mountOp.mountOp, null,
+                                           Lang.bind(this, this._onEject));
+            } else if (mount.can_unmount()) {
+                mount.unmount_with_operation(0, mountOp.mountOp, null,
+                                             Lang.bind(this, this._onUnmount));
+            }
+        }
     },
 
-    _onMountEject: function(mount, res) {
+    _onUnmount: function(mount, res) {
         try {
-            if (mount.can_eject())
-                mount.eject_with_operation_finish(res);
-            else
-                mount.unmount_with_operation_finish(res);
+            mount.unmount_with_operation_finish(res);
         } catch (e) {
             // FIXME: we need to ignore G_IO_ERROR_FAILED_HANDLED errors here
             // but we can't access the error code from JS.
@@ -226,6 +241,30 @@ AutorunManager.prototype = {
                 + ': ' + e.toString());
         }
     },
+
+    _onEject: function(source, res) {
+        try {
+            source.eject_with_operation_finish(res);
+        } catch (e) {
+            // FIXME: we need to ignore G_IO_ERROR_FAILED_HANDLED errors here
+            // but we can't access the error code from JS.
+            // See https://bugzilla.gnome.org/show_bug.cgi?id=591480
+            log('Unable to eject the drive ' + source.get_name() 
+                + ': ' + e.toString());
+        }
+    },
+
+    _onStop: function(drive, res) {
+        try {
+            drive.stop_finish(res);
+        } catch (e) {
+            // FIXME: we need to ignore G_IO_ERROR_FAILED_HANDLED errors here
+            // but we can't access the error code from JS.
+            // See https://bugzilla.gnome.org/show_bug.cgi?id=591480
+            log('Unable to stop the drive ' + drive.get_name() 
+                + ': ' + e.toString());
+        }
+    },
 }
 
 function AutorunResidentSource() {



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