Hello Mikkel, Michael and Jamie.

There were quite a few bug reports regarding the deskbar handlers in
the last days:

1] http://bugzilla.gnome.org/show_bug.cgi?id=474131
2] http://bugzilla.gnome.org/show_bug.cgi?id=474660
3] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=441889

For one I proposed a patch which was then useless as the problem was
fixed in deskbar itself. For 3 I sent Michael a patch which is not yet
committed.

Here i propose a patch fixing all the latest problems.

* The deskbar handler for deskbar <2.19 is split into 2 files which
contain only one handler each in order to get the prerequisites right
(I added it to Makefile.am too). This addresses the Debian bug and
Mikkels concerns about the warning dialog.

* The critical gnome bug (No. 1) is addressed by doing nothing as
deskbar is doing those checks for me.

* Bug no. 2 is fixed by not adding an extra 'search with t-s-t' when
only the live search is enabled.

This patch brings also compatibility and extensions for Thunderbird
and KMail (which is yet untested) MUAs. Michal Pryc helped me a great
deal smoothing out issues with the Thunderbird part.

Ah, Michael; is that Makefile.am enough and OK for you?

Cheers, Marcus
diff --git a/python/deskbar-handler/Makefile.am b/python/deskbar-handler/Makefile.am
index 7bd5de9..e7c4c89 100644
--- a/python/deskbar-handler/Makefile.am
+++ b/python/deskbar-handler/Makefile.am
@@ -1,7 +1,7 @@
 
 if USING_DESKBAR_HANDLER
 handlerdir = $(DESKBAR_HANDLER_DIR)
-handler_DATA = tracker-handler.py 
+handler_DATA = tracker-handler.py tracker-handler-static.py
 endif
 
 if USING_DESKBAR_MODULE
@@ -11,5 +11,6 @@ endif
 
 EXTRA_DIST = \
 	tracker-handler.py \
+	tracker-handler-static.py \
 	tracker-module.py \
 	README
diff --git a/python/deskbar-handler/tracker-handler-static.py b/python/deskbar-handler/tracker-handler-static.py
new file mode 100644
index 0000000..a87956c
--- /dev/null
+++ b/python/deskbar-handler/tracker-handler-static.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+#    This handler was originaly created by Mikkel Kamstrup (c) 2006 and updated by Eugenio Cutolo (eulin)
+#
+#    The static search Handler was splitted to a separate file by Marcus Fritzsch
+#
+#    This program can be distributed under the terms of the GNU GPL version 2 or later.
+#    See the file COPYING.
+#
+
+import sys
+import os.path
+import gnome
+import gobject
+
+import gettext
+gettext.install('tracker')
+
+import deskbar.Handler
+import deskbar.Match
+
+
+
+
+class TrackerSearchToolMatch (deskbar.Match.Match):
+
+	def __init__(self, backend, **args):
+		deskbar.Match.Match.__init__(self, backend, **args)
+		self._icon = deskbar.Utils.load_icon ('tracker')
+
+	def action(self, text=None):
+		gobject.spawn_async(['tracker-search-tool', self.name], flags=gobject.SPAWN_SEARCH_PATH)
+
+	def get_verb(self):
+		return _('Search for %s with Tracker Search Tool') % ('<b>%(name)s</b>')
+
+	def get_category (self):
+		return 'actions'
+
+	def get_hash (self, text=None):
+		return 'tst-more-hits-action-'+self.name
+
+
+
+
+class TrackerSearchToolHandler(deskbar.Handler.Handler):
+
+	def __init__(self):
+		deskbar.Handler.Handler.__init__(self, 'tracker')
+
+	def query(self, query):
+		return [TrackerSearchToolMatch(self, name=query)]
+
+	@staticmethod
+	def requirements ():
+		if deskbar.Utils.is_program_in_path ('tracker-search-tool'):
+			return (deskbar.Handler.HANDLER_IS_HAPPY, None, None)
+		return (deskbar.Handler.HANDLER_IS_NOT_APPLICABLE, 'tracker-search-tool seems not to be installed properly.', None)
+
+
+
+
+HANDLERS = {
+	'TrackerSearchToolHandler': {
+		'name': 'Search for files using Tracker Search Tool',
+		'description': _('Search all of your documents with Tracker Search Tool'),
+		'requirements': TrackerSearchToolHandler.requirements, # XXX makes deskbar 2.18.1 not load the handler!!
+	},
+}
diff --git a/python/deskbar-handler/tracker-handler.py b/python/deskbar-handler/tracker-handler.py
index 89f99b0..d12b200 100644
--- a/python/deskbar-handler/tracker-handler.py
+++ b/python/deskbar-handler/tracker-handler.py
@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 #    This handler was originaly created by Mikkel Kamstrup (c) 2006 and updated by Eugenio Cutolo (eulin)
 #
