From: anishmangal2002 <anishmangal2002@gmail.com>
To: Bernie Innocenti <bernie@codewiz.org>
Cc: sugar-devel <sugar-devel@lists.sugarlabs.org>, anishmangal2002 <anishmangal2002@gmail.com>
Subject: [PATCH] Journal:show error message on write failure: #1842
Date: Sat,  3 Jul 2010 00:55:56 +0530

volumestoolbar.py now catches the IOError and ValueError
exceptions and emits 'volume-error'signal. This signal is
caught in journalactivity.py which displays the error as
an ErrorAlert message.

Signed-off-by: anishmangal2002 <anishmangal2002@gmail.com>
---
 src/jarabe/journal/journalactivity.py |   16 ++++++++++++++++
 src/jarabe/journal/volumestoolbar.py  |   22 +++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 0559560..eab292b 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -27,6 +27,9 @@ import statvfs
 import os
 
 from sugar.graphics.window import Window
+from sugar.graphics.alert import ErrorAlert
+from sugar.graphics.icon import Icon
+
 from sugar.bundle.bundle import ZipExtractException, RegistrationException
 from sugar import env
 from sugar.activity import activityfactory
@@ -138,6 +141,17 @@ class JournalActivity(Window):
         self._critical_space_alert = None
         self._check_available_space()
 
+    def _alert_notify_cb(self, gobject, strerror, severity):
+        alert = ErrorAlert()
+        alert.props.title= severity
+        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 +175,8 @@ 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,
+                                      'Error')
         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..a6acebe 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._volume_error_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 _volume_error_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


