예제 #1
0
    def __init__(self, name, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = True

        self.set_default = urwid.CheckBox(
            _('Use as default profile (overwrites any previous default)'))
        #self.cur_default =
        # Add widgets to listbox
        self._w.body.body.append(self.set_default)

        self.parent = parent
        encryption_t = _('Use Encryption')

        self.encryption_chkbox = urwid.CheckBox(
            encryption_t, on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
        self.set_values()

        self.prof_name = name
        title = _('Configuring preferences for wired profile "$A"'). \
            replace('$A', self.prof_name)
        self._w.header = urwid.Text(('header', title), align='right')

        self.set_values()
예제 #2
0
    def __init__(self, networkID, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = False

        self.bitrates = None

        self.networkid = networkID
        self.parent = parent
        global_settings_t = \
            _('Use these settings for all networks sharing this essid')
        encryption_t = _('Use Encryption')
        autoconnect_t = _('Automatically connect to this network')
        bitrate_t = _('Wireless bitrate')
        allow_lower_bitrates_t = _('Allow lower bitrates')

        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(
            encryption_t,
            on_state_change=self.
            encryption_toggle
        )
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.bitrate_combo = ComboBox(bitrate_t)
        self.allow_lower_bitrates_chkbox = \
            urwid.CheckBox(allow_lower_bitrates_t)

        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.bitrate_combo)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.allow_lower_bitrates_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(urwid.Text(''))
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.global_settings_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.autoconnect_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = _('Configuring preferences for wireless network "$A" ($B)'). \
            replace('$A', wireless.GetWirelessProperty(networkID, 'essid')). \
            replace('$B', wireless.GetWirelessProperty(networkID, 'bssid'))
        self._w.header = urwid.Text(('header', title), align='right')
예제 #3
0
    def keypress(self, size, key):
        """ Handle keypresses. """
        prev_focus = self.get_focus()[1]
        key = ComboBox.keypress(self, size, key)
        if key == ' ':
            if self.get_focus()[1] == len(self.list) - 1:
                dialog = InputDialog(
                    ('header', _('Add a new wired profile')),
                    7, 30
                )
                exitcode, name = dialog.run(ui, self.parent)
                if exitcode == 0:
                    name = name.strip()
                    if not name:
                        error(ui, self.parent, 'Invalid profile name')
                        self.set_focus(prev_focus)
                        return key

                    wired.CreateWiredNetworkProfile(name, False)
                    self.set_list(wired.GetWiredProfileList())
                    self.rebuild_combobox()
                self.set_focus(prev_focus)
            else:
                wired.ReadWiredNetworkProfile(self.get_selected_profile())
        if key == 'delete':
            if len(self.theList) == 1:
                error(
                    self.ui,
                    self.parent,
                    _('wicd-curses does not support deleting the last wired '
                    'profile.  Try renaming it ("F2")')
                )
                return key
            wired.DeleteWiredNetworkProfile(self.get_selected_profile())
            # Return to the top of the list if something is deleted.

            if wired.GetDefaultWiredNetwork() is not None:
                self.set_focus(
                    self.theList.index(wired.GetDefaultWiredNetwork())
                )
            else:
                prev_focus -= 1
                self.set_focus(prev_focus)
            self.set_list(wired.GetWiredProfileList())
            self.rebuild_combobox()
        if key == 'f2':
            dialog = InputDialog(
                ('header', _('Rename wired profile')),
                7, 30,
                edit_text=unicode(self.get_selected_profile())
            )
            exitcode, name = dialog.run(ui, self.parent)
            if exitcode == 0:
                # Save the new one, then kill the old one
                wired.SaveWiredNetworkProfile(name)
                wired.DeleteWiredNetworkProfile(self.get_selected_profile())
                self.set_list(wired.GetWiredProfileList())
                self.set_focus(self.theList.index(name))
                self.rebuild_combobox()
        return key
예제 #4
0
    def __init__(self, name, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = True

        self.set_default = urwid.CheckBox(
            _('Use as default profile (overwrites any previous default)')
        )
        #self.cur_default =
        # Add widgets to listbox
        self._w.body.body.append(self.set_default)

        self.parent = parent
        encryption_t = _('Use Encryption')

        self.encryption_chkbox = urwid.CheckBox(
            encryption_t,
            on_state_change=self.
            encryption_toggle
        )
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
        self.set_values()

        self.prof_name = name
        title = _('Configuring preferences for wired profile "$A"'). \
            replace('$A', self.prof_name)
        self._w.header = urwid.Text(('header', title), align='right')

        self.set_values()
예제 #5
0
    def keypress(self, size, key):
        """ Handle keypresses. """
        prev_focus = self.get_focus()[1]
        key = ComboBox.keypress(self, size, key)
        if key == ' ':
            if self.get_focus()[1] == len(self.list) - 1:
                dialog = InputDialog(
                    ('header', _('Add a new wired profile')),
                    7, 30
                )
                exitcode, name = dialog.run(ui, self.parent)
                if exitcode == 0:
                    name = name.strip()
                    if not name:
                        error(ui, self.parent, 'Invalid profile name')
                        self.set_focus(prev_focus)
                        return key

                    wired.CreateWiredNetworkProfile(name, False)
                    self.set_list(wired.GetWiredProfileList())
                    self.rebuild_combobox()
                self.set_focus(prev_focus)
            else:
                wired.ReadWiredNetworkProfile(self.get_selected_profile())
        if key == 'delete':
            if len(self.theList) == 1:
                error(
                    self.ui,
                    self.parent,
                    _('wicd-curses does not support deleting the last wired '
                    'profile.  Try renaming it ("F2")')
                )
                return key
            wired.DeleteWiredNetworkProfile(self.get_selected_profile())
            # Return to the top of the list if something is deleted.

            if wired.GetDefaultWiredNetwork() is not None:
                self.set_focus(
                    self.theList.index(wired.GetDefaultWiredNetwork())
                )
            else:
                prev_focus -= 1
                self.set_focus(prev_focus)
            self.set_list(wired.GetWiredProfileList())
            self.rebuild_combobox()
        if key == 'f2':
            dialog = InputDialog(
                ('header', _('Rename wired profile')),
                7, 30,
                edit_text=unicode(self.get_selected_profile())
            )
            exitcode, name = dialog.run(ui, self.parent)
            if exitcode == 0:
                # Save the new one, then kill the old one
                wired.SaveWiredNetworkProfile(name)
                wired.DeleteWiredNetworkProfile(self.get_selected_profile())
                self.set_list(wired.GetWiredProfileList())
                self.set_focus(self.theList.index(name))
                self.rebuild_combobox()
        return key
예제 #6
0
    def __init__(self, networkID, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = False

        self.bitrates = None

        self.networkid = networkID
        self.parent = parent
        global_settings_t = \
            _('Use these settings for all networks sharing this essid')
        encryption_t = _('Use Encryption')
        autoconnect_t = _('Automatically connect to this network')
        bitrate_t = _('Wireless bitrate')
        allow_lower_bitrates_t = _('Allow lower bitrates')

        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(
            encryption_t, on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.bitrate_combo = ComboBox(bitrate_t)
        self.allow_lower_bitrates_chkbox = \
            urwid.CheckBox(allow_lower_bitrates_t)

        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.bitrate_combo)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.allow_lower_bitrates_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(urwid.Text(''))
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.global_settings_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.autoconnect_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = _('Configuring preferences for wireless network "$A" ($B)'). \
            replace('$A', wireless.GetWirelessProperty(networkID, 'essid')). \
            replace('$B', wireless.GetWirelessProperty(networkID, 'bssid'))
        self._w.header = urwid.Text(('header', title), align='right')
예제 #7
0
    def __init__(self,networkID,parent):
        global wireless, daemon
        AdvancedSettingsDialog.__init__(self)
        self.networkid = networkID
        self.parent = parent
        global_settings_t = language['global_settings']
        encryption_t = language['use_encryption']
        autoconnect_t = language['automatic_connect']
        
        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(encryption_t,on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker :-)
        self._listbox.body.append(self.global_settings_chkbox)
        self._listbox.body.append(self.autoconnect_chkbox)
        self._listbox.body.append(self.encryption_chkbox)
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = language['configuring_wireless'].replace('$A',wireless.GetWirelessProperty(networkID,'essid')).replace('$B',wireless.GetWirelessProperty(networkID,'bssid'))
        self._w.header = urwid.Text(('header',title),align='right' )
예제 #8
0
class WiredSettingsDialog(AdvancedSettingsDialog):
    """ Settings dialog for wired interface. """
    def __init__(self, name, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = True

        self.set_default = urwid.CheckBox(
            _('Use as default profile (overwrites any previous default)')
        )
        #self.cur_default =
        # Add widgets to listbox
        self._w.body.body.append(self.set_default)

        self.parent = parent
        encryption_t = _('Use Encryption')

        self.encryption_chkbox = urwid.CheckBox(
            encryption_t,
            on_state_change=self.
            encryption_toggle
        )
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
        self.set_values()

        self.prof_name = name
        title = _('Configuring preferences for wired profile "$A"'). \
            replace('$A', self.prof_name)
        self._w.header = urwid.Text(('header', title), align='right')

        self.set_values()

    def set_net_prop(self, option, value):
        """ Set network property. """
        wired.SetWiredProperty(option, value)

    def set_values(self):
        """ Load saved values. """
        self.ip_edit.set_edit_text(self.format_entry("ip"))
        self.netmask_edit.set_edit_text(self.format_entry("netmask"))
        self.gateway_edit.set_edit_text(self.format_entry("gateway"))

        self.global_dns_cb.set_state(
            bool(wired.GetWiredProperty('use_global_dns'))
        )
        self.static_dns_cb.set_state(
            bool(wired.GetWiredProperty('use_static_dns'))
        )

        # Set static ip checkbox.  Forgot to do this the first time.
        if stringToNone(self.ip_edit.get_edit_text()):
            self.static_ip_cb.set_state(True)
        self.dns1.set_edit_text(self.format_entry("dns1"))
        self.dns2.set_edit_text(self.format_entry("dns2"))
        self.dns3.set_edit_text(self.format_entry("dns3"))
        self.dns_dom_edit.set_edit_text(self.format_entry("dns_domain"))
        self.search_dom_edit.set_edit_text(self.format_entry("search_domain"))

        self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))

        # Throw the encryption stuff into a list
        l = []
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            l.append(enc_type['name'])
            if enc_type['type'] == wired.GetWiredProperty("enctype"):
                activeID = x
        self.encryption_combo.set_list(l)

        self.encryption_combo.set_focus(activeID)
        if wired.GetWiredProperty("encryption_enabled"):
            self.encryption_chkbox.set_state(True, do_callback=False)
            self.encryption_combo.set_sensitive(True)
            #self.lbox_encrypt_info.set_sensitive(True)
        else:
            self.encryption_combo.set_focus(0)
            self.encryption_combo.set_sensitive(False)

        self.change_encrypt_method()

        dhcphname = wired.GetWiredProperty("dhcphostname")
        if dhcphname is None:
            dhcphname = os.uname()[1]

        self.use_dhcp_h.set_state(
            bool(wired.GetWiredProperty('usedhcphostname'))
        )
        self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
        self.dhcp_h.set_edit_text(unicode(dhcphname))

    def save_settings(self):
        """ Save settings to disk. """
        # Check encryption info
        if self.encryption_chkbox.get_state():
            encrypt_info = self.encryption_info
            encrypt_methods = self.encrypt_types
            self.set_net_prop(
                "enctype",
                encrypt_methods[self.encryption_combo.get_focus()[1]]['type'])
            self.set_net_prop("encryption_enabled", True)
            # Make sure all required fields are filled in.
            for entry_info in encrypt_info.itervalues():
                if entry_info[0].get_edit_text() == "" \
                  and entry_info[1] == 'required':
                    error(
                        self.ui,
                        self.parent,
                        "%s (%s)" % (
                            _('Required encryption information is missing.'),
                            entry_info[0].get_caption()[0:-2]
                        )
                    )
                    return False

            for entry_key, entry_info in encrypt_info.iteritems():
                self.set_net_prop(entry_key, noneToString(entry_info[0].
                                                   get_edit_text()))
        else:
            self.set_net_prop("enctype", "None")
            self.set_net_prop("encryption_enabled", False)

        AdvancedSettingsDialog.save_settings(self)
        if self.set_default.get_state():
            wired.UnsetWiredDefault()
        if self.set_default.get_state():
            set_default = True
        else:
            set_default = False
        wired.SetWiredProperty("default", set_default)
        wired.SaveWiredNetworkProfile(self.prof_name)
        return True

    def format_entry(self, label):
        """ Helper method to fetch and format wired properties. """
        return noneToBlankString(wired.GetWiredProperty(label))

    def prerun(self, ui, dim, display):
        pass
예제 #9
0
    def __init__(self, body, pos, ui, dbus=None):
        global daemon, wireless, wired

        daemon = dbus['daemon']
        wireless = dbus['wireless']
        wired = dbus['wired']

        width, height = ui.get_cols_rows()
        height -= 3
        #width = 80
        #height = 20
        # Stuff that goes at the top

        header0_t = language["gen_settings"]
        header1_t = language["ext_programs"]
        header2_t = language["advanced_settings"]
        self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active',
                                      'focus')
        self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
        self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
        title = language['preferences']

        # Blank line
        _blank = urwid.Text('')

        ####
        #### Text in the widgets
        ####

        # General Settings
        net_cat_t = ('header', language['network_interfaces'])
        wired_t = ('editcp', language['wired_interface'] + ':   ')
        wless_t = ('editcp', language['wireless_interface'] + ':')
        always_show_wired_t = language['wired_always_on']
        prefer_wired_t = language['always_switch_to_wired']

        global_dns_cat_t = ('header', language['global_dns_servers'])
        global_dns_t = ('editcp', language['use_global_dns'])
        dns_dom_t = ('editcp', '    ' + language['dns_domain'] + ':   ')
        search_dom_t = ('editcp', '    ' + language['search_domain'] + ':')
        dns1_t = ('editcp', '    DNS server 1: ')
        dns2_t = ('editcp', '    DNS server 2: ')
        dns3_t = ('editcp', '    DNS server 3: ')

        wired_auto_cat_t = ('header', language['wired_autoconnect_settings'])
        wired_auto_1_t = language['use_default_profile']
        wired_auto_2_t = language['show_wired_list']
        wired_auto_3_t = language['use_last_used_profile']

        auto_reconn_cat_t = ('header', language['automatic_reconnection'])
        auto_reconn_t = language['auto_reconnect']

        #### External Programs
        automatic_t = language['wicd_auto_config']

        dhcp_header_t = ('header', language["dhcp_client"])
        # Automatic
        dhcp1_t = 'dhclient'
        dhcp2_t = 'dhcpcd'
        dhcp3_t = 'pump'
        dhcp4_t = 'udhcpc'

        wired_detect_header_t = ('header', language["wired_detect"])
        wired1_t = 'ethtool'
        wired2_t = 'mii-tool'

        flush_header_t = ('header', language["route_flush"])
        flush1_t = 'ip'
        flush2_t = 'route'

        #### Advanced Settings
        wpa_cat_t = ('header', language['wpa_supplicant'])
        wpa_t = ('editcp', 'Driver:')
        wpa_list = []
        wpa_warn_t = ('important', language['always_use_wext'])

        backend_cat_t = ('header', language['backend'])
        backend_t = language['backend'] + ':'
        backend_list = []

        debug_cat_t = ('header', language['debugging'])
        debug_mode_t = language['use_debug_mode']

        wless_cat_t = ('header', language['wireless_interface'])
        use_dbm_t = language['display_type_dialog']
        verify_ap_t = language['verify_ap_dialog']

        ####
        #### UI Widgets
        ####

        # General Settings
        self.net_cat = urwid.Text(net_cat_t)
        self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t), 'editbx',
                                         'editfc')
        self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t), 'editbx',
                                         'editfc')
        self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
        self.global_dns_cat = urwid.Text(global_dns_cat_t)
        # Default the global DNS settings to off.  They will be reenabled later
        # if so required.
        global_dns_state = False
        self.global_dns_checkb = urwid.CheckBox(
            global_dns_t,
            global_dns_state,
            on_state_change=self.global_dns_trigger)
        self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
        self.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
        self.dns1 = DynWrap(urwid.Edit(dns1_t), global_dns_state)
        self.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state)
        self.dns3 = DynWrap(urwid.Edit(dns3_t), global_dns_state)

        self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)

        self.wired_auto_l = []
        self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
        self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_1_t)
        self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_2_t)
        self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_3_t)

        self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
        self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
        generalLB = urwid.ListBox([
            self.net_cat,
            self.wless_edit,  #_blank,
            self.wired_edit,
            self.always_show_wired_checkb,
            self.prefer_wired_chkbx,
            _blank,
            self.global_dns_cat,
            self.global_dns_checkb,  #_blank,
            self.search_dom,
            self.dns_dom,
            self.dns1,
            self.dns2,
            self.dns3,
            _blank,
            self.wired_auto_cat,
            self.wired_auto_1,
            self.wired_auto_2,
            self.wired_auto_3,
            _blank,
            self.auto_reconn_cat,
            self.auto_reconn_checkb
        ])

        #### External Programs tab
        automatic_t = language['wicd_auto_config']

        self.dhcp_header = urwid.Text(dhcp_header_t)
        self.dhcp_l = []

        # Order of these is flipped in the actual interface,
        # (2,3,1 -> dhcpcd, pump, dhclient), because dhclient often doesn't like
        # to work on several distros.
        self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
        self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
        self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
        self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
        self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
        self.dhcp_l = [
            self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4
        ]

        self.wired_l = []
        self.wired_detect_header = urwid.Text(wired_detect_header_t)
        self.wired0 = urwid.RadioButton(self.wired_l, automatic_t)
        self.wired1 = DynRadioButton(self.wired_l, wired1_t)
        self.wired2 = DynRadioButton(self.wired_l, wired2_t)
        self.wired_l = [self.wired0, self.wired1, self.wired2]

        self.flush_l = []
        self.flush_header = urwid.Text(flush_header_t)
        self.flush0 = urwid.RadioButton(self.flush_l, automatic_t)
        self.flush1 = DynRadioButton(self.flush_l, flush1_t)
        self.flush2 = DynRadioButton(self.flush_l, flush2_t)
        self.flush_l = [self.flush0, self.flush1, self.flush2]

        externalLB = urwid.ListBox([
            self.dhcp_header, self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1,
            self.dhcp4, _blank, self.wired_detect_header, self.wired0,
            self.wired1, self.wired2, _blank, self.flush_header, self.flush0,
            self.flush1, self.flush2
        ])

        #### Advanced settings
        self.wpa_cat = urwid.Text(wpa_cat_t)
        self.wpa_cbox = ComboBox(wpa_t)
        self.wpa_warn = urwid.Text(wpa_warn_t)

        self.backend_cat = urwid.Text(backend_cat_t)
        self.backend_cbox = ComboBox(backend_t)

        self.debug_cat = urwid.Text(debug_cat_t)
        self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)

        self.wless_cat = urwid.Text(wless_cat_t)
        self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
        self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)

        advancedLB = urwid.ListBox([
            self.wpa_cat, self.wpa_cbox, self.wpa_warn, _blank,
            self.backend_cat, self.backend_cbox, _blank, self.debug_cat,
            self.debug_mode_checkb, _blank, self.wless_cat,
            self.use_dbm_checkb, _blank, self.verify_ap_checkb, _blank
        ])

        headerList = [self.header0, self.header1, self.header2]
        lbList = [generalLB, externalLB, advancedLB]
        self.tab_map = {
            self.header0: generalLB,
            self.header1: externalLB,
            self.header2: advancedLB
        }
        #self.load_settings()

        self.tabs = TabColumns(headerList, lbList, language['preferences'])
        self.__super.__init__(self.tabs)
