Ticket #1654: 0002-Pin-Puk-Configuration.patch

File 0002-Pin-Puk-Configuration.patch, 10.1 KB (added by Dcastelo, 14 years ago)
  • extensions/cpsection/modemconfiguration/model.py

    From c2ac7c8f6b909f7333c21b4da38937d03060116a Mon Sep 17 00:00:00 2001
    From: latu <latu@localhost.localdomain>
    Date: Thu, 11 Feb 2010 10:43:52 -0200
    Subject: [PATCH 2/2] Pin Puk Configuration
    
    ---
     extensions/cpsection/modemconfiguration/model.py |   19 ++++++++-
     extensions/cpsection/modemconfiguration/view.py  |   51 +++++++++++++++++++---
     extensions/deviceicon/network.py                 |   14 ++++++-
     src/jarabe/model/network.py                      |   22 ++++++---
     4 files changed, 91 insertions(+), 15 deletions(-)
     mode change 100644 => 100755 extensions/cpsection/modemconfiguration/model.py
    
    diff --git a/extensions/cpsection/modemconfiguration/model.py b/extensions/cpsection/modemconfiguration/model.py
    old mode 100644
    new mode 100755
    index f96e88f..2545ce1
    a b  
    1717import gconf
    1818
    1919from jarabe.model.network import GSM_USERNAME_PATH, GSM_PASSWORD_PATH, \
    20                                  GSM_NUMBER_PATH, GSM_APN_PATH
     20                                 GSM_NUMBER_PATH, GSM_APN_PATH, GSM_PIN_PATH, \
     21                                 GSM_PUK_PATH
    2122
    2223def get_username():
    2324    client = gconf.client_get_default()
    def get_apn(): 
    3536    client = gconf.client_get_default()
    3637    return client.get_string(GSM_APN_PATH) or ''
    3738
     39def get_pin():
     40    client = gconf.client_get_default()
     41    return client.get_string(GSM_PIN_PATH) or ''
     42
     43def get_puk():
     44    client = gconf.client_get_default()
     45    return client.get_string(GSM_PUK_PATH) or ''
     46
    3847def set_username(username):
    3948    client = gconf.client_get_default()
    4049    client.set_string(GSM_USERNAME_PATH, username)
    def set_apn(apn): 
    5160    client = gconf.client_get_default()
    5261    client.set_string(GSM_APN_PATH, apn)
    5362
     63def set_pin(pin):
     64    client = gconf.client_get_default()
     65    client.set_string(GSM_PIN_PATH, pin)
     66
     67def set_puk(puk):
     68    client = gconf.client_get_default()
     69    client.set_string(GSM_PUK_PATH, puk)
     70
  • extensions/cpsection/modemconfiguration/view.py

    diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py
    index d66f1d5..2445005 100644
    a b class UsernameEntry(EntryWithLabel): 
    9494        return self._model.get_username()
    9595
    9696    def set_value(self, username):
    97         return self._model.set_username(username)
     97        self._model.set_username(username)
    9898
    9999class PasswordEntry(EntryWithLabel):
    100100    def __init__(self, model):
    class PasswordEntry(EntryWithLabel): 
    105105        return self._model.get_password()
    106106
    107107    def set_value(self, password):
    108         return self._model.set_password(password)
     108        self._model.set_password(password)
    109109
    110110class NumberEntry(EntryWithLabel):
    111111    def __init__(self, model):
    class NumberEntry(EntryWithLabel): 
    116116        return self._model.get_number()
    117117
    118118    def set_value(self, number):
    119         return self._model.set_number(number)
     119        self._model.set_number(number)
    120120
    121121class ApnEntry(EntryWithLabel):
    122122    def __init__(self, model):
    class ApnEntry(EntryWithLabel): 
    127127        return self._model.get_apn()
    128128
    129129    def set_value(self, apn):
    130         return self._model.set_apn(apn)
     130        self._model.set_apn(apn)
     131
     132class PinEntry(EntryWithLabel):
     133    def __init__(self, model):
     134        EntryWithLabel.__init__(self, _('PIN:'))
     135        self._model = model
     136
     137    def get_value(self):
     138        return self._model.get_pin()
     139
     140    def set_value(self, pin):
     141        self._model.set_pin(pin)
     142
     143class PukEntry(EntryWithLabel):
     144    def __init__(self, model):
     145        EntryWithLabel.__init__(self, _('PUK:'))
     146        self._model = model
     147
     148    def get_value(self):
     149        return self._model.get_puk()
     150
     151    def set_value(self, puk):
     152        self._model.set_puk(puk)
     153
    131154
    132155class ModemConfiguration(SectionView):
    133156    def __init__(self, model, alerts=None):
    class ModemConfiguration(SectionView): 
    163186        self.pack_start(self._apn_entry, expand=False)
    164187        self._apn_entry.show()
    165188
     189        self._pin_entry = PinEntry(model)
     190        self._pin_entry.connect('notify::is-valid',
     191                                self.__notify_is_valid_cb)
     192        self.pack_start(self._pin_entry, expand=False)
     193        self._pin_entry.show()
     194       
     195        self._puk_entry = PukEntry(model)
     196        self._puk_entry.connect('notify::is-valid',
     197                                self.__notify_is_valid_cb)
     198        self.pack_start(self._puk_entry, expand=False)       
     199        self._puk_entry.show()
     200
    166201        self.setup()
    167202
    168203    def setup(self):
    class ModemConfiguration(SectionView): 
    170205        self._password_entry.set_text_from_model()
    171206        self._number_entry.set_text_from_model()
    172207        self._apn_entry.set_text_from_model()
     208        self._pin_entry.set_text_from_model()
     209        self._puk_entry.set_text_from_model()
    173210
    174211        self.needs_restart = False
    175212
    class ModemConfiguration(SectionView): 
    180217        if self._username_entry.is_valid and \
    181218            self._password_entry.is_valid and \
    182219                self._number_entry.is_valid and \
    183                     self._apn_entry.is_valid:
    184                         self.props.is_valid = True
     220                    self._apn_entry.is_valid and \
     221                        self._pin_entry.is_valid and \
     222                            self._puk_entry.is_valid:
     223                                self.props.is_valid = True
    185224        else:
    186225            self.props.is_valid = False
    187226
  • extensions/deviceicon/network.py

    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 04b38fd..519a7c9 100644
    a b _GSM_STATE_NOT_READY = 0 
    6262_GSM_STATE_DISCONNECTED = 1
    6363_GSM_STATE_CONNECTING = 2
    6464_GSM_STATE_CONNECTED = 3
     65_GSM_STATE_NEED_AUTH = 4
    6566
    6667def frequency_to_channel(frequency):
    6768    ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4,
    class GsmPalette(Palette): 
    284285        elif self._current_state == _GSM_STATE_CONNECTED:
    285286            self._toggle_state_item.get_child().set_label(_('Disconnect'))
    286287            self.props.secondary_text = _('Connected')
     288           
     289        elif self._current_state == _GSM_STATE_NEED_AUTH:
     290            self._toggle_state_item.get_child().set_label(_('Sim requires Pin/Puk'))
     291            self.props.secondary_text = _('Authentication Error')
     292           
    287293        else:
    288294            raise ValueError('Invalid GSM state while updating label and ' \
    289295                             'text, %s' % str(self._current_state))
    class GsmPalette(Palette): 
    297303            self.emit('gsm-disconnect')
    298304        elif self._current_state == _GSM_STATE_CONNECTED:
    299305            self.emit('gsm-disconnect')
     306        elif self._current_state == _GSM_STATE_NEED_AUTH:
     307            self.emit('gsm-disconnect')
    300308        else:
    301309            raise ValueError('Invalid GSM state while emitting signal, %s' % \
    302310                             str(self._current_state))
    class GsmDeviceView(TrayIcon): 
    795803        raise RuntimeError('Error when disconnecting gsm device, %s' % error)
    796804
    797805    def __state_changed_cb(self, new_state, old_state, reason):
     806        logging.debug('State: %s to %s, reason %s', old_state, new_state, reason)
    798807        self._update_state(int(new_state))
    799808
    800809    def __current_state_check_cb(self, properties):
    class GsmDeviceView(TrayIcon): 
    833842                       network.DEVICE_STATE_CONFIG,
    834843                       network.DEVICE_STATE_IP_CONFIG]:
    835844            gsm_state = _GSM_STATE_CONNECTING
    836 
     845           
     846        elif state in [network.DEVICE_STATE_NEED_AUTH]:
     847            gsm_state = _GSM_STATE_NEED_AUTH
     848           
    837849        if self._palette is not None:
    838850            self._palette.set_state(gsm_state)
    839851
  • src/jarabe/model/network.py

    diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
    index 00db4e7..bab67e4 100644
    a b GSM_USERNAME_PATH = '/sugar/network/gsm/username' 
    9292GSM_PASSWORD_PATH = '/sugar/network/gsm/password'
    9393GSM_NUMBER_PATH = '/sugar/network/gsm/number'
    9494GSM_APN_PATH = '/sugar/network/gsm/apn'
     95GSM_PIN_PATH = '/sugar/network/gsm/pin'
     96GSM_PUK_PATH = '/sugar/network/gsm/puk'
    9597
    9698_nm_settings = None
    9799_conn_counter = 0
    class SettingsGsm(object): 
    287289class SecretsGsm(object):
    288290    def __init__(self):
    289291        self.password = None
    290 
     292        self.pin = None
     293        self.puk = None
     294       
    291295    def get_dict(self):
    292296        secrets = {}
    293297        if self.password is not None:
    294298            secrets['password'] = self.password
     299        if self.pin is not None:
     300            secrets['pin'] = self.pin
     301        if self.puk is not None:   
     302            secrets['puk'] = self.puk
    295303        return {'gsm': secrets}
    296304
    297305class NMSettings(dbus.service.Object):
    class NMSettingsConnection(dbus.service.Object): 
    435443    def GetSecrets(self, setting_name, hints, request_new, reply, error):
    436444        logging.debug('Secrets requested for connection %s request_new=%s',
    437445            self.path, request_new)
    438 
    439446        if request_new or self._secrets is None:
    440447            # request_new is for example the case when the pw on the AP changes
    441448            response = SecretsResponse(self, reply, error)
    def load_wifi_connections(): 
    651658
    652659
    653660def load_gsm_connection():
    654     settings = SettingsGsm()
    655     secrets = SecretsGsm()
    656 
    657661    client = gconf.client_get_default()
     662
     663    settings = SettingsGsm()
    658664    settings.gsm.username = client.get_string(GSM_USERNAME_PATH) or ''
    659665    settings.gsm.number = client.get_string(GSM_NUMBER_PATH) or ''
    660666    settings.gsm.apn = client.get_string(GSM_APN_PATH) or ''
    661667    password = client.get_string(GSM_PASSWORD_PATH) or ''
    662668
    663     if password:
    664         secrets.password = password
     669    secrets = SecretsGsm()
     670    secrets.pin = client.get_string(GSM_PIN_PATH) or ''
     671    secrets.puk = client.get_string(GSM_PUK_PATH) or ''
     672    secrets.password = password
    665673
    666674    settings.connection.id = 'gsm'
    667675    settings.connection.type = NM_CONNECTION_TYPE_GSM