Ticket #1630: gsm-provider-db-v4-1630.patch
File gsm-provider-db-v4-1630.patch, 20.1 KB (added by aa, 14 years ago) |
---|
-
configure.ac
diff --git a/configure.ac b/configure.ac index fb38cad..f3fa6c0 100644
a b extensions/cpsection/frame/Makefile 56 56 extensions/cpsection/keyboard/Makefile 57 57 extensions/cpsection/language/Makefile 58 58 extensions/cpsection/modemconfiguration/Makefile 59 extensions/cpsection/modemconfiguration/config.py 59 60 extensions/cpsection/Makefile 60 61 extensions/cpsection/network/Makefile 61 62 extensions/cpsection/power/Makefile -
extensions/cpsection/modemconfiguration/Makefile.am
diff --git a/extensions/cpsection/modemconfiguration/Makefile.am b/extensions/cpsection/modemconfiguration/Makefile.am index 3e2613e..525e02e 100644
a b sugar_PYTHON = \ 4 4 __init__.py \ 5 5 model.py \ 6 6 view.py 7 8 nodist_sugar_PYTHON = config.py -
new file extensions/cpsection/modemconfiguration/config.py.in
diff --git a/extensions/cpsection/modemconfiguration/config.py.in b/extensions/cpsection/modemconfiguration/config.py.in new file mode 100644 index 0000000..6fa688e
- + 1 # -*- encoding: utf-8 -*- 2 # Copyright (C) 2010 Andrés Ambrois 3 # 4 # This program is free software; you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation; either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program; if not, write to the Free Software 16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US 17 18 PROVIDERS_PATH = "@prefix@/share/mobile-broadband-provider-info/serviceproviders.xml" 19 PROVIDERS_FORMAT_SUPPORTED = "2.0" 20 COUNTRY_CODES_PATH = "@prefix@/share/zoneinfo/iso3166.tab" -
extensions/cpsection/modemconfiguration/model.py
diff --git a/extensions/cpsection/modemconfiguration/model.py b/extensions/cpsection/modemconfiguration/model.py old mode 100755 new mode 100644 index 2545ce1..dbec47d
a b 15 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US 16 16 17 17 import gconf 18 import gtk 19 import os 20 import locale 21 import logging 22 23 from xml.etree.cElementTree import ElementTree 24 from gettext import gettext as _ 18 25 19 26 from jarabe.model.network import GSM_USERNAME_PATH, GSM_PASSWORD_PATH, \ 20 27 GSM_NUMBER_PATH, GSM_APN_PATH, GSM_PIN_PATH, \ 21 28 GSM_PUK_PATH 22 29 30 from cpsection.modemconfiguration.config import PROVIDERS_PATH, \ 31 PROVIDERS_FORMAT_SUPPORTED, \ 32 COUNTRY_CODES_PATH 33 23 34 def get_username(): 24 35 client = gconf.client_get_default() 25 36 return client.get_string(GSM_USERNAME_PATH) or '' … … def set_puk(puk): 68 79 client = gconf.client_get_default() 69 80 client.set_string(GSM_PUK_PATH, puk) 70 81 82 def has_providers_db(): 83 if not os.path.isfile(COUNTRY_CODES_PATH): 84 logging.debug("Mobile broadband provider database: Country " \ 85 "codes path %s not found.", COUNTRY_CODES_PATH) 86 return False 87 try: 88 tree = ElementTree(file=PROVIDERS_PATH) 89 except (IOError, SyntaxError), e: 90 logging.debug("Mobile broadband provider database: Could not read " \ 91 "provider information %s error=%s", PROVIDERS_PATH) 92 return False 93 else: 94 elem = tree.getroot() 95 if elem is None or elem.get('format') != PROVIDERS_FORMAT_SUPPORTED: 96 logging.debug("Mobile broadband provider database: Could not " \ 97 "read provider information. %s is wrong format.", 98 elem.get('format')) 99 return False 100 return True 101 102 103 class CountryListStore(gtk.ListStore): 104 COUNTRY_CODE = locale.getdefaultlocale()[0][3:5].lower() 105 106 def __init__(self): 107 gtk.ListStore.__init__(self, str, object) 108 codes = {} 109 with open(COUNTRY_CODES_PATH) as codes_file: 110 for line in codes_file: 111 if line.startswith('#'): 112 continue 113 code, name = line.split('\t')[:2] 114 codes[code.lower()] = name.strip() 115 etree = ElementTree(file=PROVIDERS_PATH).getroot() 116 self._country_idx = None 117 i = 0 118 for elem in etree.findall('.//country'): 119 code = elem.attrib['code'] 120 if code == self.COUNTRY_CODE: 121 self._country_idx = i 122 else: 123 i += 1 124 if code in codes: 125 self.append((codes[code], elem)) 126 else: 127 self.append((code, elem)) 128 129 def get_row_providers(self, row): 130 return self[row][1] 131 132 def guess_country_row(self): 133 if self._country_idx is not None: 134 return self._country_idx 135 else: 136 return -1 137 138 class ProviderListStore(gtk.ListStore): 139 def __init__(self, elem): 140 gtk.ListStore.__init__(self, str, object) 141 for provider_elem in elem.findall('.//provider'): 142 apns = provider_elem.findall('.//apn') 143 if not apns: 144 # Skip carriers with CDMA entries only 145 continue 146 self.append((provider_elem.find('.//name').text, apns)) 147 148 def get_row_plans(self, row): 149 return self[row][1] 150 151 class PlanListStore(gtk.ListStore): 152 LANG_NS_ATTR = '{http://www.w3.org/XML/1998/namespace}lang' 153 LANG = locale.getdefaultlocale()[0][:2] 154 DEFAULT_NUMBER = '*99#' 155 156 def __init__(self, elems): 157 gtk.ListStore.__init__(self, str, object) 158 for apn_elem in elems: 159 plan = {} 160 names = apn_elem.findall('.//name') 161 if names: 162 for name in names: 163 if name.get(self.LANG_NS_ATTR) is None: 164 # serviceproviders.xml default value 165 plan['name'] = name.text 166 elif name.get(self.LANG_NS_ATTR) == self.LANG: 167 # Great! We found a name value for our locale! 168 plan['name'] = name.text 169 break 170 else: 171 plan['name'] = _('Default') 172 plan['apn'] = apn_elem.get('value') 173 user = apn_elem.find('.//username') 174 if user is not None: 175 plan['username'] = user.text 176 else: 177 plan['username'] = '' 178 passwd = apn_elem.find('.//password') 179 if passwd is not None: 180 plan['password'] = passwd.text 181 else: 182 plan['password'] = '' 183 184 plan['number'] = self.DEFAULT_NUMBER 185 186 self.append((plan['name'], plan)) 187 188 def get_row_plan(self, row): 189 return self[row][1] -
extensions/cpsection/modemconfiguration/view.py
diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py index b236f3f..3b03b3d 100644
a b 14 14 # along with this program; if not, write to the Free Software 15 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US 16 16 17 import os18 import logging19 17 from gettext import gettext as _ 20 18 21 19 import gtk … … class EntryWithLabel(gtk.HBox): 31 29 __gtype_name__ = "SugarEntryWithLabel" 32 30 33 31 def __init__(self, label_text): 34 gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING )32 gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING * 2) 35 33 36 34 self._timeout_sid = 0 37 35 self._changed_handler = None … … class EntryWithLabel(gtk.HBox): 44 42 self.pack_start(self.label, expand=False) 45 43 self.label.show() 46 44 47 self. _entry = gtk.Entry(25)48 self. _entry.connect('changed', self.__entry_changed_cb)49 self. _entry.set_width_chars(25)50 self.pack_start(self. _entry, expand=False)51 self. _entry.show()45 self.entry = gtk.Entry(25) 46 self.entry.connect('changed', self.__entry_changed_cb) 47 self.entry.set_width_chars(25) 48 self.pack_start(self.entry, expand=False) 49 self.entry.show() 52 50 53 51 def __entry_changed_cb(self, widget, data=None): 54 52 if self._timeout_sid: … … class EntryWithLabel(gtk.HBox): 59 57 def __timeout_cb(self): 60 58 self._timeout_sid = 0 61 59 62 if self. _entry.get_text() == self.get_value():60 if self.entry.get_text() == self.get_value(): 63 61 return False 64 62 65 63 try: 66 self.set_value(self. _entry.get_text())64 self.set_value(self.entry.get_text()) 67 65 except ValueError: 68 66 self._is_valid = False 69 67 else: … … class EntryWithLabel(gtk.HBox): 74 72 return False 75 73 76 74 def set_text_from_model(self): 77 self. _entry.set_text(self.get_value())75 self.entry.set_text(self.get_value()) 78 76 79 77 def get_value(self): 80 78 raise NotImplementedError 81 79 82 def set_value(self ):80 def set_value(self, value): 83 81 raise NotImplementedError 84 82 85 83 def _get_is_valid(self): 86 84 return self._is_valid 85 87 86 is_valid = gobject.property(type=bool, getter=_get_is_valid, default=True) 88 87 88 89 89 class UsernameEntry(EntryWithLabel): 90 90 def __init__(self, model): 91 91 EntryWithLabel.__init__(self, _('Username:')) … … class UsernameEntry(EntryWithLabel): 97 97 def set_value(self, username): 98 98 self._model.set_username(username) 99 99 100 100 101 class PasswordEntry(EntryWithLabel): 101 102 def __init__(self, model): 102 103 EntryWithLabel.__init__(self, _('Password:')) … … class PasswordEntry(EntryWithLabel): 108 109 def set_value(self, password): 109 110 self._model.set_password(password) 110 111 112 111 113 class NumberEntry(EntryWithLabel): 112 114 def __init__(self, model): 113 115 EntryWithLabel.__init__(self, _('Number:')) … … class NumberEntry(EntryWithLabel): 119 121 def set_value(self, number): 120 122 self._model.set_number(number) 121 123 124 122 125 class ApnEntry(EntryWithLabel): 123 126 def __init__(self, model): 124 127 EntryWithLabel.__init__(self, _('Access Point Name (APN):')) … … class ApnEntry(EntryWithLabel): 130 133 def set_value(self, apn): 131 134 self._model.set_apn(apn) 132 135 136 133 137 class PinEntry(EntryWithLabel): 134 138 def __init__(self, model): 135 139 EntryWithLabel.__init__(self, _('Personal Identity Number (PIN):')) … … class PinEntry(EntryWithLabel): 141 145 def set_value(self, pin): 142 146 self._model.set_pin(pin) 143 147 148 144 149 class PukEntry(EntryWithLabel): 145 150 def __init__(self, model): 146 151 EntryWithLabel.__init__(self, _('Personal Unblocking Key (PUK):')) … … class ModemConfiguration(SectionView): 160 165 self._model = model 161 166 self.restart_alerts = alerts 162 167 163 self.set_border_width(style.DEFAULT_SPACING)164 168 self.set_spacing(style.DEFAULT_SPACING) 165 self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 169 170 label_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 171 combo_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 172 173 scrolled_win = gtk.ScrolledWindow() 174 scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 175 scrolled_win.show() 176 self.add(scrolled_win) 177 178 main_box = gtk.VBox(spacing=style.DEFAULT_SPACING) 179 main_box.set_border_width(style.DEFAULT_SPACING) 180 main_box.show() 181 scrolled_win.add_with_viewport(main_box) 166 182 167 183 explanation = _("You will need to provide the following " \ 168 184 "information to set up a mobile " \ 169 185 "broadband connection to a cellular "\ 170 186 "(3G) network.") 171 187 self._text = gtk.Label(explanation) 172 self._text.set_width_chars(100)173 188 self._text.set_line_wrap(True) 174 189 self._text.set_alignment(0, 0) 175 self.pack_start(self._text, False)190 main_box.pack_start(self._text, False) 176 191 self._text.show() 177 192 193 if model.has_providers_db(): 194 self._upper_box = gtk.VBox(spacing=style.DEFAULT_SPACING) 195 self._upper_box.set_border_width(style.DEFAULT_SPACING) 196 main_box.pack_start(self._upper_box, expand=False) 197 self._upper_box.show() 198 199 200 box = gtk.HBox(spacing=style.DEFAULT_SPACING * 2) 201 label = gtk.Label(_('Country:')) 202 label.set_alignment(1, 0.5) 203 label_group.add_widget(label) 204 box.pack_start(label, False) 205 label.show() 206 country_store = model.CountryListStore() 207 country_combo = gtk.ComboBox(country_store) 208 combo_group.add_widget(country_combo) 209 cell = gtk.CellRendererText() 210 cell.props.xalign = 0.5 211 country_combo.pack_start(cell) 212 country_combo.add_attribute(cell, 'text', 0) 213 country_combo.connect('changed', self.__country_selected_cb) 214 box.pack_start(country_combo, False) 215 country_combo.show() 216 self._upper_box.pack_start(box, False) 217 box.show() 218 219 box = gtk.HBox(spacing=style.DEFAULT_SPACING * 2) 220 label = gtk.Label(_('Provider:')) 221 label.set_alignment(1, 0.5) 222 label_group.add_widget(label) 223 box.pack_start(label, False) 224 label.show() 225 self._providers_combo = gtk.ComboBox() 226 combo_group.add_widget(self._providers_combo) 227 cell = gtk.CellRendererText() 228 cell.props.xalign = 0.5 229 self._providers_combo.pack_start(cell) 230 self._providers_combo.add_attribute(cell, 'text', 0) 231 self._providers_combo.connect('changed', 232 self.__provider_selected_cb) 233 box.pack_start(self._providers_combo, False) 234 self._providers_combo.show() 235 self._upper_box.pack_start(box, False) 236 box.show() 237 238 box = gtk.HBox(spacing=style.DEFAULT_SPACING*2) 239 label = gtk.Label(_('Plan:')) 240 label.set_alignment(1, 0.5) 241 label_group.add_widget(label) 242 box.pack_start(label, False) 243 label.show() 244 self._plan_combo = gtk.ComboBox() 245 combo_group.add_widget(self._plan_combo) 246 cell = gtk.CellRendererText() 247 cell.props.xalign = 0.5 248 self._plan_combo.pack_start(cell) 249 self._plan_combo.add_attribute(cell, 'text', 0) 250 self._plan_combo.connect('changed', self.__plan_selected_cb) 251 box.pack_start(self._plan_combo, False) 252 self._plan_combo.show() 253 self._upper_box.pack_start(box, False) 254 box.show() 255 256 country_combo.set_active(country_store.guess_country_row()) 257 258 separator = gtk.HSeparator() 259 main_box.pack_start(separator, False) 260 separator.show() 261 262 self._lower_box = gtk.VBox(spacing=style.DEFAULT_SPACING) 263 self._lower_box.set_border_width(style.DEFAULT_SPACING) 264 main_box.pack_start(self._lower_box, expand=False) 265 self._lower_box.show() 266 178 267 self._username_entry = UsernameEntry(model) 179 268 self._username_entry.connect('notify::is-valid', 180 269 self.__notify_is_valid_cb) 181 self._group.add_widget(self._username_entry.label) 182 self.pack_start(self._username_entry, expand=False) 270 label_group.add_widget(self._username_entry.label) 271 combo_group.add_widget(self._username_entry.entry) 272 self._lower_box.pack_start(self._username_entry, fill=False) 183 273 self._username_entry.show() 184 274 185 275 self._password_entry = PasswordEntry(model) 186 276 self._password_entry.connect('notify::is-valid', 187 277 self.__notify_is_valid_cb) 188 self._group.add_widget(self._password_entry.label) 189 self.pack_start(self._password_entry, expand=False) 278 label_group.add_widget(self._password_entry.label) 279 combo_group.add_widget(self._password_entry.entry) 280 self._lower_box.pack_start(self._password_entry, fill=False) 190 281 self._password_entry.show() 191 282 192 283 self._number_entry = NumberEntry(model) 193 284 self._number_entry.connect('notify::is-valid', 194 285 self.__notify_is_valid_cb) 195 self._group.add_widget(self._number_entry.label) 196 self.pack_start(self._number_entry, expand=False) 286 label_group.add_widget(self._number_entry.label) 287 combo_group.add_widget(self._number_entry.entry) 288 self._lower_box.pack_start(self._number_entry, fill=False) 197 289 self._number_entry.show() 198 290 199 291 self._apn_entry = ApnEntry(model) 200 292 self._apn_entry.connect('notify::is-valid', 201 293 self.__notify_is_valid_cb) 202 self._group.add_widget(self._apn_entry.label) 203 self.pack_start(self._apn_entry, expand=False) 294 label_group.add_widget(self._apn_entry.label) 295 combo_group.add_widget(self._apn_entry.entry) 296 self._lower_box.pack_start(self._apn_entry, fill=False) 204 297 self._apn_entry.show() 205 298 206 299 self._pin_entry = PinEntry(model) 207 300 self._pin_entry.connect('notify::is-valid', 208 301 self.__notify_is_valid_cb) 209 self._group.add_widget(self._pin_entry.label)210 self. pack_start(self._pin_entry, expand=False)302 label_group.add_widget(self._pin_entry.label) 303 self._lower_box.pack_start(self._pin_entry, fill=False) 211 304 self._pin_entry.show() 212 305 213 306 self._puk_entry = PukEntry(model) 214 307 self._puk_entry.connect('notify::is-valid', 215 308 self.__notify_is_valid_cb) 216 self._group.add_widget(self._puk_entry.label) 217 self.pack_start(self._puk_entry, expand=False) 309 label_group.add_widget(self._puk_entry.label) 310 combo_group.add_widget(self._puk_entry.entry) 311 self._lower_box.pack_start(self._puk_entry, fill=False) 218 312 self._puk_entry.show() 219 313 220 314 self.setup() … … class ModemConfiguration(SectionView): 232 326 def undo(self): 233 327 self._model.undo() 234 328 329 def __country_selected_cb(self, combo): 330 model = combo.get_model() 331 providers = model.get_row_providers(combo.get_active()) 332 self._providers_combo.set_model( 333 self._model.ProviderListStore(providers)) 334 335 def __provider_selected_cb(self, combo): 336 model = combo.get_model() 337 plans = model.get_row_plans(combo.get_active()) 338 self._plan_combo.set_model(self._model.PlanListStore(plans)) 339 340 def __plan_selected_cb(self, combo): 341 model = combo.get_model() 342 plan = model.get_row_plan(combo.get_active()) 343 self._username_entry.set_value(plan['username']) 344 self._username_entry.set_text_from_model() 345 self._password_entry.set_value(plan['password']) 346 self._password_entry.set_text_from_model() 347 self._number_entry.set_value(plan['number']) 348 self._number_entry.set_text_from_model() 349 self._apn_entry.set_value(plan['apn']) 350 self._apn_entry.set_text_from_model() 351 235 352 def _validate(self): 236 353 if self._username_entry.is_valid and \ 237 self._password_entry.is_valid and \354 self._password_entry.is_valid and \ 238 355 self._number_entry.is_valid and \ 239 240 241 242 356 self._apn_entry.is_valid and \ 357 self._pin_entry.is_valid and \ 358 self._puk_entry.is_valid: 359 self.props.is_valid = True 243 360 else: 244 361 self.props.is_valid = False 245 362 … … class ModemConfiguration(SectionView): 247 364 if entry.is_valid: 248 365 self.needs_restart = True 249 366 self._validate() 250