예제 #10
0
class PrefsDialog(urwid.WidgetWrap):
    def __init__(self, body, pos, ui, dbus=None):
        global daemon, wireless, wired

        daemon = dbus['daemon']
        wireless = dbus['wireless']
        wired = dbus['wired']

        width, height = ui.get_cols_rows()
        height -= 3
        #width = 80
        #height = 20
        # Stuff that goes at the top

        header0_t = language["gen_settings"]
        header1_t = language["ext_programs"]
        header2_t = language["advanced_settings"]
        self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active',
                                      'focus')
        self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
        self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
        title = language['preferences']

        # Blank line
        _blank = urwid.Text('')

        ####
        #### Text in the widgets
        ####

        # General Settings
        net_cat_t = ('header', language['network_interfaces'])
        wired_t = ('editcp', language['wired_interface'] + ':   ')
        wless_t = ('editcp', language['wireless_interface'] + ':')
        always_show_wired_t = language['wired_always_on']
        prefer_wired_t = language['always_switch_to_wired']

        global_dns_cat_t = ('header', language['global_dns_servers'])
        global_dns_t = ('editcp', language['use_global_dns'])
        dns_dom_t = ('editcp', '    ' + language['dns_domain'] + ':   ')
        search_dom_t = ('editcp', '    ' + language['search_domain'] + ':')
        dns1_t = ('editcp', '    DNS server 1: ')
        dns2_t = ('editcp', '    DNS server 2: ')
        dns3_t = ('editcp', '    DNS server 3: ')

        wired_auto_cat_t = ('header', language['wired_autoconnect_settings'])
        wired_auto_1_t = language['use_default_profile']
        wired_auto_2_t = language['show_wired_list']
        wired_auto_3_t = language['use_last_used_profile']

        auto_reconn_cat_t = ('header', language['automatic_reconnection'])
        auto_reconn_t = language['auto_reconnect']

        #### External Programs
        automatic_t = language['wicd_auto_config']

        dhcp_header_t = ('header', language["dhcp_client"])
        # Automatic
        dhcp1_t = 'dhclient'
        dhcp2_t = 'dhcpcd'
        dhcp3_t = 'pump'
        dhcp4_t = 'udhcpc'

        wired_detect_header_t = ('header', language["wired_detect"])
        wired1_t = 'ethtool'
        wired2_t = 'mii-tool'

        flush_header_t = ('header', language["route_flush"])
        flush1_t = 'ip'
        flush2_t = 'route'

        #### Advanced Settings
        wpa_cat_t = ('header', language['wpa_supplicant'])
        wpa_t = ('editcp', 'Driver:')
        wpa_list = []
        wpa_warn_t = ('important', language['always_use_wext'])

        backend_cat_t = ('header', language['backend'])
        backend_t = language['backend'] + ':'
        backend_list = []

        debug_cat_t = ('header', language['debugging'])
        debug_mode_t = language['use_debug_mode']

        wless_cat_t = ('header', language['wireless_interface'])
        use_dbm_t = language['display_type_dialog']
        verify_ap_t = language['verify_ap_dialog']

        ####
        #### UI Widgets
        ####

        # General Settings
        self.net_cat = urwid.Text(net_cat_t)
        self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t), 'editbx',
                                         'editfc')
        self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t), 'editbx',
                                         'editfc')
        self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
        self.global_dns_cat = urwid.Text(global_dns_cat_t)
        # Default the global DNS settings to off.  They will be reenabled later
        # if so required.
        global_dns_state = False
        self.global_dns_checkb = urwid.CheckBox(
            global_dns_t,
            global_dns_state,
            on_state_change=self.global_dns_trigger)
        self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
        self.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
        self.dns1 = DynWrap(urwid.Edit(dns1_t), global_dns_state)
        self.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state)
        self.dns3 = DynWrap(urwid.Edit(dns3_t), global_dns_state)

        self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)

        self.wired_auto_l = []
        self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
        self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_1_t)
        self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_2_t)
        self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_3_t)

        self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
        self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
        generalLB = urwid.ListBox([
            self.net_cat,
            self.wless_edit,  #_blank,
            self.wired_edit,
            self.always_show_wired_checkb,
            self.prefer_wired_chkbx,
            _blank,
            self.global_dns_cat,
            self.global_dns_checkb,  #_blank,
            self.search_dom,
            self.dns_dom,
            self.dns1,
            self.dns2,
            self.dns3,
            _blank,
            self.wired_auto_cat,
            self.wired_auto_1,
            self.wired_auto_2,
            self.wired_auto_3,
            _blank,
            self.auto_reconn_cat,
            self.auto_reconn_checkb
        ])

        #### External Programs tab
        automatic_t = language['wicd_auto_config']

        self.dhcp_header = urwid.Text(dhcp_header_t)
        self.dhcp_l = []

        # Order of these is flipped in the actual interface,
        # (2,3,1 -> dhcpcd, pump, dhclient), because dhclient often doesn't like
        # to work on several distros.
        self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
        self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
        self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
        self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
        self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
        self.dhcp_l = [
            self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4
        ]

        self.wired_l = []
        self.wired_detect_header = urwid.Text(wired_detect_header_t)
        self.wired0 = urwid.RadioButton(self.wired_l, automatic_t)
        self.wired1 = DynRadioButton(self.wired_l, wired1_t)
        self.wired2 = DynRadioButton(self.wired_l, wired2_t)
        self.wired_l = [self.wired0, self.wired1, self.wired2]

        self.flush_l = []
        self.flush_header = urwid.Text(flush_header_t)
        self.flush0 = urwid.RadioButton(self.flush_l, automatic_t)
        self.flush1 = DynRadioButton(self.flush_l, flush1_t)
        self.flush2 = DynRadioButton(self.flush_l, flush2_t)
        self.flush_l = [self.flush0, self.flush1, self.flush2]

        externalLB = urwid.ListBox([
            self.dhcp_header, self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1,
            self.dhcp4, _blank, self.wired_detect_header, self.wired0,
            self.wired1, self.wired2, _blank, self.flush_header, self.flush0,
            self.flush1, self.flush2
        ])

        #### Advanced settings
        self.wpa_cat = urwid.Text(wpa_cat_t)
        self.wpa_cbox = ComboBox(wpa_t)
        self.wpa_warn = urwid.Text(wpa_warn_t)

        self.backend_cat = urwid.Text(backend_cat_t)
        self.backend_cbox = ComboBox(backend_t)

        self.debug_cat = urwid.Text(debug_cat_t)
        self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)

        self.wless_cat = urwid.Text(wless_cat_t)
        self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
        self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)

        advancedLB = urwid.ListBox([
            self.wpa_cat, self.wpa_cbox, self.wpa_warn, _blank,
            self.backend_cat, self.backend_cbox, _blank, self.debug_cat,
            self.debug_mode_checkb, _blank, self.wless_cat,
            self.use_dbm_checkb, _blank, self.verify_ap_checkb, _blank
        ])

        headerList = [self.header0, self.header1, self.header2]
        lbList = [generalLB, externalLB, advancedLB]
        self.tab_map = {
            self.header0: generalLB,
            self.header1: externalLB,
            self.header2: advancedLB
        }
        #self.load_settings()

        self.tabs = TabColumns(headerList, lbList, language['preferences'])
        self.__super.__init__(self.tabs)

    def load_settings(self):

        ### General Settings
        # ComboBox does not like dbus.Strings as text markups.  My fault. :/
        wless_iface = unicode(daemon.GetWirelessInterface())
        wired_iface = unicode(daemon.GetWiredInterface())
        self.wless_edit.set_edit_text(wless_iface)
        self.wired_edit.set_edit_text(wired_iface)

        self.always_show_wired_checkb.set_state(
            daemon.GetAlwaysShowWiredInterface())
        self.prefer_wired_chkbx.set_state(daemon.GetPreferWiredNetwork())
        # DNS
        self.global_dns_checkb.set_state(daemon.GetUseGlobalDNS())
        theDNS = daemon.GetGlobalDNSAddresses()

        i = 0
        for w in self.dns1, self.dns2, self.dns3, self.dns_dom, self.search_dom:
            w.set_edit_text(misc.noneToBlankString(theDNS[i]))
            i += 1

        # Wired Automatic Connection
        self.wired_auto_l[daemon.GetWiredAutoConnectMethod() - 1]
        self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())

        def find_avail(apps):
            for app in apps[1:]:
                app.set_sensitive(daemon.GetAppAvailable(app.get_label()))

        ### External Programs
        find_avail(self.dhcp_l)
        dhcp_method = daemon.GetDHCPClient()
        self.dhcp_l[dhcp_method].set_state(True)

        find_avail(self.wired_l)
        wired_link_method = daemon.GetLinkDetectionTool()
        self.wired_l[wired_link_method].set_state(True)

        find_avail(self.flush_l)
        flush_method = daemon.GetFlushTool()
        self.flush_l[flush_method].set_state(True)

        ### Advanced settings
        # wpa_supplicant janx
        self.wpadrivers = wireless.GetWpaSupplicantDrivers()
        self.wpadrivers.append("ralink_legacy")
        # Same as above with the dbus.String
        self.thedrivers = [unicode(w) for w in self.wpadrivers]
        self.wpa_cbox.set_list(self.thedrivers)

        # Pick where to begin first:
        def_driver = daemon.GetWPADriver()
        try:
            self.wpa_cbox.set_focus(self.wpadrivers.index(def_driver))
        except ValueError:
            pass  # It defaults to 0 anyway (I hope)

        self.backends = daemon.GetBackendList()
        self.thebackends = [unicode(w) for w in self.backends]
        self.backend_cbox.set_list(self.thebackends)
        cur_backend = daemon.GetSavedBackend()
        try:
            self.backend_cbox.set_focus(self.thebackends.index(cur_backend))
        except ValueError:
            self.backend_cbox.set_focus(0)

        # Three last checkboxes
        self.debug_mode_checkb.set_state(daemon.GetDebugMode())
        self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
        self.verify_ap_checkb.set_state(daemon.GetShouldVerifyAp())

    def save_settings(self):
        """ Pushes the selected settings to the daemon.
            This exact order is found in prefs.py"""
        daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())

        for i in [
                self.dns1, self.dns2, self.dns3, self.dns_dom, self.search_dom,
                self.dns_dom
        ]:
            i.set_edit_text(i.get_edit_text().strip())

        daemon.SetGlobalDNS(self.dns1.get_edit_text(),
                            self.dns2.get_edit_text(),
                            self.dns3.get_edit_text(),
                            self.dns_dom.get_edit_text(),
                            self.search_dom.get_edit_text())
        daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
        daemon.SetWiredInterface(self.wired_edit.get_edit_text())
        daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_focus()[1]])
        daemon.SetAlwaysShowWiredInterface(
            self.always_show_wired_checkb.get_state())
        daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
        daemon.SetDebugMode(self.debug_mode_checkb.get_state())
        daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
        daemon.SetShouldVerifyAp(int(self.verify_ap_checkb.get_state()))
        daemon.SetPreferWiredNetwork(bool(self.prefer_wired_chkbx.get_state()))
        if self.wired_auto_2.get_state():
            daemon.SetWiredAutoConnectMethod(2)
        elif self.wired_auto_3.get_state():
            daemon.SetWiredAutoConnectMethod(3)
        else:
            daemon.SetWiredAutoConnectMethod(1)

        daemon.SetBackend(self.backends[self.backend_cbox.get_focus()[1]])

        # External Programs Tab
        if self.dhcp0.get_state():
            dhcp_client = misc.AUTO
        elif self.dhcp1.get_state():
            dhcp_client = misc.DHCLIENT
        elif self.dhcp2.get_state():
            dhcp_client = misc.DHCPCD
        elif self.dhcp3.get_state():
            dhcp_client = misc.PUMP
        else:
            dhcp_client = misc.UDHCPC
        daemon.SetDHCPClient(dhcp_client)

        if self.wired0.get_state():
            link_tool = misc.AUTO
        elif self.wired1.get_state():
            link_tool = misc.ETHTOOL
        else:
            link_tool = misc.MIITOOL
        daemon.SetLinkDetectionTool(link_tool)

        if self.flush0.get_state():
            flush_tool = misc.AUTO
        elif self.flush1.get_state():
            flush_tool = misc.IP
        else:
            flush_tool = misc.ROUTE
        daemon.SetFlushTool(flush_tool)

    # DNS CheckBox callback
    def global_dns_trigger(self, check_box, new_state, user_data=None):
        for w in self.dns1, self.dns2, self.dns3, self.dns_dom, self.search_dom:
            w.set_sensitive(new_state)

    def ready_widgets(self, ui, body):
        self.wpa_cbox.build_combobox(body, ui, 4)
        self.backend_cbox.build_combobox(body, ui, 8)
