A shiny new volume handler for you testing desires. It doesn't depend on any new fancy stuff (read async). Just stick it in handlers/ and knock yourselves out! Cheers Mikkel PS: I'm really sorry Raphael. This handler makes you network places handler obsolete PPS: The priorities of the handler needs to be fixed, but hey. Release early release often!
Attachment:
volume_icons.tar.bz2
Description: application/bzip-compressed-tar
import os, sys
import ConfigParser
import gnomevfs
import deskbar
from deskbar.handler import Handler
from deskbar.handler import Match
from gettext import gettext as _
import cgi
import gtk
from os.path import join
NAME = "Search for Volumes"
EXPORTED_CLASS = "VolumeHandler"
PRIORITY = 1000
NETWORK_URIS = ["http", "ftp", "smb", "sftp"]
AUDIO_URIS = ["cdda"]
class VolumeMatch (Match):
def __init__(self, backend, drive, icon=None):
deskbar.handler.Match.__init__(self,
backend,
drive.get_display_name(), icon)
self.__drive = drive
def action(self, text=None):
os.spawnlp(os.P_NOWAIT, "gnome-open", "gnome-open", self.__drive.get_activation_uri())
def get_verb(self):
return _("Open " +self.get_uri_desc()+ " <b>%(name)s</b>")
def get_uri_desc (self):
uri_scheme = gnomevfs.get_uri_scheme( self.__drive.get_activation_uri() )
if uri_scheme in NETWORK_URIS:
return _("network place")
elif uri_scheme in AUDIO_URIS:
return _("audio disk")
else:
return _("location")
class VolumeHandler (Handler):
def __init__(self):
deskbar.handler.Handler.__init__(self, "gnome-dev-harddisk.png")
self.__locations = []
def initialize(self):
for drive in gnomevfs.VolumeMonitor().get_mounted_volumes():
if drive.is_user_visible():
print drive.get_display_name()
print " -- ",drive.get_icon()
def get_priority(self):
return PRIORITY
def query(self, query, max=5):
result = []
query = query.lower()
for drive in gnomevfs.VolumeMonitor().get_mounted_volumes() + gnomevfs.VolumeMonitor().get_connected_drives():
if not drive.is_user_visible() : continue
if not drive.is_mounted () : continue
if not drive.get_display_name().lower().startswith(query): continue
iconfile = join(deskbar.ART_DATA_DIR, drive.get_icon()) + ".png"
try:
icon = gtk.gdk.pixbuf_new_from_file_at_size(iconfile, deskbar.ICON_SIZE, deskbar.ICON_SIZE)
except Exception, e:
print >> sys.stderr, "Error: when loading icon", iconfile
print >> sys.stderr, e.value
result.append (VolumeMatch (self, drive, icon))
return result[:max]