[Sugar-devel] [PATCH] Journal: Fix for sl#1842
anishmangal2002 at gmail.com
anishmangal2002 at gmail.com
Tue Jun 15 14:15:47 EDT 2010
From: anishmangal2002 <anishmangal2002 at gmail.com>
volumestoolbar.py now catches the IOError and ValueError
exceptions and emits 'volume-error' which is caught in
journalactivity.py which inturn displayes the error as a
NotifyRedAlert message.
Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
---
src/jarabe/journal/journalactivity.py | 13 +++++++++++++
src/jarabe/journal/volumestoolbar.py | 22 +++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletions(-)
diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 0559560..d14adf7 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -27,6 +27,7 @@ import statvfs
import os
from sugar.graphics.window import Window
+from sugar.graphics.alert import NotifyRedAlert
from sugar.bundle.bundle import ZipExtractException, RegistrationException
from sugar import env
from sugar.activity import activityfactory
@@ -138,6 +139,17 @@ class JournalActivity(Window):
self._critical_space_alert = None
self._check_available_space()
+ def _alert_notify_cb(self, gobject, strerror):
+ alert = NotifyRedAlert(10)
+ alert.props.title=_('Alert')
+ alert.props.msg = strerror
+ alert.connect('response', self._alert_response_cb)
+ self.add_alert(alert)
+ alert.show()
+
+ def _alert_response_cb(self, alert, response_id):
+ self.remove_alert(alert)
+
def __realize_cb(self, window):
wm.set_bundle_id(window.window, _BUNDLE_ID)
activity_id = activityfactory.create_activity_id()
@@ -161,6 +173,7 @@ class JournalActivity(Window):
self._volumes_toolbar = VolumesToolbar()
self._volumes_toolbar.connect('volume-changed',
self.__volume_changed_cb)
+ self._volumes_toolbar.connect('volume-error', self._alert_notify_cb)
self._main_view.pack_start(self._volumes_toolbar, expand=False)
search_toolbar = self._main_toolbox.search_toolbar
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 74b974c..2182c78 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -35,6 +35,9 @@ class VolumesToolbar(gtk.Toolbar):
__gsignals__ = {
'volume-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
+ ([str])),
+ 'volume-error': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
([str]))
}
@@ -81,6 +84,7 @@ class VolumesToolbar(gtk.Toolbar):
button = VolumeButton(mount)
button.props.group = self._volume_buttons[0]
button.connect('toggled', self._button_toggled_cb)
+ button.connect('volume-error', self._data_ioerror_cb)
position = self.get_item_index(self._volume_buttons[-1]) + 1
self.insert(button, position)
button.show()
@@ -90,6 +94,9 @@ class VolumesToolbar(gtk.Toolbar):
if len(self.get_children()) > 1:
self.show()
+ def _data_ioerror_cb(self, button, strerror):
+ self.emit('volume-error', strerror)
+
def _button_toggled_cb(self, button):
if button.props.active:
self.emit('volume-changed', button.mount_point)
@@ -123,6 +130,12 @@ class VolumesToolbar(gtk.Toolbar):
button.props.active = True
class BaseButton(RadioToolButton):
+ __gsignals__ = {
+ 'volume-error': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([str]))
+ }
+
def __init__(self, mount_point):
RadioToolButton.__init__(self)
@@ -137,7 +150,14 @@ class BaseButton(RadioToolButton):
info, timestamp):
object_id = selection_data.data
metadata = model.get(object_id)
- model.copy(metadata, self.mount_point)
+ try:
+ model.copy(metadata, self.mount_point)
+ except IOError as (errno, strerror):
+ logging.error('BaseButton._drag_data_received_cb: IOError: %s; %s' % (errno, strerror))
+ self.emit('volume-error', strerror)
+ except ValueError as (strerror):
+ logging.error('BaseButton._drag_data_received_cb: ValueError: %s' % (strerror))
+ self.emit('volume-error', strerror)
class VolumeButton(BaseButton):
def __init__(self, mount):
--
1.7.0.1
More information about the Sugar-devel
mailing list