예제 #11
0
class WirelessSettingsDialog(AdvancedSettingsDialog):
    """ Settings dialog for wireless interfaces. """
    def __init__(self, networkID, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = False

        self.bitrates = None

        self.networkid = networkID
        self.parent = parent
        global_settings_t = \
            _('Use these settings for all networks sharing this essid')
        encryption_t = _('Use Encryption')
        autoconnect_t = _('Automatically connect to this network')
        bitrate_t = _('Wireless bitrate')
        allow_lower_bitrates_t = _('Allow lower bitrates')

        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(
            encryption_t, on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.bitrate_combo = ComboBox(bitrate_t)
        self.allow_lower_bitrates_chkbox = \
            urwid.CheckBox(allow_lower_bitrates_t)

        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.bitrate_combo)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.allow_lower_bitrates_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(urwid.Text(''))
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.global_settings_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.autoconnect_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = _('Configuring preferences for wireless network "$A" ($B)'). \
            replace('$A', wireless.GetWirelessProperty(networkID, 'essid')). \
            replace('$B', wireless.GetWirelessProperty(networkID, 'bssid'))
        self._w.header = urwid.Text(('header', title), align='right')

    def set_values(self):
        """ Set the various network settings to the right values. """
        networkID = self.networkid
        self.ip_edit.set_edit_text(self.format_entry(networkID, "ip"))
        self.netmask_edit.set_edit_text(self.format_entry(
            networkID, "netmask"))
        self.gateway_edit.set_edit_text(self.format_entry(
            networkID, "gateway"))

        self.global_dns_cb.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'use_global_dns')))
        self.static_dns_cb.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'use_static_dns')))

        if stringToNone(self.ip_edit.get_edit_text()):
            self.static_ip_cb.set_state(True)
        self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
        self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
        self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
        self.dns_dom_edit.set_edit_text(
            self.format_entry(networkID, "dns_domain"))
        self.search_dom_edit.set_edit_text(
            self.format_entry(networkID, "search_domain"))

        self.autoconnect_chkbox.set_state(
            to_bool(self.format_entry(networkID, "automatic")))

        self.bitrates = wireless.GetAvailableBitrates()
        self.bitrates.append('auto')
        self.bitrate_combo.set_list(self.bitrates)
        bitrate = wireless.GetWirelessProperty(networkID, 'bitrate')
        if bitrate is not None:
            self.bitrate_combo.set_focus(self.bitrates.index(bitrate))
        self.allow_lower_bitrates_chkbox.set_state(
            to_bool(self.format_entry(networkID, 'allow_lower_bitrates')))

        #self.reset_static_checkboxes()
        self.encryption_chkbox.set_state(bool(
            wireless.GetWirelessProperty(networkID, 'encryption')),
                                         do_callback=False)
        self.global_settings_chkbox.set_state(
            bool(
                wireless.GetWirelessProperty(networkID,
                                             'use_settings_globally')))

        # Throw the encryption stuff into a list
        l = []
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            l.append(enc_type['name'])
            if enc_type['type'] == \
              wireless.GetWirelessProperty(networkID, "enctype"):
                activeID = x
        self.encryption_combo.set_list(l)

        self.encryption_combo.set_focus(activeID)
        if activeID != -1:
            self.encryption_chkbox.set_state(True, do_callback=False)
            self.encryption_combo.set_sensitive(True)
            #self.lbox_encrypt_info.set_sensitive(True)
        else:
            self.encryption_combo.set_focus(0)

        self.change_encrypt_method()
        dhcphname = wireless.GetWirelessProperty(networkID, "dhcphostname")
        if dhcphname is None:
            dhcphname = os.uname()[1]
        self.use_dhcp_h.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'usedhcphostname')))
        self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
        self.dhcp_h.set_edit_text(str(dhcphname))

    def set_net_prop(self, option, value):
        """ Sets the given option to the given value for this network. """
        wireless.SetWirelessProperty(self.networkid, option, value)

    def format_entry(self, networkid, label):
        """ Helper method for fetching/formatting wireless properties. """
        return noneToBlankString(wireless.GetWirelessProperty(
            networkid, label))

    # Ripped from netentry.py
    def save_settings(self):
        """ Save settings to disk. """
        # Check encryption info
        if self.encryption_chkbox.get_state():
            encrypt_info = self.encryption_info
            encrypt_methods = self.encrypt_types
            self.set_net_prop(
                "enctype",
                encrypt_methods[self.encryption_combo.get_focus()[1]]['type'])
            # Make sure all required fields are filled in.
            for entry_info in encrypt_info.values():
                if entry_info[0].get_edit_text() == "" \
                    and entry_info[1] == 'required':
                    error(
                        self.ui, self.parent, "%s (%s)" %
                        (_('Required encryption information is missing.'),
                         entry_info[0].get_caption()[0:-2]))
                    return False

            for entry_key, entry_info in encrypt_info.items():
                self.set_net_prop(entry_key,
                                  noneToString(entry_info[0].get_edit_text()))
        elif not self.encryption_chkbox.get_state() and \
             wireless.GetWirelessProperty(self.networkid, "encryption"):
            # Encrypt checkbox is off, but the network needs it.
            error(self.ui, self.parent,
                  _('This network requires encryption to be enabled.'))
            return False
        else:
            self.set_net_prop("enctype", "None")
        AdvancedSettingsDialog.save_settings(self)

        # Save the autoconnect setting.  This is not where it originally was
        # in the GTK UI.
        self.set_net_prop("automatic", self.autoconnect_chkbox.get_state())

        if self.global_settings_chkbox.get_state():
            self.set_net_prop('use_settings_globally', True)
        else:
            self.set_net_prop('use_settings_globally', False)
            wireless.RemoveGlobalEssidEntry(self.networkid)

        self.set_net_prop('bitrate',
                          self.bitrates[self.bitrate_combo.get_focus()[1]])
        self.set_net_prop('allow_lower_bitrates',
                          self.allow_lower_bitrates_chkbox.get_state())
        wireless.SaveWirelessNetworkProfile(self.networkid)
        return True

    def ready_widgets(self, ui, body):
        """ Build comboboxes. """
        AdvancedSettingsDialog.ready_widgets(self, ui, body)
        self.ui = ui
        self.body = body
        self.bitrate_combo.build_combobox(body, ui, 17)
