From 168e0b5a42ecb4a4d622e0d5d7b3f0eac973a361 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Mon, 9 Jul 2012 21:58:12 -0400 Subject: [PATCH] mount-operation: implement show-unmount-progress Show a notification when we receive a show-unmount-progress signal on the mount operation we use for unmounting. The notification will either turn fade out automatically with a completion message when the unmount successfully completes, or will disappear in case the operation is aborted underway (for example because the device has been unplugged in the meantime). https://bugzilla.gnome.org/show_bug.cgi?id=676125 --- js/ui/shellMountOperation.js | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js index 465891a5c..f65b74edf 100644 --- a/js/ui/shellMountOperation.js +++ b/js/ui/shellMountOperation.js @@ -117,6 +117,8 @@ const ShellMountOperation = new Lang.Class({ Lang.bind(this, this._onShowProcesses2)); this.mountOp.connect('aborted', Lang.bind(this, this.close)); + this.mountOp.connect('show-unmount-progress', + Lang.bind(this, this._onShowUnmountProgress)); this._gicon = source.get_icon(); }, @@ -178,6 +180,11 @@ const ShellMountOperation = new Lang.Class({ this._dialog.close(); this._dialog = null; } + + if (this._notifier) { + this._notifier.done(); + this._notifier = null; + } }, _onShowProcesses2: function(op) { @@ -208,6 +215,16 @@ const ShellMountOperation = new Lang.Class({ this._processesDialog.update(message, processes, choices); }, + _onShowUnmountProgress: function(op, message, timeLeft, bytesLeft) { + if (!this._notifier) + this._notifier = new ShellUnmountNotifier(); + + if (bytesLeft == 0) + this._notifier.done(message); + else + this._notifier.show(message); + }, + borrowDialog: function() { if (this._dialogId != 0) { this._dialog.disconnect(this._dialogId); @@ -218,6 +235,46 @@ const ShellMountOperation = new Lang.Class({ } }); +const ShellUnmountNotifier = new Lang.Class({ + Name: 'ShellUnmountNotifier', + Extends: MessageTray.Source, + + _init: function() { + this.parent('', 'media-removable', St.IconType.FULLCOLOR); + + this._notification = null; + Main.messageTray.add(this); + }, + + show: function(message) { + let [header, text] = message.split('\n', 2); + + if (!this._notification) { + this._notification = new MessageTray.Notification(this, header, text); + this._notification.setTransient(true); + this._notification.setUrgency(MessageTray.Urgency.CRITICAL); + } else { + this._notification.update(header, text); + } + + this.notify(this._notification); + }, + + done: function(message) { + if (this._notification) { + this._notification.destroy(); + this._notification = null; + } + + if (message) { + let notification = new MessageTray.Notification(this, message, null); + notification.setTransient(true); + + this.notify(notification); + } + } +}); + const ShellMountQuestionDialog = new Lang.Class({ Name: 'ShellMountQuestionDialog', Extends: ModalDialog.ModalDialog,