Ticket #1759: Showing Errors-Palette Mockup-V2.patch

File Showing Errors-Palette Mockup-V2.patch, 16.6 KB (added by Dcastelo, 14 years ago)
  • extensions/deviceicon/network.py

    From a31aeefde5a0317335642f977d092e40a457dd29 Mon Sep 17 00:00:00 2001
    From: latu <latu@localhost.localdomain>
    Date: Tue, 2 Mar 2010 16:30:20 -0200
    Subject: [PATCH] Showing Errors- Apply Mockup
    
    ---
     extensions/deviceicon/network.py |  184 ++++++++++++++++++++++++++------------
     src/jarabe/model/network.py      |   34 +++++---
     2 files changed, 148 insertions(+), 70 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 94a4293..c278a4c 100644
    a b from sugar.graphics.tray import TrayIcon 
    3939from sugar.graphics import xocolor
    4040from sugar.util import unique_id
    4141from sugar import profile
     42from sugar.graphics.icon import Icon
     43from sugar.graphics.menuitem import MenuItem
    4244
    4345from jarabe.model import network
    4446from jarabe.model.network import Settings
    _GSM_STATE_NOT_READY = 0 
    6365_GSM_STATE_DISCONNECTED = 1
    6466_GSM_STATE_CONNECTING = 2
    6567_GSM_STATE_CONNECTED = 3
    66 _GSM_STATE_NEED_AUTH = 4
     68_GSM_STATE_FAILED = 4
    6769
    6870def frequency_to_channel(frequency):
    6971    ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4,
    class WiredPalette(Palette): 
    214216            ip_address_text = ""
    215217        self._ip_address_label.set_text(ip_address_text)
    216218
     219
    217220class GsmPalette(Palette):
    218221    __gtype_name__ = 'SugarGsmPalette'
    219222
    class GsmPalette(Palette): 
    227230    def __init__(self):
    228231
    229232        Palette.__init__(self, label=_('Wireless modem'))
    230 
    231233        self._current_state = None
     234        self._alert = False
    232235
    233         self._toggle_state_item = gtk.MenuItem('')
     236        self._toggle_state_item = MenuItem('')
    234237        self._toggle_state_item.connect('activate', self.__toggle_state_cb)
    235238        self.menu.append(self._toggle_state_item)
    236239        self._toggle_state_item.show()
    237240
    238         self.set_state(_GSM_STATE_NOT_READY)
    239 
    240241        self.info_box = gtk.VBox()
    241 
    242         self.data_label = gtk.Label()
    243         self.data_label.props.xalign = 0.0
    244         label_alignment = self._add_widget_with_padding(self.data_label)
    245         self.info_box.pack_start(label_alignment)
    246         self.data_label.show()
     242        self.connection_info_box = gtk.HBox()
     243
     244        icon = Icon(icon_name='go-up', icon_size=gtk.ICON_SIZE_MENU)
     245        self.connection_info_box.pack_start(icon)
     246        icon.show()
     247        self._data_label_up = gtk.Label()
     248        self._data_label_up.props.xalign = 0.0
     249        label_alignment = self._add_widget_with_padding(self._data_label_up)
     250        self.connection_info_box.pack_start(label_alignment)
     251        self._data_label_up.show()
    247252        label_alignment.show()
    248253
    249         self.connection_time_label = gtk.Label()
    250         self.connection_time_label.props.xalign = 0.0
    251         label_alignment = self._add_widget_with_padding( \
    252                 self.connection_time_label)
    253         self.info_box.pack_start(label_alignment)
    254         self.connection_time_label.show()
     254        icon = Icon(icon_name='go-down', icon_size=gtk.ICON_SIZE_MENU)
     255        self.connection_info_box.pack_start(icon)
     256        icon.show()
     257        self._data_label_down = gtk.Label()
     258        self._data_label_down.props.xalign = 0.0
     259        label_alignment = self._add_widget_with_padding(self._data_label_down)
     260        self.connection_info_box.pack_start(label_alignment)
     261        self._data_label_down.show()
    255262        label_alignment.show()
    256 
     263       
     264        self.connection_info_box.show()
     265        self.info_box.pack_start(self.connection_info_box)
     266
     267        self._error_accept_item = MenuItem('')
     268        self._error_accept_item.connect('activate', self.__error_accept_cb)
     269        self.menu.append(self._error_accept_item)
     270       
    257271        self.info_box.show()
    258272        self.set_content(self.info_box)
    259273
     274        self.set_state(_GSM_STATE_NOT_READY)
     275
    260276    def _add_widget_with_padding(self, child, xalign=0, yalign=0.5):
    261277        alignment = gtk.Alignment(xalign=xalign, yalign=yalign,
    262278                                  xscale=1, yscale=0.33)
    class GsmPalette(Palette): 
    267283        alignment.add(child)
    268284        return alignment
    269285
    270     def set_state(self, state):
     286    def set_state(self, state, reason=0):
    271287        self._current_state = state
    272         self._update_label_and_text()
     288        self._update_label_and_text(reason)
    273289
    274     def _update_label_and_text(self):
     290    def _update_label_and_text(self, reason=0):
     291       
    275292        if self._current_state == _GSM_STATE_NOT_READY:
    276293            self._toggle_state_item.get_child().set_label('...')
    277294            self.props.secondary_text = _('Please wait...')
    278 
     295   
    279296        elif self._current_state == _GSM_STATE_DISCONNECTED:
    280297            self._toggle_state_item.get_child().set_label(_('Connect'))
    281             self.props.secondary_text = _('Disconnected')
    282 
     298            if not self._alert:
     299                self.props.secondary_text = _('Disconnected')
     300            icon = Icon(icon_name='media-playback-start', \
     301                        icon_size=gtk.ICON_SIZE_MENU)
     302            self._toggle_state_item.set_image(icon)
     303         
    283304        elif self._current_state == _GSM_STATE_CONNECTING:
    284305            self._toggle_state_item.get_child().set_label(_('Cancel'))
    285306            self.props.secondary_text = _('Connecting...')
     307            icon = Icon(icon_name='media-playback-stop', \
     308                        icon_size=gtk.ICON_SIZE_MENU)
     309            self._toggle_state_item.set_image(icon)           
    286310
    287311        elif self._current_state == _GSM_STATE_CONNECTED:
    288312            self._toggle_state_item.get_child().set_label(_('Disconnect'))
    289             self.props.secondary_text = _('Connected')
    290            
    291         elif self._current_state == _GSM_STATE_NEED_AUTH:
    292             self._toggle_state_item.get_child().set_label(_('Sim requires Pin/Puk'))
    293             self.props.secondary_text = _('Authentication Error')
     313            self.update_connection_time()
     314            icon = Icon(icon_name='media-eject', \
     315                        icon_size=gtk.ICON_SIZE_MENU)
     316            self._toggle_state_item.set_image(icon)
     317                       
     318        elif self._current_state == _GSM_STATE_FAILED:
     319            self.add_alert(_('Connection Error'), \
     320                            self._get_error_by_nm_reason(reason))
    294321           
    295322        else:
    296323            raise ValueError('Invalid GSM state while updating label and ' \
    297324                             'text, %s' % str(self._current_state))
    298 
     325   
     326    def add_alert(self, title, message):
     327        self._alert = True
     328        self.props.secondary_text = title
     329        self._error_accept_item.get_child().set_label(message)
     330        self._error_accept_item.show()
     331        self._toggle_state_item.set_sensitive(False)
     332                     
     333    def __error_accept_cb(self, alert):
     334        self._alert = False
     335        self._update_label_and_text()
     336        self._error_accept_item.get_child().set_label('')
     337        self._error_accept_item.hide()
     338        self._toggle_state_item.set_sensitive(True)
     339                     
     340    def update_connection_time(self, connection_time=None):
     341        if (connection_time is not None):
     342            self.props.secondary_text = _('Connected for ' + \
     343                                      connection_time.strftime('%H:%M:%S'))
     344        else:
     345            self.props.secondary_text = _('Connected for ' \
     346                                          + '00:00:00')
     347             
     348    def update_stats(self, in_bytes, out_bytes):
     349        in_KBytes = in_bytes / 1024
     350        out_KBytes = out_bytes / 1024
     351        self._data_label_up.set_text(_("%d KB") % (out_KBytes))
     352        self._data_label_down.set_text(_("%d KB") % (in_KBytes))
     353       
     354    def _get_error_by_nm_reason(self, reason):
     355        if reason in [network.NM_DEVICE_STATE_REASON_NO_SECRETS, network.NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED]:
     356            message = _('The Pin/Puk configuration is not valid.')
     357        elif reason in [network.NM_DEVICE_STATE_REASON_PPP_DISCONNECT, network.NM_DEVICE_STATE_REASON_PPP_FAILED]:
     358            message = _('Check the APN configuration.')
     359        elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER]:
     360            message = _('Check the tel number configuration.')
     361        elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT]:
     362            message = _('Time out. Check the tel configuration')
     363        else:
     364            message = _('Unexpected error.')
     365        return message
     366   
    299367    def __toggle_state_cb(self, menuitem):
    300368        if self._current_state == _GSM_STATE_NOT_READY:
    301369            pass
    class GsmPalette(Palette): 
    305373            self.emit('gsm-disconnect')
    306374        elif self._current_state == _GSM_STATE_CONNECTED:
    307375            self.emit('gsm-disconnect')
    308         elif self._current_state == _GSM_STATE_NEED_AUTH:
    309             self.emit('gsm-disconnect')
    310376        else:
    311377            raise ValueError('Invalid GSM state while emitting signal, %s' % \
    312378                             str(self._current_state))
    313 
     379           
    314380
    315381class WirelessDeviceView(ToolButton):
    316382
    class GsmDeviceView(TrayIcon): 
    747813                                      signal_name='PppStats',
    748814                                      path=self._device.object_path,
    749815                                      dbus_interface=_NM_SERIAL_IFACE)
     816       
    750817    def create_palette(self):
    751818        palette = GsmPalette()
    752819
    class GsmDeviceView(TrayIcon): 
    774841                                        '/',
    775842                                        reply_handler=self.__connect_cb,
    776843                                        error_handler=self.__connect_error_cb)
     844        else:
     845            self._palette.add_alert(_('Connection Error'), \
     846                                    _('There is no gsm connection available'))
    777847
    778848    def __connect_cb(self, active_connection):
    779849        logging.debug('Connected successfully to gsm device, %s',
    class GsmDeviceView(TrayIcon): 
    807877
    808878    def __state_changed_cb(self, new_state, old_state, reason):
    809879        logging.debug('State: %s to %s, reason %s', old_state, new_state, reason)
    810         self._update_state(int(new_state))
     880        self._update_state(int(new_state), int(old_state), int(reason))
    811881
    812882    def __current_state_check_cb(self, properties):
    813         self._update_state(int(properties['State']))
     883        self._update_state(int(properties['State']), 0, 0)
    814884
    815885    def __current_state_check_error_cb(self, error):
    816886        raise RuntimeError('Error when checking gsm device state, %s' % error)
    817887
    818     def _update_state(self, state):
     888    def _update_state(self, state, old_state, reason):
    819889        gsm_state = None
    820890
    821891        if state is network.DEVICE_STATE_ACTIVATED:
    class GsmDeviceView(TrayIcon): 
    823893            connection = network.find_gsm_connection()
    824894            if connection is not None:
    825895                connection.set_connected()
    826                 self._connection_timestamp =  time.time() - \
     896                self._connection_timestamp = time.time() - \
    827897                        connection.get_settings().connection.timestamp
    828898                self._connection_time_handler = gobject.timeout_add_seconds( \
    829899                        1, self.__connection_timecount_cb)
    830                 self._update_stats(0, 0)
    831                 self._update_connection_time()               
    832                 self._palette.info_box.show()
     900                self._palette.update_connection_time()               
     901                self._palette.update_stats(0, 0)
     902                if self._palette is not None:     
     903                    self._palette.connection_info_box.show()
    833904
    834905        elif state is network.DEVICE_STATE_DISCONNECTED:
    835906            gsm_state = _GSM_STATE_DISCONNECTED
    836907            self._connection_timestamp = 0
    837908            if self._connection_time_handler is not None:
    838909                gobject.source_remove(self._connection_time_handler)
    839             self._palette.info_box.hide()
     910            if self._palette is not None:
     911                self._palette.connection_info_box.hide()
    840912
    841913        elif state in [network.DEVICE_STATE_UNMANAGED,
    842914                       network.DEVICE_STATE_UNAVAILABLE,
    class GsmDeviceView(TrayIcon): 
    845917
    846918        elif state in [network.DEVICE_STATE_PREPARE,
    847919                       network.DEVICE_STATE_CONFIG,
    848                        network.DEVICE_STATE_IP_CONFIG]:
     920                       network.DEVICE_STATE_IP_CONFIG,
     921                       network.DEVICE_STATE_NEED_AUTH]:
    849922            gsm_state = _GSM_STATE_CONNECTING
    850            
    851         elif state in [network.DEVICE_STATE_NEED_AUTH]:
    852             gsm_state = _GSM_STATE_NEED_AUTH
     923
     924        elif state == network.DEVICE_STATE_FAILED:
     925            gsm_state = _GSM_STATE_FAILED
    853926           
    854927        if self._palette is not None:
    855             self._palette.set_state(gsm_state)
     928            self._palette.set_state(gsm_state, reason)
    856929
    857930    def disconnect(self):
    858931        self._bus.remove_signal_receiver(self.__state_changed_cb,
    class GsmDeviceView(TrayIcon): 
    861934                                         dbus_interface=_NM_DEVICE_IFACE)
    862935
    863936    def __ppp_stats_changed_cb(self, in_bytes, out_bytes):
    864         self._update_stats(in_bytes, out_bytes)
    865 
    866     def _update_stats(self, in_bytes, out_bytes):
    867         in_KBytes = in_bytes / 1024
    868         out_KBytes = out_bytes / 1024
    869         text = _("Data sent %d KB / received %d KB") % (out_KBytes, in_KBytes)
    870         self._palette.data_label.set_text(text)
     937        self._palette.update_stats(in_bytes, out_bytes)
    871938
    872939    def __connection_timecount_cb(self):
    873940        self._connection_timestamp = self._connection_timestamp + 1
    874         self._update_connection_time()
     941        connection_time = \
     942            datetime.datetime.fromtimestamp(self._connection_timestamp)
     943        self._palette.update_connection_time(connection_time)
    875944        return True
    876945
    877     def _update_connection_time(self):
    878         connection_time = datetime.datetime.fromtimestamp( \
    879                 self._connection_timestamp)
    880         text = _("Connection time ") + connection_time.strftime('%H : %M : %S')
    881         self._palette.connection_time_label.set_text(text)
    882946
     947   
    883948class WirelessDeviceObserver(object):
    884949    def __init__(self, device, tray, device_type):
    885950        self._device = device
    class WiredDeviceObserver(object): 
    9501015                del self._device_view
    9511016                self._device_view = None
    9521017
     1018
    9531019class GsmDeviceObserver(object):
    9541020    def __init__(self, device, tray):
    9551021        self._device = device
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 3a949da..579ed8d 100644
    a b NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0 
    5454NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1
    5555NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2
    5656
     57NM_DEVICE_STATE_REASON_NO_SECRETS = 7
     58NM_DEVICE_STATE_REASON_PPP_DISCONNECT = 13
     59NM_DEVICE_STATE_REASON_PPP_FAILED = 14
     60NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER = 25
     61NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT = 26
     62NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED = 34
     63
    5764NM_802_11_AP_FLAGS_NONE = 0x00000000
    5865NM_802_11_AP_FLAGS_PRIVACY = 0x00000001
    5966
    class NMSettingsConnection(dbus.service.Object): 
    444451    def GetSecrets(self, setting_name, hints, request_new, reply, error):
    445452        logging.debug('Secrets requested for connection %s request_new=%s',
    446453            self.path, request_new)
    447         if request_new or self._secrets is None:
    448             # request_new is for example the case when the pw on the AP changes
    449             response = SecretsResponse(self, reply, error)
    450             try:
    451                 self.secrets_request.send(self, response=response)
    452             except Exception:
    453                 logging.exception('Error requesting the secrets via dialog')
    454         else:
    455             reply(self._secrets.get_dict())
    456 
    457 
     454        if self._settings.connection.type is not 'gsm':
     455                if request_new or self._secrets is None:
     456                    # request_new is for example the case when the pw on the AP changes
     457                    response = SecretsResponse(self, reply, error)
     458                    try:
     459                        self.secrets_request.send(self, response=response)
     460                    except Exception:
     461                        logging.exception('Error requesting the secrets via dialog')
     462                else:
     463                    reply(self._secrets.get_dict())
     464        else:
     465                if not request_new:
     466                    reply(self._secrets.get_dict())
     467                else:
     468                    raise Exception('The stored GSM secret has already been supplied ')
     469                   
    458470class AccessPoint(gobject.GObject):
    459471    __gsignals__ = {
    460472        'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,