예제 #12
0
    def __init__(self, body, pos, ui, dbus=None):
        global daemon, wireless, wired

        self.thebackends = None
        self.backends = None
        self.wpadrivers = None
        self.thedrivers = None

        daemon = dbus['daemon']
        wireless = dbus['wireless']
        wired = dbus['wired']

        width, height = ui.get_cols_rows()
        height -= 3
        #width = 80
        #height = 20
        # Stuff that goes at the top

        header0_t = _('General Settings')
        header1_t = _('External Programs')
        header2_t = _('Advanced Settings')
        self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active', 'focus')
        self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
        self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
        title = ('Preferences')

        # Blank line
        _blank = urwid.Text('')

        ####
        #### Text in the widgets
        ####

        # General Settings
        net_cat_t = ('header', ('Network Interfaces'))
        wired_t = ('editcp', ('Wired Interface') + ':   ')
        wless_t = ('editcp', ('Wireless Interface') + ':')
        always_show_wired_t = _('Always show wired interface')
        prefer_wired_t = _('Always switch to wired connection when available')

        global_dns_cat_t = ('header', _('Global DNS servers'))
        global_dns_t = ('editcp', _('Use global DNS servers'))
        dns_dom_t = ('editcp', '    ' + _('DNS domain') + ':   ')
        search_dom_t = ('editcp', '    ' + _('Search domain') + ':')
        dns1_t = ('editcp', '    ' + _('DNS server') + ' 1: ')
        dns2_t = ('editcp', '    ' + _('DNS server') + ' 2: ')
        dns3_t = ('editcp', '    ' + _('DNS server') + ' 3: ')

        wired_auto_cat_t = ('header', _('Wired Autoconnect Settings'))
        wired_auto_1_t = _('Use default profile on wired autoconnect')
        wired_auto_2_t = _('Prompt for profile on wired autoconnect')
        wired_auto_3_t = _('Use last used profile on wired autoconnect')

        auto_reconn_cat_t = ('header', _('Automatic Reconnection'))
        auto_reconn_t = _('Automatically reconnect on connection loss')

        #### External Programs
        automatic_t = _('Automatic (recommended)')

        dhcp_header_t = ('header', _('DHCP Client'))
        # Automatic
        dhcp1_t = 'dhclient'
        dhcp2_t = 'dhcpcd'
        dhcp3_t = 'pump'
        dhcp4_t = 'udhcpc'

        wired_detect_header_t = ('header', _('Wired Link Detection'))
        wired1_t = 'ethtool'
        wired2_t = 'mii-tool'

        flush_header_t = ('header', _('Route Table Flushing'))
        flush1_t = 'ip'
        flush2_t = 'route'

        #### Advanced Settings
        wpa_cat_t = ('header', _('WPA Supplicant'))
        wpa_t = ('editcp', 'Driver:')
        wpa_list = []
        wpa_warn_t = ('important',
            _('You should almost always use wext as the WPA supplicant driver'))

        backend_cat_t = ('header', _('Backend'))
        backend_t = _('Backend') + ':'
        backend_list = []

        debug_cat_t = ('header', _('Debugging'))
        debug_mode_t = _('Enable debug mode')

        wless_cat_t = ('header', _('Wireless Interface'))
        use_dbm_t = _('Use dBm to measure signal strength')
        verify_ap_t = \
            _('Ping static gateways after connecting to verify association')

        ####
        #### UI Widgets
        ####

        # General Settings
        self.net_cat = urwid.Text(net_cat_t)
        self.wired_edit = \
            urwid.AttrWrap(urwid.Edit(wired_t), 'editbx', 'editfc')
        self.wless_edit = \
            urwid.AttrWrap(urwid.Edit(wless_t), 'editbx', 'editfc')
        self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
        self.global_dns_cat = urwid.Text(global_dns_cat_t)
        # Default the global DNS settings to off.  They will be reenabled later
        # if so required.
        global_dns_state = False
        self.global_dns_checkb = urwid.CheckBox(global_dns_t,
             global_dns_state,
            on_state_change=self.global_dns_trigger
        )
        self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
        self.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
        self.dns1 = DynWrap(urwid.Edit(dns1_t), global_dns_state)
        self.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state)
        self.dns3 = DynWrap(urwid.Edit(dns3_t), global_dns_state)

        self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)

        self.wired_auto_l = []
        self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
        self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l, wired_auto_1_t)
        self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l, wired_auto_2_t)
        self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l, wired_auto_3_t)

        self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
        self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
        generalLB = urwid.ListBox([
            self.net_cat,
            self.wless_edit,  # _blank,
            self.wired_edit,
            self.always_show_wired_checkb,
            self.prefer_wired_chkbx, _blank,
            self.global_dns_cat,
            self.global_dns_checkb,  # _blank,
            self.search_dom, self.dns_dom,
            self.dns1, self.dns2, self.dns3, _blank,
            self.wired_auto_cat,
            self.wired_auto_1,
            self.wired_auto_2,
            self.wired_auto_3, _blank,
            self.auto_reconn_cat,
            self.auto_reconn_checkb
        ])

        #### External Programs tab
        automatic_t = _('Automatic (recommended)')

        self.dhcp_header = urwid.Text(dhcp_header_t)
        self.dhcp_l = []

        # Order of these is flipped in the actual interface,
        # (2, 3, 1 -> dhcpcd, pump, dhclient), because dhclient often doesn't
        # like to work on several distros.
        self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
        self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
        self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
        self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
        self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
        self.dhcp_l = [
            self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4
        ]

        self.wired_l = []
        self.wired_detect_header = urwid.Text(wired_detect_header_t)
        self.wired0 = urwid.RadioButton(self.wired_l, automatic_t)
        self.wired1 = DynRadioButton(self.wired_l, wired1_t)
        self.wired2 = DynRadioButton(self.wired_l, wired2_t)
        self.wired_l = [self.wired0, self.wired1, self.wired2]

        self.flush_l = []
        self.flush_header = urwid.Text(flush_header_t)
        self.flush0 = urwid.RadioButton(self.flush_l, automatic_t)
        self.flush1 = DynRadioButton(self.flush_l, flush1_t)
        self.flush2 = DynRadioButton(self.flush_l, flush2_t)
        self.flush_l = [self.flush0, self.flush1, self.flush2]

        externalLB = urwid.ListBox([
            self.dhcp_header,
            self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1, self.dhcp4,
            _blank,
            self.wired_detect_header,
            self.wired0, self.wired1, self.wired2,
            _blank,
            self.flush_header,
            self.flush0, self.flush1, self.flush2
        ])

        #### Advanced settings
        self.wpa_cat = urwid.Text(wpa_cat_t)
        self.wpa_cbox = ComboBox(wpa_t)
        self.wpa_warn = urwid.Text(wpa_warn_t)

        self.backend_cat = urwid.Text(backend_cat_t)
        self.backend_cbox = ComboBox(backend_t)

        self.debug_cat = urwid.Text(debug_cat_t)
        self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)

        self.wless_cat = urwid.Text(wless_cat_t)
        self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
        self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)

        advancedLB = urwid.ListBox([
            self.wpa_cat,
            self.wpa_cbox, self.wpa_warn, _blank,
            self.backend_cat,
            self.backend_cbox, _blank,
            self.debug_cat,
            self.debug_mode_checkb, _blank,
            self.wless_cat,
            self.use_dbm_checkb, _blank,
            self.verify_ap_checkb, _blank
        ])

        headerList = [self.header0, self.header1, self.header2]
        lbList = [generalLB, externalLB, advancedLB]
        self.tab_map = {
            self.header0: generalLB,
            self.header1: externalLB,
            self.header2: advancedLB
        }
        #self.load_settings()

        self.tabs = TabColumns(headerList, lbList, _('Preferences'))
        # pylint: disable-msg=E1101
        self.__super.__init__(self.tabs)
예제 #13
0
class WirelessSettingsDialog(AdvancedSettingsDialog):
    """ Settings dialog for wireless interfaces. """
    def __init__(self, networkID, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = False

        self.bitrates = None

        self.networkid = networkID
        self.parent = parent
        global_settings_t = \
            _('Use these settings for all networks sharing this essid')
        encryption_t = _('Use Encryption')
        autoconnect_t = _('Automatically connect to this network')
        bitrate_t = _('Wireless bitrate')
        allow_lower_bitrates_t = _('Allow lower bitrates')

        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(
            encryption_t,
            on_state_change=self.
            encryption_toggle
        )
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.bitrate_combo = ComboBox(bitrate_t)
        self.allow_lower_bitrates_chkbox = \
            urwid.CheckBox(allow_lower_bitrates_t)

        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.bitrate_combo)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.allow_lower_bitrates_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(urwid.Text(''))
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.global_settings_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.autoconnect_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = _('Configuring preferences for wireless network "$A" ($B)'). \
            replace('$A', wireless.GetWirelessProperty(networkID, 'essid')). \
            replace('$B', wireless.GetWirelessProperty(networkID, 'bssid'))
        self._w.header = urwid.Text(('header', title), align='right')

    def set_values(self):
        """ Set the various network settings to the right values. """
        networkID = self.networkid
        self.ip_edit.set_edit_text(self.format_entry(networkID, "ip"))
        self.netmask_edit.set_edit_text(self.format_entry(networkID, "netmask"))
        self.gateway_edit.set_edit_text(self.format_entry(networkID, "gateway"))

        self.global_dns_cb.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'use_global_dns')))
        self.static_dns_cb.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'use_static_dns')))

        if stringToNone(self.ip_edit.get_edit_text()):
            self.static_ip_cb.set_state(True)
        self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
        self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
        self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
        self.dns_dom_edit.set_edit_text(
            self.format_entry(networkID, "dns_domain")
        )
        self.search_dom_edit.set_edit_text(
            self.format_entry(networkID, "search_domain")
        )

        self.autoconnect_chkbox.set_state(
            to_bool(self.format_entry(networkID, "automatic"))
        )

        self.bitrates = wireless.GetAvailableBitrates()
        self.bitrates.append('auto')
        self.bitrate_combo.set_list(self.bitrates)
        self.bitrate_combo.set_focus(
            self.bitrates.index(
                wireless.GetWirelessProperty(networkID, 'bitrate')
            )
        )
        self.allow_lower_bitrates_chkbox.set_state(
            to_bool(self.format_entry(networkID, 'allow_lower_bitrates'))
        )

        #self.reset_static_checkboxes()
        self.encryption_chkbox.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'encryption')),
            do_callback=False)
        self.global_settings_chkbox.set_state(
            bool(wireless.GetWirelessProperty(
                networkID,
                'use_settings_globally')
            )
        )

        # Throw the encryption stuff into a list
        l = []
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            l.append(enc_type['name'])
            if enc_type['type'] == \
              wireless.GetWirelessProperty(networkID, "enctype"):
                activeID = x
        self.encryption_combo.set_list(l)

        self.encryption_combo.set_focus(activeID)
        if activeID != -1:
            self.encryption_chkbox.set_state(True, do_callback=False)
            self.encryption_combo.set_sensitive(True)
            #self.lbox_encrypt_info.set_sensitive(True)
        else:
            self.encryption_combo.set_focus(0)

        self.change_encrypt_method()
        dhcphname = wireless.GetWirelessProperty(networkID, "dhcphostname")
        if dhcphname is None:
            dhcphname = os.uname()[1]
        self.use_dhcp_h.set_state(
            bool(wireless.GetWirelessProperty(networkID, 'usedhcphostname'))
        )
        self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
        self.dhcp_h.set_edit_text(unicode(dhcphname))

    def set_net_prop(self, option, value):
        """ Sets the given option to the given value for this network. """
        wireless.SetWirelessProperty(self.networkid, option, value)

    def format_entry(self, networkid, label):
        """ Helper method for fetching/formatting wireless properties. """
        return noneToBlankString(wireless.GetWirelessProperty(networkid, label))

    # Ripped from netentry.py
    def save_settings(self):
        """ Save settings to disk. """
        # Check encryption info
        if self.encryption_chkbox.get_state():
            encrypt_info = self.encryption_info
            encrypt_methods = self.encrypt_types
            self.set_net_prop(
                "enctype",
                encrypt_methods[self.encryption_combo.get_focus()[1]]['type']
            )
            # Make sure all required fields are filled in.
            for entry_info in encrypt_info.itervalues():
                if entry_info[0].get_edit_text() == "" \
                    and entry_info[1] == 'required':
                    error(
                        self.ui,
                        self.parent,
                        "%s (%s)" % (
                            _('Required encryption information is missing.'),
                            entry_info[0].get_caption()[0:-2]
                        )
                    )
                    return False

            for entry_key, entry_info in encrypt_info.iteritems():
                self.set_net_prop(entry_key, noneToString(entry_info[0].
                                                   get_edit_text()))
        elif not self.encryption_chkbox.get_state() and \
             wireless.GetWirelessProperty(self.networkid, "encryption"):
            # Encrypt checkbox is off, but the network needs it.
            error(
                self.ui,
                self.parent,
                _('This network requires encryption to be enabled.')
            )
            return False
        else:
            self.set_net_prop("enctype", "None")
        AdvancedSettingsDialog.save_settings(self)

        # Save the autoconnect setting.  This is not where it originally was
        # in the GTK UI.
        self.set_net_prop("automatic", self.autoconnect_chkbox.get_state())

        if self.global_settings_chkbox.get_state():
            self.set_net_prop('use_settings_globally', True)
        else:
            self.set_net_prop('use_settings_globally', False)
            wireless.RemoveGlobalEssidEntry(self.networkid)

        self.set_net_prop(
            'bitrate',
            self.bitrates[self.bitrate_combo.get_focus()[1]]
        )
        self.set_net_prop(
            'allow_lower_bitrates',
            self.allow_lower_bitrates_chkbox.get_state()
        )
        wireless.SaveWirelessNetworkProfile(self.networkid)
        return True

    def ready_widgets(self, ui, body):
        """ Build comboboxes. """
        AdvancedSettingsDialog.ready_widgets(self, ui, body)
        self.ui = ui
        self.body = body
        self.bitrate_combo.build_combobox(body, ui, 17)
