Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-11-29 17:59:24 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-11-29 17:59:24 (GMT)
commit83d05f18f3255643cbaf887e8653ad36decc95e8 (patch)
tree3b5cdfd47d1aa1aa047b25b72766b7b3a31f7a0e /src
parente4a9e038748684ba8149aebb03091fac02a34e4a (diff)
Remove jarabe/model/volume.py and use gio instead
Diffstat (limited to 'src')
-rw-r--r--src/jarabe/journal/journalactivity.py11
-rw-r--r--src/jarabe/journal/journaltoolbox.py21
-rw-r--r--src/jarabe/journal/model.py2
-rw-r--r--src/jarabe/journal/volumestoolbar.py113
-rw-r--r--src/jarabe/model/Makefile.am3
-rw-r--r--src/jarabe/model/volume.py253
6 files changed, 82 insertions, 321 deletions
diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 5ab99ef..1fd3b74 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -239,9 +239,10 @@ class JournalActivity(Window):
self._show_secondary_view(metadata)
return True
- def __volume_changed_cb(self, volume_toolbar, volume):
- logging.debug('Selected volume: %r.' % volume.udi)
- self._main_toolbox.search_toolbar.set_mount_point(volume.mount_point)
+ def __volume_changed_cb(self, volume_toolbar, mount):
+ mount_point = mount.get_root().get_path()
+ logging.debug('Selected volume: %r.' % mount_point)
+ self._main_toolbox.search_toolbar.set_mount_point(mount_point)
self._main_toolbox.set_current_toolbar(0)
def __model_created_cb(self, object_id):
@@ -320,8 +321,8 @@ class JournalActivity(Window):
self.present()
self._critical_space_alert = None
- def set_active_volume(self, mount_point):
- self._volumes_toolbar.set_active_volume(mount_point)
+ def set_active_volume(self, mount):
+ self._volumes_toolbar.set_active_volume(mount)
_journal = None
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index beda184..f8052eb 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -21,6 +21,7 @@ import os
import gconf
import gobject
+import gio
import gtk
from sugar.graphics.toolbox import Toolbox
@@ -35,7 +36,6 @@ from sugar.graphics import style
from sugar import mime
from jarabe.model import bundleregistry
-from jarabe.model import volume
from jarabe.journal import misc
from jarabe.journal import model
@@ -373,8 +373,8 @@ class EntryToolbar(gtk.Toolbar):
def _resume_menu_item_activate_cb(self, menu_item, service_name):
misc.resume(self._metadata, service_name)
- def _copy_menu_item_activate_cb(self, menu_item, vol):
- model.copy(self._metadata, vol.mount_point)
+ def _copy_menu_item_activate_cb(self, menu_item, mount):
+ model.copy(self._metadata, mount.get_root().get_path())
def _refresh_copy_palette(self):
palette = self._copy.get_palette()
@@ -383,16 +383,19 @@ class EntryToolbar(gtk.Toolbar):
palette.menu.remove(menu_item)
menu_item.destroy()
- volumes_manager = volume.get_volumes_manager()
- for vol in volumes_manager.get_volumes():
- if self._metadata['mountpoint'] == vol.mount_point:
+ volume_monitor = gio.volume_monitor_get()
+ for mount in volume_monitor.get_mounts():
+ if self._metadata['mountpoint'] == mount.get_root().get_path():
continue
- menu_item = MenuItem(vol.name)
- menu_item.set_image(Icon(icon_name=vol.icon_name,
+ menu_item = MenuItem(mount.get_name())
+
+ # TODO: fallback to the more generic icons when needed
+ menu_item.set_image(Icon(icon_name=mount.get_icon().props.names[0],
icon_size=gtk.ICON_SIZE_MENU))
+
menu_item.connect('activate',
self._copy_menu_item_activate_cb,
- vol)
+ mount)
palette.menu.append(menu_item)
menu_item.show()
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 19068f2..5d2b5e1 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -229,7 +229,7 @@ def _query_mount_point(mount_point, query):
files = files[offset:offset + limit]
result = []
- for file_path, timestamp in files:
+ for file_path, timestamp_ in files:
metadata = _get_file_metadata(file_path)
metadata['mountpoint'] = mount_point
result.append(metadata)
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())
diff --git a/src/jarabe/model/Makefile.am b/src/jarabe/model/Makefile.am
index 71ba988..91d9a3e 100644
--- a/src/jarabe/model/Makefile.am
+++ b/src/jarabe/model/Makefile.am
@@ -12,5 +12,4 @@ sugar_PYTHON = \
shell.py \
screen.py \
session.py \
- sound.py \
- volume.py
+ sound.py
diff --git a/src/jarabe/model/volume.py b/src/jarabe/model/volume.py
deleted file mode 100644
index 0d3d9a5..0000000
--- a/src/jarabe/model/volume.py
+++ /dev/null
@@ -1,253 +0,0 @@
-# Copyright (C) 2007-2008, One Laptop Per Child
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-import logging
-
-import gobject
-import dbus
-
-from sugar import profile
-
-HAL_SERVICE_NAME = 'org.freedesktop.Hal'
-HAL_MANAGER_PATH = '/org/freedesktop/Hal/Manager'
-HAL_MANAGER_IFACE = 'org.freedesktop.Hal.Manager'
-HAL_DEVICE_IFACE = 'org.freedesktop.Hal.Device'
-HAL_VOLUME_IFACE = 'org.freedesktop.Hal.Device.Volume'
-
-MOUNT_OPTION_UID = 500
-MOUNT_OPTION_UMASK = 000
-
-_volumes_manager = None
-
-class VolumesManager(gobject.GObject):
-
- __gtype_name__ = 'VolumesManager'
-
- __gsignals__ = {
- 'volume-added': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ([object])),
- 'volume-removed': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ([object]))
- }
-
- def __init__(self):
- gobject.GObject.__init__(self)
-
- self._volumes = {}
-
- bus = dbus.SystemBus()
- proxy = bus.get_object(HAL_SERVICE_NAME, HAL_MANAGER_PATH)
- self._hal_manager = dbus.Interface(proxy, HAL_MANAGER_IFACE)
- self._hal_manager.connect_to_signal('DeviceAdded',
- self._hal_device_added_cb)
-
- for udi in self._hal_manager.FindDeviceByCapability('volume'):
- if self._is_device_relevant(udi):
- try:
- self._add_hal_device(udi)
- except Exception, e:
- logging.error('Exception when mounting device %r: %r' % \
- (udi, e))
-
- def get_volumes(self):
- return self._volumes.values()
-
- def _hal_device_added_cb(self, udi):
- bus = dbus.SystemBus()
- device_object = bus.get_object(HAL_SERVICE_NAME, udi)
- device = dbus.Interface(device_object, HAL_DEVICE_IFACE)
- if device.QueryCapability('volume'):
- logging.debug('VolumesManager._hal_device_added_cb: %r', udi)
- if self._is_device_relevant(udi):
- self._add_hal_device(udi)
-
- def _is_device_relevant(self, udi):
- bus = dbus.SystemBus()
- device_object = bus.get_object(HAL_SERVICE_NAME, udi)
- device = dbus.Interface(device_object, HAL_DEVICE_IFACE)
-
- # Ignore volumes without a filesystem.
- if device.GetProperty('volume.fsusage') != 'filesystem':
- return False
-
- return True
-
- def _add_hal_device(self, udi):
- logging.debug('VolumeToolbar._add_hal_device: %r' % udi)
-
- bus = dbus.SystemBus()
- device_object = bus.get_object(HAL_SERVICE_NAME, udi)
- device = dbus.Interface(device_object, HAL_DEVICE_IFACE)
-
- # listen to mount/unmount
- device.connect_to_signal('PropertyModified',
- lambda *args: self._hal_device_property_modified_cb(udi, *args))
-
- bus.add_signal_receiver(self._hal_device_removed_cb,
- 'DeviceRemoved',
- HAL_MANAGER_IFACE, HAL_SERVICE_NAME,
- HAL_MANAGER_PATH, arg0=udi)
-
- if device.GetProperty('volume.is_mounted'):
- self._add_volume(udi)
- return
-
- label = device.GetProperty('volume.label')
- fs_type = device.GetProperty('volume.fstype')
- valid_options = device.GetProperty('volume.mount.valid_options')
- options = []
-
- if 'uid=' in valid_options:
- options.append('uid=%i' % MOUNT_OPTION_UID)
-
- if 'umask=' in valid_options:
- options.append('umask=%i' % MOUNT_OPTION_UMASK)
-
- if 'noatime' in valid_options:
- options.append('noatime')
-
- if 'utf8' in valid_options:
- options.append('utf8')
-
- if 'iocharset=' in valid_options:
- options.append('iocharset=utf8')
-
- mount_point = label
- if not mount_point:
- mount_point = device.GetProperty('volume.uuid')
-
- volume = dbus.Interface(device_object, HAL_VOLUME_IFACE)
-
- # Try 100 times to get a mount point
- mounted = False
- i = 0
- while not mounted:
- try:
- if i > 0:
- volume.Mount('%s_%d' % (mount_point, i), fs_type, options)
- else:
- volume.Mount(mount_point, fs_type, options)
- mounted = True
- except dbus.DBusException, e:
- s = 'org.freedesktop.Hal.Device.Volume.MountPointNotAvailable'
- if i < 100 and e.get_dbus_name() == s:
- i += 1
- else:
- raise
-
- def _hal_device_property_modified_cb(self, udi, count, changes):
- if 'volume.is_mounted' in [change[0] for change in changes]:
- logging.debug('VolumesManager._hal_device_property_modified: %r' % \
- (udi))
- bus = dbus.SystemBus()
- #proxy = bus.get_object(HAL_SERVICE_NAME, HAL_MANAGER_PATH)
- #hal_manager = dbus.Interface(proxy, HAL_MANAGER_IFACE)
- # TODO: Why this doesn't work?
- #if not hal_manager.DeviceExists(udi):
- # return
-
- proxy = bus.get_object(HAL_SERVICE_NAME, udi)
- device = dbus.Interface(proxy, HAL_DEVICE_IFACE)
- try:
- is_mounted = device.GetProperty('volume.is_mounted')
- except dbus.DBusException, e:
- logging.debug('e: %s' % e)
- return
-
- if is_mounted:
- if udi not in self._volumes:
- self._add_volume(udi)
- else:
- if udi in self._volumes:
- self._remove_volume(udi)
-
- def _add_volume(self, udi):
- logging.debug('_add_volume %r' % udi)
- bus = dbus.SystemBus()
- device_object = bus.get_object(HAL_SERVICE_NAME, udi)
- device = dbus.Interface(device_object, HAL_DEVICE_IFACE)
-
- volume_name = device.GetProperty('volume.label')
- if not volume_name:
- volume_name = device.GetProperty('volume.uuid')
-
- mount_point = device.GetProperty('volume.mount_point')
-
- storage_udi = device.GetProperty('block.storage_device')
- obj = bus.get_object(HAL_SERVICE_NAME, storage_udi)
- storage_device = dbus.Interface(obj, HAL_DEVICE_IFACE)
- can_eject = storage_device.GetProperty('storage.hotpluggable')
-
- volume = Volume(volume_name,
- self._get_icon_for_volume(device),
- profile.get_color(),
- udi,
- mount_point,
- can_eject)
- self._volumes[udi] = volume
-
- logging.debug('mounted volume %s' % udi)
- self.emit('volume-added', volume)
-
- def _remove_volume(self, udi):
- volume = self._volumes[udi]
- del self._volumes[udi]
- self.emit('volume-removed', volume)
-
- def _hal_device_removed_cb(self, udi):
- logging.debug('VolumesManager._hal_device_removed_cb: %r', udi)
- if udi in self._volumes:
- self._remove_volume(udi)
-
- def _get_icon_for_volume(self, device):
- bus = dbus.SystemBus()
- storage_udi = device.GetProperty('block.storage_device')
- obj = bus.get_object(HAL_SERVICE_NAME, storage_udi)
- storage_device = dbus.Interface(obj, HAL_DEVICE_IFACE)
-
- storage_drive_type = storage_device.GetProperty('storage.drive_type')
- if storage_drive_type == 'sd_mmc':
- return 'media-flash-sd-mmc'
- elif device.GetProperty('volume.mount_point') == '/':
- return 'computer-xo'
- else:
- return 'media-flash-usb'
-
-class Volume(object):
- def __init__(self, name, icon_name, icon_color, udi, mount_point,
- can_eject):
- self.name = name
- self.icon_name = icon_name
- self.icon_color = icon_color
- self.udi = udi
- self.mount_point = mount_point
- self.can_eject = can_eject
-
- def unmount(self):
- logging.debug('Volumes.unmount: %r', self.udi)
- bus = dbus.SystemBus()
- device_object = bus.get_object(HAL_SERVICE_NAME, self.udi)
- volume = dbus.Interface(device_object, HAL_VOLUME_IFACE)
- volume.Unmount([])
-
-def get_volumes_manager():
- global _volumes_manager
- if _volumes_manager is None:
- _volumes_manager = VolumesManager()
- return _volumes_manager
-