diff --git a/data/wicd.glade b/data/wicd.glade index a199fa1..4a5cf77 100644 --- a/data/wicd.glade +++ b/data/wicd.glade @@ -1,6 +1,6 @@ - + 450 @@ -424,7 +424,7 @@ True - 17 + 18 2 4 4 @@ -455,19 +455,6 @@ True True - - 1 - 2 - 7 - 8 - - - - - - True - True - 1 2 @@ -477,7 +464,7 @@ - + True True @@ -489,6 +476,19 @@ + + + True + True + + + 1 + 2 + 10 + 11 + + + True @@ -498,8 +498,8 @@ 2 - 4 - 5 + 5 + 6 @@ -519,8 +519,8 @@ 2 - 5 - 6 + 6 + 7 @@ -537,8 +537,8 @@ - 7 - 8 + 8 + 9 @@ -555,8 +555,8 @@ - 8 - 9 + 9 + 10 @@ -573,8 +573,8 @@ - 9 - 10 + 10 + 11 @@ -586,8 +586,8 @@ 1 2 - 10 - 11 + 11 + 12 @@ -604,8 +604,8 @@ - 10 - 11 + 11 + 12 @@ -692,8 +692,8 @@ 2 - 11 - 12 + 12 + 13 @@ -715,8 +715,8 @@ 2 - 12 - 13 + 13 + 14 @@ -738,8 +738,8 @@ 2 - 13 - 14 + 14 + 15 @@ -760,8 +760,8 @@ 2 - 14 - 15 + 15 + 16 @@ -774,8 +774,8 @@ 2 - 15 - 16 + 16 + 17 @@ -795,8 +795,8 @@ 2 - 16 - 17 + 17 + 18 @@ -808,8 +808,8 @@ 1 2 - 6 - 7 + 7 + 8 GTK_FILL @@ -826,11 +826,35 @@ - 6 - 7 + 7 + 8 + + + True + + + True + True + True + If selected, wicd will automatically connect to a wired network +as soon as a cable is plugged in, even if a wireless connection +is already active. + Always switch to a wired connection when available + 0 + True + + + + + 2 + 4 + 5 + 24 + + diff --git a/images/wired-gui.svg b/images/wired-gui.svg new file mode 100644 index 0000000..437efcd --- /dev/null +++ b/images/wired-gui.svg @@ -0,0 +1,682 @@ + + + + + + + image/svg+xml + + + + Lapo Calamandrei + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wicd/autoconnect.py b/wicd/autoconnect.py index 310de8b..b21672d 100755 --- a/wicd/autoconnect.py +++ b/wicd/autoconnect.py @@ -49,7 +49,6 @@ def error_handler(*args): if __name__ == '__main__': try: time.sleep(2) - wireless.Scan(True) daemon.SetSuspend(False) if not daemon.CheckIfConnecting(): daemon.AutoConnect(True, reply_handler=handler, error_handler=handler) diff --git a/wicd/backends/be-ioctl.py b/wicd/backends/be-ioctl.py index b261449..08a6a79 100644 --- a/wicd/backends/be-ioctl.py +++ b/wicd/backends/be-ioctl.py @@ -376,9 +376,8 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): False otherwise. """ - def error(): - print "Unable to find ctrl_interface for wpa_supplicant. " + \ - "Could not validate authentication." + error= "Unable to find ctrl_interface for wpa_supplicant. " + \ + "Could not validate authentication." # Right now there's no way to do this for ralink drivers if self.wpa_driver == RALINK_DRIVER: @@ -389,7 +388,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface): socket = [os.path.join(ctrl_iface, s) \ for s in os.listdir(ctrl_iface) if s == self.iface][0] except OSError: - error() + print error return True wpa = wpactrl.WPACtrl(socket) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index 29d4320..b2755cc 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -48,7 +48,7 @@ class ConfigManager(RawConfigParser): """ Returns the path to the loaded config file. """ return self.config_file - def set_option(self, section, option, value, save=False): + def set_option(self, section, option, value, write=False): """ Wrapper around ConfigParser.set Adds the option to write the config file change right away. @@ -65,7 +65,7 @@ class ConfigManager(RawConfigParser): value = "%(ws)s%(value)s%(ws)s" % {"value" : value, "ws" : self.mrk_ws} RawConfigParser.set(self, section, str(option), value) - if save: + if write: self.write() def set(self, *args, **kargs): @@ -98,7 +98,7 @@ class ConfigManager(RawConfigParser): else: if default != "__None__": print 'did not find %s in configuration, setting default %s' % (option, str(default)) - self.set(section, option, str(default), save=True) + self.set(section, option, str(default), write=True) ret = default else: ret = None diff --git a/wicd/gui.py b/wicd/gui.py index 55f0eda..597e781 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -706,15 +706,14 @@ class appGui(object): [width, height] = self.window.get_size() try: daemon.WriteWindowSize(width, height, "main") - except: + daemon.SetGUIOpen(False) + except dbusmanager.DBusException: pass if self.standalone: sys.exit(0) self.is_visible = False - daemon.SetGUIOpen(False) - self.wait_for_events() return True def show_win(self): diff --git a/wicd/monitor.py b/wicd/monitor.py index 47fe3b5..0566b9b 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -63,20 +63,29 @@ class ConnectionStatus(object): self.last_reconnect_time = time.time() self.signal_changed = False self.iwconfig = "" + self.trigger_reconnect = False bus = dbusmanager.get_bus() bus.add_signal_receiver(self._force_update_connection_status, "UpdateState", "org.wicd.daemon") def check_for_wired_connection(self, wired_ip): - """ Checks for an active wired connection. + """ Checks for a wired connection. - Checks for and updates the tray icon for an active wired connection - Returns True if wired connection is active, false if inactive. + Checks for two states: + 1) A wired connection is not in use, but a cable is plugged + in, and the user has chosen to switch to a wired connection + whenever its available, even if already connected to a + wireless network + + 2) A wired connection is currently active. """ + if not wired_ip and daemon.GetPreferWiredNetwork(): + if not daemon.GetForcedDisconnect() and wired.CheckPluggedIn(): + self.trigger_reconnect = True - if wired_ip and wired.CheckPluggedIn(): + elif wired_ip and wired.CheckPluggedIn(): # Only change the interface if it's not already set for wired if not self.still_wired: daemon.SetCurrentInterface(daemon.GetWiredInterface()) @@ -89,14 +98,17 @@ class ConnectionStatus(object): def check_for_wireless_connection(self, wireless_ip): """ Checks for an active wireless connection. - Checks for and updates the tray icon for an active - wireless connection. Returns True if wireless connection - is active, and False otherwise. + Checks for an active wireless connection. Also notes + if the signal strength is 0, and if it remains there + for too long, triggers a wireless disconnect. + + Returns True if wireless connection is active, and + False otherwise. """ # Make sure we have an IP before we do anything else. - if wireless_ip is None: + if not wireless_ip: return False if daemon.NeedsExternalCalls(): @@ -158,6 +170,15 @@ class ConnectionStatus(object): # Check for wired. wired_ip = wired.GetWiredIP("") wired_found = self.check_for_wired_connection(wired_ip) + # Trigger an AutoConnect if we're plugged in, not connected + # to a wired network, and the "autoswitch to wired" option + # is on. + if self.trigger_reconnect: + self.trigger_reconnect = False + wireless.DisconnectWireless() + daemon.AutoConnect(False, reply_handler=lambda:None, + error_handler=lambda:None) + return True if wired_found: self.update_state(misc.WIRED, wired_ip=wired_ip) return True diff --git a/wicd/netentry.py b/wicd/netentry.py index 302b04d..8f36f13 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -234,7 +234,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog): def edit_scripts(self, widget=None, event=None): """ Launch the script editting dialog. """ - profile = self.combo_profile_names.get_active_text() + profile = self.prof_name cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"] if os.getuid() != 0: cmdbase = misc.get_sudo_cmd(language['scripts_need_pass']) @@ -535,10 +535,10 @@ class WiredNetworkEntry(NetworkEntry): """ Load the wired network entry. """ NetworkEntry.__init__(self, dbus_ifaces) # Center the picture and pad it a bit - self.image.set_alignment(.5, 0) + self.image.set_padding(0, 0) + self.image.set_alignment(.5, .5) self.image.set_size_request(60, -1) - #self.image.set_from_icon_name("network-wired", 6) - self.image.set_from_file(wpath.images + "wired.png") + self.image.set_from_file(wpath.images + "wired-gui.svg") self.image.show() self.connect_button.show() @@ -555,9 +555,17 @@ class WiredNetworkEntry(NetworkEntry): # Build the profile list. self.combo_profile_names = gtk.combo_box_new_text() self.profile_list = wired.GetWiredProfileList() + default_prof = wired.GetDefaultWiredNetwork() if self.profile_list: - for x in self.profile_list: - self.combo_profile_names.append_text(x) + starting_index = 0 + for x, prof in enumerate(self.profile_list): + self.combo_profile_names.append_text(prof) + if default_prof == prof: + starting_index = x + self.combo_profile_names.set_active(starting_index) + else: + print "no wired profiles found" + self.profile_help.show() # Format the profile help label. self.profile_help.set_justify(gtk.JUSTIFY_LEFT) @@ -580,6 +588,11 @@ class WiredNetworkEntry(NetworkEntry): self.chkbox_default_profile.connect("toggled", self.toggle_default_profile) self.combo_profile_names.connect("changed", self.change_profile) + + # Show everything, but hide the profile help label. + self.show_all() + self.profile_help.hide() + self.advanced_dialog = WiredSettingsDialog(self.combo_profile_names.get_active_text()) # Toggle the default profile checkbox to the correct state. if to_bool(wired.GetWiredProperty("default")): @@ -587,25 +600,6 @@ class WiredNetworkEntry(NetworkEntry): else: self.chkbox_default_profile.set_active(False) - # Show everything, but hide the profile help label. - self.show_all() - self.profile_help.hide() - self.advanced_dialog = WiredSettingsDialog(self.combo_profile_names.get_active_text()) - - # Display the default profile if it exists. - if self.profile_list is not None: - prof = wired.GetDefaultWiredNetwork() - if prof != None: # Make sure the default profile gets displayed. - i = 0 - while self.combo_profile_names.get_active_text() != prof: - self.combo_profile_names.set_active(i) - i += 1 - else: - self.combo_profile_names.set_active(0) - print "wired profiles found" - else: - print "no wired profiles found" - self.profile_help.show() self.check_enable() self.wireddis = self.connect("destroy", self.destroy_called) @@ -706,6 +700,7 @@ class WiredNetworkEntry(NetworkEntry): return profile_name = self.combo_profile_names.get_active_text() + self.advanced_dialog.prof_name = profile_name wired.ReadWiredNetworkProfile(profile_name) self.advanced_dialog.txt_ip.set_text(self.format_entry("ip")) @@ -734,7 +729,6 @@ class WirelessNetworkEntry(NetworkEntry): self.image.set_alignment(.5, .5) self.image.set_size_request(60, -1) self.image.show() - #self.image.set_from_icon_name("network-wired", 6) self.essid = noneToBlankString(wireless.GetWirelessProperty(networkID, "essid")) self.lbl_strength = GreyLabel() diff --git a/wicd/networking.py b/wicd/networking.py index dcecce8..e1a99f7 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -741,7 +741,8 @@ class WirelessConnectThread(ConnectThread): self.is_connecting = True # Run pre-connection script. - self.run_script_if_needed(self.before_script, 'pre-connection', self.network['bssid'], self.network['essid']) + self.run_script_if_needed(self.before_script, 'pre-connection', + self.network['bssid'], self.network['essid']) # Take down interface and clean up previous connections. @@ -783,7 +784,8 @@ class WirelessConnectThread(ConnectThread): self.set_dns_addresses() # Run post-connection script. - self.run_script_if_needed(self.after_script, 'post-connection', self.network['bssid'], self.network['essid']) + self.run_script_if_needed(self.after_script, 'post-connection', + self.network['bssid'], self.network['essid']) self.SetStatus('done') print 'Connecting thread exiting.' @@ -947,7 +949,8 @@ class WiredConnectThread(ConnectThread): self.is_connecting = True # Run pre-connection script. - self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', 'wired') + self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', + 'wired') # Take down interface and clean up previous connections. self.put_iface_down(liface) @@ -965,7 +968,8 @@ class WiredConnectThread(ConnectThread): self.set_dns_addresses() # Run post-connection script. - self.run_script_if_needed(self.after_script, 'post-connection', 'wired', 'wired') + self.run_script_if_needed(self.after_script, 'post-connection', 'wired', + 'wired') self.SetStatus('done') print 'Connecting thread exiting.' diff --git a/wicd/prefs.py b/wicd/prefs.py index b5779fb..bff88bb 100644 --- a/wicd/prefs.py +++ b/wicd/prefs.py @@ -58,6 +58,7 @@ class PreferencesDialog(object): self.reconnectcheckbox.set_active(daemon.GetAutoReconnect()) self.debugmodecheckbox.set_active(daemon.GetDebugMode()) self.displaytypecheckbox.set_active(daemon.GetSignalDisplayType()) + self.preferwiredcheckbox.set_active(daemon.GetPreferWiredNetwork()) dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio, self.pumpradio] @@ -148,6 +149,7 @@ class PreferencesDialog(object): daemon.SetAutoReconnect(self.reconnectcheckbox.get_active()) daemon.SetDebugMode(self.debugmodecheckbox.get_active()) daemon.SetSignalDisplayType(int(self.displaytypecheckbox.get_active())) + daemon.SetPreferWiredNetwork(bool(self.preferwiredcheckbox.get_active())) if self.showlistradiobutton.get_active(): daemon.SetWiredAutoConnectMethod(2) elif self.lastusedradiobutton.get_active(): @@ -253,6 +255,8 @@ class PreferencesDialog(object): self.wiredcheckbox = setup_label("pref_always_check", 'wired_always_on') + self.preferwiredcheckbox = setup_label("pref_prefer_wired_check", + "prefer_wired") self.reconnectcheckbox = setup_label("pref_auto_check", 'auto_reconnect') diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 53c9ad2..40e80ea 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -141,28 +141,28 @@ class WicdDaemon(dbus.service.Object): """ Sets the wired interface for the daemon to use. """ print "setting wired interface %s" % (str(interface)) self.wired.wired_interface = noneToBlankString(interface) - self.config.set("Settings", "wired_interface", interface, True) + self.config.set("Settings", "wired_interface", interface, write=True) @dbus.service.method('org.wicd.daemon') def SetWirelessInterface(self, interface): """ Sets the wireless interface the daemon will use. """ print "setting wireless interface %s" % (str(interface)) self.wifi.wireless_interface = noneToBlankString(interface) - self.config.set("Settings", "wireless_interface", interface, True) + self.config.set("Settings", "wireless_interface", interface, write=True) @dbus.service.method('org.wicd.daemon') def SetWPADriver(self, driver): """ Sets the wpa driver the wpa_supplicant will use. """ print "setting wpa driver", str(driver) self.wifi.wpa_driver = driver - self.config.set("Settings", "wpa_driver", driver, True) + self.config.set("Settings", "wpa_driver", driver, write=True) @dbus.service.method('org.wicd.daemon') def SetUseGlobalDNS(self, use): """ Sets a boolean which determines if global DNS is enabled. """ print 'setting use global dns to', use use = misc.to_bool(use) - self.config.set("Settings", "use_global_dns", use, True) + self.config.set("Settings", "use_global_dns", use, write=True) self.use_global_dns = use self.wifi.use_global_dns = use self.wired.use_global_dns = use @@ -197,12 +197,11 @@ class WicdDaemon(dbus.service.Object): print 'search domain is %s' % search_dom self.config.write() - @dbus.service.method('org.wicd.daemon') def SetBackend(self, backend): """ Sets a new backend. """ print "setting backend to %s" % backend - self.config.set("Settings", "backend", backend, True) + self.config.set("Settings", "backend", backend, write=True) if backend != self.GetCurrentBackend(): self.suspended = True self.wifi.LoadBackend(backend) @@ -272,7 +271,7 @@ class WicdDaemon(dbus.service.Object): @dbus.service.method('org.wicd.daemon') def SetDebugMode(self, debug): """ Sets if debugging mode is on or off. """ - self.config.set("Settings", "debug_mode", debug, True) + self.config.set("Settings", "debug_mode", debug, write=True) self.debug_mode = misc.to_bool(debug) self.wifi.debug = self.debug_mode self.wired.debug = self.debug_mode @@ -352,7 +351,8 @@ class WicdDaemon(dbus.service.Object): """ print 'setting automatically reconnect when connection drops %s' % value - self.config.set("Settings", "auto_reconnect", misc.to_bool(value), True) + self.config.set("Settings", "auto_reconnect", misc.to_bool(value), + write=True) self.auto_reconnect = misc.to_bool(value) @dbus.service.method('org.wicd.daemon') @@ -453,7 +453,7 @@ class WicdDaemon(dbus.service.Object): @dbus.service.method('org.wicd.daemon') def SetSignalDisplayType(self, value): """ Sets the signal display type and writes it the wicd config file. """ - self.config.set("Settings", "signal_display_type", value, True) + self.config.set("Settings", "signal_display_type", value, write=True) self.signal_display_type = int(value) @dbus.service.method('org.wicd.daemon') @@ -483,7 +483,7 @@ class WicdDaemon(dbus.service.Object): def SetAlwaysShowWiredInterface(self, value): """ Sets always_show_wired_interface to the given value. """ self.config.set("Settings", "always_show_wired_interface", - misc.to_bool(value), True) + misc.to_bool(value), write=True) self.always_show_wired_interface = misc.to_bool(value) @dbus.service.method('org.wicd.daemon') @@ -497,7 +497,8 @@ class WicdDaemon(dbus.service.Object): # 1 = default profile # 2 = show list # 3 = last used profile - self.config.set("Settings","wired_connect_mode", int(method), True) + self.config.set("Settings","wired_connect_mode", int(method), + write=True) self.wired_connect_mode = int(method) self.wired_bus.connect_mode = int(method) @@ -505,9 +506,8 @@ class WicdDaemon(dbus.service.Object): def GetWiredAutoConnectMethod(self): """ Returns the wired autoconnect method. """ return int(self.wired_connect_mode) - - - @dbus.service.method('org.wicd.dameon') + + @dbus.service.method('org.wicd.daemon') def GetPreferWiredNetwork(self): """ Returns True if wired network preference is set. @@ -520,6 +520,7 @@ class WicdDaemon(dbus.service.Object): @dbus.service.method('org.wicd.daemon') def SetPreferWiredNetwork(self, value): """ Sets the prefer_wired state. """ + self.config.set("Settings", "prefer_wired", bool(value), write=True) self.prefer_wired = bool(value) @dbus.service.method('org.wicd.daemon') @@ -589,7 +590,7 @@ class WicdDaemon(dbus.service.Object): self.dhcp_client = int(client) self.wifi.dhcp_client = int(client) self.wired.dhcp_client = int(client) - self.config.set("Settings", "dhcp_client", client, True) + self.config.set("Settings", "dhcp_client", client, write=True) @dbus.service.method('org.wicd.daemon') def GetLinkDetectionTool(self): @@ -609,7 +610,7 @@ class WicdDaemon(dbus.service.Object): """ self.link_detect_tool = int(link_tool) self.wired.link_tool = int(link_tool) - self.config.set("Settings", "link_detect_tool", link_tool, True) + self.config.set("Settings", "link_detect_tool", link_tool, write=True) @dbus.service.method('org.wicd.daemon') def GetFlushTool(self): @@ -628,7 +629,7 @@ class WicdDaemon(dbus.service.Object): self.flush_tool = int(flush_tool) self.wired.flush_tool = int(flush_tool) self.wifi.flush_tool = int(flush_tool) - self.config.set("Settings", "flush_tool", flush_tool, True) + self.config.set("Settings", "flush_tool", flush_tool, write=True) @dbus.service.method('org.wicd.daemon') def WriteWindowSize(self, width, height, win_name): @@ -1018,6 +1019,7 @@ class WirelessDaemon(dbus.service.Object): """ Disconnects the wireless network. """ self.SetForcedDisconnect(True) self.wifi.Disconnect() + self.daemon.UpdateState() @dbus.service.method('org.wicd.daemon.wireless') def GetForcedDisconnect(self): @@ -1100,6 +1102,7 @@ class WirelessDaemon(dbus.service.Object): 'disconnectscript') print 'Connecting to wireless network ' + self.LastScan[id]['essid'] conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) + self.daemon.UpdateState() @dbus.service.method('org.wicd.daemon.wireless') def CheckIfWirelessConnecting(self): @@ -1354,6 +1357,7 @@ class WiredDaemon(dbus.service.Object): """ Disconnects the wired network. """ self.SetForcedDisconnect(True) self.wired.Disconnect() + self.daemon.UpdateState() @dbus.service.method('org.wicd.daemon.wired') def CheckPluggedIn(self): @@ -1402,6 +1406,7 @@ class WiredDaemon(dbus.service.Object): self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") self.wired.Connect(self.WiredNetwork, debug=self.debug_mode) + self.daemon.UpdateState() @dbus.service.method('org.wicd.daemon.wired') def CreateWiredNetworkProfile(self, profilename, default=False): @@ -1474,6 +1479,7 @@ class WiredDaemon(dbus.service.Object): self.config.set(prof, script, None) if profilename == "": + self.config.write() return "500: Bad Profile name" profilename = misc.to_unicode(profilename) self.config.remove_section(profilename)