예제 #14
0
    def __init__(self, body, pos, ui, dbus=None):
        global daemon, wireless, wired

        self.thebackends = None
        self.backends = None
        self.wpadrivers = None
        self.thedrivers = None

        daemon = dbus['daemon']
        wireless = dbus['wireless']
        wired = dbus['wired']

        width, height = ui.get_cols_rows()
        height -= 3
        #width = 80
        #height = 20
        # Stuff that goes at the top

        header0_t = _('General Settings')
        header1_t = _('External Programs')
        header2_t = _('Advanced Settings')
        self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active',
                                      'focus')
        self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
        self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
        title = ('Preferences')

        # Blank line
        _blank = urwid.Text('')

        ####
        #### Text in the widgets
        ####

        # General Settings
        net_cat_t = ('header', ('Network Interfaces'))
        wired_t = ('editcp', ('Wired Interface') + ':   ')
        wless_t = ('editcp', ('Wireless Interface') + ':')
        always_show_wired_t = _('Always show wired interface')
        prefer_wired_t = _('Always switch to wired connection when available')

        global_dns_cat_t = ('header', _('Global DNS servers'))
        global_dns_t = ('editcp', _('Use global DNS servers'))
        dns_dom_t = ('editcp', '    ' + _('DNS domain') + ':   ')
        search_dom_t = ('editcp', '    ' + _('Search domain') + ':')
        dns1_t = ('editcp', '    ' + _('DNS server') + ' 1: ')
        dns2_t = ('editcp', '    ' + _('DNS server') + ' 2: ')
        dns3_t = ('editcp', '    ' + _('DNS server') + ' 3: ')

        wired_auto_cat_t = ('header', _('Wired Autoconnect Settings'))
        wired_auto_1_t = _('Use default profile on wired autoconnect')
        wired_auto_2_t = _('Prompt for profile on wired autoconnect')
        wired_auto_3_t = _('Use last used profile on wired autoconnect')

        auto_reconn_cat_t = ('header', _('Automatic Reconnection'))
        auto_reconn_t = _('Automatically reconnect on connection loss')

        #### External Programs
        automatic_t = _('Automatic (recommended)')

        dhcp_header_t = ('header', _('DHCP Client'))
        # Automatic
        dhcp1_t = 'dhclient'
        dhcp2_t = 'dhcpcd'
        dhcp3_t = 'pump'
        dhcp4_t = 'udhcpc'

        wired_detect_header_t = ('header', _('Wired Link Detection'))
        wired1_t = 'ethtool'
        wired2_t = 'mii-tool'

        flush_header_t = ('header', _('Route Table Flushing'))
        flush1_t = 'ip'
        flush2_t = 'route'

        #### Advanced Settings
        wpa_cat_t = ('header', _('WPA Supplicant'))
        wpa_t = ('editcp', 'Driver:')
        wpa_list = []
        wpa_warn_t = (
            'important',
            _('You should almost always use wext as the WPA supplicant driver')
        )

        backend_cat_t = ('header', _('Backend'))
        backend_t = _('Backend') + ':'
        backend_list = []

        debug_cat_t = ('header', _('Debugging'))
        debug_mode_t = _('Enable debug mode')

        wless_cat_t = ('header', _('Wireless Interface'))
        use_dbm_t = _('Use dBm to measure signal strength')
        verify_ap_t = \
            _('Ping static gateways after connecting to verify association')

        ####
        #### UI Widgets
        ####

        # General Settings
        self.net_cat = urwid.Text(net_cat_t)
        self.wired_edit = \
            urwid.AttrWrap(urwid.Edit(wired_t), 'editbx', 'editfc')
        self.wless_edit = \
            urwid.AttrWrap(urwid.Edit(wless_t), 'editbx', 'editfc')
        self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
        self.global_dns_cat = urwid.Text(global_dns_cat_t)
        # Default the global DNS settings to off.  They will be reenabled later
        # if so required.
        global_dns_state = False
        self.global_dns_checkb = urwid.CheckBox(
            global_dns_t,
            global_dns_state,
            on_state_change=self.global_dns_trigger)
        self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
        self.dns_dom = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
        self.dns1 = DynWrap(urwid.Edit(dns1_t), global_dns_state)
        self.dns2 = DynWrap(urwid.Edit(dns2_t), global_dns_state)
        self.dns3 = DynWrap(urwid.Edit(dns3_t), global_dns_state)

        self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)

        self.wired_auto_l = []
        self.wired_auto_cat = urwid.Text(wired_auto_cat_t)
        self.wired_auto_1 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_1_t)
        self.wired_auto_2 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_2_t)
        self.wired_auto_3 = urwid.RadioButton(self.wired_auto_l,
                                              wired_auto_3_t)

        self.auto_reconn_cat = urwid.Text(auto_reconn_cat_t)
        self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
        generalLB = urwid.ListBox([
            self.net_cat,
            self.wless_edit,  # _blank,
            self.wired_edit,
            self.always_show_wired_checkb,
            self.prefer_wired_chkbx,
            _blank,
            self.global_dns_cat,
            self.global_dns_checkb,  # _blank,
            self.search_dom,
            self.dns_dom,
            self.dns1,
            self.dns2,
            self.dns3,
            _blank,
            self.wired_auto_cat,
            self.wired_auto_1,
            self.wired_auto_2,
            self.wired_auto_3,
            _blank,
            self.auto_reconn_cat,
            self.auto_reconn_checkb
        ])

        #### External Programs tab
        automatic_t = _('Automatic (recommended)')

        self.dhcp_header = urwid.Text(dhcp_header_t)
        self.dhcp_l = []

        # Order of these is flipped in the actual interface,
        # (2, 3, 1 -> dhcpcd, pump, dhclient), because dhclient often doesn't
        # like to work on several distros.
        self.dhcp0 = urwid.RadioButton(self.dhcp_l, automatic_t)
        self.dhcp1 = DynRadioButton(self.dhcp_l, dhcp1_t)
        self.dhcp2 = DynRadioButton(self.dhcp_l, dhcp2_t)
        self.dhcp3 = DynRadioButton(self.dhcp_l, dhcp3_t)
        self.dhcp4 = DynRadioButton(self.dhcp_l, dhcp4_t)
        self.dhcp_l = [
            self.dhcp0, self.dhcp1, self.dhcp2, self.dhcp3, self.dhcp4
        ]

        self.wired_l = []
        self.wired_detect_header = urwid.Text(wired_detect_header_t)
        self.wired0 = urwid.RadioButton(self.wired_l, automatic_t)
        self.wired1 = DynRadioButton(self.wired_l, wired1_t)
        self.wired2 = DynRadioButton(self.wired_l, wired2_t)
        self.wired_l = [self.wired0, self.wired1, self.wired2]

        self.flush_l = []
        self.flush_header = urwid.Text(flush_header_t)
        self.flush0 = urwid.RadioButton(self.flush_l, automatic_t)
        self.flush1 = DynRadioButton(self.flush_l, flush1_t)
        self.flush2 = DynRadioButton(self.flush_l, flush2_t)
        self.flush_l = [self.flush0, self.flush1, self.flush2]

        externalLB = urwid.ListBox([
            self.dhcp_header, self.dhcp0, self.dhcp2, self.dhcp3, self.dhcp1,
            self.dhcp4, _blank, self.wired_detect_header, self.wired0,
            self.wired1, self.wired2, _blank, self.flush_header, self.flush0,
            self.flush1, self.flush2
        ])

        #### Advanced settings
        self.wpa_cat = urwid.Text(wpa_cat_t)
        self.wpa_cbox = ComboBox(wpa_t)
        self.wpa_warn = urwid.Text(wpa_warn_t)

        self.backend_cat = urwid.Text(backend_cat_t)
        self.backend_cbox = ComboBox(backend_t)

        self.debug_cat = urwid.Text(debug_cat_t)
        self.debug_mode_checkb = urwid.CheckBox(debug_mode_t)

        self.wless_cat = urwid.Text(wless_cat_t)
        self.use_dbm_checkb = urwid.CheckBox(use_dbm_t)
        self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)

        advancedLB = urwid.ListBox([
            self.wpa_cat, self.wpa_cbox, self.wpa_warn, _blank,
            self.backend_cat, self.backend_cbox, _blank, self.debug_cat,
            self.debug_mode_checkb, _blank, self.wless_cat,
            self.use_dbm_checkb, _blank, self.verify_ap_checkb, _blank
        ])

        headerList = [self.header0, self.header1, self.header2]
        lbList = [generalLB, externalLB, advancedLB]
        self.tab_map = {
            self.header0: generalLB,
            self.header1: externalLB,
            self.header2: advancedLB
        }
        #self.load_settings()

        self.tabs = TabColumns(headerList, lbList, _('Preferences'))
        # pylint: disable-msg=E1101
        self.__super.__init__(self.tabs)
