Empty trash action



I've added an 'Empty' action to the Trash plugin.  Patch attached.
diff --git a/kupfer/plugin/trash.py b/kupfer/plugin/trash.py
index 7897bf1..ea7aa29 100644
--- a/kupfer/plugin/trash.py
+++ b/kupfer/plugin/trash.py
@@ -1,5 +1,5 @@
 __kupfer_name__ = _("Trash")
-__kupfer_actions__ = ("MoveToTrash", )
+__kupfer_actions__ = ("MoveToTrash", "EmptyTrash")
 __kupfer_sources__ = ("TrashSource", )
 __description__ = _("Access trash contents")
 __version__ = "2009-12-06"
@@ -68,6 +68,19 @@ class RestoreTrashedFile (Action):
 	def get_icon_name(self):
 		return "edit-undo"
 
+class EmptyTrash (Action):
+	def __init__(self, trash_uri = None):
+		Action.__init__(self, _("Empty"))
+		self._trash_uri = trash_uri
+	def activate(self, trash):
+		gfile = gio.File(self._trash_uri)
+		for info in gfile.enumerate_children("standard::*,trash::*"):
+			gfile.get_child(info.get_name()).delete()
+	def get_description(self):
+		return _("Empty the trash")
+	def get_icon_name(self):
+		return "emptytrash"
+
 class TrashFile (Leaf):
 	"""A file in the trash. Represented object is a file info object"""
 	def __init__(self, trash_uri, info):
@@ -150,6 +163,15 @@ class Trash (SpecialLocation):
 	def content_source(self, alternate=False):
 		return TrashContentSource(self.object, name=unicode(self))
 
+	def get_actions(self):
+		for action in SpecialLocation.get_actions(self):
+			try:
+				yield action
+			except StopIteration:
+				pass
+		if self.get_item_count():
+			yield EmptyTrash(self.object)
+
 	def get_item_count(self):
 		gfile = gio.File(self.object)
 		info = gfile.query_info(gio.FILE_ATTRIBUTE_TRASH_ITEM_COUNT)


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