Ticket #1630: 0002-Show-Country-Provider-Plan-comboboxes-if-DB-exists.patch
File 0002-Show-Country-Provider-Plan-comboboxes-if-DB-exists.patch, 11.5 KB (added by aa, 13 years ago) |
---|
-
extensions/cpsection/modemconfiguration/view.py
From d47e7b02972785b7debc027e18c42ee470c5ae08 Mon Sep 17 00:00:00 2001 Message-Id: <d47e7b02972785b7debc027e18c42ee470c5ae08.1282025114.git.andresambrois@gmail.com> In-Reply-To: <90106170b4d8bf0a6dbe3c25e75114b754add56e.1282025114.git.andresambrois@gmail.com> References: <90106170b4d8bf0a6dbe3c25e75114b754add56e.1282025114.git.andresambrois@gmail.com> From: =?UTF-8?q?Andr=C3=A9s=20Ambrois?= <andresambrois@gmail.com> Date: Mon, 14 Jun 2010 00:32:42 -0300 Subject: [PATCH 2/3] Show Country/Provider/Plan comboboxes if DB exists. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Display comboboxes for selecting a data plan for each country and provider if the mobile-broadband-providers-info package is installed. Populate the connection parameters with the info from the selected data plan. Signed-off-by: Andrés Ambrois <andresambrois@gmail.com> --- extensions/cpsection/modemconfiguration/view.py | 162 +++++++++++++++++++---- 1 files changed, 137 insertions(+), 25 deletions(-) diff --git a/extensions/cpsection/modemconfiguration/view.py b/extensions/cpsection/modemconfiguration/view.py index b236f3f..1d9d27f 100644
a b class EntryWithLabel(gtk.HBox): 31 31 __gtype_name__ = "SugarEntryWithLabel" 32 32 33 33 def __init__(self, label_text): 34 gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING )34 gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING*2) 35 35 36 36 self._timeout_sid = 0 37 37 self._changed_handler = None … … class EntryWithLabel(gtk.HBox): 44 44 self.pack_start(self.label, expand=False) 45 45 self.label.show() 46 46 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()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() 52 52 53 53 def __entry_changed_cb(self, widget, data=None): 54 54 if self._timeout_sid: … … class EntryWithLabel(gtk.HBox): 59 59 def __timeout_cb(self): 60 60 self._timeout_sid = 0 61 61 62 if self. _entry.get_text() == self.get_value():62 if self.entry.get_text() == self.get_value(): 63 63 return False 64 64 65 65 try: 66 self.set_value(self. _entry.get_text())66 self.set_value(self.entry.get_text()) 67 67 except ValueError: 68 68 self._is_valid = False 69 69 else: … … class EntryWithLabel(gtk.HBox): 74 74 return False 75 75 76 76 def set_text_from_model(self): 77 self. _entry.set_text(self.get_value())77 self.entry.set_text(self.get_value()) 78 78 79 79 def get_value(self): 80 80 raise NotImplementedError … … class ModemConfiguration(SectionView): 160 160 self._model = model 161 161 self.restart_alerts = alerts 162 162 163 self.set_border_width(style.DEFAULT_SPACING)164 163 self.set_spacing(style.DEFAULT_SPACING) 165 self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 164 165 label_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 166 combo_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 167 168 scrolled_win = gtk.ScrolledWindow() 169 scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 170 scrolled_win.show() 171 self.add(scrolled_win) 172 173 main_box = gtk.VBox(spacing=style.DEFAULT_SPACING) 174 main_box.set_border_width(style.DEFAULT_SPACING) 175 main_box.show() 176 scrolled_win.add_with_viewport(main_box) 166 177 167 178 explanation = _("You will need to provide the following " \ 168 179 "information to set up a mobile " \ 169 180 "broadband connection to a cellular "\ 170 181 "(3G) network.") 171 182 self._text = gtk.Label(explanation) 172 self._text.set_width_chars(100)173 183 self._text.set_line_wrap(True) 174 184 self._text.set_alignment(0, 0) 175 self.pack_start(self._text, False)185 main_box.pack_start(self._text, False) 176 186 self._text.show() 177 187 188 if model.has_providers_db(): 189 self._upper_box = gtk.VBox(spacing=style.DEFAULT_SPACING) 190 self._upper_box.set_border_width(style.DEFAULT_SPACING) 191 main_box.pack_start(self._upper_box, expand=False) 192 self._upper_box.show() 193 194 195 box = gtk.HBox(spacing=style.DEFAULT_SPACING*2) 196 label = gtk.Label(_('Country:')) 197 label.set_alignment(1, 0.5) 198 label_group.add_widget(label) 199 box.pack_start(label, False) 200 label.show() 201 country_store = model.CountryListStore() 202 country_combo = gtk.ComboBox(country_store) 203 combo_group.add_widget(country_combo) 204 cell = gtk.CellRendererText() 205 cell.props.xalign = 0.5 206 country_combo.pack_start(cell) 207 country_combo.add_attribute(cell, 'text', 0) 208 country_combo.connect('changed', self.__country_selected_cb) 209 box.pack_start(country_combo, False) 210 country_combo.show() 211 self._upper_box.pack_start(box, False) 212 box.show() 213 214 box = gtk.HBox(spacing=style.DEFAULT_SPACING*2) 215 label = gtk.Label(_('Provider:')) 216 label.set_alignment(1, 0.5) 217 label_group.add_widget(label) 218 box.pack_start(label, False) 219 label.show() 220 self._providers_combo = gtk.ComboBox() 221 combo_group.add_widget(self._providers_combo) 222 cell = gtk.CellRendererText() 223 cell.props.xalign = 0.5 224 self._providers_combo.pack_start(cell) 225 self._providers_combo.add_attribute(cell, 'text', 0) 226 self._providers_combo.connect('changed', 227 self.__provider_selected_cb) 228 box.pack_start(self._providers_combo, False) 229 self._providers_combo.show() 230 self._upper_box.pack_start(box, False) 231 box.show() 232 233 box = gtk.HBox(spacing=style.DEFAULT_SPACING*2) 234 label = gtk.Label(_('Plan:')) 235 label.set_alignment(1, 0.5) 236 label_group.add_widget(label) 237 box.pack_start(label, False) 238 label.show() 239 self._plan_combo = gtk.ComboBox() 240 combo_group.add_widget(self._plan_combo) 241 cell = gtk.CellRendererText() 242 cell.props.xalign = 0.5 243 self._plan_combo.pack_start(cell) 244 self._plan_combo.add_attribute(cell, 'text', 0) 245 self._plan_combo.connect('changed', self.__plan_selected_cb) 246 box.pack_start(self._plan_combo, False) 247 self._plan_combo.show() 248 self._upper_box.pack_start(box, False) 249 box.show() 250 251 country_combo.set_active(country_store.guess_country_row()) 252 253 separator = gtk.HSeparator() 254 main_box.pack_start(separator, False) 255 separator.show() 256 257 self._lower_box = gtk.VBox(spacing=style.DEFAULT_SPACING) 258 self._lower_box.set_border_width(style.DEFAULT_SPACING) 259 main_box.pack_start(self._lower_box, expand=False) 260 self._lower_box.show() 261 178 262 self._username_entry = UsernameEntry(model) 179 263 self._username_entry.connect('notify::is-valid', 180 264 self.__notify_is_valid_cb) 181 self._group.add_widget(self._username_entry.label) 182 self.pack_start(self._username_entry, expand=False) 265 label_group.add_widget(self._username_entry.label) 266 combo_group.add_widget(self._username_entry.entry) 267 self._lower_box.pack_start(self._username_entry, fill=False) 183 268 self._username_entry.show() 184 269 185 270 self._password_entry = PasswordEntry(model) 186 271 self._password_entry.connect('notify::is-valid', 187 272 self.__notify_is_valid_cb) 188 self._group.add_widget(self._password_entry.label) 189 self.pack_start(self._password_entry, expand=False) 273 label_group.add_widget(self._password_entry.label) 274 combo_group.add_widget(self._password_entry.entry) 275 self._lower_box.pack_start(self._password_entry, fill=False) 190 276 self._password_entry.show() 191 277 192 278 self._number_entry = NumberEntry(model) 193 279 self._number_entry.connect('notify::is-valid', 194 280 self.__notify_is_valid_cb) 195 self._group.add_widget(self._number_entry.label) 196 self.pack_start(self._number_entry, expand=False) 281 label_group.add_widget(self._number_entry.label) 282 combo_group.add_widget(self._number_entry.entry) 283 self._lower_box.pack_start(self._number_entry, fill=False) 197 284 self._number_entry.show() 198 285 199 286 self._apn_entry = ApnEntry(model) 200 287 self._apn_entry.connect('notify::is-valid', 201 288 self.__notify_is_valid_cb) 202 self._group.add_widget(self._apn_entry.label) 203 self.pack_start(self._apn_entry, expand=False) 289 label_group.add_widget(self._apn_entry.label) 290 combo_group.add_widget(self._apn_entry.entry) 291 self._lower_box.pack_start(self._apn_entry, fill=False) 204 292 self._apn_entry.show() 205 293 206 294 self._pin_entry = PinEntry(model) 207 295 self._pin_entry.connect('notify::is-valid', 208 296 self.__notify_is_valid_cb) 209 self._group.add_widget(self._pin_entry.label)210 self. pack_start(self._pin_entry, expand=False)297 label_group.add_widget(self._pin_entry.label) 298 self._lower_box.pack_start(self._pin_entry, fill=False) 211 299 self._pin_entry.show() 212 300 213 301 self._puk_entry = PukEntry(model) 214 302 self._puk_entry.connect('notify::is-valid', 215 303 self.__notify_is_valid_cb) 216 self._group.add_widget(self._puk_entry.label) 217 self.pack_start(self._puk_entry, expand=False) 304 label_group.add_widget(self._puk_entry.label) 305 combo_group.add_widget(self._puk_entry.entry) 306 self._lower_box.pack_start(self._puk_entry, fill=False) 218 307 self._puk_entry.show() 219 308 220 309 self.setup() … … class ModemConfiguration(SectionView): 232 321 def undo(self): 233 322 self._model.undo() 234 323 324 def __country_selected_cb(self, combo): 325 model = combo.get_model() 326 providers = model.get_row_providers(combo.get_active()) 327 self._providers_combo.set_model( 328 self._model.ProviderListStore(providers)) 329 330 def __provider_selected_cb(self, combo): 331 model = combo.get_model() 332 plans = model.get_row_plans(combo.get_active()) 333 self._plan_combo.set_model(self._model.PlanListStore(plans)) 334 335 def __plan_selected_cb(self, combo): 336 model = combo.get_model() 337 plan = model.get_row_plan(combo.get_active()) 338 self._username_entry.set_value(plan['username']) 339 self._username_entry.set_text_from_model() 340 self._password_entry.set_value(plan['password']) 341 self._password_entry.set_text_from_model() 342 self._number_entry.set_value(plan['number']) 343 self._number_entry.set_text_from_model() 344 self._apn_entry.set_value(plan['apn']) 345 self._apn_entry.set_text_from_model() 346 235 347 def _validate(self): 236 348 if self._username_entry.is_valid and \ 237 349 self._password_entry.is_valid and \