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
|
|
17 | 17 | import gconf |
18 | 18 | |
19 | 19 | from 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 |
21 | 22 | |
22 | 23 | def get_username(): |
23 | 24 | client = gconf.client_get_default() |
… |
… |
def get_apn(): |
35 | 36 | client = gconf.client_get_default() |
36 | 37 | return client.get_string(GSM_APN_PATH) or '' |
37 | 38 | |
| 39 | def get_pin(): |
| 40 | client = gconf.client_get_default() |
| 41 | return client.get_string(GSM_PIN_PATH) or '' |
| 42 | |
| 43 | def get_puk(): |
| 44 | client = gconf.client_get_default() |
| 45 | return client.get_string(GSM_PUK_PATH) or '' |
| 46 | |
38 | 47 | def set_username(username): |
39 | 48 | client = gconf.client_get_default() |
40 | 49 | client.set_string(GSM_USERNAME_PATH, username) |
… |
… |
def set_apn(apn): |
51 | 60 | client = gconf.client_get_default() |
52 | 61 | client.set_string(GSM_APN_PATH, apn) |
53 | 62 | |
| 63 | def set_pin(pin): |
| 64 | client = gconf.client_get_default() |
| 65 | client.set_string(GSM_PIN_PATH, pin) |
| 66 | |
| 67 | def set_puk(puk): |
| 68 | client = gconf.client_get_default() |
| 69 | client.set_string(GSM_PUK_PATH, puk) |
| 70 | |
diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py
index d66f1d5..2445005 100644
a
|
b
|
class UsernameEntry(EntryWithLabel): |
94 | 94 | return self._model.get_username() |
95 | 95 | |
96 | 96 | def set_value(self, username): |
97 | | return self._model.set_username(username) |
| 97 | self._model.set_username(username) |
98 | 98 | |
99 | 99 | class PasswordEntry(EntryWithLabel): |
100 | 100 | def __init__(self, model): |
… |
… |
class PasswordEntry(EntryWithLabel): |
105 | 105 | return self._model.get_password() |
106 | 106 | |
107 | 107 | def set_value(self, password): |
108 | | return self._model.set_password(password) |
| 108 | self._model.set_password(password) |
109 | 109 | |
110 | 110 | class NumberEntry(EntryWithLabel): |
111 | 111 | def __init__(self, model): |
… |
… |
class NumberEntry(EntryWithLabel): |
116 | 116 | return self._model.get_number() |
117 | 117 | |
118 | 118 | def set_value(self, number): |
119 | | return self._model.set_number(number) |
| 119 | self._model.set_number(number) |
120 | 120 | |
121 | 121 | class ApnEntry(EntryWithLabel): |
122 | 122 | def __init__(self, model): |
… |
… |
class ApnEntry(EntryWithLabel): |
127 | 127 | return self._model.get_apn() |
128 | 128 | |
129 | 129 | def set_value(self, apn): |
130 | | return self._model.set_apn(apn) |
| 130 | self._model.set_apn(apn) |
| 131 | |
| 132 | class 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 | |
| 143 | class 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 | |
131 | 154 | |
132 | 155 | class ModemConfiguration(SectionView): |
133 | 156 | def __init__(self, model, alerts=None): |
… |
… |
class ModemConfiguration(SectionView): |
163 | 186 | self.pack_start(self._apn_entry, expand=False) |
164 | 187 | self._apn_entry.show() |
165 | 188 | |
| 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 | |
166 | 201 | self.setup() |
167 | 202 | |
168 | 203 | def setup(self): |
… |
… |
class ModemConfiguration(SectionView): |
170 | 205 | self._password_entry.set_text_from_model() |
171 | 206 | self._number_entry.set_text_from_model() |
172 | 207 | self._apn_entry.set_text_from_model() |
| 208 | self._pin_entry.set_text_from_model() |
| 209 | self._puk_entry.set_text_from_model() |
173 | 210 | |
174 | 211 | self.needs_restart = False |
175 | 212 | |
… |
… |
class ModemConfiguration(SectionView): |
180 | 217 | if self._username_entry.is_valid and \ |
181 | 218 | self._password_entry.is_valid and \ |
182 | 219 | 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 |
185 | 224 | else: |
186 | 225 | self.props.is_valid = False |
187 | 226 | |
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 04b38fd..519a7c9 100644
a
|
b
|
_GSM_STATE_NOT_READY = 0 |
62 | 62 | _GSM_STATE_DISCONNECTED = 1 |
63 | 63 | _GSM_STATE_CONNECTING = 2 |
64 | 64 | _GSM_STATE_CONNECTED = 3 |
| 65 | _GSM_STATE_NEED_AUTH = 4 |
65 | 66 | |
66 | 67 | def frequency_to_channel(frequency): |
67 | 68 | ftoc = { 2412: 1, 2417: 2, 2422: 3, 2427: 4, |
… |
… |
class GsmPalette(Palette): |
284 | 285 | elif self._current_state == _GSM_STATE_CONNECTED: |
285 | 286 | self._toggle_state_item.get_child().set_label(_('Disconnect')) |
286 | 287 | 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 | |
287 | 293 | else: |
288 | 294 | raise ValueError('Invalid GSM state while updating label and ' \ |
289 | 295 | 'text, %s' % str(self._current_state)) |
… |
… |
class GsmPalette(Palette): |
297 | 303 | self.emit('gsm-disconnect') |
298 | 304 | elif self._current_state == _GSM_STATE_CONNECTED: |
299 | 305 | self.emit('gsm-disconnect') |
| 306 | elif self._current_state == _GSM_STATE_NEED_AUTH: |
| 307 | self.emit('gsm-disconnect') |
300 | 308 | else: |
301 | 309 | raise ValueError('Invalid GSM state while emitting signal, %s' % \ |
302 | 310 | str(self._current_state)) |
… |
… |
class GsmDeviceView(TrayIcon): |
795 | 803 | raise RuntimeError('Error when disconnecting gsm device, %s' % error) |
796 | 804 | |
797 | 805 | def __state_changed_cb(self, new_state, old_state, reason): |
| 806 | logging.debug('State: %s to %s, reason %s', old_state, new_state, reason) |
798 | 807 | self._update_state(int(new_state)) |
799 | 808 | |
800 | 809 | def __current_state_check_cb(self, properties): |
… |
… |
class GsmDeviceView(TrayIcon): |
833 | 842 | network.DEVICE_STATE_CONFIG, |
834 | 843 | network.DEVICE_STATE_IP_CONFIG]: |
835 | 844 | gsm_state = _GSM_STATE_CONNECTING |
836 | | |
| 845 | |
| 846 | elif state in [network.DEVICE_STATE_NEED_AUTH]: |
| 847 | gsm_state = _GSM_STATE_NEED_AUTH |
| 848 | |
837 | 849 | if self._palette is not None: |
838 | 850 | self._palette.set_state(gsm_state) |
839 | 851 | |
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' |
92 | 92 | GSM_PASSWORD_PATH = '/sugar/network/gsm/password' |
93 | 93 | GSM_NUMBER_PATH = '/sugar/network/gsm/number' |
94 | 94 | GSM_APN_PATH = '/sugar/network/gsm/apn' |
| 95 | GSM_PIN_PATH = '/sugar/network/gsm/pin' |
| 96 | GSM_PUK_PATH = '/sugar/network/gsm/puk' |
95 | 97 | |
96 | 98 | _nm_settings = None |
97 | 99 | _conn_counter = 0 |
… |
… |
class SettingsGsm(object): |
287 | 289 | class SecretsGsm(object): |
288 | 290 | def __init__(self): |
289 | 291 | self.password = None |
290 | | |
| 292 | self.pin = None |
| 293 | self.puk = None |
| 294 | |
291 | 295 | def get_dict(self): |
292 | 296 | secrets = {} |
293 | 297 | if self.password is not None: |
294 | 298 | 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 |
295 | 303 | return {'gsm': secrets} |
296 | 304 | |
297 | 305 | class NMSettings(dbus.service.Object): |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
435 | 443 | def GetSecrets(self, setting_name, hints, request_new, reply, error): |
436 | 444 | logging.debug('Secrets requested for connection %s request_new=%s', |
437 | 445 | self.path, request_new) |
438 | | |
439 | 446 | if request_new or self._secrets is None: |
440 | 447 | # request_new is for example the case when the pw on the AP changes |
441 | 448 | response = SecretsResponse(self, reply, error) |
… |
… |
def load_wifi_connections(): |
651 | 658 | |
652 | 659 | |
653 | 660 | def load_gsm_connection(): |
654 | | settings = SettingsGsm() |
655 | | secrets = SecretsGsm() |
656 | | |
657 | 661 | client = gconf.client_get_default() |
| 662 | |
| 663 | settings = SettingsGsm() |
658 | 664 | settings.gsm.username = client.get_string(GSM_USERNAME_PATH) or '' |
659 | 665 | settings.gsm.number = client.get_string(GSM_NUMBER_PATH) or '' |
660 | 666 | settings.gsm.apn = client.get_string(GSM_APN_PATH) or '' |
661 | 667 | password = client.get_string(GSM_PASSWORD_PATH) or '' |
662 | 668 | |
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 |
665 | 673 | |
666 | 674 | settings.connection.id = 'gsm' |
667 | 675 | settings.connection.type = NM_CONNECTION_TYPE_GSM |