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, 14 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): 
    3131    __gtype_name__ = "SugarEntryWithLabel"
    3232
    3333    def __init__(self, label_text):
    34         gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING)
     34        gtk.HBox.__init__(self, spacing=style.DEFAULT_SPACING*2)
    3535
    3636        self._timeout_sid = 0
    3737        self._changed_handler = None
    class EntryWithLabel(gtk.HBox): 
    4444        self.pack_start(self.label, expand=False)
    4545        self.label.show()
    4646
    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()
    5252
    5353    def __entry_changed_cb(self, widget, data=None):
    5454        if self._timeout_sid:
    class EntryWithLabel(gtk.HBox): 
    5959    def __timeout_cb(self):
    6060        self._timeout_sid = 0
    6161
    62         if self._entry.get_text() == self.get_value():
     62        if self.entry.get_text() == self.get_value():
    6363            return False
    6464
    6565        try:
    66             self.set_value(self._entry.get_text())
     66            self.set_value(self.entry.get_text())
    6767        except ValueError:
    6868            self._is_valid = False
    6969        else:
    class EntryWithLabel(gtk.HBox): 
    7474        return False
    7575
    7676    def set_text_from_model(self):
    77         self._entry.set_text(self.get_value())
     77        self.entry.set_text(self.get_value())
    7878
    7979    def get_value(self):
    8080        raise NotImplementedError
    class ModemConfiguration(SectionView): 
    160160        self._model = model
    161161        self.restart_alerts = alerts
    162162
    163         self.set_border_width(style.DEFAULT_SPACING)
    164163        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)
    166177
    167178        explanation = _("You will need to provide the following " \
    168179                            "information to set up a mobile " \
    169180                            "broadband connection to a cellular "\
    170181                            "(3G) network.")
    171182        self._text = gtk.Label(explanation)
    172         self._text.set_width_chars(100)
    173183        self._text.set_line_wrap(True)
    174184        self._text.set_alignment(0, 0)
    175         self.pack_start(self._text, False)
     185        main_box.pack_start(self._text, False)
    176186        self._text.show()
    177187
     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
    178262        self._username_entry = UsernameEntry(model)
    179263        self._username_entry.connect('notify::is-valid',
    180264                                     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)
    183268        self._username_entry.show()
    184269
    185270        self._password_entry = PasswordEntry(model)
    186271        self._password_entry.connect('notify::is-valid',
    187272                                     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)
    190276        self._password_entry.show()
    191277
    192278        self._number_entry = NumberEntry(model)
    193279        self._number_entry.connect('notify::is-valid',
    194280                                   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)
    197284        self._number_entry.show()
    198285
    199286        self._apn_entry = ApnEntry(model)
    200287        self._apn_entry.connect('notify::is-valid',
    201288                                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)
    204292        self._apn_entry.show()
    205293
    206294        self._pin_entry = PinEntry(model)
    207295        self._pin_entry.connect('notify::is-valid',
    208296                                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)
    211299        self._pin_entry.show()
    212300       
    213301        self._puk_entry = PukEntry(model)
    214302        self._puk_entry.connect('notify::is-valid',
    215303                                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)
    218307        self._puk_entry.show()
    219308
    220309        self.setup()
    class ModemConfiguration(SectionView): 
    232321    def undo(self):
    233322        self._model.undo()
    234323
     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
    235347    def _validate(self):
    236348        if self._username_entry.is_valid and \
    237349            self._password_entry.is_valid and \