[kupfer/maint: 335/341] kupfer_provider: Change the D-Bus signal to be more general



commit 6204c0e94f50dae581adfc6fc758e7dcd28204da
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Feb 2 15:53:37 2010 +0100

    kupfer_provider: Change the D-Bus signal to be more general
    
    Simply sending the list of all selected URIs is much more general and
    better for possible reuse of the plugin. We also send a hopefully
    unique integer window id for the selection, if the client application
    wants to track selection over multiple windows.
    
    The plugin will now send all selected files non-local, special files
    or otherwise.

 extras/kupfer_provider.py |   69 +++++++++++++--------------------------------
 1 files changed, 20 insertions(+), 49 deletions(-)
---
diff --git a/extras/kupfer_provider.py b/extras/kupfer_provider.py
index 26a23a9..e2c3f34 100644
--- a/extras/kupfer_provider.py
+++ b/extras/kupfer_provider.py
@@ -27,35 +27,29 @@ import dbus
 import dbus.glib
 from dbus.gobject_service import ExportedGObject
 import gio
-import gobject, nautilus
+import gobject
 
-service_name="se.kaizer.KupferNautilusPlugin"
-interface_name="se.kaizer.KupferNautilusPlugin"
-object_path = "/se/kaizer/kupfer/NautilusPlugin"
+import nautilus
+
+service_name="se.kaizer.FileSelection"
+interface_name="se.kaizer.FileSelection"
+object_path = "/se/kaizer/FileSelection"
 
 class Object (ExportedGObject):
-	@dbus.service.signal(interface_name, signature="aay")
-	def SelectionChanged(self, paths):
-		"""Nautilus selection changed. Passes an array of byte strings;
-		We have no idea which encoding the filesystem uses, so we
-		send filesystem bytes; the receiver should use glib to
-		decode the byte strings to strings.
-		"""
-		return paths
+	@dbus.service.signal(interface_name, signature="asi")
+	def SelectionChanged(self, uris, window_id):
+		"""Nautilus selection changed.
 
-	@dbus.service.signal(interface_name, signature="as")
-	def SelectionChangedStrings(self, paths):
-		"""Nautilus selection changed. Passes an array of strings;
-		We guess the filesystem encoding, and any files that cannot be
-		decoded are skipped
+		@uris: an array of URI strings.
+		@window_id: An ID for the window where the selection happened
 		"""
-		return paths
+		return uris
 
 class KupferSelectionProvider(nautilus.MenuProvider):
 	def __init__(self):
 		selfname = type(self).__name__
 		print "Initializing", selfname
-		self.cur_selection = []
+		self.cursel = None
 		self.max_threshold = 500
 		try:
 			session_bus = dbus.Bus()
@@ -75,38 +69,15 @@ class KupferSelectionProvider(nautilus.MenuProvider):
 
 		Ask GIO for the file path of each URI item, and pass on any that
 		have a defined path.
-		Then we try to decode the paths to strings to send if possible to
-		decode using the current encoding.
 
 		We use a threshold on the files so that we don't generate too much
 		traffic; with more than 500 files selected, we simply send nothing.
 		"""
 		if len(files) > self.max_threshold:
-			return
-		uris = (f.get_uri() for f in files)
-		paths = filter(None, (gio.File(u).get_path() for u in uris))
-		# try to decode filesystem strings
-		ustrs = []
-		encoding = locale.getpreferredencoding()
-		for p in paths:
-			try:
-				pdec = p.decode(encoding)
-			except UnicodeDecodeError:
-				continue
-			ustrs.append(pdec)
-		if paths != self.cur_selection and self.service:
-			self.service.SelectionChanged(paths)
-			self.service.SelectionChangedStrings(ustrs)
-		self.cur_selection = paths
-		return
-
-		# Put "Send to Kupfer" item here
-		"""
-		item = nautilus.MenuItem('PostrExtension::upload_files',
-								 _('Upload to Flickr...'),
-								 _('Upload the selected files into Flickr'))
-		item.connect('activate', self.upload_files, files)
-
-		return item,
-		"""
-		pass
+			return []
+		window_id = window.window.xid if window.window else 0
+		uris = [f.get_uri() for f in files]
+		if self.cursel != (uris, window_id) and self.service:
+			self.service.SelectionChanged(uris, window_id)
+		self.cursel = (uris, window_id)
+		return []



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