diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2008-11-29 17:59:24 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2008-11-29 17:59:24 (GMT) |
commit | 83d05f18f3255643cbaf887e8653ad36decc95e8 (patch) | |
tree | 3b5cdfd47d1aa1aa047b25b72766b7b3a31f7a0e /src/jarabe/journal/volumestoolbar.py | |
parent | e4a9e038748684ba8149aebb03091fac02a34e4a (diff) |
Remove jarabe/model/volume.py and use gio instead
Diffstat (limited to 'src/jarabe/journal/volumestoolbar.py')
-rw-r--r-- | src/jarabe/journal/volumestoolbar.py | 113 |
1 files changed, 62 insertions, 51 deletions
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py index 50b9aa7..7542fca 100644 --- a/src/jarabe/journal/volumestoolbar.py +++ b/src/jarabe/journal/volumestoolbar.py @@ -18,12 +18,14 @@ import logging from gettext import gettext as _ import gobject +import gio import gtk +import gconf from sugar.graphics.radiotoolbutton import RadioToolButton from sugar.graphics.palette import Palette +from sugar.graphics.xocolor import XoColor -from jarabe.model import volume from jarabe.journal import model class VolumesToolbar(gtk.Toolbar): @@ -38,48 +40,47 @@ class VolumesToolbar(gtk.Toolbar): def __init__(self): gtk.Toolbar.__init__(self) self._volume_buttons = [] - self._volume_added_hid = None - self._volume_removed_hid = None + self._mount_added_hid = None + self._mount_removed_hid = None self.connect('destroy', self.__destroy_cb) gobject.idle_add(self._set_up_volumes) def __destroy_cb(self, widget): - volumes_manager = volume.get_volumes_manager() - volumes_manager.disconnect(self._volume_added_hid) - volumes_manager.disconnect(self._volume_removed_hid) + volume_monitor = gio.volume_monitor_get() + volume_monitor.disconnect(self._mount_added_hid) + volume_monitor.disconnect(self._mount_removed_hid) def _set_up_volumes(self): - volumes_manager = volume.get_volumes_manager() + volume_monitor = gio.volume_monitor_get() self._volume_added_hid = \ - volumes_manager.connect('volume-added', self._volume_added_cb) + volume_monitor.connect('mount-added', self.__mount_added_cb) self._volume_removed_hid = \ - volumes_manager.connect('volume-removed', - self._volume_removed_cb) + volume_monitor.connect('mount-removed', self.__mount_removed_cb) - for vol in volumes_manager.get_volumes(): - self._add_button(vol) + for mount in volume_monitor.get_mounts(): + self._add_button(mount) - def _volume_added_cb(self, volumes_manager, vol): - self._add_button(vol) + def __mount_added_cb(self, volume_monitor, mount): + self._add_button(mount) - def _volume_removed_cb(self, volumes_manager, vol): - self._remove_button(vol) + def __mount_removed_cb(self, volume_monitor, mount): + self._remove_button(mount) - def _add_button(self, vol): - logging.debug('VolumeToolbar._add_button: %r' % vol.name) + def _add_button(self, mount): + logging.debug('VolumeToolbar._add_button: %r' % mount.get_name()) if self._volume_buttons: group = self._volume_buttons[0] else: group = None - palette = Palette(vol.name) + palette = Palette(mount.get_name()) - button = VolumeButton(vol, group) + button = VolumeButton(mount, group) button.set_palette(palette) - button.connect('toggled', self._button_toggled_cb, vol) + button.connect('toggled', self._button_toggled_cb, mount) if self._volume_buttons: position = self.get_item_index(self._volume_buttons[-1]) + 1 else: @@ -89,51 +90,61 @@ class VolumesToolbar(gtk.Toolbar): self._volume_buttons.append(button) - if vol.can_eject: + if mount.can_unmount(): menu_item = gtk.MenuItem(_('Unmount')) - menu_item.connect('activate', self._unmount_activated_cb, vol) + menu_item.connect('activate', self._unmount_activated_cb, mount) palette.menu.append(menu_item) menu_item.show() if len(self.get_children()) > 1: self.show() - def _button_toggled_cb(self, button, vol): + def _button_toggled_cb(self, button, mount): if button.props.active: - self.emit('volume-changed', vol) + self.emit('volume-changed', mount) - def _unmount_activated_cb(self, menu_item, vol): - logging.debug('VolumesToolbar._unmount_activated_cb: %r', vol.udi) - vol.unmount() + def _unmount_activated_cb(self, menu_item, mount): + logging.debug('VolumesToolbar._unmount_activated_cb: %r', mount) + mount.unmount(self.__unmount_cb) - def _remove_button(self, vol): - for button in self.get_children(): - if button.volume.udi == vol.udi: - self._volume_buttons.remove(button) - self.remove(button) - self.get_children()[0].props.active = True - - if len(self.get_children()) < 2: - self.hide() - return - logging.error('Couldnt find volume with udi %r' % vol.udi) - - def set_active_volume(self, mount_point): + def __unmount_cb(self, source, result): + logging.debug('__unmount_cb %r %r' % (source, result)) + + def _get_button_for_mount(self, mount): for button in self.get_children(): - logging.error('udi %r' % button.volume.mount_point) - if button.volume.mount_point == mount_point: - button.props.active = True - return - logging.error('Couldnt find volume with mount_point %r' % mount_point) + if button.mount == mount: + return button + logging.error('Couldnt find volume with mount %r' % mount) + return None + + def _remove_button(self, mount): + button = self._get_button_for_mount(mount) + self._volume_buttons.remove(button) + self.remove(button) + self.get_children()[0].props.active = True + + if len(self.get_children()) < 2: + self.hide() + + def set_active_volume(self, mount): + button = self._get_button_for_mount(mount) + button.props.active = True class VolumeButton(RadioToolButton): - def __init__(self, vol, group): + def __init__(self, mount, group): RadioToolButton.__init__(self) - self.props.named_icon = vol.icon_name - self.props.xo_color = vol.icon_color + + # TODO: fallback to the more generic icons when needed + self.props.named_icon = mount.get_icon().props.names[0] + + # TODO: retrieve the colors from the owner of the device + client = gconf.client_get_default() + color = XoColor(client.get_string('/desktop/sugar/user/color')) + self.props.xo_color = color + self.props.group = group - self.volume = vol + self.mount = mount self.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('journal-object-id', 0, 0)], gtk.gdk.ACTION_COPY) @@ -143,5 +154,5 @@ class VolumeButton(RadioToolButton): info, timestamp): object_id = selection_data.data metadata = model.get(object_id) - model.copy(metadata, self.volume.mount_point) + model.copy(metadata, self.mount.get_root().get_path()) |