[gnome-shell/hotplug: 14/21] autorun: prefer Safe Removal over eject/unmount if possible
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/hotplug: 14/21] autorun: prefer Safe Removal over eject/unmount if possible
- Date: Mon, 27 Jun 2011 19:53:08 +0000 (UTC)
commit 3b46b8c4caa9c8822db3b1f1c7456cf94e5e824d
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.
js/ui/autorunManager.js | 66 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/autorunManager.js b/js/ui/autorunManager.js
index f1ecf5d..99f1a54 100644
--- a/js/ui/autorunManager.js
+++ b/js/ui/autorunManager.js
@@ -204,12 +204,30 @@ 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._onDriveStop));
+ } else {
+ if (mount.can_eject()) {
+ mount.eject_with_operation(0, mountOp.mountOp, null,
+ Lang.bind(this, this._onMountEject));
+ } else if (volume && volume.can_eject()) {
+ volume.eject_with_operation(0, mountOp.mountOp, null,
+ Lang.bind(this, this._onVolumeEject));
+ } else if (drive && drive.can_eject()) {
+ drive.eject_with_operation(0, mountOp.mountOp, null,
+ Lang.bind(this, this._onDriveEject));
+ } else if (mount.can_unmount()) {
+ mount.unmount_with_operation(0, mountOp.mountOp, null,
+ Lang.bind(this, this._onMountEject));
+ }
+ }
},
_onMountEject: function(mount, res) {
@@ -226,6 +244,42 @@ AutorunManager.prototype = {
+ ': ' + e.toString());
}
},
+
+ _onDriveEject: function(drive, res) {
+ try {
+ drive.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 ' + drive.get_name()
+ + ': ' + e.toString());
+ }
+ },
+
+ _onDriveStop: 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());
+ }
+ },
+
+ _onVolumeEject: function(volume, res) {
+ try {
+ volume.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 volume ' + volume.get_name()
+ + ': ' + e.toString());
+ }
+ },
}
function AutorunResidentSource() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]