def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.set_padding(35, 0, 20, 0)

        self.main_box = gtk.VBox()
        self.tab_name = "sfds"
        basic = SettingSection(_("Basic"))

        self.button = Button(_("Advanced"))
        self.button.connect("clicked", self.show_more_options)
        self.wired = SettingSection(_("Wired"), always_show=False)
        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 376, 0)
        align.set_size_request(-1 , 30)
        align.add(self.button)
        
        basic.load([PPTPConf(connection, set_button, settings_obj=self.settings_obj), align])

        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)
예제 #2
0
    def __init__(self,
                 connection,
                 set_button,
                 need_ssid=False,
                 settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0, 0, 0)
        self.set_padding(35, 0, 20, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        if isinstance(connection, NMRemoteConnection):
            net_manager.set_primary_wireless(settings_obj.ap, connection)

        self.main_box = gtk.VBox()
        self.tab_name = ""
        basic = SettingSection(_("Basic"))
        log.debug("start section")

        if need_ssid:
            security = Security(connection,
                                set_button,
                                need_ssid,
                                settings_obj=settings_obj)
        else:
            security = Security(connection,
                                set_button,
                                settings_obj=settings_obj)
        security.button.connect("clicked", self.show_more_options)
        basic.load([security])
        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)
    def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0, 0, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.set_padding(35, 0, 20, 0)

        self.main_box = gtk.VBox()
        self.tab_name = "sfds"
        basic = SettingSection(_("Basic"))

        self.button = Button(_("Advanced"))
        self.button.connect("clicked", self.show_more_options)
        self.wired = SettingSection(_("Wired"), always_show=False)
        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 376, 0)
        align.set_size_request(-1, 30)
        align.add(self.button)

        basic.load([
            PPTPConf(connection, set_button, settings_obj=self.settings_obj),
            align
        ])

        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)
    def __init__(self, connection, set_button, need_ssid=False, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.set_padding(35, 0, 20, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        if isinstance(connection, NMRemoteConnection):
            net_manager.set_primary_wireless(settings_obj.ap, connection)

        self.main_box = gtk.VBox()
        self.tab_name = ""
        basic = SettingSection(_("Basic"))
        log.debug("start section")

        if need_ssid:
            security = Security(connection, set_button, need_ssid, settings_obj=settings_obj)
        else:
            security = Security(connection, set_button, settings_obj=settings_obj)
        security.button.connect("clicked", self.show_more_options)
        basic.load([security])
        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)
 def show_more_options(self, widget):
     widget.destroy()
     self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
     self.ipv4.load([IPV4Conf(self.connection, self.set_button, settings_obj=self.settings_obj)])
     ppp = SettingSection(_("PPP settings"), always_show=True)
     ppp.load([PPPConf(settings_obj=self.settings_obj)])
     Dispatcher.emit("vpn-type-change", self.connection)
     self.main_box.pack_start(self.ipv4, False, False, 15)
     self.main_box.pack_start(ppp, False, False)
예제 #6
0
    def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.set_padding(35, 0, 20, 0)

        self.main_box = gtk.VBox()
        self.tab_name = "sfds"
        basic = SettingSection(_("Basic"))

        self.button = Button(_("Advanced"))
        self.button.set_size_request(50, 22)
        self.button.connect("clicked", self.show_more_options)
        self.broadband = SettingSection(_("Broadband"), always_show=True)
        self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        self.ppp = SettingSection(_("PPP"), always_show=True)
        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 225, 0)
        align.add(self.button)
        
        self.broadband = Broadband(connection, set_button, settings_obj)
        basic.load([self.broadband, align])
        self.ipv4.load([IPV4Conf(connection, set_button, settings_obj=settings_obj)])
        self.ppp.load([PPPConf(connection, set_button, settings_obj)])

        self.space = gtk.HBox()
        self.space.set_size_request(-1 ,30)

        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)
 def show_more_options(self, widget):
     self.settings_obj.initial_lock = True
     widget.parent.destroy()
     self.wireless = SettingSection(_("Wireless"), always_show=True)
     self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
     self.ipv6 = SettingSection(_("IPv6 settings"), always_show=True)
     self.wireless.load([Wireless(self.connection, self.set_button, settings_obj=self.settings_obj)])
     self.ipv4.load([IPV4Conf(self.connection, self.set_button, settings_obj=self.settings_obj, link_local=True)])
     self.ipv6.load([IPV6Conf(self.connection, self.set_button, settings_obj=self.settings_obj, link_local=True)])
     self.main_box.pack_start(self.wireless, False, False, 15)
     self.main_box.pack_start(self.ipv4, False, False)
     self.main_box.pack_start(self.ipv6, False, False, 15)
     self.settings_obj.initial_lock = False
 def show_more_options(self, widget):
     widget.destroy()
     wired = SettingSection(_("Wired"), always_show=True)
     ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
     ppp = SettingSection(_("PPP"), always_show=True)
     wired.load([Wired(self.connection, self.set_button, settings_obj=self.settings_obj)])
     ipv4.load([IPV4Conf(self.connection, self.set_button, settings_obj=self.settings_obj)])
     ppp.load([PPPConf(self.connection, self.set_button, settings_obj=self.settings_obj)])
     #self.main_box.pack_start(self.space, False, False)
     self.main_box.pack_start(wired, False, False, 15)
     self.main_box.pack_start(ipv4, False, False)
     self.main_box.pack_start(ppp, False, False, 15)
    def show_more_options(self, widget):
        self.settings_obj.initial_lock = True
        widget.destroy()
        ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        ipv6 = SettingSection(_("IPv6 settings"), always_show=True)
        ipv4.load([IPV4Conf(self.connection, self.set_button, settings_obj=self.settings_obj, link_local=True)])
        ipv6.load([IPV6Conf(self.connection, self.set_button, settings_obj=self.settings_obj, link_local=True)])

        self.main_box.pack_start(ipv4, False, False, 15)
        self.main_box.pack_start(ipv6, False, False)
        self.settings_obj.initial_lock = False
