? ZombiePatch.diff
Index: deskbar/handlers/beagle.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/beagle.py,v
retrieving revision 1.5
diff -u -r1.5 beagle.py
--- deskbar/handlers/beagle.py	20 Oct 2005 21:39:07 -0000	1.5
+++ deskbar/handlers/beagle.py	30 Oct 2005 01:03:32 -0000
@@ -1,33 +1,112 @@
+from deskbar.handler import AsyncHandler, Match
+from deskbar import MODULES_DIRS
+
+import gobject
+
 import os
-from os.path import exists
+from os.path import expanduser, exists, join
 from gettext import gettext as _
 
-import deskbar.handler, deskbar.handler_utils
+try:
+	from SOAPpy import WSDL
+except:
+	pass
+	
+import gtk
 
-#FIXME: better way to detect beagle ?
+GOOGLE_WSDL = expanduser('~/.gnome2/deskbar-applet/GoogleSearch.wsdl')
+GOOGLE_API_KEY = expanduser('~/.gnome2/deskbar-applet/Google.key')
+HELP_FILE = 'GoogleLiveHelp.txt'
+GOOGLE_HELP = exists(join(MODULES_DIRS[0], HELP_FILE)) and join(MODULES_DIRS[0], HELP_FILE) or join(MODULES_DIRS[1], HELP_FILE)
+MAX_QUERIES = 10
+QUERY_DELAY = 1
+
+def _print_help():
+	if exists (GOOGLE_HELP): print "GoogleLive: Read the file %s for further instructions." % GOOGLE_HELP
+	else: print "GoogleLive: You need a Google API key and WSDL file. You can obtain these on api.google.com."
+		
+
+def _check_requirements():
+	try:
+		from SOAPpy import WSDL
+	except:
+		_print_help()
+		return (False, "You need SOAPpy python module for google-live to work properly.")
+	if not exists (GOOGLE_WSDL):
+		_print_help()
+		return (False, "WSDL file %s not found. Aborting." % GOOGLE_WSDL)
+	if not exists (GOOGLE_API_KEY):
+		_print_help()
+		return (False, "Google API key file %s not found. Aborting." % GOOGLE_API_KEY)
+	else:
+		return (True, None)
+		
 HANDLERS = {
-	"BeagleHandler" : {
-		"name": _("Beagle"),
-		"description": _("Use Beagle to search for documents"),
-		# Better Way to detect ?
-		"requirements": lambda: (exists("/usr/share/applications/best.desktop"), "Beagle was not detected on your system"),
+	"GoogleLiveHandler" : {
+		"name": _("Live Google search"),
+		"description": _("Search the words you type with Google and display the results in the list."),
+		"requirements" : _check_requirements
 	}
 }
 
-class BeagleMatch(deskbar.handler.Match):
-	def __init__(self, backend, name):
-		deskbar.handler.Match.__init__(self, backend, name)
+
+class GoogleMatch (Match):
+	def __init__(self, handler, name, url, icon=None):
+		Match.__init__ (self, handler, "Google: "+name, icon)
+		self.__url = url
+	
+	def get_verb(self):
+		return "%(name)s"
 		
 	def action(self, text=None):
-		os.spawnvp(os.P_NOWAIT, "best", ['best', '--no-tray', '--show-window', self._name])
+		gobject.spawn_async(["gnome-open", self.__url], flags=gobject.SPAWN_SEARCH_PATH)
+
+class GoogleLiveHandler (AsyncHandler):
+	"""
+	This handler requires the user to have a valid Google account, a Google
+	API key and a GoogleSearch.wsdl file. The file locations are specified
+	above.
 	
-	def get_verb(self):
-		return _("Search <b>%(name)s</b> with Beagle")
+	It uses SOAPpy to interact with Googles SOAP inteface.
+	"""
+	def __init__ (self):
+		AsyncHandler.__init__ (self, "google.png")
+		self.server = None
+		self.api_key = None
+		
+	def initialize (self):
+		self.server = WSDL.Proxy (GOOGLE_WSDL)
+		api_key_file = file (GOOGLE_API_KEY)
+		self.api_key = api_key_file.readline()
+		api_key_file.close ()
+		
+	
+	def query (self, qstring, qmax=5):
+		"""Behold the true power of the AsyncHandler!"""
+		
+		# Just to ensure we don't bork anything
+		qmax = min (qmax, 10)
+		
+		# Delay before we query so we *don't* make four queries
+		# "s", "sp", "spa", "spam".
+		self.check_query_changed (timeout=QUERY_DELAY)
 		
-				
-class BeagleHandler(deskbar.handler.Handler):
-	def __init__(self):
-		deskbar.handler.Handler.__init__(self, "best")
-				
-	def query(self, query, max=5):
-		return [BeagleMatch(self, query)]
+		print "GoogleLive: Querying Google for", qstring
+		results = self.server.doGoogleSearch (self.api_key, # personal google api key
+						qstring, 	# query
+						0, qmax, 	# start/end of result list
+						True, 		# filter duplicates?
+						"", 		# get results from specific country
+						False, 		# safe search (filter adult material)
+						"", 		# get results in specific language
+						"utf-8", "utf-8") # input/output encodings
+					
+		# The google search might have taken a long time
+		# better check if we're still valid	
+		self.check_query_changed ()
+		return [
+			GoogleMatch (self, r.title.encode("utf-8"), 
+					#r.snippet.encode("utf-8"),  # We don't use the description
+					r.URL.encode ("utf-8"))
+			for r in results.resultElements[:qmax-1]
+		]
Index: deskbar/handlers/directories.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/directories.py,v
retrieving revision 1.5
diff -u -r1.5 directories.py
--- deskbar/handlers/directories.py	20 Oct 2005 21:39:07 -0000	1.5
+++ deskbar/handlers/directories.py	30 Oct 2005 01:03:32 -0000
@@ -4,6 +4,7 @@
 
 from gettext import gettext as _
 
+import gobject
 import gtk, gnome.ui
 import deskbar, deskbar.indexer
 import deskbar.handler
@@ -24,7 +25,7 @@
 		self._filename = absname
 		
 	def action(self, text=None):
-		os.spawnlp(os.P_NOWAIT, "nautilus", "nautilus", self._filename)
+		gobject.spawn_async(["nautilus", self._filename], flags=gobject.SPAWN_SEARCH_PATH)
 	
 	def get_verb(self):
 		return _("Open folder <b>%(name)s</b>")
Index: deskbar/handlers/files.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/files.py,v
retrieving revision 1.6
diff -u -r1.6 files.py
--- deskbar/handlers/files.py	20 Oct 2005 21:39:07 -0000	1.6
+++ deskbar/handlers/files.py	30 Oct 2005 01:03:32 -0000
@@ -4,6 +4,7 @@
 
 from gettext import gettext as _
 
+import gobject
 import gtk, gnome.ui
 import deskbar, deskbar.indexer
 import deskbar.handler
@@ -26,7 +27,7 @@
 		self._filename = absname
 				
 	def action(self, text=None):
-		os.spawnlp(os.P_NOWAIT, "gnome-open", "gnome-open", self._filename)
+		gobject.spawn_async(["gnome-open", self._filename], flags=gobject.SPAWN_SEARCH_PATH)
 		
 	def get_verb(self):
 		return _("Open <b>%(name)s</b>")
Index: deskbar/handlers/gtkbookmarks.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/gtkbookmarks.py,v
retrieving revision 1.10
diff -u -r1.10 gtkbookmarks.py
--- deskbar/handlers/gtkbookmarks.py	22 Oct 2005 16:05:20 -0000	1.10
+++ deskbar/handlers/gtkbookmarks.py	30 Oct 2005 01:03:32 -0000
@@ -2,6 +2,7 @@
 from os.path import expanduser, split, exists
 from gettext import gettext as _
 
+import gobject
 import gnomevfs
 import deskbar.handler
 from deskbar.filewatcher import FileWatcher
@@ -22,7 +23,7 @@
 		
 	def action(self, text=None):
 		self._priority = self._priority+1
-		os.spawnlp(os.P_NOWAIT, "nautilus", "nautilus", self._path)
+		 gobject.spawn_async(["nautilus", self._path], flags=gobject.SPAWN_SEARCH_PATH)
 	
 	def get_verb(self):
 		return _("Open location <b>%(name)s</b>")
Index: deskbar/handlers/pathprograms.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/pathprograms.py,v
retrieving revision 1.7
diff -u -r1.7 pathprograms.py
--- deskbar/handlers/pathprograms.py	20 Oct 2005 23:25:48 -0000	1.7
+++ deskbar/handlers/pathprograms.py	30 Oct 2005 01:03:32 -0000
@@ -3,6 +3,7 @@
 from os.path import join, isfile, abspath, splitext, expanduser, exists, isdir
 from gettext import gettext as _
 
+import gobject
 import gtk
 import deskbar, deskbar.indexer
 import deskbar.handler
@@ -25,11 +26,11 @@
 	def action(self, text=None):
 		self._priority = self._priority+1
 		if text == None:
-			os.spawnlp(os.P_NOWAIT, self._name, self._name)
+			gobject.spawn_async([self._name], flags=gobject.SPAWN_SEARCH_PATH)
 		else:
 			args = text.split(" ")[1:]
 			args.insert(0, self._name)
-			os.spawnvp(os.P_NOWAIT, self._name, args)
+			gobject.spawn_async(args, flags=gobject.SPAWN_SEARCH_PATH)
 	
 	def get_verb(self):
 		return _("Execute <b>%(text)s</b>")
Index: deskbar/handlers/programs.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/programs.py,v
retrieving revision 1.22
diff -u -r1.22 programs.py
--- deskbar/handlers/programs.py	24 Oct 2005 21:40:15 -0000	1.22
+++ deskbar/handlers/programs.py	30 Oct 2005 01:03:33 -0000
@@ -3,6 +3,7 @@
 from os.path import join, isfile, abspath, splitext, expanduser
 from gettext import gettext as _
 
+import gobject
 import gtk
 import deskbar, deskbar.indexer, deskbar.locale_utils, deskbar.handler_utils
 import deskbar.handler
@@ -43,7 +44,7 @@
 			args.append(text)
 			
 		print 'Running "%s" "%r"' % (prog, args)
-		os.spawnvp(os.P_NOWAIT, prog, args)
+		gobject.spawn_async(args, flags=gobject.SPAWN_SEARCH_PATH)
 	
 	def get_verb(self):
 		return _("Launch <b>%(name)s</b> (%(prog)s)")
Index: deskbar/handlers/volumes.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/volumes.py,v
retrieving revision 1.7
diff -u -r1.7 volumes.py
--- deskbar/handlers/volumes.py	20 Oct 2005 21:39:07 -0000	1.7
+++ deskbar/handlers/volumes.py	30 Oct 2005 01:03:33 -0000
@@ -3,6 +3,8 @@
 from os.path import join
 from gettext import gettext as _
 
+import gobject
+
 import deskbar
 from deskbar.handler import Handler
 from deskbar.handler import Match
@@ -26,7 +28,7 @@
 	
 	def action(self, text=None):
 		self._priority = self._priority+1
-		os.spawnlp(os.P_NOWAIT, "nautilus", "nautilus", self.__drive.get_activation_uri())
+		gobject.spawn_async(["nautilus", self.__drive.get_activation_uri()], flags=gobject.SPAWN_SEARCH_PATH)
 	 
 	def get_verb(self):
 		uri_scheme = gnomevfs.get_uri_scheme(self.__drive.get_activation_uri()) 
Index: deskbar/handlers/web_address.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/handlers/web_address.py,v
retrieving revision 1.10
diff -u -r1.10 web_address.py
--- deskbar/handlers/web_address.py	23 Oct 2005 14:18:08 -0000	1.10
+++ deskbar/handlers/web_address.py	30 Oct 2005 01:03:33 -0000
@@ -1,5 +1,6 @@
 from gettext import gettext as _
 import re, os
+import gobject
 import gnomevfs
 import deskbar.handler
 
@@ -27,7 +28,7 @@
 		if self._url.startswith("http"):
 			gnomevfs.url_show(self._url)
 		else:
-			os.spawnlp(os.P_NOWAIT, "nautilus", "nautilus", self._url)
+			gobject.spawn_async(["nautilus", self._url], flags=gobject.SPAWN_SEARCH_PATH)
 	
 	def get_verb(self):
 		if not self._has_method:
