[kupfer] plugin.applications: Set Default Application action



commit be556f3c887fbdffa6a2f4c262486552cdc90c3d
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Aug 22 03:32:55 2009 +0200

    plugin.applications: Set Default Application action
    
    Permit setting default opener for a file

 kupfer/plugin/applications.py |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/plugin/applications.py b/kupfer/plugin/applications.py
index c559cd9..686b8d3 100644
--- a/kupfer/plugin/applications.py
+++ b/kupfer/plugin/applications.py
@@ -1,9 +1,16 @@
+import gio
+from gio import app_info_get_all
+from gio.unix import desktop_app_info_set_desktop_env
+
 from kupfer.objects import Source, AppLeaf, Action, FileLeaf
 from kupfer import utils
 
 __kupfer_name__ = _("Applications")
 __kupfer_sources__ = ("AppSource", )
-__kupfer_actions__ = ("OpenWith", )
+__kupfer_actions__ = (
+		"OpenWith",
+		"SetDefaultApplication",
+	)
 __description__ = _("All applications and preferences")
 __version__ = ""
 __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
@@ -19,8 +26,6 @@ class AppSource (Source):
 		super(AppSource, self).__init__(_("Applications"))
 	
 	def get_items(self):
-		from gio import app_info_get_all
-		from gio.unix import desktop_app_info_set_desktop_env
 		# If we set proper desktop environment
 		# We get exactly the apps shown in the menu,
 		# as well as the preference panes
@@ -55,3 +60,22 @@ class OpenWith (Action):
 		yield AppLeaf
 	def get_description(self):
 		return _("Open with any application")
+
+class SetDefaultApplication (Action):
+	def __init__(self):
+		Action.__init__(self, _("Set Default Application..."))
+	def activate(self, leaf, obj):
+		gfile = gio.File(leaf.object)
+		info = gfile.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)
+		content_type = info.get_attribute_string(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)
+		print content_type, gfile
+		desktop_item = obj.object
+		desktop_item.set_as_default_for_type(content_type)
+	def item_types(self):
+		yield FileLeaf
+	def requires_object(self):
+		return True
+	def object_types(self):
+		yield AppLeaf
+	def get_description(self):
+		return _("Set default application to open this file type")



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