class Sections(gtk.Alignment):
    def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0, 0, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.set_padding(35, 0, 20, 0)

        self.main_box = gtk.VBox()
        self.tab_name = "sfds"
        basic = SettingSection(_("Basic"))

        self.button = Button(_("Advanced"))
        self.button.connect("clicked", self.show_more_options)
        self.wired = SettingSection(_("Wired"), always_show=False)
        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 376, 0)
        align.set_size_request(-1, 30)
        align.add(self.button)

        basic.load([
            PPTPConf(connection, set_button, settings_obj=self.settings_obj),
            align
        ])

        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)

    def show_more_options(self, widget):
        widget.destroy()
        self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        self.ipv4.load([
            IPV4Conf(self.connection,
                     self.set_button,
                     settings_obj=self.settings_obj)
        ])
        ppp = SettingSection(_("PPP settings"), always_show=True)
        ppp.load([PPPConf(settings_obj=self.settings_obj)])
        Dispatcher.emit("vpn-type-change", self.connection)
        self.main_box.pack_start(self.ipv4, False, False, 15)
        self.main_box.pack_start(ppp, False, False)
class Sections(gtk.Alignment):

    def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.set_padding(35, 0, 20, 0)

        self.main_box = gtk.VBox()
        self.tab_name = "sfds"
        basic = SettingSection(_("Basic"))

        self.button = Button(_("Advanced"))
        self.button.connect("clicked", self.show_more_options)
        self.wired = SettingSection(_("Wired"), always_show=False)
        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 376, 0)
        align.set_size_request(-1 , 30)
        align.add(self.button)
        
        basic.load([PPTPConf(connection, set_button, settings_obj=self.settings_obj), align])

        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)

    def show_more_options(self, widget):
        widget.destroy()
        self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        self.ipv4.load([IPV4Conf(self.connection, self.set_button, settings_obj=self.settings_obj)])
        ppp = SettingSection(_("PPP settings"), always_show=True)
        ppp.load([PPPConf(settings_obj=self.settings_obj)])
        Dispatcher.emit("vpn-type-change", self.connection)
        self.main_box.pack_start(self.ipv4, False, False, 15)
        self.main_box.pack_start(ppp, False, False)
    def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.set_padding(35, 0, 20, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        
        if isinstance(connection, NMRemoteConnection):
            net_manager.set_primary_wire(settings_obj.device, connection)

        self.main_box = gtk.VBox()

        basic = SettingSection(_("Wired"), always_show=True)
        button = Button(_("Advanced"))
        button.connect("clicked", self.show_more_options)

        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 285, 0)
        align.add(button)

        basic.load([Wired(self.connection, self.set_button, settings_obj), align])
        self.main_box.pack_start(basic, False, False)
        self.add(self.main_box)
 def show_more_options(self, widget):
     widget.destroy()
     self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
     self.ipv4.load([
         IPV4Conf(self.connection,
                  self.set_button,
                  settings_obj=self.settings_obj)
     ])
     ppp = SettingSection(_("PPP settings"), always_show=True)
     ppp.load([PPPConf(settings_obj=self.settings_obj)])
     Dispatcher.emit("vpn-type-change", self.connection)
     self.main_box.pack_start(self.ipv4, False, False, 15)
     self.main_box.pack_start(ppp, False, False)
