Ticket #1842: 0001-Journal-Provide-error-message-on-write-errors-1842.patch

File 0001-Journal-Provide-error-message-on-write-errors-1842.patch, 7.1 KB (added by erikos, 10 years ago)

Patch against 0.84: add functionality to detail view, better error message

  • src/jarabe/journal/journalactivity.py

    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 
    2727import os
    2828
    2929from sugar.graphics.window import Window
     30from sugar.graphics.alert import Alert
     31from sugar.graphics.icon import Icon
     32
    3033from sugar.bundle.bundle import ZipExtractException, RegistrationException
    3134from sugar import env
    3235from sugar.activity import activityfactory
    class JournalActivity(Window): 
    138141        self._critical_space_alert = None
    139142        self._check_available_space()
    140143
     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
    141159    def __realize_cb(self, window):
    142160        wm.set_bundle_id(window.window, _BUNDLE_ID)
    143161        activity_id = activityfactory.create_activity_id()
    class JournalActivity(Window): 
    161179        self._volumes_toolbar = VolumesToolbar()
    162180        self._volumes_toolbar.connect('volume-changed',
    163181                                      self.__volume_changed_cb)
     182        self._volumes_toolbar.connect('volume-error',
     183                                      self.__volume_error_cb)
    164184        self._main_view.pack_start(self._volumes_toolbar, expand=False)
    165185
    166186        search_toolbar = self._main_toolbox.search_toolbar
    class JournalActivity(Window): 
    171191        self._secondary_view = gtk.VBox()
    172192
    173193        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)
    176196        self._detail_view = DetailView()
    177197        self._detail_view.connect('go-back-clicked', self.__go_back_clicked_cb)
    178198        self._secondary_view.pack_end(self._detail_view)
  • src/jarabe/journal/journaltoolbox.py

    diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
    index 17a65e6..6350c9b 100644
    a b class DetailToolbox(Toolbox): 
    325325        self.entry_toolbar.show()
    326326
    327327class EntryToolbar(gtk.Toolbar):
     328    __gsignals__ = {
     329        'volume-error': (gobject.SIGNAL_RUN_FIRST,
     330                         gobject.TYPE_NONE,
     331                         ([str, str]))
     332        }
    328333    def __init__(self):
    329334        gtk.Toolbar.__init__(self)
    330335
    class EntryToolbar(gtk.Toolbar): 
    394399        misc.resume(self._metadata, service_name)
    395400
    396401    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'))
    398416
    399417    def _refresh_copy_palette(self):
    400418        palette = self._copy.get_palette()
  • src/jarabe/journal/volumestoolbar.py

    diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
    index b21832e..633de10 100644
    a b  
    1515# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1616
    1717import logging
     18import os
    1819from gettext import gettext as _
    1920
    2021import gobject
    class VolumesToolbar(gtk.Toolbar): 
    3536    __gsignals__ = {
    3637        'volume-changed': (gobject.SIGNAL_RUN_FIRST,
    3738                           gobject.TYPE_NONE,
    38                            ([str]))
     39                           ([str])),
     40        'volume-error': (gobject.SIGNAL_RUN_FIRST,
     41                         gobject.TYPE_NONE,
     42                         ([str, str]))
    3943    }
    4044
    4145    def __init__(self):
    class VolumesToolbar(gtk.Toolbar): 
    8185        button = VolumeButton(mount)
    8286        button.props.group = self._volume_buttons[0]
    8387        button.connect('toggled', self._button_toggled_cb)
     88        button.connect('volume-error', self.__volume_error_cb)
    8489        position = self.get_item_index(self._volume_buttons[-1]) + 1
    8590        self.insert(button, position)
    8691        button.show()
    class VolumesToolbar(gtk.Toolbar): 
    9095        if len(self.get_children()) > 1:
    9196            self.show()
    9297
     98    def __volume_error_cb(self, button, strerror, severity):
     99        self.emit('volume-error', strerror, severity)
     100
    93101    def _button_toggled_cb(self, button):
    94102        if button.props.active:
    95103            self.emit('volume-changed', button.mount_point)
    class VolumesToolbar(gtk.Toolbar): 
    123131        button.props.active = True
    124132
    125133class BaseButton(RadioToolButton):
     134    __gsignals__ = {
     135        'volume-error': (gobject.SIGNAL_RUN_FIRST,
     136                         gobject.TYPE_NONE,
     137                         ([str, str]))
     138        }
     139   
    126140    def __init__(self, mount_point):
    127141        RadioToolButton.__init__(self)
    128142
    class BaseButton(RadioToolButton): 
    137151                               info, timestamp):
    138152        object_id = selection_data.data
    139153        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'))
    141168
    142169class VolumeButton(BaseButton):
    143170    def __init__(self, mount):