diff --git a/python/deskbar-handler/tracker-handler.py b/python/deskbar-handler/tracker-handler.py index 72fb72f..7990aca 100644 --- a/python/deskbar-handler/tracker-handler.py +++ b/python/deskbar-handler/tracker-handler.py @@ -64,14 +64,25 @@ HANDLERS = { "videos" : { "name": _("Videos"), }, + "conversations" : { + "name": _("Conversations"), + }, + "applications" : { + "name": _("Applications"), + }, }, }, } #For now description param it's not used TYPES = { - "Conversations" : { - "description": (_("See conversations %s") % "%(publisher)s" ) + "\n%(base)s", + "Applications" : { + "description": (_("Run application %s") % "%(name)s" ), + "category": "applications", + "action": "xdg-open %(uri)s", + }, + "GaimConversations" : { + "description": (_("See %s conversation\n%s %s\nfrom %s") % ("%(proto)s", "%(channel)s", "%(conv_to)s", "%(time)s")), "category": "conversations", }, "Email" : { @@ -232,6 +243,7 @@ class TrackerLiveFileMatch (Match): class TrackerLiveSearchHandler(SignallingHandler): def __init__(self): + import re SignallingHandler.__init__(self, "tracker") bus = dbus.SessionBus() self.tracker = bus.get_object('org.freedesktop.Tracker','/org/freedesktop/tracker') @@ -239,7 +251,8 @@ class TrackerLiveSearchHandler(SignallingHandler): self.keywords_iface = dbus.Interface(self.tracker, 'org.freedesktop.Tracker.Keywords') self.files_iface = dbus.Interface(self.tracker, 'org.freedesktop.Tracker.Files') self.set_delay (500) - + self.conv_re = re.compile (r'^.*?/logs/([^/]+)/([^/]+)/([^/]+)/(.+?)\.(:?txt|html)$') # all, proto, account, to-whom, time + def recieve_hits (self, qstring, hits, max): matches = [] self.results = {} @@ -259,7 +272,29 @@ class TrackerLiveSearchHandler(SignallingHandler): if output["type"] == "Email": output["title"] = cgi.escape(info[3]) output["publisher"] = cgi.escape(info[4]) - + + elif output['type'] == "GaimConversations": + uri = output['uri'] + m = self.conv_re.match (uri) + output['channel']=_("with") + output['proto']=output['conv_from']=output['conv_to']=output['time']="" # XXX, never happened during tests + if m: + output['proto'] = m.group (1) + output['conv_from'] = m.group (2) + output['conv_to'] = m.group (3) + output['time'] = m.group (4) + if output['conv_to'].endswith ('.chat'): + output['channel'] = _("in channel") + output['conv_to'] = output['conv_to'].replace (".chat","") + if output['proto'] == 'irc': + nick_server = output['conv_from'].split ('@') + if len (nick_server) > 1: + output['conv_to'] = "%s on %s" % (output['conv_to'], nick_server[1]) + output['uri'] = output['uri'].replace ("%", "%25") # escape the escapes + + elif output['type'] == 'Applications': + output['uri'] = output['uri'].replace ("%U", "").replace ("%u", "") + for key in self.results.keys(): for res in self.results[key][0:MAX_RESULTS]: matches.append(TrackerLiveFileMatch(self,res)) @@ -273,8 +308,8 @@ class TrackerLiveSearchHandler(SignallingHandler): def query (self, qstring, max): if qstring.count("tag:") == 0: - self.search_iface.TextDetailed (-1, "Files", qstring, 0,10, reply_handler=lambda hits : self.recieve_hits(qstring, hits, max), error_handler=self.recieve_error) - self.search_iface.TextDetailed (-1, "Emails", qstring, 0,10, reply_handler=lambda hits : self.recieve_hits(qstring, hits, max), error_handler=self.recieve_error) + for service in ("Files", "Emails", "Conversations", "Applications"): + self.search_iface.TextDetailed (-1, service, qstring, 0,10, reply_handler=lambda hits : self.recieve_hits(qstring, hits, max), error_handler=self.recieve_error) print "Tracker query:", qstring else: if self.tracker.GetVersion() == 502: