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

File 0002-Showing-Errors-Palette-Mockup.patch, 17.7 KB (added by Dcastelo, 10 years ago)

Ebens Mockup for GSM Connection Palett. Improve feature to show connection errors

  • extensions/deviceicon/network.py

    From 834d8070102ffceae5b4e002a502257d784f25a7 Mon Sep 17 00:00:00 2001
    From: latu <latu@localhost.localdomain>
    Date: Fri, 26 Feb 2010 16:48:23 -0200
    Subject: [PATCH 2/2] Showing Errors - Palette Mockup
    
    ---
     extensions/deviceicon/network.py |  176 +++++++++++++++++++++++++-------------
     src/jarabe/model/network.py      |   70 +++++++++++++---
     2 files changed, 176 insertions(+), 70 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index fc72b6d..b4296d1 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
     44from sugar.graphics.alert import NotifyAlert
    4245
    4346from jarabe.model import network
    4447from jarabe.model.network import Settings
    _GSM_STATE_NOT_READY = 0 
    6366_GSM_STATE_DISCONNECTED = 1
    6467_GSM_STATE_CONNECTING = 2
    6568_GSM_STATE_CONNECTED = 3
    66 _GSM_STATE_NEED_AUTH = 4
     69_GSM_STATE_FAILED = 4
    6770
    6871def frequency_to_channel(frequency):
    6972    ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4,
    class WiredPalette(Palette): 
    214217            ip_address_text = ""
    215218        self._ip_address_label.set_text(ip_address_text)
    216219
     220
    217221class GsmPalette(Palette):
    218222    __gtype_name__ = 'SugarGsmPalette'
    219223
    class GsmPalette(Palette): 
    225229    }
    226230
    227231    def __init__(self):
    228 
     232       
    229233        Palette.__init__(self, label=_('Wireless modem'))
    230 
    231234        self._current_state = None
    232 
    233         self._toggle_state_item = gtk.MenuItem('')
     235        self._alert = None
     236       
     237        self._toggle_state_item = MenuItem('')
    234238        self._toggle_state_item.connect('activate', self.__toggle_state_cb)
    235239        self.menu.append(self._toggle_state_item)
    236240        self._toggle_state_item.show()
    237241
    238         self.set_state(_GSM_STATE_NOT_READY)
    239 
    240242        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()
     243        self.conn_info_box = gtk.HBox()
     244       
     245        icon = Icon(icon_name='go-up', icon_size=gtk.ICON_SIZE_MENU)
     246        self.conn_info_box.pack_start(icon)
     247        icon.show()
     248        self._data_label_up = gtk.Label()
     249        self._data_label_up.props.xalign = 0.0
     250        label_alignment = self._add_widget_with_padding(self._data_label_up)
     251        self.conn_info_box.pack_start(label_alignment)
     252        self._data_label_up.show()
    247253        label_alignment.show()
    248254
    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()
     255        icon = Icon(icon_name='go-down', icon_size=gtk.ICON_SIZE_MENU)
     256        self.conn_info_box.pack_start(icon)
     257        icon.show()
     258        self._data_label_down = gtk.Label()
     259        self._data_label_down.props.xalign = 0.0
     260        label_alignment = self._add_widget_with_padding(self._data_label_down)
     261        self.conn_info_box.pack_start(label_alignment)
     262        self._data_label_down.show()
    255263        label_alignment.show()
    256 
     264       
     265        self.conn_info_box.show()
     266        self.info_box.pack_start(self.conn_info_box)
     267
     268        self._error_accept_item = MenuItem('')
     269        self._error_accept_item.connect('activate', self.__error_accept_cb)
     270        self.menu.append(self._error_accept_item)
     271       
    257272        self.info_box.show()
    258273        self.set_content(self.info_box)
    259274
     275        self.set_state(_GSM_STATE_NOT_READY)
     276
    260277    def _add_widget_with_padding(self, child, xalign=0, yalign=0.5):
    261278        alignment = gtk.Alignment(xalign=xalign, yalign=yalign,
    262279                                  xscale=1, yscale=0.33)
    class GsmPalette(Palette): 
    267284        alignment.add(child)
    268285        return alignment
    269286
    270     def set_state(self, state):
     287    def set_state(self, state, reason=0):
    271288        self._current_state = state
    272         self._update_label_and_text()
     289        self._update_label_and_text(reason)
    273290
    274     def _update_label_and_text(self):
     291    def _update_label_and_text(self, reason=0):
     292       
    275293        if self._current_state == _GSM_STATE_NOT_READY:
    276294            self._toggle_state_item.get_child().set_label('...')
    277295            self.props.secondary_text = _('Please wait...')
    278 
     296   
    279297        elif self._current_state == _GSM_STATE_DISCONNECTED:
    280298            self._toggle_state_item.get_child().set_label(_('Connect'))
    281299            self.props.secondary_text = _('Disconnected')
    282 
     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(_('Error'), \
     320                            self._get_connection_errors_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._error_accept_item.get_child().set_label(title + ' : ' + message)
     328            self._error_accept_item.show()
     329            self._toggle_state_item.set_sensitive(False)
     330                     
     331    def __error_accept_cb(self, alert):
     332            self._update_label_and_text()
     333            self._error_accept_item.get_child().set_label('')
     334            self._error_accept_item.hide()
     335            self._toggle_state_item.set_sensitive(True)
     336                     
     337    def update_connection_time(self, connection_time=None):
     338        if (connection_time is not None):
     339            self.props.secondary_text = _('Connected for ' + \
     340                                      connection_time.strftime('%H:%M:%S'))
     341        else:
     342            self.props.secondary_text = _('Connected for ' \
     343                                          + '00:00:00')
     344             
     345    def update_stats(self, in_bytes, out_bytes):
     346        in_KBytes = in_bytes / 1024
     347        out_KBytes = out_bytes / 1024
     348        self._data_label_up.set_text(_("%d KB") % (out_KBytes))
     349        self._data_label_down.set_text(_("%d KB") % (in_KBytes))
     350       
     351    def _get_connection_errors_by_nm_reason(self, reason):
     352        if reason in [network.NM_DEVICE_STATE_REASON_NO_SECRETS]:
     353            message = _('The Pin/Puk configuration is not valid')
     354        elif reason in [network.NM_DEVICE_STATE_REASON_PPP_DISCONNECT]:
     355             message = _('Check the connection configuration')
     356        else:
     357            message = _('Check the connection configuration')
     358        return message
     359   
    299360    def __toggle_state_cb(self, menuitem):
    300361        if self._current_state == _GSM_STATE_NOT_READY:
    301362            pass
    class GsmPalette(Palette): 
    305366            self.emit('gsm-disconnect')
    306367        elif self._current_state == _GSM_STATE_CONNECTED:
    307368            self.emit('gsm-disconnect')
    308         elif self._current_state == _GSM_STATE_NEED_AUTH:
    309             self.emit('gsm-disconnect')
    310369        else:
    311370            raise ValueError('Invalid GSM state while emitting signal, %s' % \
    312371                             str(self._current_state))
    313 
     372           
    314373
    315374class WirelessDeviceView(ToolButton):
    316375
    class GsmDeviceView(TrayIcon): 
    747806                                      signal_name='PppStats',
    748807                                      path=self._device.object_path,
    749808                                      dbus_interface=_NM_SERIAL_IFACE)
     809       
    750810    def create_palette(self):
    751811        palette = GsmPalette()
    752812
    class GsmDeviceView(TrayIcon): 
    775835                                        reply_handler=self.__connect_cb,
    776836                                        error_handler=self.__connect_error_cb)
    777837        else:
    778             raise RuntimeError('There is no gsm connection available')
     838            self._palette.add_alert(_('Error'), \
     839                                    _('There is no gsm connection available'))
    779840
    780841    def __connect_cb(self, active_connection):
    781842        logging.debug('Connected successfully to gsm device, %s',
    class GsmDeviceView(TrayIcon): 
    809870
    810871    def __state_changed_cb(self, new_state, old_state, reason):
    811872        logging.debug('State: %s to %s, reason %s', old_state, new_state, reason)
    812         self._update_state(int(new_state))
     873        self._update_state(int(new_state), int(old_state), int(reason))
    813874
    814875    def __current_state_check_cb(self, properties):
    815         self._update_state(int(properties['State']))
     876        self._update_state(int(properties['State']), 0, 0)
    816877
    817878    def __current_state_check_error_cb(self, error):
    818879        raise RuntimeError('Error when checking gsm device state, %s' % error)
    819880
    820     def _update_state(self, state):
     881    def _update_state(self, state, old_state, reason):
    821882        gsm_state = None
    822883
    823884        if state is network.DEVICE_STATE_ACTIVATED:
    class GsmDeviceView(TrayIcon): 
    829890                        connection.get_settings().connection.timestamp
    830891                self._connection_time_handler = gobject.timeout_add_seconds( \
    831892                        1, self.__connection_timecount_cb)
    832                 self._update_stats(0, 0)
    833                 self._update_connection_time()               
    834                 self._palette.info_box.show()
     893                self._palette.update_connection_time()               
     894                self._palette.update_stats(0, 0)
     895                if self._palette is not None:     
     896                    self._palette.conn_info_box.show()
    835897
    836898        elif state is network.DEVICE_STATE_DISCONNECTED:
    837899            gsm_state = _GSM_STATE_DISCONNECTED
    838900            self._connection_timestamp = 0
    839901            if self._connection_time_handler is not None:
    840902                gobject.source_remove(self._connection_time_handler)
    841             self._palette.info_box.hide()
     903            if self._palette is not None:
     904                self._palette.conn_info_box.hide()
    842905
    843906        elif state in [network.DEVICE_STATE_UNMANAGED,
    844907                       network.DEVICE_STATE_UNAVAILABLE,
    class GsmDeviceView(TrayIcon): 
    847910
    848911        elif state in [network.DEVICE_STATE_PREPARE,
    849912                       network.DEVICE_STATE_CONFIG,
    850                        network.DEVICE_STATE_IP_CONFIG]:
     913                       network.DEVICE_STATE_IP_CONFIG,
     914                       network.DEVICE_STATE_NEED_AUTH]:
    851915            gsm_state = _GSM_STATE_CONNECTING
    852            
    853         elif state in [network.DEVICE_STATE_NEED_AUTH]:
    854             gsm_state = _GSM_STATE_NEED_AUTH
     916
     917        elif state == network.DEVICE_STATE_FAILED:
     918            gsm_state = _GSM_STATE_FAILED
    855919           
    856920        if self._palette is not None:
    857             self._palette.set_state(gsm_state)
     921            self._palette.set_state(gsm_state, reason)
    858922
    859923    def disconnect(self):
    860924        self._bus.remove_signal_receiver(self.__state_changed_cb,
    class GsmDeviceView(TrayIcon): 
    863927                                         dbus_interface=_NM_DEVICE_IFACE)
    864928
    865929    def __ppp_stats_changed_cb(self, in_bytes, out_bytes):
    866         self._update_stats(in_bytes, out_bytes)
     930        self._palette.update_stats(in_bytes, out_bytes)
    867931
    868     def _update_stats(self, in_bytes, out_bytes):
    869         in_KBytes = in_bytes / 1024
    870         out_KBytes = out_bytes / 1024
    871         text = _("Data sent %d KB / received %d KB") % (out_KBytes, in_KBytes)
    872         self._palette.data_label.set_text(text)
    873932
    874933    def __connection_timecount_cb(self):
    875934        self._connection_timestamp = self._connection_timestamp + 1
    876         self._update_connection_time()
     935        connection_time = \
     936            datetime.datetime.fromtimestamp(self._connection_timestamp)
     937        self._palette.update_connection_time(connection_time)
    877938        return True
    878939
    879     def _update_connection_time(self):
    880         connection_time = datetime.datetime.fromtimestamp( \
    881                 self._connection_timestamp)
    882         text = _("Connection time ") + connection_time.strftime('%H : %M : %S')
    883         self._palette.connection_time_label.set_text(text)
    884940
     941   
    885942class WirelessDeviceObserver(object):
    886943    def __init__(self, device, tray, device_type):
    887944        self._device = device
    class WiredDeviceObserver(object): 
    9521009                del self._device_view
    9531010                self._device_view = None
    9541011
     1012
    9551013class GsmDeviceObserver(object):
    9561014    def __init__(self, device, tray):
    9571015        self._device = device
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 03d48c4..9a32897 100644
    a b  
    1818# along with this program; if not, write to the Free Software
    1919# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2020
     21from gettext import gettext as _
    2122import logging
    2223import os
    2324import time
    NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0 
    5455NM_ACTIVE_CONNECTION_STATE_ACTIVATING = 1
    5556NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2
    5657
     58NM_DEVICE_STATE_REASON_UNKNOWN = 0
     59NM_DEVICE_STATE_REASON_NONE = 1
     60NM_DEVICE_STATE_REASON_NOW_MANAGED = 2
     61NM_DEVICE_STATE_REASON_NOW_UNMANAGED = 3
     62NM_DEVICE_STATE_REASON_CONFIG_FAILED = 4
     63NM_DEVICE_STATE_REASON_CONFIG_UNAVAILABLE = 5
     64NM_DEVICE_STATE_REASON_CONFIG_EXPIRED = 6
     65NM_DEVICE_STATE_REASON_NO_SECRETS = 7
     66NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT = 8
     67NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED = 9
     68NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED = 10
     69NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT = 11
     70NM_DEVICE_STATE_REASON_PPP_START_FAILED = 12
     71NM_DEVICE_STATE_REASON_PPP_DISCONNECT = 13
     72NM_DEVICE_STATE_REASON_PPP_FAILED = 14
     73NM_DEVICE_STATE_REASON_DHCP_START_FAILED = 15
     74NM_DEVICE_STATE_REASON_DHCP_ERROR = 16
     75NM_DEVICE_STATE_REASON_DHCP_FAILED = 17
     76NM_DEVICE_STATE_REASON_SHARED_START_FAILED = 18
     77NM_DEVICE_STATE_REASON_SHARED_FAILED = 19
     78NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED = 20
     79NM_DEVICE_STATE_REASON_AUTOIP_ERROR = 21
     80NM_DEVICE_STATE_REASON_AUTOIP_FAILED = 22
     81NM_DEVICE_STATE_REASON_MODEM_BUSY = 23
     82NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE = 24
     83NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER = 25
     84NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT = 26
     85NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED = 27
     86NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED = 28
     87NM_DEVICE_STATE_REASON_GSM_APN_FAILED = 29
     88NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING = 30
     89NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED = 31
     90NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT = 32
     91NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED = 33
     92NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED = 34
     93NM_DEVICE_STATE_REASON_FIRMWARE_MISSING = 35
     94NM_DEVICE_STATE_REASON_REMOVED = 36
     95NM_DEVICE_STATE_REASON_SLEEPING = 37
     96NM_DEVICE_STATE_REASON_CONNECTION_REMOVED = 38
     97NM_DEVICE_STATE_REASON_USER_REQUESTED = 39
     98NM_DEVICE_STATE_REASON_CARRIER = 40
     99
    57100NM_802_11_AP_FLAGS_NONE = 0x00000000
    58101NM_802_11_AP_FLAGS_PRIVACY = 0x00000001
    59102
    class NMSettingsConnection(dbus.service.Object): 
    444487    def GetSecrets(self, setting_name, hints, request_new, reply, error):
    445488        logging.debug('Secrets requested for connection %s request_new=%s',
    446489            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 
     490        if self._settings.connection.type is not 'gsm':
     491                if request_new or self._secrets is None:
     492                    # request_new is for example the case when the pw on the AP changes
     493                    response = SecretsResponse(self, reply, error)
     494                    try:
     495                        self.secrets_request.send(self, response=response)
     496                    except Exception:
     497                        logging.exception('Error requesting the secrets via dialog')
     498                else:
     499                    reply(self._secrets.get_dict())
     500        else:
     501                if not request_new:
     502                     reply(self._secrets.get_dict())
     503                else:
     504                    raise Exception('The stored GSM secret has already been supplied ')
     505                   
    458506class AccessPoint(gobject.GObject):
    459507    __gsignals__ = {
    460508        'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,