[Dextrose] [PATCH sugar 04/11] Journal: Alert if an error occures when copying to devices in the detail view #1842

Aleksey Lim alsroot at member.fsf.org
Sat Jan 15 09:10:43 EST 2011


From: Simon Schampijer <simon at schampijer.de>

Includes better error messages for both cases
(detail view and dragging in main view).
---
 src/jarabe/journal/journalactivity.py |    9 +++++----
 src/jarabe/journal/journaltoolbox.py  |   22 +++++++++++++++++++++-
 src/jarabe/journal/volumestoolbar.py  |   16 +++++++++-------
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 5d74ae9..d022d97 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -142,8 +142,8 @@ class JournalActivity(JournalWindow):
         self._critical_space_alert = None
         self._check_available_space()
 
-    def __alert_notify_cb(self, gobject, strerror, severity):
-        alert = ErrorAlert(title=severity, msg=strerror)
+    def __volume_error_cb(self, gobject, message, severity):
+        alert = ErrorAlert(title=severity, msg=message)
         alert.connect('response', self.__alert_response_cb)
         self.add_alert(alert)
         alert.show()
@@ -174,7 +174,7 @@ class JournalActivity(JournalWindow):
         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._volumes_toolbar.connect('volume-error', self.__volume_error_cb)
         self._main_view.pack_start(self._volumes_toolbar, expand=False)
 
         search_toolbar = self._main_toolbox.search_toolbar
@@ -185,7 +185,8 @@ class JournalActivity(JournalWindow):
         self._secondary_view = gtk.VBox()
 
         self._detail_toolbox = DetailToolbox()
-        entry_toolbar = self._detail_toolbox.entry_toolbar
+        self._detail_toolbox.entry_toolbar.connect('volume-error',
+                                                   self.__volume_error_cb)
 
         self._detail_view = DetailView()
         self._detail_view.connect('go-back-clicked', self.__go_back_clicked_cb)
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index 03afb4e..8f5e376 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -363,6 +363,11 @@ class DetailToolbox(Toolbox):
         self.entry_toolbar.show()
 
 class EntryToolbar(gtk.Toolbar):
+    __gsignals__ = {
+        'volume-error': (gobject.SIGNAL_RUN_FIRST,
+                         gobject.TYPE_NONE,
+                         ([str, str]))
+        }
     def __init__(self):
         gtk.Toolbar.__init__(self)
 
@@ -432,7 +437,22 @@ class EntryToolbar(gtk.Toolbar):
         misc.resume(self._metadata, service_name)
 
     def _copy_menu_item_activate_cb(self, menu_item, mount_point):
-        model.copy(self._metadata, mount_point)
+        file_path = model.get_file(self._metadata['uid'])
+
+        if not file_path or not os.path.exists(file_path):
+            logging.warn('Entries without a file cannot be copied.')
+            self.emit('volume-error',
+                      _('Entries without a file cannot be copied.'),
+                      _('Warning'))
+            return
+
+        try:
+            model.copy(self._metadata, mount_point)
+        except IOError, e:
+            logging.exception('Error while copying the entry. %s', e.strerror)
+            self.emit('volume-error', 
+                      _('Error while copying the entry. %s') % e.strerror,
+                      _('Error'))
 
     def _refresh_copy_palette(self):
         palette = self._copy.get_palette()
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index dd6fcec..54d051b 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -177,17 +177,19 @@ class BaseButton(RadioToolButton):
         metadata = model.get(object_id)
         file_path = model.get_file(metadata['uid'])
         if not file_path or not os.path.exists(file_path):
-            logging.warn('File does not exist')
-            self.emit('volume-error', _('Entries without a file cannot'
-                ' be copied'), _('Warning'))
+            logging.warn('Entries without a file cannot be copied.')
+            self.emit('volume-error',
+                      _('Entries without a file cannot be copied.'),
+                      _('Warning'))
             return
 
         try:
             model.copy(metadata, self.mount_point)
-        except IOError:
-            logging.exception('BaseButton._drag_data_received_cb: Error'
-                'while copying')
-            self.emit('volume-error', _('Input/Output error'), _('Error'))
+        except IOError, e:
+            logging.exception('Error while copying the entry. %s', e.strerror)
+            self.emit('volume-error',
+                      _('Error while copying the entry. %s') % e.strerror,
+                      _('Error'))
 
 class VolumeButton(BaseButton):
     def __init__(self, mount):
-- 
1.7.3.4



More information about the Dextrose mailing list