class Sections(gtk.Alignment):

    def __init__(self, connection, set_button, need_ssid=False, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.set_padding(35, 0, 20, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        if isinstance(connection, NMRemoteConnection):
            net_manager.set_primary_wireless(settings_obj.ap, connection)

        self.main_box = gtk.VBox()
        self.tab_name = ""
        basic = SettingSection(_("Basic"))
        log.debug("start section")

        if need_ssid:
            security = Security(connection, set_button, need_ssid, settings_obj=settings_obj)
        else:
            security = Security(connection, set_button, settings_obj=settings_obj)
        security.button.connect("clicked", self.show_more_options)
        basic.load([security])
        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)

    def show_more_options(self, widget):
        self.settings_obj.initial_lock = True
        widget.parent.destroy()
        self.wireless = SettingSection(_("Wireless"), always_show=True)
        self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        self.ipv6 = SettingSection(_("IPv6 settings"), always_show=True)
        self.wireless.load([Wireless(self.connection, self.set_button, settings_obj=self.settings_obj)])
        self.ipv4.load([IPV4Conf(self.connection, self.set_button, settings_obj=self.settings_obj, link_local=True)])
        self.ipv6.load([IPV6Conf(self.connection, self.set_button, settings_obj=self.settings_obj, link_local=True)])
        self.main_box.pack_start(self.wireless, False, False, 15)
        self.main_box.pack_start(self.ipv4, False, False)
        self.main_box.pack_start(self.ipv6, False, False, 15)
        self.settings_obj.initial_lock = False
예제 #15
0
    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                                enable_select=False,
                                enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"), "infrastructure"),
                                    (_("Ad-hoc"), "adhoc")],
                                   fixed_width=130)

        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                                enable_select=False,
                                enable_double_click=False)

        self.band_combo = ComboBox([(_("Automatic"), None), ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                   fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                       enable_select=False,
                                       enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                      enable_select=False,
                                      enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)
        """
        wrap with alignment
        """
        widget_list = [
            "ssid_label", "ssid_entry", "mode_label", "mode_combo",
            "band_label", "band_combo", "channel_label", "channel_spin",
            "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
            "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"
        ]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"),
                                      always_show=False,
                                      revert=True,
                                      label_right=True,
                                      has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed,
                                  "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed,
                                 "cloned_mac_address")
