[Deskbar] Tracker handler (*small*) update
- From: "Mikkel Kamstrup Erlandsen" <mikkel kamstrup gmail com>
- To: deskbar-applet-list gnome org, "Tracker List" <tracker-list gnome org>
- Subject: [Deskbar] Tracker handler (*small*) update
- Date: Sat, 1 Jul 2006 23:06:12 +0200
There was an empty method stop_query() in the Tracker handler that made the handler not stop correctly when interupted. I removed it and the handler should now be stopable as other async handlers.
Cheers,
Mikkel
import gnome
import deskbar
from deskbar.Handler import SignallingHandler
from deskbar.Match import Match
import gobject
from gettext import gettext as _
from os.path import expanduser
HOME = expanduser ("~/")
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
self.tracker_id = self.name
self.name = self.calc_display_string ()
def get_verb(self):
return "%(name)s"
def action(self, text=None):
print "Opening Tracker hit:", self.name
gnome.url_show ("file://" + self.tracker_id)
#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"
def calc_display_string (self):
dirname = self.name
filename = ""
# Don't include the /home/myuser part of the path
if dirname.startswith (HOME):
dirname = dirname [len(HOME):]
filename = dirname
last_dir_idx = filename.rfind("/")
if last_dir_idx == -1:
# There are no "/"s left in the path string,
# this must be a file directly in the home folder
return "<b>" + filename +"</b>\nin home folder"
filename = filename[last_dir_idx+1:]
dirname = dirname[:last_dir_idx]
return "<b>%s</b>\nin folder <i>%s</i>" % (filename,dirname)
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
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]