[kupfer] plugin.session*: Add support for XFCE environment



commit e4fdeb5309072d1af2c7d1beb059cfc8e2cceb49
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Sat Dec 5 18:40:16 2009 +0100

    plugin.session*: Add support for XFCE environment
    
    - extract base object from common.py to session_support.py
    - create session_gnome.py for manage Gnome Session
    - create session_xfce.py for XFCE environment.

 kupfer/plugin/session_gnome.py                  |   25 +++++++++
 kupfer/plugin/{common.py => session_support.py} |   64 ++++++++++-------------
 kupfer/plugin/session_xfce.py                   |   22 ++++++++
 3 files changed, 75 insertions(+), 36 deletions(-)
---
diff --git a/kupfer/plugin/session_gnome.py b/kupfer/plugin/session_gnome.py
new file mode 100644
index 0000000..35ccc6e
--- /dev/null
+++ b/kupfer/plugin/session_gnome.py
@@ -0,0 +1,25 @@
+from kupfer.plugin import session_support as support
+
+__kupfer_name__ = _("Gnome Session Manager")
+__kupfer_sources__ = ("GnomeItemsSource", )
+__description__ = _("Special items and actions for Gnome environment")
+__version__ = "2009-12-05"
+__author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
+
+
+LOGOUT_CMD = ("gnome-panel-logout", "gnome-session-save --kill")
+SHUTDOWN_CMD = ("gnome-panel-logout --shutdown", 
+		"gnome-session-save --shutdown-dialog")
+LOCKSCREEN_CMD = ("gnome-screensaver-command --lock", "xdg-screensaver lock")
+TRASH_URI = 'trash://'
+
+
+class GnomeItemsSource (support.CommonSource):
+	def get_items(self):
+		return (
+			support.Trash(TRASH_URI),
+			support.Logout(LOGOUT_CMD),
+			support.LockScreen(LOCKSCREEN_CMD),
+			support.Shutdown(SHUTDOWN_CMD),
+		)
+
diff --git a/kupfer/plugin/common.py b/kupfer/plugin/session_support.py
similarity index 80%
rename from kupfer/plugin/common.py
rename to kupfer/plugin/session_support.py
index e5cd51f..fc194b7 100644
--- a/kupfer/plugin/common.py
+++ b/kupfer/plugin/session_support.py
@@ -1,17 +1,16 @@
-import gtk
 import gio
-import gobject
 
 from kupfer.objects import Leaf, Action, Source, RunnableLeaf
 from kupfer import objects, utils, icons, pretty
-from kupfer.plugin import about_support
 
-__kupfer_name__ = _("Common")
-__kupfer_sources__ = ("CommonSource", )
-__description__ = _("Special items and actions")
-__version__ = ""
+'''
+Common objects for session_* plugins.
+'''
+
+__version__ = "2009-12-05"
 __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 
+
 def launch_commandline_with_fallbacks(commands, print_error=True):
 	"""Try the sequence of @commands with utils.launch_commandline,
 	and return with the first successful command.
@@ -25,12 +24,12 @@ def launch_commandline_with_fallbacks(commands, print_error=True):
 
 class Logout (RunnableLeaf):
 	"""Log out from desktop"""
-	def __init__(self, name=None):
+	def __init__(self, commands, name=None):
 		if not name: name = _("Log Out...")
 		super(Logout, self).__init__(name=name)
+		self._commands = commands
 	def run(self):
-		launch_commandline_with_fallbacks(("gnome-panel-logout",
-			"gnome-session-save --kill"))
+		launch_commandline_with_fallbacks(self._commands)
 	def get_description(self):
 		return _("Log out or change user")
 	def get_icon_name(self):
@@ -38,12 +37,12 @@ class Logout (RunnableLeaf):
 
 class Shutdown (RunnableLeaf):
 	"""Shutdown computer or reboot"""
-	def __init__(self, name=None):
+	def __init__(self, commands, name=None):
 		if not name: name = _("Shut Down...")
 		super(Shutdown, self).__init__(name=name)
+		self._commands = commands
 	def run(self):
-		launch_commandline_with_fallbacks(("gnome-panel-logout --shutdown",
-			"gnome-session-save --shutdown-dialog"))
+		launch_commandline_with_fallbacks(self._commands)
 
 	def get_description(self):
 		return _("Shut down, restart or suspend computer")
@@ -52,12 +51,12 @@ class Shutdown (RunnableLeaf):
 
 class LockScreen (RunnableLeaf):
 	"""Lock screen"""
-	def __init__(self, name=None):
+	def __init__(self, commands, name=None):
 		if not name: name = _("Lock Screen")
 		super(LockScreen, self).__init__(name=name)
+		self._commands = commands
 	def run(self):
-		launch_commandline_with_fallbacks(("gnome-screensaver-command --lock",
-			"xdg-screensaver lock"))
+		launch_commandline_with_fallbacks(self._commands)
 	def get_description(self):
 		return _("Enable screensaver and lock")
 	def get_icon_name(self):
@@ -87,8 +86,6 @@ class SpecialLocation (objects.Leaf):
 	def get_icon_name(self):
 		return "folder"
 
-TRASH_URI="trash://"
-
 class RestoreTrashedFile (Action):
 	def __init__(self):
 		Action.__init__(self, _("Restore"))
@@ -112,14 +109,15 @@ class RestoreTrashedFile (Action):
 
 class TrashFile (Leaf):
 	"""A file in the trash. Represented object is a file info object"""
-	def __init__(self, info):
+	def __init__(self, trash_uri, info):
 		name = info.get_display_name()
 		Leaf.__init__(self, info, name)
+		self._trash_uri = trash_uri
 	def get_actions(self):
 		if self.get_orig_path():
 			yield RestoreTrashedFile()
 	def get_gfile(self):
-		cur_gfile = gio.File(TRASH_URI).get_child(self.object.get_name())
+		cur_gfile = gio.File(self._trash_uri).get_child(self.object.get_name())
 		return cur_gfile
 	def get_orig_path(self):
 		try:
@@ -142,26 +140,30 @@ class TrashFile (Leaf):
 		return "gtk-file"
 
 class TrashContentSource (Source):
+	def __init__(self, trash_uri, name):
+		Source.__init__(self, name)
+		self._trash_uri = trash_uri
+
 	def is_dynamic(self):
 		return True
 	def get_items(self):
-		gfile = gio.File(TRASH_URI)
+		gfile = gio.File(self._trash_uri)
 		enumerator = gfile.enumerate_children("standard::*,trash::*")
 		for info in enumerator:
-			yield TrashFile(info)
+			yield TrashFile(self._trash_uri, info)
 	def should_sort_lexically(self):
 		return True
 	def get_gicon(self):
-		return icons.get_gicon_for_file(TRASH_URI)
+		return icons.get_gicon_for_file(self._trash_uri)
 
 class Trash (SpecialLocation):
-	def __init__(self, name=None):
-		SpecialLocation.__init__(self, TRASH_URI, name=name)
+	def __init__(self, trash_uri, name=None):
+		SpecialLocation.__init__(self, trash_uri, name=name)
 
 	def has_content(self):
 		return self.get_item_count()
 	def content_source(self, alternate=False):
-		return TrashContentSource(name=unicode(self))
+		return TrashContentSource(self._uri, name=unicode(self))
 
 	def get_item_count(self):
 		gfile = gio.File(self.object)
@@ -181,16 +183,6 @@ class CommonSource (Source):
 		super(CommonSource, self).__init__(name)
 	def is_dynamic(self):
 		return True
-	def get_items(self):
-		return (
-			# These seem to be included in applications now..
-			#SpecialLocation("computer://", description=_("Browse local disks and mounts")),
-			#SpecialLocation("burn://"),
-			Trash(),
-			Logout(),
-			LockScreen(),
-			Shutdown(),
-		)
 	def get_description(self):
 		return _("Items and special actions")
 	def get_icon_name(self):
diff --git a/kupfer/plugin/session_xfce.py b/kupfer/plugin/session_xfce.py
new file mode 100644
index 0000000..7addc31
--- /dev/null
+++ b/kupfer/plugin/session_xfce.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*
+
+from kupfer.plugin import session_support as support
+
+__kupfer_name__ = _("XFCE Session Manager")
+__kupfer_sources__ = ("XfceItemsSource", )
+__description__ = _("Special items and actions for XFCE environment")
+__version__ = "2009-12-05"
+__author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
+
+LOGOUT_CMD = ("xfce4-session-logout --logout", )
+SHUTDOWN_CMD = ("xfce4-session-logout --shutdown", )
+LOCKSCREEN_CMD = ("xdg-screensaver lock", )
+
+
+class XfceItemsSource (support.CommonSource):
+	def get_items(self):
+		return (
+			support.Logout(LOGOUT_CMD),
+			support.LockScreen(LOCKSCREEN_CMD),
+			support.Shutdown(SHUTDOWN_CMD),
+		)



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