~nataliabidart/ubuntuone-control-panel/better-to-translate

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gtk/gui.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2011-04-01 18:31:38 UTC
  • mfrom: (121.1.1 services-more-robust)
  • Revision ID: tarmac-20110401183138-5lkrazlrnqo9yfdv
- Small improvement to show something else besides the generic "Value can not be retrieved." error (LP: #722485).

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
from ubuntuone.controlpanel.backend import (DEVICE_TYPE_PHONE,
56
56
    DEVICE_TYPE_COMPUTER, bool_str)
57
57
from ubuntuone.controlpanel.logger import setup_logging, log_call
58
 
from ubuntuone.controlpanel.utils import get_data_file
 
58
from ubuntuone.controlpanel.utils import (get_data_file,
 
59
    ERROR_TYPE, ERROR_MESSAGE)
59
60
 
60
61
from ubuntuone.controlpanel.gtk import package_manager, TRANSLATION_DOMAIN
61
62
 
68
69
ERROR_COLOR = 'red'
69
70
LOADING = _('Loading...')
70
71
VALUE_ERROR = _('Value could not be retrieved.')
 
72
UNKNOWN_ERROR = _('Unknown error')
71
73
WARNING_MARKUP = '<span foreground="%s"><b>%%s</b></span>' % ERROR_COLOR
72
74
KILOBYTES = 1024
73
75
NO_OP = lambda *a, **kw: None
240
242
        self.message.set_markup(message)
241
243
 
242
244
    @log_call(logger.error)
243
 
    def on_error(self, message=None):
 
245
    def on_error(self, message=None, error_dict=None):
244
246
        """Use this callback to stop the Loading and set a warning message."""
245
 
        if message == None:
 
247
        if message is None and error_dict is None:
246
248
            message = VALUE_ERROR
 
249
        elif message is None and error_dict is not None:
 
250
            error_type = error_dict.get(ERROR_TYPE, UNKNOWN_ERROR)
 
251
            error_msg = error_dict.get(ERROR_MESSAGE)
 
252
            if error_msg:
 
253
                message = "%s (%s: %s)" % (VALUE_ERROR, error_type, error_msg)
 
254
            else:
 
255
                message = "%s (%s)" % (VALUE_ERROR, error_type)
 
256
 
 
257
        assert message is not None
247
258
 
248
259
        self.message.stop()
249
260
        self.message.set_markup(WARNING_MARKUP % message)
557
568
    @log_call(logger.error)
558
569
    def on_volumes_info_error(self, error_dict=None):
559
570
        """Backend notifies of an error when fetching volumes info."""
560
 
        self.on_error()
 
571
        self.on_error(error_dict=error_dict)
561
572
 
562
573
    @log_call(logger.info)
563
574
    def on_volume_settings_changed(self, volume_id):
875
886
    @log_call(logger.error)
876
887
    def on_devices_info_error(self, error_dict=None):
877
888
        """Backend notifies of an error when fetching volumes info."""
878
 
        self.on_error()
 
889
        self.on_error(error_dict=error_dict)
879
890
        self.is_processing = False
880
891
 
881
892
    @log_call(logger.warning)
1200
1211
    @log_call(logger.debug)
1201
1212
    def load(self):
1202
1213
        """Load info."""
 
1214
        self.replications.hide()
1203
1215
        if self.install_box is not None:
1204
1216
            self.itself.remove(self.install_box)
1205
1217
            self.install_box = None
1207
1219
        logger.info('load: has_desktopcouch? %r', self.has_desktopcouch)
1208
1220
        if not self.has_desktopcouch:
1209
1221
            self.message.set_text('')
1210
 
            self.replications.hide()
1211
1222
 
1212
1223
            self.install_box = InstallPackage(self.DESKTOPCOUCH_PKG)
1213
1224
            self.install_box.connect('finished', self.load_replications)
1259
1270
           error_dict.get('error_type', None) == 'NoPairingRecord':
1260
1271
            self.on_error(self.NO_PAIRING_RECORD)
1261
1272
        else:
1262
 
            self.on_error()
 
1273
            self.on_error(error_dict=error_dict)
1263
1274
 
1264
1275
 
1265
1276
class FileSyncStatus(gtk.HBox, ControlPanelMixin):