Ticket #1759: Showing-Errors-Pallete-Mockup V3.patch

File Showing-Errors-Pallete-Mockup V3.patch, 16.6 KB (added by Dcastelo, 10 years ago)

Minor changes: Change "up-down" icons

  • extensions/deviceicon/network.py

    From c13e9698aa65c7db10399ecfec3d8bd80b646188 Mon Sep 17 00:00:00 2001
    From: latu <latu@localhost.localdomain>
    Date: Tue, 9 Mar 2010 13:43:39 -0200
    Subject: [PATCH] Showing Errors-Pallete Mockup
    
    ---
     extensions/deviceicon/network.py |  183 ++++++++++++++++++++++++++------------
     src/jarabe/model/network.py      |   34 +++++---
     2 files changed, 148 insertions(+), 69 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 94a4293..210dae7 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='data-upload', 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='data-download', 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()
     263       
     264        self.info_box.pack_start(self.connection_info_box)
    256265
     266        self._error_accept_item = MenuItem('')
     267        self._error_accept_item.connect('activate', self.__error_accept_cb)
     268        self.menu.append(self._error_accept_item)
     269       
    257270        self.info_box.show()
    258271        self.set_content(self.info_box)
    259272
     273        self.set_state(_GSM_STATE_NOT_READY)
     274
    260275    def _add_widget_with_padding(self, child, xalign=0, yalign=0.5):
    261276        alignment = gtk.Alignment(xalign=xalign, yalign=yalign,
    262277                                  xscale=1, yscale=0.33)
    class GsmPalette(Palette): 
    267282        alignment.add(child)
    268283        return alignment
    269284
    270     def set_state(self, state):
     285    def set_state(self, state, reason=0):
    271286        self._current_state = state
    272         self._update_label_and_text()
     287        self._update_label_and_text(reason)
    273288
    274     def _update_label_and_text(self):
     289    def _update_label_and_text(self, reason=0):
     290       
    275291        if self._current_state == _GSM_STATE_NOT_READY:
    276292            self._toggle_state_item.get_child().set_label('...')
    277293            self.props.secondary_text = _('Please wait...')
    278 
     294   
    279295        elif self._current_state == _GSM_STATE_DISCONNECTED:
    280296            self._toggle_state_item.get_child().set_label(_('Connect'))
    281             self.props.secondary_text = _('Disconnected')
    282 
     297            if not self._alert:
     298                self.props.secondary_text = _('Disconnected')
     299            icon = Icon(icon_name='media-playback-start', \
     300                        icon_size=gtk.ICON_SIZE_MENU)
     301            self._toggle_state_item.set_image(icon)
     302         
    283303        elif self._current_state == _GSM_STATE_CONNECTING:
    284304            self._toggle_state_item.get_child().set_label(_('Cancel'))
    285305            self.props.secondary_text = _('Connecting...')
     306            icon = Icon(icon_name='media-playback-stop', \
     307                        icon_size=gtk.ICON_SIZE_MENU)
     308            self._toggle_state_item.set_image(icon)           
    286309
    287310        elif self._current_state == _GSM_STATE_CONNECTED:
    288311            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')
     312            self.update_connection_time()
     313            icon = Icon(icon_name='media-eject', \
     314                        icon_size=gtk.ICON_SIZE_MENU)
     315            self._toggle_state_item.set_image(icon)
     316                       
     317        elif self._current_state == _GSM_STATE_FAILED:
     318            self.add_alert(_('Connection Error'), \
     319                            self._get_error_by_nm_reason(reason))
    294320           
    295321        else:
    296322            raise ValueError('Invalid GSM state while updating label and ' \
    297323                             'text, %s' % str(self._current_state))
    298 
     324   
     325    def add_alert(self, title, message):
     326        self._alert = True
     327        self.props.secondary_text = title
     328        self._error_accept_item.get_child().set_label(message)
     329        self._error_accept_item.show()
     330        self._toggle_state_item.set_sensitive(False)
     331       
     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        self._full_request = [0, 0]
     340                       
     341    def update_connection_time(self, connection_time=None):
     342        if (connection_time is not None):
     343            self.props.secondary_text = _('Connected for ' + \
     344                                      connection_time.strftime('%H:%M:%S'))
     345        else:
     346            self.props.secondary_text = _('Connected for ' \
     347                                          + '00:00:00')
     348             
     349    def update_stats(self, in_bytes, out_bytes):
     350        in_KBytes = in_bytes / 1024
     351        out_KBytes = out_bytes / 1024
     352        self._data_label_up.set_text(_("%d KB") % (out_KBytes))
     353        self._data_label_down.set_text(_("%d KB") % (in_KBytes))
     354       
     355    def _get_error_by_nm_reason(self, reason):
     356        if reason in [network.NM_DEVICE_STATE_REASON_NO_SECRETS, network.NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED]:
     357            message = _('The Pin/Puk configuration is not valid.')
     358        elif reason in [network.NM_DEVICE_STATE_REASON_PPP_DISCONNECT, network.NM_DEVICE_STATE_REASON_PPP_FAILED]:
     359            message = _('Check the APN configuration.')
     360        elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER]:
     361            message = _('Check the tel number configuration.')
     362        elif reason in [network.NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT]:
     363            message = _('Time out. Check the tel configuration')
     364        else:
     365            message = _('Unexpected error.')
     366        return message
     367   
    299368    def __toggle_state_cb(self, menuitem):
    300369        if self._current_state == _GSM_STATE_NOT_READY:
    301370            pass
    class GsmPalette(Palette): 
    305374            self.emit('gsm-disconnect')
    306375        elif self._current_state == _GSM_STATE_CONNECTED:
    307376            self.emit('gsm-disconnect')
    308         elif self._current_state == _GSM_STATE_NEED_AUTH:
    309             self.emit('gsm-disconnect')
    310377        else:
    311378            raise ValueError('Invalid GSM state while emitting signal, %s' % \
    312379                             str(self._current_state))
    313 
     380           
    314381
    315382class WirelessDeviceView(ToolButton):
    316383
    class GsmDeviceView(TrayIcon): 
    747814                                      signal_name='PppStats',
    748815                                      path=self._device.object_path,
    749816                                      dbus_interface=_NM_SERIAL_IFACE)
     817       
    750818    def create_palette(self):
    751819        palette = GsmPalette()
    752820
    class GsmDeviceView(TrayIcon): 
    774842                                        '/',
    775843                                        reply_handler=self.__connect_cb,
    776844                                        error_handler=self.__connect_error_cb)
     845        else:
     846            self._palette.add_alert(_('Connection Error'), \
     847                                    _('There is no gsm connection available'))
    777848
    778849    def __connect_cb(self, active_connection):
    779850        logging.debug('Connected successfully to gsm device, %s',
    class GsmDeviceView(TrayIcon): 
    807878
    808879    def __state_changed_cb(self, new_state, old_state, reason):
    809880        logging.debug('State: %s to %s, reason %s', old_state, new_state, reason)
    810         self._update_state(int(new_state))
     881        self._update_state(int(new_state), int(old_state), int(reason))
    811882
    812883    def __current_state_check_cb(self, properties):
    813         self._update_state(int(properties['State']))
     884        self._update_state(int(properties['State']), 0, 0)
    814885
    815886    def __current_state_check_error_cb(self, error):
    816887        raise RuntimeError('Error when checking gsm device state, %s' % error)
    817888
    818     def _update_state(self, state):
     889    def _update_state(self, state, old_state, reason):
    819890        gsm_state = None
    820891
    821892        if state is network.DEVICE_STATE_ACTIVATED:
    class GsmDeviceView(TrayIcon): 
    823894            connection = network.find_gsm_connection()
    824895            if connection is not None:
    825896                connection.set_connected()
    826                 self._connection_timestamp =  time.time() - \
     897                self._connection_timestamp = time.time() - \
    827898                        connection.get_settings().connection.timestamp
    828899                self._connection_time_handler = gobject.timeout_add_seconds( \
    829900                        1, self.__connection_timecount_cb)
    830                 self._update_stats(0, 0)
    831                 self._update_connection_time()               
    832                 self._palette.info_box.show()
     901                self._palette.update_connection_time()               
     902                self._palette.update_stats(0, 0)
     903                if self._palette is not None:     
     904                    self._palette.connection_info_box.show()
    833905
    834906        elif state is network.DEVICE_STATE_DISCONNECTED:
    835907            gsm_state = _GSM_STATE_DISCONNECTED
    836908            self._connection_timestamp = 0
    837909            if self._connection_time_handler is not None:
    838910                gobject.source_remove(self._connection_time_handler)
    839             self._palette.info_box.hide()
     911            if self._palette is not None:
     912                self._palette.connection_info_box.hide()
    840913
    841914        elif state in [network.DEVICE_STATE_UNMANAGED,
    842915                       network.DEVICE_STATE_UNAVAILABLE,
    class GsmDeviceView(TrayIcon): 
    845918
    846919        elif state in [network.DEVICE_STATE_PREPARE,
    847920                       network.DEVICE_STATE_CONFIG,
    848                        network.DEVICE_STATE_IP_CONFIG]:
     921                       network.DEVICE_STATE_IP_CONFIG,
     922                       network.DEVICE_STATE_NEED_AUTH]:
    849923            gsm_state = _GSM_STATE_CONNECTING
    850            
    851         elif state in [network.DEVICE_STATE_NEED_AUTH]:
    852             gsm_state = _GSM_STATE_NEED_AUTH
     924
     925        elif state == network.DEVICE_STATE_FAILED:
     926            gsm_state = _GSM_STATE_FAILED
    853927           
    854928        if self._palette is not None:
    855             self._palette.set_state(gsm_state)
     929            self._palette.set_state(gsm_state, reason)
    856930
    857931    def disconnect(self):
    858932        self._bus.remove_signal_receiver(self.__state_changed_cb,
    class GsmDeviceView(TrayIcon): 
    861935                                         dbus_interface=_NM_DEVICE_IFACE)
    862936
    863937    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)
     938        self._palette.update_stats(in_bytes, out_bytes)
    871939
    872940    def __connection_timecount_cb(self):
    873941        self._connection_timestamp = self._connection_timestamp + 1
    874         self._update_connection_time()
     942        connection_time = \
     943            datetime.datetime.fromtimestamp(self._connection_timestamp)
     944        self._palette.update_connection_time(connection_time)
    875945        return True
    876946
    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)
    882947
     948   
    883949class WirelessDeviceObserver(object):
    884950    def __init__(self, device, tray, device_type):
    885951        self._device = device
    class WiredDeviceObserver(object): 
    9501016                del self._device_view
    9511017                self._device_view = None
    9521018
     1019
    9531020class GsmDeviceObserver(object):
    9541021    def __init__(self, device, tray):
    9551022        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,