diff options
author | Simon Schampijer <simon@schampijer.de> | 2008-10-14 12:49:50 (GMT) |
---|---|---|
committer | Simon Schampijer <simon@schampijer.de> | 2008-10-14 12:49:50 (GMT) |
commit | 05c1244133aa5657c168b052cbef3899bfd79e04 (patch) | |
tree | 74f84c7656bdd7f647475a1c249f8eff28f1302f /extensions | |
parent | 18b089182829029b9581eb27979393ee5896aa0e (diff) | |
parent | 0c6dd4e9543946d3ddd7149c07e70e78585f9edf (diff) |
Merge branch 'master' of ssh+git://dev.laptop.org/git/sugar
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/deviceicon/Makefile.am | 3 | ||||
-rw-r--r-- | extensions/deviceicon/volume.py | 111 |
2 files changed, 113 insertions, 1 deletions
diff --git a/extensions/deviceicon/Makefile.am b/extensions/deviceicon/Makefile.am index 66268fd..865ef27 100644 --- a/extensions/deviceicon/Makefile.am +++ b/extensions/deviceicon/Makefile.am @@ -4,4 +4,5 @@ sugar_PYTHON = \ __init__.py \ wireless.py \ battery.py \ - speaker.py + speaker.py \ + volume.py diff --git a/extensions/deviceicon/volume.py b/extensions/deviceicon/volume.py new file mode 100644 index 0000000..7db84ad --- /dev/null +++ b/extensions/deviceicon/volume.py @@ -0,0 +1,111 @@ +# Copyright (C) 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 os +import statvfs +from gettext import gettext as _ + +import gtk + +from sugar.graphics.tray import TrayIcon +from sugar.graphics.palette import Palette +from sugar.graphics.menuitem import MenuItem +from sugar.graphics.icon import Icon + +from jarabe.model import volume + +_icons = {} + +class DeviceView(TrayIcon): + + FRAME_POSITION_RELATIVE = 800 + + def __init__(self, model): + TrayIcon.__init__(self, icon_name=model.icon_name, + xo_color=model.icon_color) + self._model = model + + def create_palette(self): + return VolumePalette(self._model) + +class VolumePalette(Palette): + def __init__(self, model): + Palette.__init__(self, label=model.name, + secondary_text=model.mount_point) + self._model = model + + vbox = gtk.VBox() + self.set_content(vbox) + vbox.show() + + self._progress_bar = gtk.ProgressBar() + vbox.add(self._progress_bar) + self._progress_bar.show() + + self._free_space_label = gtk.Label() + self._free_space_label.set_alignment(0.5, 0.5) + vbox.add(self._free_space_label) + self._free_space_label.show() + + self.connect('popup', self.__popup_cb) + + menu_item = MenuItem(_('Unmount')) + + icon = Icon(icon_name='media-eject', icon_size=gtk.ICON_SIZE_MENU) + menu_item.set_image(icon) + icon.show() + + menu_item.connect('activate', self.__unmount_activate_cb) + self.menu.append(menu_item) + menu_item.show() + + def __unmount_activate_cb(self, menu_item): + self._model.unmount() + + def __popup_cb(self, palette): + stat = os.statvfs(self._model.mount_point) + free_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL] + total_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BLOCKS] + + fraction = (total_space - free_space) / float(total_space) + self._progress_bar.props.fraction = fraction + self._free_space_label.props.label = _('%(free_space)d MB Free') % \ + {'free_space': free_space / (1024 * 1024)} + +def setup(tray): + volumes_manager = volume.get_volumes_manager() + + for vol in volumes_manager.get_volumes(): + _add_device(vol, tray) + + volumes_manager.connect('volume-added', _volume_added_cb, tray) + volumes_manager.connect('volume-removed', _volume_removed_cb, tray) + +def _volume_added_cb(volumes_manager, vol, tray): + _add_device(vol, tray) + +def _volume_removed_cb(volumes_manager, vol, tray): + _remove_device(vol, tray) + +def _add_device(vol, tray): + icon = DeviceView(vol) + _icons[vol] = icon + tray.add_device(icon) + +def _remove_device(vol, tray): + icon = _icons[vol] + tray.remove_device(icon) + del _icons[vol] |