[Deskbar] Tracker handler



I've hacked together a handler for Tracker. At the moment it doesn't
utilize the entire feature set of tracker at all, but hey - it works!

What it does; search thorugh your files via trackerd, communicating via
dbus. 

If you don't know what tracker is, read Jamie McCrackens blog:
http://www.advogato.org/person/jamiemcc/

If you try and compile tracker yourself (it is not packaged anywhere I
think) read on...

1) Be sure to use mysqlclient based on mysql 4.1.*. The default in
Dapper repos is 5.0 based!

2) libextractor might not build (gives you wierd errors), you can
install a version from the Dapper repos if you use Ubuntu. Then just
"make install" anyways. trackerd will be installed and working...

3) Be aware that Jamie might commit some changes to tracker soon that
will obsolete the mysql 4.1.* requirement and only use 5.0...

Cheers
Mikkel

PS: the tracker handler requires the latest deskbar cvs to work
properly.
import deskbar
from deskbar.Handler import SignallingHandler
from deskbar.Match import Match
import gobject

_check_requirements ():
	try:
		import dbus
		return (deskbar.Handler.HANDLER_IS_HAPPY, None, None)
	except:
		return (deskbar.Handler.HANDLER_IS_NOT_APPLICABLE, "Python dbus bindings not found.", None)
	
HANDLERS = {
	"TrackerFileSearchHandler" : {
		"name": "Search for files using Tracker",
		"description": _("Search all of your documents (using Beagle), as you type"),
		"requirements" : _check_requirements,
	}
}

class TrackerFileMatch (Match):
	def __init__(self, handler, **args):
		Match.__init__ (self, handler, **args)
		
		try:
			self._icon = deskbar.Utils.load_icon_for_file(self.name)
		except Exception:
			pass
				
	def get_verb(self):
		return "%(name)s"
		
	def action(self, text=None):
		print "Opening Tracker hit:", self.name
		args = ["gnome-open", str(self.name)] # FIXME for some odd reason we need the str() cast
		gobject.spawn_async(args, flags=gobject.SPAWN_SEARCH_PATH)
		
	def get_category (self):
		return "files"


class TrackerFileSearchHandler(SignallingHandler):
	def __init__(self):
		SignallingHandler.__init__(self, "stock_file")
		
		import dbus
		# We have to do this or it won't work
		if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
			import dbus.glib

		# Set up dbus conenction to trackerd
		self.bus = dbus.SessionBus()
		self.proxy_obj = self.bus.get_object('org.freedesktop.file.metadata', '/org/freedesktop/file/metadata')
		self.tracker_iface = dbus.Interface(self.proxy_obj, 'org.freedesktop.file.metadata')
		
		self.set_delay (500)
		
	def query (self, qstring, max):
		
		self.tracker_iface.SearchMetadataByText (qstring, reply_handler=lambda hits : self.__recieve_hits(qstring, hits, max), error_handler=self.__recieve_error)
		print "Tracker query:", qstring

	def __recieve_hits (self, qstring, hits, max):
		matches = []
		for filename in hits:
			matches.append( TrackerFileMatch(self, name=filename) )
			if len (matches) > max:
				break
		self.emit_query_ready(qstring, matches)
		print "Tracker response:", qstring
		
	def __recieve_error (self, error):
		print "*** Tracker dbus error:", error
		
	def stop_query(self):
		pass


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