+#    The handler was rewritten and splitted into live and static search by Marcus Fritzsch
+#
 #    This program can be distributed under the terms of the GNU GPL version 2 or later.
 #    See the file COPYING.
 #
@@ -32,7 +34,6 @@ TYPES = {
 	'Applications': {
 		'description': (_('Launch %s (%s)') % ('<b>%(name)s</b>', '%(app_name)s')),
 		'category': 'actions',
-		#'icon': 'stock_run',
 	},
 
 	'GaimConversations': {
@@ -44,26 +45,28 @@ TYPES = {
 	'Emails': {
 		'description': (_('Email from %s') % '<i>%(publisher)s</i>' ) + '\n<b>%(title)s</b>',
 		'category': 'emails',
-		'action': 'evolution %(uri)s',
+		'action': { # more actions for different MUAs
+			'key': 'mua', # see TrackerLiveSearchMatch.action for a demo
+			'Evolution':          'evolution %(uri)s',
+			'Thunderbird/Email':  'thunderbird -viewbeagle %(uri)s',
+			'KMail':              'kmail --view %(uri)s',
+		},
 		'icon': 'stock_mail',
 	},
 
 	'Music': {
 		'description': _('Listen to music %s\nin %s')	% ('<b>%(base)s</b>', '<i>%(dir)s</i>'),
 		'category': 'music',
-		#'icon': 'audio',
 	},
 
 	'Documents': {
 		'description': _('See document %s\nin %s')	% ('<b>%(base)s</b>', '<i>%(dir)s</i>'),
 		'category': 'documents',
-		#'icon': 'file',
 	},
 
 	'Development': {
 		'description': _('Open file %s\nin %s')	% ('<b>%(base)s</b>', '<i>%(dir)s</i>'),
 		'category': 'develop',
-		#'icon': 'file',
 	},
 
 	'Images': {
@@ -81,7 +84,6 @@ TYPES = {
 	'Files': {
 		'description': _('Open file %s\nin %s')	% ('<b>%(base)s</b>', '<i>%(dir)s</i>'),
 		'category': 'files',
-		#'icon': 'file',
 	},
 
 	'Folders': {
@@ -89,53 +91,11 @@ TYPES = {
 		'category': 'places',
 		'icon': 'stock_folder',
 	},
-
-	'Extra': {
-		'description': _('Search for %s with Tracker Search Tool') % ('<b>%(name)s</b>'),
-	},
 }
 
 
 
 
-class TrackerSearchToolMatch (deskbar.Match.Match):
-
-	def __init__(self, backend, **args):
-		deskbar.Match.Match.__init__(self, backend, **args)
-		self._icon = deskbar.Utils.load_icon ('tracker')
-
-	def action(self, text=None):
-		gobject.spawn_async(['tracker-search-tool', self.name], flags=gobject.SPAWN_SEARCH_PATH)
-
-	def get_verb(self):
-		return TYPES['Extra']['description'] % { 'name': self.name }
-
-	def get_category (self):
-		return 'actions'
-
-	def get_hash (self, text=None):
-		return 'tst-more-hits-action-'+self.name
-
-
-
-
-class TrackerSearchToolHandler(deskbar.Handler.Handler):
-
-	def __init__(self):
-		deskbar.Handler.Handler.__init__(self, 'tracker')
-
-	def query(self, query):
-		return [TrackerSearchToolMatch(self, name=query)]
-
-	@staticmethod
-	def requirements ():
-		if deskbar.Utils.is_program_in_path ('tracker-search-tool'):
-			return (deskbar.Handler.HANDLER_IS_HAPPY, None, None)
-		return (deskbar.Handler.HANDLER_IS_NOT_APPLICABLE, 'tracker-search-tool not found', None)
-
-
-
-
 class TrackerLiveSearchMatch (deskbar.Match.Match):
 
 	def __init__(self, handler,result=None, **args):
@@ -169,7 +129,15 @@ class TrackerLiveSearchMatch (deskbar.Match.Match):
 
 	def action(self, text=None):
 		if TYPES[self.result['type']].has_key('action'):
-			cmd = TYPES[self.result['type']]['action']
+			if isinstance (TYPES[self.result['type']]['action'], dict):
+				try:
+					key = TYPES[self.result['type']]['action']['key']
+					cmd = TYPES[self.result['type']]['action'][self.result[key]]
+				except:
+					print >> sys.stderr, "Unknown action for URI %s (Error: %s)" % (self.result['uri'], sys.exc_info()[1])
+					return
+			else:
+				cmd = TYPES[self.result['type']]['action']
 			cmd = map(lambda arg : arg % self.result, cmd.split()) # we need this to handle spaces correctly
 
 			print 'Opening Tracker hit with command:', cmd
@@ -178,7 +146,7 @@ class TrackerLiveSearchMatch (deskbar.Match.Match):
 				deskbar.Utils.spawn_async(cmd)
 			except AttributeError:
 				# deskbar <= 2.16
-				gobject.spawn_async(args, flags=gobject.SPAWN_SEARCH_PATH)
+				gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH)
 		else:
 			if self.result.has_key ('desktop'):
 				self.result['desktop'].launch([])
@@ -223,11 +191,13 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler):
 		self.tracker = self.search_iface = self.keywords_iface = self.files_iface = None
 		self.set_delay (500)
 		self.conv_re = re.compile (r'^.*?/logs/([^/]+)/([^/]+)/([^/]+)/(.+?)\.(:?txt|html)$') # all, proto, account, to-whom, time
-		self.have_tst = deskbar.Utils.is_program_in_path ('tracker-search-tool')
 
 	def handle_email_hits (self, info, output):
 		output['title'] = cgi.escape(info[3])
 		output['publisher'] = cgi.escape(info[4])
+		output['mua'] = info[2]
+		if output['mua'] == 'Thunderbird/Email':
+			output['uri'] = info[0]
 
 	def handle_conversation_hits (self, info, output):
 		m = self.conv_re.match (output['escaped_uri'])
@@ -282,7 +252,7 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler):
 			info = [str (i) for i in info]
 
 			output['escaped_uri'] = cgi.escape (info[0])
-			output['uri'] = urllib.quote (info[0])
+			output['uri'] = urllib.quote (info[0], ';?:@&=+$,./')
 			output['name'] = os.path.basename(output['escaped_uri'])
 			output['type'] = info[1]
 
@@ -325,14 +295,11 @@ class TrackerLiveSearchHandler(deskbar.Handler.SignallingHandler):
 			except:
 				print >> sys.stderr, '*** DBus connection to tracker failed, check your settings.'
 				return
-		for service in [key for key in TYPES.iterkeys () if key != 'Extra']:
+		for service in TYPES.iterkeys ():
 			self.search_iface.TextDetailed (-1, service, qstring, 0, max, \
 					reply_handler = lambda hits: self.receive_hits (qstring, hits, max), \
 					error_handler = self.recieve_error)
 		print 'Tracker query:', qstring
-		if self.have_tst:
-			# explicitly add one hit to search with t-s-t
-			self.emit_query_ready (qstring, [TrackerSearchToolMatch (self, name=qstring)])
 
 	@staticmethod
 	def requirements ():
@@ -388,12 +355,6 @@ def time_from_purple_log (instr):
 
 
 HANDLERS = {
-	'TrackerSearchToolHandler': {
-		'name': 'Search for files using Tracker Search Tool',
-		'description': _('Search all of your documents with Tracker Search Tool'),
-		#'requirements': TrackerSearchToolHandler.requirements, # XXX makes deskbar 2.18.1 not load the handler!!
-	},
-
 	'TrackerLiveSearchHandler': {
 		'name': 'Search for files using Tracker',
 		'description': _('Search all of your documents, <b>as you type</b>'),
diff --git a/python/deskbar-handler/tracker-module.py b/python/deskbar-handler/tracker-module.py
index 90a9ccb..14dfb86 100644
--- a/python/deskbar-handler/tracker-module.py
+++ b/python/deskbar-handler/tracker-module.py
@@ -1,3 +1,5 @@
+# This deskbar module was ported from deskbar <= 2.18 handler by Marcus Fritzsch
+
 import gnome
 import gobject
 import re
@@ -103,7 +105,12 @@ TYPES = {
 	'Emails': {
 		'description': (_('Email from %s') % '<i>%(publisher)s</i>' ) + '\n<b>%(title)s</b>',
 		'category': 'emails',
-		'action' : 'evolution %(uri)s',
+		'action': { # more actions for different MUAs
+			'key': 'mua', # see TrackerLiveSearchAction.action for a demo
+			'Evolution':          'evolution %(uri)s',
+			'Thunderbird/Email':  'thunderbird -viewbeagle %(uri)s',
+			'KMail':              'kmail --view %(uri)s',
+		},
 	},
 
 	'Music': {
@@ -210,7 +217,7 @@ class TrackerLiveSearchAction (deskbar.interfaces.Action):
 		self.name = result['name']
 		self.desktop = desktop
 		self.result = result
-		self.init_names (result['unquoted_uri'])
+		self.init_names (result['uri'])
 
 	def get_name(self, text=None):
 		return self.result
@@ -229,7 +236,15 @@ class TrackerLiveSearchAction (deskbar.interfaces.Action):
 
 	def activate (self, text=None):
 		if TYPES[self.result['type']].has_key('action'):
-			cmd = TYPES[self.result['type']]['action']
+			if isinstance (TYPES[self.result['type']]['action'], dict):
+				try:
+					key = TYPES[self.result['type']]['action']['key']
+					cmd = TYPES[self.result['type']]['action'][self.result[key]]
+				except:
+					print >> sys.stderr, "Unknown action for URI %s (Error: %s)" % (self.result['uri'], sys.exc_info()[1])
+					return
+			else:
+				cmd = TYPES[self.result['type']]['action']
 			cmd = map(lambda arg : arg % self.result, cmd.split()) # we need this to handle spaces correctly
 
 			print 'Opening Tracker hit with command:', cmd
@@ -238,8 +253,8 @@ class TrackerLiveSearchAction (deskbar.interfaces.Action):
 			if self.desktop:
 				self.desktop.launch ([])
 			else:
-				deskbar.core.Utils.url_show ('file://'+urllib.quote (self.result['uri']))
-			print 'Opening Tracker hit:', urllib.quote (self.result['uri'])
+				deskbar.core.Utils.url_show ('file://'+urllib.quote (self.result['uri'], ';?:@&=+$,./'))
+			print 'Opening Tracker hit:', urllib.quote (self.result['uri'], ';?:@&=+$,./')
 
 	def init_names (self, fullpath):
 		dirname, filename = os.path.split(fullpath)
@@ -309,11 +324,11 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module):
 		# initing on search request, see self.query
 		self.tracker = self.search_iface = self.keywords_iface = self.files_iface = None
 		self.conv_re = re.compile (r'^.*?/logs/([^/]+)/([^/]+)/([^/]+)/(.+?)\.(:?txt|html)$') # all, proto, account, to-whom, time
-		self.have_tst = is_program_in_path ('tracker-search-tool')
 
 	def handle_email_hits (self, info, output):
 		output['title'] = info[3]
 		output['publisher'] = info[4]
+		output['mua'] = info[2]
 
 	def handle_conversation_hits (self, info, output):
 		output ['uri'] = info [0]
@@ -365,8 +380,8 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module):
 
 			info = [str (i) for i in info]
 
-			output['unquoted_uri'] = output['uri'] = info[0]
-			output['name'] = os.path.basename(output['unquoted_uri'])
+			output['uri'] = info[0]
+			output['name'] = os.path.basename(output['uri'])
 			output['type'] = info[1]
 
 			if not TYPES.has_key(output['type']):
@@ -417,8 +432,6 @@ class TrackerLiveSearchHandler(deskbar.interfaces.Module):
 					reply_handler = lambda hits: self.recieve_hits(qstring, hits, max),
 					error_handler = self.recieve_error)
 		print 'Tracker query:', qstring
-		if self.have_tst:
-			self._emit_query_ready (qstring, [TrackerSearchToolMatch (name=qstring, priority=self.get_priority ())])
 
 
 
_______________________________________________
tracker-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tracker-list

Reply via email to