예제 #15
0
    def __init__(self, body, pos, ui, dbus=None):
        global daemon, wireless, wired

        daemon = dbus['daemon']
        wireless = dbus['wireless']
        wired = dbus['wired']

        width,height =  ui.get_cols_rows()
        height -= 3
        #width = 80
        #height = 20
        # Stuff that goes at the top

        header0_t = language["gen_settings"]
        header1_t = language["ext_programs"]
        header2_t = language["advanced_settings"]
        self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active', 'focus')
        self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
        self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
        title   = language['preferences']

        # Blank line
        _blank = urwid.Text('')

        ####
        #### Text in the widgets
        ####

        # General Settings
        net_cat_t           = ('header', language['network_interfaces'])
        wired_t             = ('editcp', language['wired_interface']+':   ')
        wless_t             = ('editcp', language['wireless_interface']+':')
        always_show_wired_t = language['wired_always_on']
        prefer_wired_t      = language['always_switch_to_wired']

        global_dns_cat_t = ('header', language['global_dns_servers'])
        global_dns_t     = ('editcp', language['use_global_dns'])
        dns_dom_t        = ('editcp', '    '+language['dns_domain']+':   ')
        search_dom_t     = ('editcp', '    '+language['search_domain']+':')
        dns1_t           = ('editcp', '    DNS server 1: ')
        dns2_t           = ('editcp', '    DNS server 2: ')
        dns3_t           = ('editcp', '    DNS server 3: ')


        wired_auto_cat_t= ('header', language['wired_autoconnect_settings'])
        wired_auto_1_t = language['use_default_profile']
        wired_auto_2_t = language['show_wired_list']
        wired_auto_3_t = language['use_last_used_profile']

        auto_reconn_cat_t = ('header', language['automatic_reconnection'])
        auto_reconn_t = language['auto_reconnect']

        #### External Programs
        automatic_t = language['wicd_auto_config']

        dhcp_header_t = ('header', language["dhcp_client"])
        # Automatic
        dhcp1_t  = 'dhclient'
        dhcp2_t  = 'dhcpcd'
        dhcp3_t  = 'pump'
        dhcp4_t  = 'udhcpc'

        wired_detect_header_t = ('header', language["wired_detect"])
        wired1_t              = 'ethtool'
        wired2_t              = 'mii-tool'

        flush_header_t = ('header', language["route_flush"])
        flush1_t           = 'ip'
        flush2_t           = 'route'
 
        #### Advanced Settings
        wpa_cat_t=('header', language['wpa_supplicant'])
        wpa_t=('editcp','Driver:')
        wpa_list = []
        wpa_warn_t = ('important', language['always_use_wext'])
        
        backend_cat_t = ('header', language['backend'])
        backend_t = language['backend']+':'
        backend_list = []
        
        debug_cat_t = ('header', language['debugging'])
        debug_mode_t = language['use_debug_mode']

        wless_cat_t = ('header', language['wireless_interface'])
        use_dbm_t = language['display_type_dialog']
        verify_ap_t = language['verify_ap_dialog']
        


        ####
        #### UI Widgets
        ####

        # General Settings
        self.net_cat    = urwid.Text(net_cat_t)
        self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc')
        self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc')
        self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
        self.global_dns_cat = urwid.Text(global_dns_cat_t)
        # Default the global DNS settings to off.  They will be reenabled later
        # if so required.
        global_dns_state = False
        self.global_dns_checkb  = urwid.CheckBox(global_dns_t, global_dns_state,
                on_state_change=self.global_dns_trigger)
        self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
        self.dns_dom    = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
        self.dns1       = DynWrap(urwid.Edit(dns1_t), global_dns_state)
        self.dns2       = DynWrap(urwid.Edit(dns2_t), global_dns_state)
        self.dns3       = DynWrap(urwid.Edit(dns3_t), global_dns_state)


        self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)

        self.wired_auto_l  = []
        self.wired_auto_cat= urwid.Text(wired_auto_cat_t)
        self.wired_auto_1  = urwid.RadioButton(self.wired_auto_l,wired_auto_1_t)
        self.wired_auto_2  = urwid.RadioButton(self.wired_auto_l,wired_auto_2_t)
        self.wired_auto_3  = urwid.RadioButton(self.wired_auto_l,wired_auto_3_t)

        self.auto_reconn_cat    = urwid.Text(auto_reconn_cat_t)
        self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
        generalLB = urwid.ListBox([self.net_cat,
                                   self.wless_edit,#_blank,
                                   self.wired_edit,
                                   self.always_show_wired_checkb,
                                   self.prefer_wired_chkbx,_blank,
                                   self.global_dns_cat,
                                   self.global_dns_checkb,#_blank,
                                   self.search_dom,self.dns_dom,
                                   self.dns1,self.dns2,self.dns3,_blank,
                                   self.wired_auto_cat,
                                   self.wired_auto_1,
                                   self.wired_auto_2,
                                   self.wired_auto_3, _blank,
                                   self.auto_reconn_cat,
                                   self.auto_reconn_checkb
                                  ])

        #### External Programs tab
        automatic_t = language['wicd_auto_config']

        self.dhcp_header = urwid.Text(dhcp_header_t)
        self.dhcp_l = []

        # Order of these is flipped in the actual interface,
        # (2,3,1 -> dhcpcd, pump, dhclient), because dhclient often doesn't like
        # to work on several distros.
        self.dhcp0  = urwid.RadioButton(self.dhcp_l ,automatic_t)
        self.dhcp1  = DynRadioButton(self.dhcp_l, dhcp1_t)
        self.dhcp2  = DynRadioButton(self.dhcp_l, dhcp2_t)
        self.dhcp3  = DynRadioButton(self.dhcp_l, dhcp3_t)
        self.dhcp4  = DynRadioButton(self.dhcp_l, dhcp4_t)
        self.dhcp_l = [self.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3,self.dhcp4]

        self.wired_l = []
        self.wired_detect_header = urwid.Text(wired_detect_header_t)
        self.wired0         = urwid.RadioButton(self.wired_l, automatic_t)
        self.wired1         = DynRadioButton(self.wired_l, wired1_t)
        self.wired2         = DynRadioButton(self.wired_l, wired2_t)
        self.wired_l = [self.wired0, self.wired1, self.wired2]

        self.flush_l = []
        self.flush_header   = urwid.Text(flush_header_t)
        self.flush0         = urwid.RadioButton(self.flush_l,automatic_t)
        self.flush1         = DynRadioButton(self.flush_l,flush1_t)
        self.flush2         = DynRadioButton(self.flush_l,flush2_t)
        self.flush_l = [self.flush0,self.flush1,self.flush2]

        externalLB = urwid.ListBox([self.dhcp_header,
                                    self.dhcp0,self.dhcp2,self.dhcp3,self.dhcp1,
                                    self.dhcp4,
                                    _blank,
                                    self.wired_detect_header,
                                    self.wired0,self.wired1,self.wired2,
                                    _blank,
                                    self.flush_header,
                                    self.flush0,self.flush1,self.flush2
                                   ])


        #### Advanced settings
        self.wpa_cat      = urwid.Text(wpa_cat_t)
        self.wpa_cbox     = ComboBox(wpa_t)
        self.wpa_warn     = urwid.Text(wpa_warn_t)
        
        self.backend_cat  = urwid.Text(backend_cat_t)
        self.backend_cbox = ComboBox(backend_t)
        
        self.debug_cat           = urwid.Text(debug_cat_t)
        self.debug_mode_checkb   = urwid.CheckBox(debug_mode_t)

        self.wless_cat        = urwid.Text(wless_cat_t)
        self.use_dbm_checkb   = urwid.CheckBox(use_dbm_t)
        self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)


        advancedLB = urwid.ListBox([self.wpa_cat,
                                    self.wpa_cbox,self.wpa_warn,_blank,
                                    self.backend_cat,
                                    self.backend_cbox,_blank,
                                    self.debug_cat,
                                    self.debug_mode_checkb, _blank,
                                    self.wless_cat,
                                    self.use_dbm_checkb, _blank,
                                    self.verify_ap_checkb, _blank
                                    ])


        headerList = [self.header0,self.header1,self.header2]
        lbList = [generalLB,externalLB,advancedLB]
        self.tab_map = {self.header0 : generalLB,
                        self.header1 : externalLB,
                        self.header2 : advancedLB}
        #self.load_settings()

        self.tabs = TabColumns(headerList,lbList,language['preferences'])
        self.__super.__init__(self.tabs)
예제 #16
0
class PrefsDialog(urwid.WidgetWrap):
    def __init__(self, body, pos, ui, dbus=None):
        global daemon, wireless, wired

        daemon = dbus['daemon']
        wireless = dbus['wireless']
        wired = dbus['wired']

        width,height =  ui.get_cols_rows()
        height -= 3
        #width = 80
        #height = 20
        # Stuff that goes at the top

        header0_t = language["gen_settings"]
        header1_t = language["ext_programs"]
        header2_t = language["advanced_settings"]
        self.header0 = urwid.AttrWrap(SelText(header0_t), 'tab active', 'focus')
        self.header1 = urwid.AttrWrap(SelText(header1_t), 'body', 'focus')
        self.header2 = urwid.AttrWrap(SelText(header2_t), 'body', 'focus')
        title   = language['preferences']

        # Blank line
        _blank = urwid.Text('')

        ####
        #### Text in the widgets
        ####

        # General Settings
        net_cat_t           = ('header', language['network_interfaces'])
        wired_t             = ('editcp', language['wired_interface']+':   ')
        wless_t             = ('editcp', language['wireless_interface']+':')
        always_show_wired_t = language['wired_always_on']
        prefer_wired_t      = language['always_switch_to_wired']

        global_dns_cat_t = ('header', language['global_dns_servers'])
        global_dns_t     = ('editcp', language['use_global_dns'])
        dns_dom_t        = ('editcp', '    '+language['dns_domain']+':   ')
        search_dom_t     = ('editcp', '    '+language['search_domain']+':')
        dns1_t           = ('editcp', '    DNS server 1: ')
        dns2_t           = ('editcp', '    DNS server 2: ')
        dns3_t           = ('editcp', '    DNS server 3: ')


        wired_auto_cat_t= ('header', language['wired_autoconnect_settings'])
        wired_auto_1_t = language['use_default_profile']
        wired_auto_2_t = language['show_wired_list']
        wired_auto_3_t = language['use_last_used_profile']

        auto_reconn_cat_t = ('header', language['automatic_reconnection'])
        auto_reconn_t = language['auto_reconnect']

        #### External Programs
        automatic_t = language['wicd_auto_config']

        dhcp_header_t = ('header', language["dhcp_client"])
        # Automatic
        dhcp1_t  = 'dhclient'
        dhcp2_t  = 'dhcpcd'
        dhcp3_t  = 'pump'
        dhcp4_t  = 'udhcpc'

        wired_detect_header_t = ('header', language["wired_detect"])
        wired1_t              = 'ethtool'
        wired2_t              = 'mii-tool'

        flush_header_t = ('header', language["route_flush"])
        flush1_t           = 'ip'
        flush2_t           = 'route'
 
        #### Advanced Settings
        wpa_cat_t=('header', language['wpa_supplicant'])
        wpa_t=('editcp','Driver:')
        wpa_list = []
        wpa_warn_t = ('important', language['always_use_wext'])
        
        backend_cat_t = ('header', language['backend'])
        backend_t = language['backend']+':'
        backend_list = []
        
        debug_cat_t = ('header', language['debugging'])
        debug_mode_t = language['use_debug_mode']

        wless_cat_t = ('header', language['wireless_interface'])
        use_dbm_t = language['display_type_dialog']
        verify_ap_t = language['verify_ap_dialog']
        


        ####
        #### UI Widgets
        ####

        # General Settings
        self.net_cat    = urwid.Text(net_cat_t)
        self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc')
        self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc')
        self.prefer_wired_chkbx = urwid.CheckBox(prefer_wired_t)
        self.global_dns_cat = urwid.Text(global_dns_cat_t)
        # Default the global DNS settings to off.  They will be reenabled later
        # if so required.
        global_dns_state = False
        self.global_dns_checkb  = urwid.CheckBox(global_dns_t, global_dns_state,
                on_state_change=self.global_dns_trigger)
        self.search_dom = DynWrap(urwid.Edit(search_dom_t), global_dns_state)
        self.dns_dom    = DynWrap(urwid.Edit(dns_dom_t), global_dns_state)
        self.dns1       = DynWrap(urwid.Edit(dns1_t), global_dns_state)
        self.dns2       = DynWrap(urwid.Edit(dns2_t), global_dns_state)
        self.dns3       = DynWrap(urwid.Edit(dns3_t), global_dns_state)


        self.always_show_wired_checkb = urwid.CheckBox(always_show_wired_t)

        self.wired_auto_l  = []
        self.wired_auto_cat= urwid.Text(wired_auto_cat_t)
        self.wired_auto_1  = urwid.RadioButton(self.wired_auto_l,wired_auto_1_t)
        self.wired_auto_2  = urwid.RadioButton(self.wired_auto_l,wired_auto_2_t)
        self.wired_auto_3  = urwid.RadioButton(self.wired_auto_l,wired_auto_3_t)

        self.auto_reconn_cat    = urwid.Text(auto_reconn_cat_t)
        self.auto_reconn_checkb = urwid.CheckBox(auto_reconn_t)
        generalLB = urwid.ListBox([self.net_cat,
                                   self.wless_edit,#_blank,
                                   self.wired_edit,
                                   self.always_show_wired_checkb,
                                   self.prefer_wired_chkbx,_blank,
                                   self.global_dns_cat,
                                   self.global_dns_checkb,#_blank,
                                   self.search_dom,self.dns_dom,
                                   self.dns1,self.dns2,self.dns3,_blank,
                                   self.wired_auto_cat,
                                   self.wired_auto_1,
                                   self.wired_auto_2,
                                   self.wired_auto_3, _blank,
                                   self.auto_reconn_cat,
                                   self.auto_reconn_checkb
                                  ])

        #### External Programs tab
        automatic_t = language['wicd_auto_config']

        self.dhcp_header = urwid.Text(dhcp_header_t)
        self.dhcp_l = []

        # Order of these is flipped in the actual interface,
        # (2,3,1 -> dhcpcd, pump, dhclient), because dhclient often doesn't like
        # to work on several distros.
        self.dhcp0  = urwid.RadioButton(self.dhcp_l ,automatic_t)
        self.dhcp1  = DynRadioButton(self.dhcp_l, dhcp1_t)
        self.dhcp2  = DynRadioButton(self.dhcp_l, dhcp2_t)
        self.dhcp3  = DynRadioButton(self.dhcp_l, dhcp3_t)
        self.dhcp4  = DynRadioButton(self.dhcp_l, dhcp4_t)
        self.dhcp_l = [self.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3,self.dhcp4]

        self.wired_l = []
        self.wired_detect_header = urwid.Text(wired_detect_header_t)
        self.wired0         = urwid.RadioButton(self.wired_l, automatic_t)
        self.wired1         = DynRadioButton(self.wired_l, wired1_t)
        self.wired2         = DynRadioButton(self.wired_l, wired2_t)
        self.wired_l = [self.wired0, self.wired1, self.wired2]

        self.flush_l = []
        self.flush_header   = urwid.Text(flush_header_t)
        self.flush0         = urwid.RadioButton(self.flush_l,automatic_t)
        self.flush1         = DynRadioButton(self.flush_l,flush1_t)
        self.flush2         = DynRadioButton(self.flush_l,flush2_t)
        self.flush_l = [self.flush0,self.flush1,self.flush2]

        externalLB = urwid.ListBox([self.dhcp_header,
                                    self.dhcp0,self.dhcp2,self.dhcp3,self.dhcp1,
                                    self.dhcp4,
                                    _blank,
                                    self.wired_detect_header,
                                    self.wired0,self.wired1,self.wired2,
                                    _blank,
                                    self.flush_header,
                                    self.flush0,self.flush1,self.flush2
                                   ])


        #### Advanced settings
        self.wpa_cat      = urwid.Text(wpa_cat_t)
        self.wpa_cbox     = ComboBox(wpa_t)
        self.wpa_warn     = urwid.Text(wpa_warn_t)
        
        self.backend_cat  = urwid.Text(backend_cat_t)
        self.backend_cbox = ComboBox(backend_t)
        
        self.debug_cat           = urwid.Text(debug_cat_t)
        self.debug_mode_checkb   = urwid.CheckBox(debug_mode_t)

        self.wless_cat        = urwid.Text(wless_cat_t)
        self.use_dbm_checkb   = urwid.CheckBox(use_dbm_t)
        self.verify_ap_checkb = urwid.CheckBox(verify_ap_t)


        advancedLB = urwid.ListBox([self.wpa_cat,
                                    self.wpa_cbox,self.wpa_warn,_blank,
                                    self.backend_cat,
                                    self.backend_cbox,_blank,
                                    self.debug_cat,
                                    self.debug_mode_checkb, _blank,
                                    self.wless_cat,
                                    self.use_dbm_checkb, _blank,
                                    self.verify_ap_checkb, _blank
                                    ])


        headerList = [self.header0,self.header1,self.header2]
        lbList = [generalLB,externalLB,advancedLB]
        self.tab_map = {self.header0 : generalLB,
                        self.header1 : externalLB,
                        self.header2 : advancedLB}
        #self.load_settings()

        self.tabs = TabColumns(headerList,lbList,language['preferences'])
        self.__super.__init__(self.tabs)
        
    def load_settings(self):

        ### General Settings
        # ComboBox does not like dbus.Strings as text markups.  My fault. :/
        wless_iface = unicode(daemon.GetWirelessInterface())
        wired_iface = unicode(daemon.GetWiredInterface())
        self.wless_edit.set_edit_text(wless_iface)
        self.wired_edit.set_edit_text(wired_iface)

        self.always_show_wired_checkb.set_state(
                daemon.GetAlwaysShowWiredInterface())
        self.prefer_wired_chkbx.set_state(daemon.GetPreferWiredNetwork())
        # DNS
        self.global_dns_checkb.set_state(daemon.GetUseGlobalDNS())
        theDNS = daemon.GetGlobalDNSAddresses()

        i = 0
        for w in self.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom :
            w.set_edit_text(misc.noneToBlankString(theDNS[i]))
            i+=1

        # Wired Automatic Connection
        self.wired_auto_l[daemon.GetWiredAutoConnectMethod()-1]
        self.auto_reconn_checkb.set_state(daemon.GetAutoReconnect())

        def find_avail(apps):
            for app in apps[1:]:
                app.set_sensitive(daemon.GetAppAvailable(app.get_label()))

        ### External Programs
        find_avail(self.dhcp_l)
        dhcp_method = daemon.GetDHCPClient()
        self.dhcp_l[dhcp_method].set_state(True)
        
        find_avail(self.wired_l)
        wired_link_method = daemon.GetLinkDetectionTool()
        self.wired_l[wired_link_method].set_state(True)

        find_avail(self.flush_l)
        flush_method = daemon.GetFlushTool()
        self.flush_l[flush_method].set_state(True)

        ### Advanced settings
        # wpa_supplicant janx
        self.wpadrivers = wireless.GetWpaSupplicantDrivers()
        self.wpadrivers.append("ralink_legacy")
        # Same as above with the dbus.String
        self.thedrivers = [unicode(w) for w in self.wpadrivers]
        self.wpa_cbox.set_list(self.thedrivers)
        
        # Pick where to begin first:
        def_driver = daemon.GetWPADriver()
        try:
            self.wpa_cbox.set_focus(self.wpadrivers.index(def_driver))
        except ValueError:
            pass # It defaults to 0 anyway (I hope)

        self.backends = daemon.GetBackendList()
        self.thebackends= [unicode(w) for w in self.backends]
        self.backend_cbox.set_list(self.thebackends) 
        cur_backend = daemon.GetSavedBackend()
        try:
            self.backend_cbox.set_focus(self.thebackends.index(cur_backend))
        except ValueError:
            self.backend_cbox.set_focus(0)

        # Three last checkboxes
        self.debug_mode_checkb.set_state(daemon.GetDebugMode())
        self.use_dbm_checkb.set_state(daemon.GetSignalDisplayType())
        self.verify_ap_checkb.set_state(daemon.GetShouldVerifyAp())

    def save_settings(self):
        """ Pushes the selected settings to the daemon.
            This exact order is found in prefs.py"""
        daemon.SetUseGlobalDNS(self.global_dns_checkb.get_state())

        for i in [self.dns1, self.dns2,
                  self.dns3,self.dns_dom, self.search_dom, self.dns_dom]:
            i.set_edit_text(i.get_edit_text().strip())

        daemon.SetGlobalDNS(self.dns1.get_edit_text(), self.dns2.get_edit_text(),
                            self.dns3.get_edit_text(), self.dns_dom.get_edit_text(),
                            self.search_dom.get_edit_text())
        daemon.SetWirelessInterface(self.wless_edit.get_edit_text())
        daemon.SetWiredInterface(self.wired_edit.get_edit_text())
        daemon.SetWPADriver(self.wpadrivers[self.wpa_cbox.get_focus()[1]])
        daemon.SetAlwaysShowWiredInterface(self.always_show_wired_checkb.get_state())
        daemon.SetAutoReconnect(self.auto_reconn_checkb.get_state())
        daemon.SetDebugMode(self.debug_mode_checkb.get_state())
        daemon.SetSignalDisplayType(int(self.use_dbm_checkb.get_state()))
        daemon.SetShouldVerifyAp(int(self.verify_ap_checkb.get_state()))
        daemon.SetPreferWiredNetwork(bool(self.prefer_wired_chkbx.get_state()))
        if self.wired_auto_2.get_state():
            daemon.SetWiredAutoConnectMethod(2)
        elif self.wired_auto_3.get_state():
            daemon.SetWiredAutoConnectMethod(3)
        else:
            daemon.SetWiredAutoConnectMethod(1)

        daemon.SetBackend(self.backends[self.backend_cbox.get_focus()[1]])
            
        # External Programs Tab
        if self.dhcp0.get_state():
            dhcp_client = misc.AUTO
        elif self.dhcp1.get_state():
            dhcp_client = misc.DHCLIENT
        elif self.dhcp2.get_state():
            dhcp_client = misc.DHCPCD
        elif self.dhcp3.get_state():
            dhcp_client = misc.PUMP
        else:
            dhcp_client = misc.UDHCPC
        daemon.SetDHCPClient(dhcp_client)
        
        if self.wired0.get_state():
            link_tool = misc.AUTO
        elif self.wired1.get_state():
            link_tool = misc.ETHTOOL
        else:
            link_tool = misc.MIITOOL
        daemon.SetLinkDetectionTool(link_tool)
        
        if self.flush0.get_state():
            flush_tool = misc.AUTO
        elif self.flush1.get_state():
            flush_tool = misc.IP
        else:
            flush_tool = misc.ROUTE
        daemon.SetFlushTool(flush_tool)

    # DNS CheckBox callback
    def global_dns_trigger(self,check_box,new_state,user_data=None):
        for w in self.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom:
            w.set_sensitive(new_state)

    def ready_widgets(self,ui,body):
        self.wpa_cbox.build_combobox(body,ui,4)
        self.backend_cbox.build_combobox(body,ui,8)
