[Deskbar] Tracker handler updated
- From: "Mikkel Kamstrup Erlandsen" <mikkel kamstrup gmail com>
- To: "Tracker List" <tracker-list gnome org>, deskbar-applet-list gnome org
- Cc:
- Subject: [Deskbar] Tracker handler updated
- Date: Mon, 8 May 2006 12:40:05 +0200
I updated the deskbar tracker handler to the "new" tracker api. This should be compatible with both the current tracker version (0.0.3) and the very soon to come 0.0.4.
Cheers,
Mikkel
import deskbar
from deskbar.Handler import SignallingHandler
from deskbar.Match import Match
import gobject
from gettext import gettext as _
def _check_requirements ():
try:
import dbus
try :
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
except:
return (deskbar.Handler.HANDLER_IS_NOT_APPLICABLE, "Python dbus.glib bindings not found.", None)
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 Tracker), 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.Tracker', '/org/freedesktop/tracker')
self.tracker_iface = dbus.Interface(self.proxy_obj, 'org.freedesktop.Tracker')
self.set_delay (500)
def query (self, qstring, max):
self.tracker_iface.SearchMetadataText ("Files", qstring, 100, False, 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 for %s, - %s hits returned, %s shown" % (qstring, len(hits), len(matches))
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]