class AdvancedSettingsDialog(gtk.Dialog): def __init__(self, network_name=None): """ Build the base advanced settings dialog. This class isn't used by itself, instead it is used as a parent for the WiredSettingsDialog and WirelessSettingsDialog. """ # if no network name was passed, just use Properties as the title if network_name: title = '%s - %s' % (network_name, language['properties']) else: title = language['properties'] gtk.Dialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.set_default_size() self.connect('show', lambda *a, **k: self.set_default_size()) # Set up the Advanced Settings Dialog. self.txt_ip = LabelEntry(language['ip']) self.txt_ip.entry.connect('focus-out-event', self.set_defaults) self.txt_netmask = LabelEntry(language['netmask']) self.txt_gateway = LabelEntry(language['gateway']) self.txt_search_dom = LabelEntry(language['search_domain']) self.txt_domain = LabelEntry(language['dns_domain']) self.txt_dns_1 = LabelEntry(language['dns'] + ' 1') self.txt_dns_2 = LabelEntry(language['dns'] + ' 2') self.txt_dns_3 = LabelEntry(language['dns'] + ' 3') dhcp_hostname_hbox = gtk.HBox(False, 0) self.chkbox_use_dhcp_hostname = gtk.CheckButton() self.txt_dhcp_hostname = LabelEntry("DHCP Hostname") dhcp_hostname_hbox.pack_start(self.chkbox_use_dhcp_hostname, fill=False, expand=False) dhcp_hostname_hbox.pack_start(self.txt_dhcp_hostname) self.chkbox_static_ip = gtk.CheckButton(language['use_static_ip']) self.chkbox_static_dns = gtk.CheckButton(language['use_static_dns']) self.chkbox_global_dns = gtk.CheckButton(language['use_global_dns']) self.hbox_dns = gtk.HBox(False, 0) self.hbox_dns.pack_start(self.chkbox_static_dns) self.hbox_dns.pack_start(self.chkbox_global_dns) # Set up the script settings button self.script_button = gtk.Button() script_image = gtk.Image() script_image.set_from_stock(gtk.STOCK_EXECUTE, 4) script_image.set_padding(4, 0) #self.script_button.set_alignment(.5, .5) self.script_button.set_image(script_image) self.script_button.set_label(language['scripts']) self.button_hbox = gtk.HBox(False, 2) self.button_hbox.pack_start(self.script_button, fill=False, expand=False) self.button_hbox.show() self.swindow = gtk.ScrolledWindow() self.swindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.viewport = gtk.Viewport() self.viewport.set_shadow_type(gtk.SHADOW_NONE) self.cvbox = gtk.VBox() self.viewport.add(self.cvbox) self.swindow.add(self.viewport) self.vbox.pack_start(self.swindow) assert (isinstance(self.cvbox, gtk.VBox)) self.cvbox.pack_start(self.chkbox_static_ip, fill=False, expand=False) self.cvbox.pack_start(self.txt_ip, fill=False, expand=False) self.cvbox.pack_start(self.txt_netmask, fill=False, expand=False) self.cvbox.pack_start(self.txt_gateway, fill=False, expand=False) self.cvbox.pack_start(self.hbox_dns, fill=False, expand=False) self.cvbox.pack_start(self.txt_domain, fill=False, expand=False) self.cvbox.pack_start(self.txt_search_dom, fill=False, expand=False) self.cvbox.pack_start(self.txt_dns_1, fill=False, expand=False) self.cvbox.pack_start(self.txt_dns_2, fill=False, expand=False) self.cvbox.pack_start(self.txt_dns_3, fill=False, expand=False) self.cvbox.pack_start(dhcp_hostname_hbox, fill=False, expand=False) self.cvbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5) # Connect the events to the actions self.chkbox_static_ip.connect("toggled", self.toggle_ip_checkbox) self.chkbox_static_dns.connect("toggled", self.toggle_dns_checkbox) self.chkbox_global_dns.connect("toggled", self.toggle_global_dns_checkbox) self.chkbox_use_dhcp_hostname.connect( 'toggled', self.toggle_dhcp_hostname_checkbox) # Start with all disabled, then they will be enabled later. self.chkbox_static_ip.set_active(False) self.chkbox_static_dns.set_active(False) def set_default_size(self): width, height = self.get_size() s_height = gtk.gdk.screen_height() if s_height < 768: height = s_height * .75 else: height = 600 self.resize(int(width), int(height)) def set_defaults(self, widget=None, event=None): """ Put some default values into entries to help the user out. """ self.txt_ip.set_text(self.txt_ip.get_text().strip()) ipAddress = self.txt_ip.get_text() # For easy typing :) netmask = self.txt_netmask gateway = self.txt_gateway ip_parts = misc.IsValidIP(ipAddress) if ip_parts: if stringToNone(gateway.get_text() ) is None: # Make sure the gateway box is blank # Fill it in with a .1 at the end gateway.set_text('.'.join(ip_parts[0:3]) + '.1') if stringToNone(netmask.get_text() ) is None: # Make sure the netmask is blank netmask.set_text( '255.255.255.0') # Fill in the most common one elif ipAddress != "": error(None, language['invalid_ip_address']) def reset_static_checkboxes(self): # Enable the right stuff if stringToNone(self.txt_ip.get_text()): self.chkbox_static_ip.set_active(True) self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_sensitive(False) else: self.chkbox_static_ip.set_active(False) self.chkbox_static_dns.set_sensitive(True) if stringToNone(self.txt_dns_1.get_text()) or \ self.chkbox_global_dns.get_active(): self.chkbox_static_dns.set_active(True) else: self.chkbox_static_dns.set_active(False) # This will properly disable unused boxes. self.toggle_ip_checkbox() self.toggle_dns_checkbox() self.toggle_global_dns_checkbox() def toggle_ip_checkbox(self, widget=None): """Toggle entries/checkboxes based on the static IP checkbox. """ # Should disable the static IP text boxes, and also enable the DNS # checkbox when disabled and disable when enabled. if self.chkbox_static_ip.get_active(): self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_sensitive(False) else: self.chkbox_static_dns.set_sensitive(True) self.txt_ip.set_sensitive(self.chkbox_static_ip.get_active()) self.txt_netmask.set_sensitive(self.chkbox_static_ip.get_active()) self.txt_gateway.set_sensitive(self.chkbox_static_ip.get_active()) def toggle_dns_checkbox(self, widget=None): """ Toggle entries and checkboxes based on the static dns checkbox. """ # Should disable the static DNS boxes if self.chkbox_static_ip.get_active(): self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_sensitive(False) self.chkbox_global_dns.set_sensitive( self.chkbox_static_dns.get_active()) l = [ self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom ] if self.chkbox_static_dns.get_active(): # If global dns is on, don't use local dns for w in l: w.set_sensitive(not self.chkbox_global_dns.get_active()) else: for w in l: w.set_sensitive(False) self.chkbox_global_dns.set_active(False) def toggle_dhcp_hostname_checkbox(self, widget=None): self.txt_dhcp_hostname.set_sensitive( self.chkbox_use_dhcp_hostname.get_active()) def toggle_global_dns_checkbox(self, widget=None): """ Set the DNS entries' sensitivity based on the Global checkbox. """ global_dns_active = daemon.GetUseGlobalDNS() if not global_dns_active and self.chkbox_global_dns.get_active(): error(None, language['global_dns_not_enabled']) self.chkbox_global_dns.set_active(False) if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active(): for w in [ self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom ]: w.set_sensitive(not self.chkbox_global_dns.get_active()) def destroy_called(self, *args): """ Clean up everything. """ super(AdvancedSettingsDialog, self).destroy() self.destroy() del self def save_settings(self): """ Save settings common to wired and wireless settings dialogs. """ if self.chkbox_static_ip.get_active(): self.set_net_prop("ip", noneToString(self.txt_ip.get_text())) self.set_net_prop("netmask", noneToString(self.txt_netmask.get_text())) self.set_net_prop("gateway", noneToString(self.txt_gateway.get_text())) else: self.set_net_prop("ip", '') self.set_net_prop("netmask", '') self.set_net_prop("gateway", '') if self.chkbox_static_dns.get_active() and \ not self.chkbox_global_dns.get_active(): self.set_net_prop('use_static_dns', True) self.set_net_prop('use_global_dns', False) self.set_net_prop('dns_domain', noneToString(self.txt_domain.get_text())) self.set_net_prop("search_domain", noneToString(self.txt_search_dom.get_text())) self.set_net_prop("dns1", noneToString(self.txt_dns_1.get_text())) self.set_net_prop("dns2", noneToString(self.txt_dns_2.get_text())) self.set_net_prop("dns3", noneToString(self.txt_dns_3.get_text())) elif self.chkbox_static_dns.get_active() and \ self.chkbox_global_dns.get_active(): self.set_net_prop('use_static_dns', True) self.set_net_prop('use_global_dns', True) else: self.set_net_prop('use_static_dns', False) self.set_net_prop('use_global_dns', False) self.set_net_prop('dns_domain', '') self.set_net_prop("search_domain", '') self.set_net_prop("dns1", '') self.set_net_prop("dns2", '') self.set_net_prop("dns3", '') self.set_net_prop('use_dhcphostname', self.chkbox_use_dhcp_hostname.get_active()) self.set_net_prop("dhcphostname", noneToString(self.txt_dhcp_hostname.get_text()))
class AdvancedSettingsDialog(gtk.Dialog): def __init__(self, network_name=None): """ Build the base advanced settings dialog. This class isn't used by itself, instead it is used as a parent for the WiredSettingsDialog and WirelessSettingsDialog. """ # if no network name was passed, just use Properties as the title if network_name: title = '%s - %s' % (network_name, language['properties']) else: title = language['properties'] gtk.Dialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.set_default_size() self.connect('show', lambda *a, **k: self.set_default_size()) # Set up the Advanced Settings Dialog. self.txt_ip = LabelEntry(language['ip']) self.txt_ip.entry.connect('focus-out-event', self.set_defaults) self.txt_netmask = LabelEntry(language['netmask']) self.txt_gateway = LabelEntry(language['gateway']) self.txt_search_dom = LabelEntry(language['search_domain']) self.txt_domain = LabelEntry(language['dns_domain']) self.txt_dns_1 = LabelEntry(language['dns'] + ' 1') self.txt_dns_2 = LabelEntry(language['dns'] + ' 2') self.txt_dns_3 = LabelEntry(language['dns'] + ' 3') dhcp_hostname_hbox = gtk.HBox(False, 0) self.chkbox_use_dhcp_hostname = gtk.CheckButton() self.txt_dhcp_hostname = LabelEntry("DHCP Hostname") dhcp_hostname_hbox.pack_start(self.chkbox_use_dhcp_hostname, fill=False, expand=False) dhcp_hostname_hbox.pack_start(self.txt_dhcp_hostname) self.chkbox_static_ip = gtk.CheckButton(language['use_static_ip']) self.chkbox_static_dns = gtk.CheckButton(language['use_static_dns']) self.chkbox_global_dns = gtk.CheckButton(language['use_global_dns']) self.hbox_dns = gtk.HBox(False, 0) self.hbox_dns.pack_start(self.chkbox_static_dns) self.hbox_dns.pack_start(self.chkbox_global_dns) # Set up the script settings button self.script_button = gtk.Button() script_image = gtk.Image() script_image.set_from_stock(gtk.STOCK_EXECUTE, 4) script_image.set_padding(4, 0) #self.script_button.set_alignment(.5, .5) self.script_button.set_image(script_image) self.script_button.set_label(language['scripts']) self.button_hbox = gtk.HBox(False, 2) self.button_hbox.pack_start(self.script_button, fill=False, expand=False) self.button_hbox.show() self.swindow = gtk.ScrolledWindow() self.swindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.viewport = gtk.Viewport() self.viewport.set_shadow_type(gtk.SHADOW_NONE) self.cvbox = gtk.VBox() self.viewport.add(self.cvbox) self.swindow.add(self.viewport) self.vbox.pack_start(self.swindow) assert(isinstance(self.cvbox, gtk.VBox)) self.cvbox.pack_start(self.chkbox_static_ip, fill=False, expand=False) self.cvbox.pack_start(self.txt_ip, fill=False, expand=False) self.cvbox.pack_start(self.txt_netmask, fill=False, expand=False) self.cvbox.pack_start(self.txt_gateway, fill=False, expand=False) self.cvbox.pack_start(self.hbox_dns, fill=False, expand=False) self.cvbox.pack_start(self.txt_domain, fill=False, expand=False) self.cvbox.pack_start(self.txt_search_dom, fill=False, expand=False) self.cvbox.pack_start(self.txt_dns_1, fill=False, expand=False) self.cvbox.pack_start(self.txt_dns_2, fill=False, expand=False) self.cvbox.pack_start(self.txt_dns_3, fill=False, expand=False) self.cvbox.pack_start(dhcp_hostname_hbox, fill=False, expand=False) self.cvbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5) # Connect the events to the actions self.chkbox_static_ip.connect("toggled", self.toggle_ip_checkbox) self.chkbox_static_dns.connect("toggled", self.toggle_dns_checkbox) self.chkbox_global_dns.connect("toggled", self.toggle_global_dns_checkbox) self.chkbox_use_dhcp_hostname.connect('toggled', self.toggle_dhcp_hostname_checkbox) # Start with all disabled, then they will be enabled later. self.chkbox_static_ip.set_active(False) self.chkbox_static_dns.set_active(False) def set_default_size(self): width, height = self.get_size() s_height = gtk.gdk.screen_height() if s_height < 768: height = s_height * .75 else: height = 600 self.resize(int(width), int(height)) def set_defaults(self, widget=None, event=None): """ Put some default values into entries to help the user out. """ self.txt_ip.set_text(self.txt_ip.get_text().strip()) ipAddress = self.txt_ip.get_text() # For easy typing :) netmask = self.txt_netmask gateway = self.txt_gateway ip_parts = misc.IsValidIP(ipAddress) if ip_parts: if stringToNone(gateway.get_text()) is None: # Make sure the gateway box is blank # Fill it in with a .1 at the end gateway.set_text('.'.join(ip_parts[0:3]) + '.1') if stringToNone(netmask.get_text()) is None: # Make sure the netmask is blank netmask.set_text('255.255.255.0') # Fill in the most common one elif ipAddress != "": error(None, language['invalid_ip_address']) def reset_static_checkboxes(self): # Enable the right stuff if stringToNone(self.txt_ip.get_text()): self.chkbox_static_ip.set_active(True) self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_sensitive(False) else: self.chkbox_static_ip.set_active(False) self.chkbox_static_dns.set_sensitive(True) if stringToNone(self.txt_dns_1.get_text()) or \ self.chkbox_global_dns.get_active(): self.chkbox_static_dns.set_active(True) else: self.chkbox_static_dns.set_active(False) # This will properly disable unused boxes. self.toggle_ip_checkbox() self.toggle_dns_checkbox() self.toggle_global_dns_checkbox() def toggle_ip_checkbox(self, widget=None): """Toggle entries/checkboxes based on the static IP checkbox. """ # Should disable the static IP text boxes, and also enable the DNS # checkbox when disabled and disable when enabled. if self.chkbox_static_ip.get_active(): self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_sensitive(False) else: self.chkbox_static_dns.set_sensitive(True) self.txt_ip.set_sensitive(self.chkbox_static_ip.get_active()) self.txt_netmask.set_sensitive(self.chkbox_static_ip.get_active()) self.txt_gateway.set_sensitive(self.chkbox_static_ip.get_active()) def toggle_dns_checkbox(self, widget=None): """ Toggle entries and checkboxes based on the static dns checkbox. """ # Should disable the static DNS boxes if self.chkbox_static_ip.get_active(): self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_sensitive(False) self.chkbox_global_dns.set_sensitive(self.chkbox_static_dns. get_active()) l = [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom] if self.chkbox_static_dns.get_active(): # If global dns is on, don't use local dns for w in l: w.set_sensitive(not self.chkbox_global_dns.get_active()) else: for w in l: w.set_sensitive(False) self.chkbox_global_dns.set_active(False) def toggle_dhcp_hostname_checkbox(self, widget=None): self.txt_dhcp_hostname.set_sensitive( self.chkbox_use_dhcp_hostname.get_active()) def toggle_global_dns_checkbox(self, widget=None): """ Set the DNS entries' sensitivity based on the Global checkbox. """ global_dns_active = daemon.GetUseGlobalDNS() if not global_dns_active and self.chkbox_global_dns.get_active(): error(None, language['global_dns_not_enabled']) self.chkbox_global_dns.set_active(False) if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active(): for w in [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3, self.txt_domain, self.txt_search_dom]: w.set_sensitive(not self.chkbox_global_dns.get_active()) def destroy_called(self, *args): """ Clean up everything. """ super(AdvancedSettingsDialog, self).destroy() self.destroy() del self def save_settings(self): """ Save settings common to wired and wireless settings dialogs. """ if self.chkbox_static_ip.get_active(): self.set_net_prop("ip", noneToString(self.txt_ip.get_text())) self.set_net_prop("netmask", noneToString(self.txt_netmask.get_text())) self.set_net_prop("gateway", noneToString(self.txt_gateway.get_text())) else: self.set_net_prop("ip", '') self.set_net_prop("netmask", '') self.set_net_prop("gateway", '') if self.chkbox_static_dns.get_active() and \ not self.chkbox_global_dns.get_active(): self.set_net_prop('use_static_dns', True) self.set_net_prop('use_global_dns', False) self.set_net_prop('dns_domain', noneToString(self.txt_domain.get_text())) self.set_net_prop("search_domain", noneToString(self.txt_search_dom.get_text())) self.set_net_prop("dns1", noneToString(self.txt_dns_1.get_text())) self.set_net_prop("dns2", noneToString(self.txt_dns_2.get_text())) self.set_net_prop("dns3", noneToString(self.txt_dns_3.get_text())) elif self.chkbox_static_dns.get_active() and \ self.chkbox_global_dns.get_active(): self.set_net_prop('use_static_dns', True) self.set_net_prop('use_global_dns', True) else: self.set_net_prop('use_static_dns', False) self.set_net_prop('use_global_dns', False) self.set_net_prop('dns_domain', '') self.set_net_prop("search_domain", '') self.set_net_prop("dns1", '') self.set_net_prop("dns2", '') self.set_net_prop("dns3", '') self.set_net_prop('use_dhcphostname', self.chkbox_use_dhcp_hostname.get_active()) self.set_net_prop("dhcphostname",noneToString(self.txt_dhcp_hostname.get_text()))