예제 #17
0
class WirelessSettingsDialog(AdvancedSettingsDialog):
    def __init__(self,networkID,parent):
        global wireless, daemon
        AdvancedSettingsDialog.__init__(self)
        self.networkid = networkID
        self.parent = parent
        global_settings_t = _('Use these settings for all networks sharing this essid')
        encryption_t = _('Use Encryption')
        autoconnect_t = _('Automatically connect to this network')
        
        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(encryption_t,on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker :-)
        self._listbox.body.append(self.global_settings_chkbox)
        self._listbox.body.append(self.autoconnect_chkbox)
        self._listbox.body.append(self.encryption_chkbox)
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = _('Configuring preferences for wireless network "$A" ($B)').replace('$A',wireless.GetWirelessProperty(networkID,'essid')).replace('$B',wireless.GetWirelessProperty(networkID,'bssid'))
        self._w.header = urwid.Text(('header',title),align='right' )
    
    def encryption_toggle(self,chkbox,new_state,user_data=None):
        self.encryption_combo.set_sensitive(new_state)
        self.pile_encrypt.set_sensitive(new_state)

    def combo_on_change(self,combobox,new_index,user_data=None):
        self.change_encrypt_method()

    def set_values(self):
        """ Set the various network settings to the right values. """
        networkID = self.networkid
        self.ip_edit.set_edit_text(self.format_entry(networkID,"ip"))
        self.netmask_edit.set_edit_text(self.format_entry(networkID,"netmask"))
        self.gateway_edit.set_edit_text(self.format_entry(networkID,"gateway"))

        self.global_dns_cb.set_state(bool(wireless.GetWirelessProperty(networkID,
                                                                  'use_global_dns')))
        self.static_dns_cb.set_state(bool(wireless.GetWirelessProperty(networkID,
                                                                  'use_static_dns')))
        
        if stringToNone(self.ip_edit.get_edit_text()):
            self.static_ip_cb.set_state(True)
        self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
        self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
        self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
        self.dns_dom_edit.set_edit_text(self.format_entry(networkID, "dns_domain"))
        self.search_dom_edit.set_edit_text(self.format_entry(networkID, "search_domain"))
        
        self.autoconnect_chkbox.set_state(to_bool(self.format_entry(networkID, "automatic")))

        #self.reset_static_checkboxes()
        self.encryption_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID,
            'encryption')),do_callback=False)
        self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID
            ,'use_settings_globally')))

        # Throw the encryption stuff into a list
        list = []
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            list.append(enc_type['name'])
            if enc_type['type'] == wireless.GetWirelessProperty(networkID, "enctype"):
                activeID = x
        self.encryption_combo.set_list(list)

        self.encryption_combo.set_focus(activeID)
        if activeID != -1:
            self.encryption_chkbox.set_state(True,do_callback=False)
            self.encryption_combo.set_sensitive(True)
            #self.lbox_encrypt_info.set_sensitive(True)
        else:
            self.encryption_combo.set_focus(0)

        self.change_encrypt_method()
        dhcphname = wireless.GetWirelessProperty(networkID,"dhcphostname")
        if dhcphname is None:
            dhcphname = os.uname()[1]
        self.use_dhcp_h.set_state(bool(wireless.GetWirelessProperty(networkID,'usedhcphostname')))
        self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
        self.dhcp_h.set_edit_text(unicode(dhcphname))
        

    def set_net_prop(self, option, value):
        """ Sets the given option to the given value for this network. """
        wireless.SetWirelessProperty(self.networkid, option, value)

    def format_entry(self, networkid, label):
        """ Helper method for fetching/formatting wireless properties. """
        return noneToBlankString(wireless.GetWirelessProperty(networkid, label))

    # Ripped from netentry.py
    def save_settings(self):
        # Check encryption info
        if self.encryption_chkbox.get_state():
            encrypt_info = self.encryption_info
            encrypt_methods = self.encrypt_types
            self.set_net_prop("enctype",
                               encrypt_methods[self.encryption_combo.get_focus()[1] ]['type'])
            # Make sure all required fields are filled in.
            for entry_info in encrypt_info.itervalues():
                if entry_info[0].get_edit_text() == "" \
                    and entry_info[1] == 'required':
                    error(self.ui, self.parent,"%s (%s)" \
                            % (_('Required encryption information is missing.'),
                                entry_info[0].get_caption()[0:-2] )
                          )
                    return False

            for entry_key, entry_info in encrypt_info.iteritems():
                self.set_net_prop(entry_key, noneToString(entry_info[0].
                                                   get_edit_text()))
        elif not self.encryption_chkbox.get_state() and \
             wireless.GetWirelessProperty(self.networkid, "encryption"):
            # Encrypt checkbox is off, but the network needs it.
            error(self.ui, self.parent, _('This network requires encryption to be enabled.'))
            return False
        else:
            self.set_net_prop("enctype", "None")
        AdvancedSettingsDialog.save_settings(self)

        # Save the autoconnect setting.  This is not where it originally was
        # in the GTK UI.
        self.set_net_prop("automatic",self.autoconnect_chkbox.get_state())
        
        if self.global_settings_chkbox.get_state():
            self.set_net_prop('use_settings_globally', True)
        else:
            self.set_net_prop('use_settings_globally', False)
            wireless.RemoveGlobalEssidEntry(self.networkid)
            
        wireless.SaveWirelessNetworkProfile(self.networkid)
        return True

    # More or less ripped from netentry.py
    def change_encrypt_method(self):
        #self.lbox_encrypt = urwid.ListBox()
        self.encryption_info = {}
        wid,ID = self.encryption_combo.get_focus()
        methods = misc.LoadEncryptionMethods()

        if self._w.body.body.__contains__(self.pile_encrypt):
            self._w.body.body.pop(self._w.body.body.__len__()-1)

        # If nothing is selected, select the first entry.
        if ID == -1:
            self.encryption_combo.set_focus(0)
            ID = 0

        theList = []
        for type_ in ['required', 'optional']:
            fields = methods[ID][type_]
            for field in fields:
                edit = MaskingEdit(('editcp',language[field[1].lower().replace(' ','_')]+': '))
                edit.set_mask_mode('no_focus')
                theList.append(edit)
                # Add the data to any array, so that the information
                # can be easily accessed by giving the name of the wanted
                # data.
                self.encryption_info[field[0]] = [edit, type_]

                edit.set_edit_text(noneToBlankString(
                    wireless.GetWirelessProperty(self.networkid, field[0])))

        #FIXME: This causes the entire pile to light up upon use.
        # Make this into a listbox?
        self.pile_encrypt = DynWrap(urwid.Pile(theList),attrs=('editbx','editnfc'))
        self._w.body.body.insert(self._w.body.body.__len__(),self.pile_encrypt)
        #self._w.body.body.append(self.pile_encrypt)

    def ready_widgets(self,ui,body):
        self.ui = ui
        self.body = body
        self.encryption_combo.build_combobox(body,ui,14)
        self.change_encrypt_method()