예제 #16
0
class Wireless(gtk.VBox):
    ENTRY_WIDTH = 222

    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                                enable_select=False,
                                enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"), "infrastructure"),
                                    (_("Ad-hoc"), "adhoc")],
                                   fixed_width=130)

        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                                enable_select=False,
                                enable_double_click=False)

        self.band_combo = ComboBox([(_("Automatic"), None), ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                   fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                       enable_select=False,
                                       enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                      enable_select=False,
                                      enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)
        """
        wrap with alignment
        """
        widget_list = [
            "ssid_label", "ssid_entry", "mode_label", "mode_combo",
            "band_label", "band_combo", "channel_label", "channel_spin",
            "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
            "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"
        ]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"),
                                      always_show=False,
                                      revert=True,
                                      label_right=True,
                                      has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed,
                                  "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed,
                                 "cloned_mac_address")

    def use_default_setting(self):
        log.debug()
        self.bssid_entry.set_address("")
        self.mac_entry.set_address("")
        self.clone_entry.set_address("")
        self.mtu_spin.set_value(0)

    def use_user_setting(self):
        pass

    def spin_user_set(self, widget, value):
        if value == "":
            return
        value = int(value)
        if self.mtu_spin.lower_value <= value <= self.mtu_spin.upper_value:
            self.mtu_spin.update_and_emit(value)
        elif value < self.mtu_spin.lower_value:
            self.mtu_spin.update_and_emit(self.mtu_spin.lower_value)
        else:
            self.mtu_spin.update_and_emit(self.mtu_spin.upper_value)

    def spin_value_changed(self, widget, value, types):
        setattr(self.wireless, types, value)
        is_valid = self.connection.check_setting_finish()
        self.settings_obj.set_button("save", is_valid)

    def entry_changed(self, widget, content, types):
        is_valid = True
        if types == "ssid":
            setattr(self.wireless, types, content)
        else:
            from nmlib.nm_utils import TypeConvert
            if (content == "") or TypeConvert.is_valid_mac_address(content):
                setattr(self.wireless, types, content)
                #check_settings(self.connection, self.set_button)
                is_valid = self.connection.check_setting_finish()
            else:
                is_valid = False
                #Dispatcher.set_button("save", False)
        self.settings_obj.mac_is_valid = is_valid
        self.settings_obj.set_button("save", is_valid)

    def band_combo_selected(self, widget, content, value, index):
        self.wirless.band = value

    def mode_combo_selected(self, widget, content, value, index):
        self.wireless.mode = value
        self.wireless.adapt_wireless_commit()
        self.reset_table()

    def reset_table(self):
        container_remove_all(self.table)
        mode = self.mode_combo.get_current_item()[1]

        #self.table.attach(self.ssid_label_align, 0, 1, 0, 1)
        #self.table.attach(self.ssid_entry_align, 1, 2, 0, 1)
        # Mode
        self.table.attach(self.mode_label_align, 0, 1, 1, 2)
        self.table.attach(self.mode_combo_align, 1, 2, 1, 2)
        if mode == "adhoc":
            self.table.attach(self.band_label_align, 0, 1, 2, 3)
            self.table.attach(self.band_combo_align, 1, 2, 2, 3)
            self.table.attach(self.channel_label_align, 0, 1, 3, 4)
            self.table.attach(self.channel_spin_align, 1, 2, 3, 4)

        # Bssid
        self.table.attach(self.bssid_label_align, 0, 1, 4, 5)
        self.table.attach(self.bssid_entry_align, 1, 2, 4, 5)

        # MAC
        self.table.attach(self.mac_address_label_align, 0, 1, 5, 6)
        self.table.attach(self.mac_entry_align, 1, 2, 5, 6)
        # MAC_CLONE
        self.table.attach(self.clone_addr_label_align, 0, 1, 6, 7)
        self.table.attach(self.clone_entry_align, 1, 2, 6, 7)
        # MTU
        self.table.attach(self.mtu_spin_align, 1, 2, 7, 8)
        self.table.attach(self.mtu_label_align, 0, 1, 7, 8)

    def reset(self):
        wireless = self.wireless
        ## retrieve wireless info
        setting_list = ['bssid', 'mac_address', 'cloned_mac_address', 'mtu']
        if wireless.ssid != None:
            self.ssid_entry.set_text(wireless.ssid)

        if wireless.bssid != None:
            self.bssid_entry.set_address(wireless.bssid)

        if wireless.mode == 'infrastructure':
            #self.mode_combo.set_select_index(0)
            self.mode_combo.set_select_index(0)
        else:
            #self.mode_combo.set_select_index(1)
            self.mode_combo.set_select_index(1)

        if wireless.mac_address != None:
            self.mac_entry.set_address(wireless.mac_address)

        if wireless.cloned_mac_address != None:
            self.clone_entry.set_address(wireless.cloned_mac_address)

        if wireless.mtu != None:
            self.mtu_spin.set_value(int(wireless.mtu))

        if any(map(lambda i: getattr(wireless, i), setting_list)):
            self.section.set_active(False)

        self.reset_table()

    def save_change(self):

        self.wireless.ssid = self.ssid_entry.get_text()
        self.wireless.mode = self.mode_combo.get_current_item()[0]

        if self.bssid_entry.get_address() != "":
            self.wireless.bssid = self.bssid_entry.get_address()
        if self.mac_entry.get_address() != "":
            self.wireless.mac_address = self.mac_entry.get_address()
        if self.clone_entry.get_address() != "":
            self.wireless.cloned_mac_address = self.clone_entry.get_address()

        self.wireless.mtu = self.mtu_spin.get_value()
        self.wireless.adapt_wireless_commit()
