From f4e43254beda14b127e3d5b4f0bd568c68c0a2cb Mon Sep 17 00:00:00 2001
From: Simon Schampijer <simon@schampijer.de>
Date: Tue, 31 Aug 2010 14:16:09 +0200
Subject: [PATCH] Journal: Provide error message on write errors #1842
---
src/jarabe/journal/journalactivity.py | 24 ++++++++++++++++++++++--
src/jarabe/journal/journaltoolbox.py | 20 +++++++++++++++++++-
src/jarabe/journal/volumestoolbar.py | 31 +++++++++++++++++++++++++++++--
3 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 18cc64a..00c25c4 100644
a
|
b
|
import statvfs |
27 | 27 | import os |
28 | 28 | |
29 | 29 | from sugar.graphics.window import Window |
| 30 | from sugar.graphics.alert import Alert |
| 31 | from sugar.graphics.icon import Icon |
| 32 | |
30 | 33 | from sugar.bundle.bundle import ZipExtractException, RegistrationException |
31 | 34 | from sugar import env |
32 | 35 | from sugar.activity import activityfactory |
… |
… |
class JournalActivity(Window): |
138 | 141 | self._critical_space_alert = None |
139 | 142 | self._check_available_space() |
140 | 143 | |
| 144 | def __volume_error_cb(self, gobject, strerror, severity): |
| 145 | self._add_alert(strerror, severity) |
| 146 | |
| 147 | def _add_alert(self, strerror, severity): |
| 148 | alert = Alert(title=severity, msg=strerror) |
| 149 | icon = Icon(icon_name='dialog-ok') |
| 150 | alert.add_button(gtk.RESPONSE_OK, _('Ok'), icon) |
| 151 | icon.show() |
| 152 | alert.connect('response', self.__alert_response_cb) |
| 153 | self.add_alert(alert) |
| 154 | alert.show() |
| 155 | |
| 156 | def __alert_response_cb(self, alert, response_id): |
| 157 | self.remove_alert(alert) |
| 158 | |
141 | 159 | def __realize_cb(self, window): |
142 | 160 | wm.set_bundle_id(window.window, _BUNDLE_ID) |
143 | 161 | activity_id = activityfactory.create_activity_id() |
… |
… |
class JournalActivity(Window): |
161 | 179 | self._volumes_toolbar = VolumesToolbar() |
162 | 180 | self._volumes_toolbar.connect('volume-changed', |
163 | 181 | self.__volume_changed_cb) |
| 182 | self._volumes_toolbar.connect('volume-error', |
| 183 | self.__volume_error_cb) |
164 | 184 | self._main_view.pack_start(self._volumes_toolbar, expand=False) |
165 | 185 | |
166 | 186 | search_toolbar = self._main_toolbox.search_toolbar |
… |
… |
class JournalActivity(Window): |
171 | 191 | self._secondary_view = gtk.VBox() |
172 | 192 | |
173 | 193 | self._detail_toolbox = DetailToolbox() |
174 | | entry_toolbar = self._detail_toolbox.entry_toolbar |
175 | | |
| 194 | self._detail_toolbox.entry_toolbar.connect('volume-error', |
| 195 | self.__volume_error_cb) |
176 | 196 | self._detail_view = DetailView() |
177 | 197 | self._detail_view.connect('go-back-clicked', self.__go_back_clicked_cb) |
178 | 198 | self._secondary_view.pack_end(self._detail_view) |
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index 17a65e6..6350c9b 100644
a
|
b
|
class DetailToolbox(Toolbox): |
325 | 325 | self.entry_toolbar.show() |
326 | 326 | |
327 | 327 | class EntryToolbar(gtk.Toolbar): |
| 328 | __gsignals__ = { |
| 329 | 'volume-error': (gobject.SIGNAL_RUN_FIRST, |
| 330 | gobject.TYPE_NONE, |
| 331 | ([str, str])) |
| 332 | } |
328 | 333 | def __init__(self): |
329 | 334 | gtk.Toolbar.__init__(self) |
330 | 335 | |
… |
… |
class EntryToolbar(gtk.Toolbar): |
394 | 399 | misc.resume(self._metadata, service_name) |
395 | 400 | |
396 | 401 | def _copy_menu_item_activate_cb(self, menu_item, mount): |
397 | | model.copy(self._metadata, mount.get_root().get_path()) |
| 402 | file_path = model.get_file(self._metadata['uid']) |
| 403 | |
| 404 | if not file_path or not os.path.exists(file_path): |
| 405 | logging.warn('Entries without a file cannot be copied.') |
| 406 | self.emit('volume-error', _('Entries without a file cannot' |
| 407 | ' be copied'), _('Warning')) |
| 408 | return |
| 409 | |
| 410 | try: |
| 411 | model.copy(self._metadata, mount.get_root().get_path()) |
| 412 | except IOError: |
| 413 | logging.exception('Error while copying the file.') |
| 414 | self.emit('volume-error', _('Error while copying the file.'), |
| 415 | _('Error')) |
398 | 416 | |
399 | 417 | def _refresh_copy_palette(self): |
400 | 418 | palette = self._copy.get_palette() |
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index b21832e..633de10 100644
a
|
b
|
|
15 | 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
16 | 16 | |
17 | 17 | import logging |
| 18 | import os |
18 | 19 | from gettext import gettext as _ |
19 | 20 | |
20 | 21 | import gobject |
… |
… |
class VolumesToolbar(gtk.Toolbar): |
35 | 36 | __gsignals__ = { |
36 | 37 | 'volume-changed': (gobject.SIGNAL_RUN_FIRST, |
37 | 38 | gobject.TYPE_NONE, |
38 | | ([str])) |
| 39 | ([str])), |
| 40 | 'volume-error': (gobject.SIGNAL_RUN_FIRST, |
| 41 | gobject.TYPE_NONE, |
| 42 | ([str, str])) |
39 | 43 | } |
40 | 44 | |
41 | 45 | def __init__(self): |
… |
… |
class VolumesToolbar(gtk.Toolbar): |
81 | 85 | button = VolumeButton(mount) |
82 | 86 | button.props.group = self._volume_buttons[0] |
83 | 87 | button.connect('toggled', self._button_toggled_cb) |
| 88 | button.connect('volume-error', self.__volume_error_cb) |
84 | 89 | position = self.get_item_index(self._volume_buttons[-1]) + 1 |
85 | 90 | self.insert(button, position) |
86 | 91 | button.show() |
… |
… |
class VolumesToolbar(gtk.Toolbar): |
90 | 95 | if len(self.get_children()) > 1: |
91 | 96 | self.show() |
92 | 97 | |
| 98 | def __volume_error_cb(self, button, strerror, severity): |
| 99 | self.emit('volume-error', strerror, severity) |
| 100 | |
93 | 101 | def _button_toggled_cb(self, button): |
94 | 102 | if button.props.active: |
95 | 103 | self.emit('volume-changed', button.mount_point) |
… |
… |
class VolumesToolbar(gtk.Toolbar): |
123 | 131 | button.props.active = True |
124 | 132 | |
125 | 133 | class BaseButton(RadioToolButton): |
| 134 | __gsignals__ = { |
| 135 | 'volume-error': (gobject.SIGNAL_RUN_FIRST, |
| 136 | gobject.TYPE_NONE, |
| 137 | ([str, str])) |
| 138 | } |
| 139 | |
126 | 140 | def __init__(self, mount_point): |
127 | 141 | RadioToolButton.__init__(self) |
128 | 142 | |
… |
… |
class BaseButton(RadioToolButton): |
137 | 151 | info, timestamp): |
138 | 152 | object_id = selection_data.data |
139 | 153 | metadata = model.get(object_id) |
140 | | model.copy(metadata, self.mount_point) |
| 154 | file_path = model.get_file(metadata['uid']) |
| 155 | |
| 156 | if not file_path or not os.path.exists(file_path): |
| 157 | logging.warn('Entries without a file cannot be copied.') |
| 158 | self.emit('volume-error', _('Entries without a file cannot' |
| 159 | ' be copied'), _('Warning')) |
| 160 | return |
| 161 | |
| 162 | try: |
| 163 | model.copy(metadata, self.mount_point) |
| 164 | except IOError: |
| 165 | logging.exception('Error while copying the file.') |
| 166 | self.emit('volume-error', _('Error while copying the file.'), |
| 167 | _('Error')) |
141 | 168 | |
142 | 169 | class VolumeButton(BaseButton): |
143 | 170 | def __init__(self, mount): |