예제 #18
0
class WiredSettingsDialog(AdvancedSettingsDialog):
    """ Settings dialog for wired interface. """
    def __init__(self, name, parent):
        AdvancedSettingsDialog.__init__(self)
        self.wired = True

        self.set_default = urwid.CheckBox(
            _('Use as default profile (overwrites any previous default)'))
        #self.cur_default =
        # Add widgets to listbox
        self._w.body.body.append(self.set_default)

        self.parent = parent
        encryption_t = _('Use Encryption')

        self.encryption_chkbox = urwid.CheckBox(
            encryption_t, on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_chkbox)
        # pylint: disable-msg=E1103
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods(wired=True)
        self.set_values()

        self.prof_name = name
        title = _('Configuring preferences for wired profile "$A"'). \
            replace('$A', self.prof_name)
        self._w.header = urwid.Text(('header', title), align='right')

        self.set_values()

    def set_net_prop(self, option, value):
        """ Set network property. """
        wired.SetWiredProperty(option, value)

    def set_values(self):
        """ Load saved values. """
        self.ip_edit.set_edit_text(self.format_entry("ip"))
        self.netmask_edit.set_edit_text(self.format_entry("netmask"))
        self.gateway_edit.set_edit_text(self.format_entry("gateway"))

        self.global_dns_cb.set_state(
            bool(wired.GetWiredProperty('use_global_dns')))
        self.static_dns_cb.set_state(
            bool(wired.GetWiredProperty('use_static_dns')))

        # Set static ip checkbox.  Forgot to do this the first time.
        if stringToNone(self.ip_edit.get_edit_text()):
            self.static_ip_cb.set_state(True)
        self.dns1.set_edit_text(self.format_entry("dns1"))
        self.dns2.set_edit_text(self.format_entry("dns2"))
        self.dns3.set_edit_text(self.format_entry("dns3"))
        self.dns_dom_edit.set_edit_text(self.format_entry("dns_domain"))
        self.search_dom_edit.set_edit_text(self.format_entry("search_domain"))

        self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))

        # Throw the encryption stuff into a list
        l = []
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            l.append(enc_type['name'])
            if enc_type['type'] == wired.GetWiredProperty("enctype"):
                activeID = x
        self.encryption_combo.set_list(l)

        self.encryption_combo.set_focus(activeID)
        if wired.GetWiredProperty("encryption_enabled"):
            self.encryption_chkbox.set_state(True, do_callback=False)
            self.encryption_combo.set_sensitive(True)
            #self.lbox_encrypt_info.set_sensitive(True)
        else:
            self.encryption_combo.set_focus(0)
            self.encryption_combo.set_sensitive(False)

        self.change_encrypt_method()

        dhcphname = wired.GetWiredProperty("dhcphostname")
        if dhcphname is None:
            dhcphname = os.uname()[1]

        self.use_dhcp_h.set_state(
            bool(wired.GetWiredProperty('usedhcphostname')))
        self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
        self.dhcp_h.set_edit_text(str(dhcphname))

    def save_settings(self):
        """ Save settings to disk. """
        # Check encryption info
        if self.encryption_chkbox.get_state():
            encrypt_info = self.encryption_info
            encrypt_methods = self.encrypt_types
            self.set_net_prop(
                "enctype",
                encrypt_methods[self.encryption_combo.get_focus()[1]]['type'])
            self.set_net_prop("encryption_enabled", True)
            # Make sure all required fields are filled in.
            for entry_info in encrypt_info.values():
                if entry_info[0].get_edit_text() == "" \
                  and entry_info[1] == 'required':
                    error(
                        self.ui, self.parent, "%s (%s)" %
                        (_('Required encryption information is missing.'),
                         entry_info[0].get_caption()[0:-2]))
                    return False

            for entry_key, entry_info in encrypt_info.items():
                self.set_net_prop(entry_key,
                                  noneToString(entry_info[0].get_edit_text()))
        else:
            self.set_net_prop("enctype", "None")
            self.set_net_prop("encryption_enabled", False)

        AdvancedSettingsDialog.save_settings(self)
        if self.set_default.get_state():
            wired.UnsetWiredDefault()
        if self.set_default.get_state():
            set_default = True
        else:
            set_default = False
        wired.SetWiredProperty("default", set_default)
        wired.SaveWiredNetworkProfile(self.prof_name)
        return True

    def format_entry(self, label):
        """ Helper method to fetch and format wired properties. """
        return noneToBlankString(wired.GetWiredProperty(label))

    def prerun(self, ui, dim, display):
        pass
예제 #19
0
class WirelessSettingsDialog(AdvancedSettingsDialog):
    def __init__(self,networkID,parent):
        global wireless, daemon
        AdvancedSettingsDialog.__init__(self)
        self.networkid = networkID
        self.parent = parent
        global_settings_t = language['global_settings']
        encryption_t = language['use_encryption']
        autoconnect_t = language['automatic_connect']
        
        self.global_settings_chkbox = urwid.CheckBox(global_settings_t)
        self.encryption_chkbox = urwid.CheckBox(encryption_t,on_state_change=self.encryption_toggle)
        self.encryption_combo = ComboBox(callback=self.combo_on_change)
        self.autoconnect_chkbox = urwid.CheckBox(autoconnect_t)
        self.pile_encrypt = None
        # _w is a Frame, _w.body is a ListBox, _w.body.body is the ListWalker :-)
        self._listbox.body.append(self.global_settings_chkbox)
        self._listbox.body.append(self.autoconnect_chkbox)
        self._listbox.body.append(self.encryption_chkbox)
        self._listbox.body.append(self.encryption_combo)
        self.encrypt_types = misc.LoadEncryptionMethods()
        self.set_values()

        title = language['configuring_wireless'].replace('$A',wireless.GetWirelessProperty(networkID,'essid')).replace('$B',wireless.GetWirelessProperty(networkID,'bssid'))
        self._w.header = urwid.Text(('header',title),align='right' )
    
    def encryption_toggle(self,chkbox,new_state,user_data=None):
        self.encryption_combo.set_sensitive(new_state)
        self.pile_encrypt.set_sensitive(new_state)

    def combo_on_change(self,combobox,new_index,user_data=None):
        self.change_encrypt_method()

    def set_values(self):
        """ Set the various network settings to the right values. """
        networkID = self.networkid
        self.ip_edit.set_edit_text(self.format_entry(networkID,"ip"))
        self.netmask_edit.set_edit_text(self.format_entry(networkID,"netmask"))
        self.gateway_edit.set_edit_text(self.format_entry(networkID,"gateway"))

        self.global_dns_cb.set_state(bool(wireless.GetWirelessProperty(networkID,
                                                                  'use_global_dns')))
        self.static_dns_cb.set_state(bool(wireless.GetWirelessProperty(networkID,
                                                                  'use_static_dns')))
        
        if stringToNone(self.ip_edit.get_edit_text()):
            self.static_ip_cb.set_state(True)
        self.dns1.set_edit_text(self.format_entry(networkID, "dns1"))
        self.dns2.set_edit_text(self.format_entry(networkID, "dns2"))
        self.dns3.set_edit_text(self.format_entry(networkID, "dns3"))
        self.dns_dom_edit.set_edit_text(self.format_entry(networkID, "dns_domain"))
        self.search_dom_edit.set_edit_text(self.format_entry(networkID, "search_domain"))
        
        self.autoconnect_chkbox.set_state(to_bool(self.format_entry(networkID, "automatic")))

        #self.reset_static_checkboxes()
        self.encryption_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID,
            'encryption')),do_callback=False)
        self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID
            ,'use_settings_globally')))

        # Throw the encryption stuff into a list
        list = []
        activeID = -1  # Set the menu to this item when we are done
        for x, enc_type in enumerate(self.encrypt_types):
            list.append(enc_type['name'])
            if enc_type['type'] == wireless.GetWirelessProperty(networkID, "enctype"):
                activeID = x
        self.encryption_combo.set_list(list)

        self.encryption_combo.set_focus(activeID)
        if activeID != -1:
            self.encryption_chkbox.set_state(True,do_callback=False)
            self.encryption_combo.set_sensitive(True)
            #self.lbox_encrypt_info.set_sensitive(True)
        else:
            self.encryption_combo.set_focus(0)

        self.change_encrypt_method()
        dhcphname = wireless.GetWirelessProperty(networkID,"dhcphostname")
        if dhcphname is None:
            dhcphname = os.uname()[1]
        self.use_dhcp_h.set_state(bool(wireless.GetWirelessProperty(networkID,'usedhcphostname')))
        self.dhcp_h.set_sensitive(self.use_dhcp_h.get_state())
        self.dhcp_h.set_edit_text(unicode(dhcphname))
        

    def set_net_prop(self, option, value):
        """ Sets the given option to the given value for this network. """
        wireless.SetWirelessProperty(self.networkid, option, value)

    def format_entry(self, networkid, label):
        """ Helper method for fetching/formatting wireless properties. """
        return noneToBlankString(wireless.GetWirelessProperty(networkid, label))

    # Ripped from netentry.py
    def save_settings(self):
        # Check encryption info
        if self.encryption_chkbox.get_state():
            encrypt_info = self.encryption_info
            encrypt_methods = self.encrypt_types
            self.set_net_prop("enctype",
                               encrypt_methods[self.encryption_combo.get_focus()[1] ]['type'])
            # Make sure all required fields are filled in.
            for entry_info in encrypt_info.itervalues():
                if entry_info[0].get_edit_text() == "" \
                    and entry_info[1] == 'required':
                    error(self.ui, self.parent,"%s (%s)" \
                            % (language['encrypt_info_missing'], 
                                entry_info[0].get_caption()[0:-2] )
                          )
                    return False

            for entry_key, entry_info in encrypt_info.iteritems():
                self.set_net_prop(entry_key, noneToString(entry_info[0].
                                                   get_edit_text()))
        elif not self.encryption_chkbox.get_state() and \
             wireless.GetWirelessProperty(self.networkid, "encryption"):
            # Encrypt checkbox is off, but the network needs it.
            error(self.ui, self.parent, language['enable_encryption'])
            return False
        else:
            self.set_net_prop("enctype", "None")
        AdvancedSettingsDialog.save_settings(self)

        # Save the autoconnect setting.  This is not where it originally was
        # in the GTK UI.
        self.set_net_prop("automatic",self.autoconnect_chkbox.get_state())
        
        if self.global_settings_chkbox.get_state():
            self.set_net_prop('use_settings_globally', True)
        else:
            self.set_net_prop('use_settings_globally', False)
            wireless.RemoveGlobalEssidEntry(self.networkid)
            
        wireless.SaveWirelessNetworkProfile(self.networkid)
        return True

    # More or less ripped from netentry.py
    def change_encrypt_method(self):
        #self.lbox_encrypt = urwid.ListBox()
        self.encryption_info = {}
        wid,ID = self.encryption_combo.get_focus()
        methods = misc.LoadEncryptionMethods()

        if self._w.body.body.__contains__(self.pile_encrypt):
            self._w.body.body.pop(self._w.body.body.__len__()-1)

        # If nothing is selected, select the first entry.
        if ID == -1:
            self.encryption_combo.set_focus(0)
            ID = 0

        theList = []
        for type_ in ['required', 'optional']:
            fields = methods[ID][type_]
            for field in fields:
                if language.has_key(field[1]):
                    edit = MaskingEdit(('editcp',language[field[1].lower().replace(' ','_')]+': '))
                else:
                    edit = MaskingEdit(('editcp',field[1].replace('_',' ')+': '))
                edit.set_mask_mode('no_focus')
                theList.append(edit)
                # Add the data to any array, so that the information
                # can be easily accessed by giving the name of the wanted
                # data.
                self.encryption_info[field[0]] = [edit, type_]

                edit.set_edit_text(noneToBlankString(
                    wireless.GetWirelessProperty(self.networkid, field[0])))

        #FIXME: This causes the entire pile to light up upon use.
        # Make this into a listbox?
        self.pile_encrypt = DynWrap(urwid.Pile(theList),attrs=('editbx','editnfc'))
        self._w.body.body.insert(self._w.body.body.__len__(),self.pile_encrypt)
        #self._w.body.body.append(self.pile_encrypt)

    def ready_widgets(self,ui,body):
        self.ui = ui
        self.body = body
        self.encryption_combo.build_combobox(body,ui,14)
        self.change_encrypt_method()