[kupfer] volumes: Treat a volume like a folder. Report errors on unmount.



commit 94cfe45be952fdc597fb1a9c6f6fe1728b2e6df8
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 21 18:05:23 2011 +0100

    volumes: Treat a volume like a folder. Report errors on unmount.
    
    Finally update volumes plugin to treat volumes like folders (so they
    are easily accessible in Copy/Move file actions. Also finally use the
    async error reporting possibilities to display a notification when we
    find an error while unmounting.

 kupfer/plugin/volumes.py |   47 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 14 deletions(-)
---
diff --git a/kupfer/plugin/volumes.py b/kupfer/plugin/volumes.py
index 1e04183..f8b34e0 100644
--- a/kupfer/plugin/volumes.py
+++ b/kupfer/plugin/volumes.py
@@ -6,12 +6,21 @@ __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 
 import gio
 
-from kupfer.objects import Leaf, Action, Source
-from kupfer.obj.fileactions import Open
-from kupfer.obj.sources import DirectorySource
+from kupfer.objects import Leaf, Action, Source, FileLeaf
+from kupfer.obj.fileactions import Open, OpenTerminal
+from kupfer.objects import OperationError
+from kupfer import commandexec
+from kupfer import utils
 
 
-class Volume (Leaf):
+class Volume (FileLeaf):
+	"""
+	The Volume class actually represents one instance
+	of GIO's GMount (as long as it is mounted)
+	"""
+	# NOTE: marking as non-serializable
+	serializable = None
+
 	def __init__(self, volume):
 		self.volume = volume
 		fil = self.volume.get_root()
@@ -20,22 +29,19 @@ class Volume (Leaf):
 
 	def get_actions(self):
 		yield Open()
+		yield OpenTerminal()
 		if self.volume.can_eject():
 			yield Eject()
 		elif self.volume.can_unmount():
 			yield Unmount()
 
-	def has_content(self):
-		return True
-	def content_source(self, alternate=False):
-		return DirectorySource(self.object, show_hidden=alternate)
-
 	def is_valid(self):
 		vm = gio.volume_monitor_get()
 		return any(self.volume == v for v in vm.get_mounts())
 
 	def get_description(self):
-		return _("Volume mounted at %s") % self.object
+		return _("Volume mounted at %s") % \
+				utils.get_display_path_for_bytestring(self.object)
 	def get_gicon(self):
 		return self.volume.get_icon()
 	def get_icon_name(self):
@@ -45,17 +51,30 @@ class Unmount (Action):
 	def __init__(self, name=None):
 		super(Unmount, self).__init__(name or _("Unmount"))
 
-	def _callback(self, *args):
-		pass
+	def eject_callback(self, mount, async_result, token):
+		ctx = commandexec.DefaultActionExecutionContext()
+		try:
+			mount.eject_finish(async_result)
+		except gio.Error:
+			ctx.register_late_error(token)
+
+	def unmount_callback(self, mount, async_result, token):
+		ctx = commandexec.DefaultActionExecutionContext()
+		try:
+			mount.unmount_finish(async_result)
+		except gio.Error:
+			ctx.register_late_error(token)
 
 	def activate(self, leaf):
 		if not leaf.is_valid():
 			return
+		ctx = commandexec.DefaultActionExecutionContext()
+		token = ctx.get_async_token()
 		vol = leaf.volume
 		if vol.can_eject():
-			vol.eject(self._callback)
+			vol.eject(self.eject_callback, user_data=token)
 		elif vol.can_unmount():
-			vol.unmount(self._callback)
+			vol.unmount(self.unmount_callback, user_data=token)
 
 	def get_description(self):
 		return _("Unmount this volume")



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