예제 #17
0
class Sections(gtk.Alignment):
    def __init__(self,
                 connection,
                 set_button,
                 need_ssid=False,
                 settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0, 0, 0)
        self.set_padding(35, 0, 20, 0)
        self.connection = connection
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        if isinstance(connection, NMRemoteConnection):
            net_manager.set_primary_wireless(settings_obj.ap, connection)

        self.main_box = gtk.VBox()
        self.tab_name = ""
        basic = SettingSection(_("Basic"))
        log.debug("start section")

        if need_ssid:
            security = Security(connection,
                                set_button,
                                need_ssid,
                                settings_obj=settings_obj)
        else:
            security = Security(connection,
                                set_button,
                                settings_obj=settings_obj)
        security.button.connect("clicked", self.show_more_options)
        basic.load([security])
        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)

    def show_more_options(self, widget):
        self.settings_obj.initial_lock = True
        widget.parent.destroy()
        self.wireless = SettingSection(_("Wireless"), always_show=True)
        self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        self.ipv6 = SettingSection(_("IPv6 settings"), always_show=True)
        self.wireless.load([
            Wireless(self.connection,
                     self.set_button,
                     settings_obj=self.settings_obj)
        ])
        self.ipv4.load([
            IPV4Conf(self.connection,
                     self.set_button,
                     settings_obj=self.settings_obj,
                     link_local=True)
        ])
        self.ipv6.load([
            IPV6Conf(self.connection,
                     self.set_button,
                     settings_obj=self.settings_obj,
                     link_local=True)
        ])
        self.main_box.pack_start(self.wireless, False, False, 15)
        self.main_box.pack_start(self.ipv4, False, False)
        self.main_box.pack_start(self.ipv6, False, False, 15)
        self.settings_obj.initial_lock = False
    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection 
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"),"infrastructure"),(_("Ad-hoc"), "adhoc")], fixed_width=130)
        
        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                               enable_select=False,
                               enable_double_click=False)
                                
        self.band_combo = ComboBox([(_("Automatic"), None),
                                    ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                    fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                           enable_select=False,
                           enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)

        """
        wrap with alignment
        """
        widget_list = ["ssid_label", "ssid_entry", "mode_label", "mode_combo",
                       "band_label", "band_combo", "channel_label", "channel_spin",
                       "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
                       "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"), always_show= False, revert=True, label_right=True, has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed, "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed, "cloned_mac_address")
class Wireless(gtk.VBox):
    ENTRY_WIDTH = 222

    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection 
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"),"infrastructure"),(_("Ad-hoc"), "adhoc")], fixed_width=130)
        
        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                               enable_select=False,
                               enable_double_click=False)
                                
        self.band_combo = ComboBox([(_("Automatic"), None),
                                    ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                    fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                           enable_select=False,
                           enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)

        """
        wrap with alignment
        """
        widget_list = ["ssid_label", "ssid_entry", "mode_label", "mode_combo",
                       "band_label", "band_combo", "channel_label", "channel_spin",
                       "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
                       "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"), always_show= False, revert=True, label_right=True, has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed, "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed, "cloned_mac_address")

    def use_default_setting(self):
        log.debug()
        self.bssid_entry.set_address("")
        self.mac_entry.set_address("")
        self.clone_entry.set_address("")
        self.mtu_spin.set_value(0)

    def use_user_setting(self):
        pass

    def spin_user_set(self, widget, value):
        if value == "":
            return
        value = int(value)
        if self.mtu_spin.lower_value <= value <= self.mtu_spin.upper_value:
            self.mtu_spin.update_and_emit(value)
        elif value < self.mtu_spin.lower_value:
            self.mtu_spin.update_and_emit(self.mtu_spin.lower_value)
        else:
            self.mtu_spin.update_and_emit(self.mtu_spin.upper_value)
            

    def spin_value_changed(self, widget, value, types):
        setattr(self.wireless, types, value)
        is_valid = self.connection.check_setting_finish()
        self.settings_obj.set_button("save", is_valid)

    def entry_changed(self, widget, content, types):
        is_valid = True
        if types == "ssid":
            setattr(self.wireless, types, content)
        else:
            from nmlib.nm_utils import TypeConvert
            if (content == "") or TypeConvert.is_valid_mac_address(content):
                setattr(self.wireless, types, content)
                #check_settings(self.connection, self.set_button)
                is_valid = self.connection.check_setting_finish()
            else:
                is_valid = False
                #Dispatcher.set_button("save", False)
        self.settings_obj.mac_is_valid = is_valid
        self.settings_obj.set_button("save", is_valid)

    def band_combo_selected(self, widget, content, value, index):
        self.wirless.band = value

    def mode_combo_selected(self, widget, content, value, index):
        self.wireless.mode = value
        self.wireless.adapt_wireless_commit()
        self.reset_table()

    def reset_table(self):
        container_remove_all(self.table)
        mode = self.mode_combo.get_current_item()[1]

        #self.table.attach(self.ssid_label_align, 0, 1, 0, 1)
        #self.table.attach(self.ssid_entry_align, 1, 2, 0, 1)
        # Mode
        self.table.attach(self.mode_label_align, 0, 1, 1, 2)
        self.table.attach(self.mode_combo_align, 1, 2, 1, 2)
        if mode == "adhoc":
            self.table.attach(self.band_label_align, 0, 1, 2, 3)
            self.table.attach(self.band_combo_align, 1, 2, 2, 3)
            self.table.attach(self.channel_label_align, 0, 1, 3, 4)
            self.table.attach(self.channel_spin_align, 1, 2, 3, 4)

        # Bssid
        self.table.attach(self.bssid_label_align, 0, 1, 4, 5)
        self.table.attach(self.bssid_entry_align, 1, 2, 4, 5)

        # MAC
        self.table.attach(self.mac_address_label_align, 0, 1, 5, 6)
        self.table.attach(self.mac_entry_align, 1, 2, 5, 6)
        # MAC_CLONE
        self.table.attach(self.clone_addr_label_align, 0, 1, 6, 7)
        self.table.attach(self.clone_entry_align, 1,2, 6, 7)
        # MTU
        self.table.attach(self.mtu_spin_align, 1, 2, 7, 8)
        self.table.attach(self.mtu_label_align, 0, 1, 7, 8)

    def reset(self):
        wireless = self.wireless
        ## retrieve wireless info
        setting_list = ['bssid','mac_address', 'cloned_mac_address', 'mtu']
        if wireless.ssid != None:
            self.ssid_entry.set_text(wireless.ssid)

        if wireless.bssid != None:
            self.bssid_entry.set_address(wireless.bssid)

        if wireless.mode == 'infrastructure':
            #self.mode_combo.set_select_index(0)
            self.mode_combo.set_select_index(0)
        else:
            #self.mode_combo.set_select_index(1)
            self.mode_combo.set_select_index(1)

        if wireless.mac_address != None:
            self.mac_entry.set_address(wireless.mac_address)

        if wireless.cloned_mac_address !=None:
            self.clone_entry.set_address(wireless.cloned_mac_address)

        if wireless.mtu != None:
            self.mtu_spin.set_value(int(wireless.mtu))

        if any(map(lambda i: getattr(wireless, i), setting_list)):
            self.section.set_active(False)
        
        self.reset_table()
    
    def save_change(self):
        
        self.wireless.ssid = self.ssid_entry.get_text()
        self.wireless.mode = self.mode_combo.get_current_item()[0]

        if self.bssid_entry.get_address() != "":
            self.wireless.bssid = self.bssid_entry.get_address()
        if self.mac_entry.get_address() != "":
            self.wireless.mac_address = self.mac_entry.get_address()
        if self.clone_entry.get_address() != "":
            self.wireless.cloned_mac_address = self.clone_entry.get_address()

        self.wireless.mtu = self.mtu_spin.get_value()
        self.wireless.adapt_wireless_commit()