From 8a0a47176467392c99fadbc3e6705fbf5cbebba0 Mon Sep 17 00:00:00 2001 From: imdano <> Date: Wed, 19 Dec 2007 22:35:07 +0000 Subject: [PATCH] Fixed cancelling a connection not working. Stopped the gui status bar from updating while the gui is closed, which reduces CPU usage and should hopefully fix problems with hibernation not working while wicd was running. --- daemon.py | 2 +- gui.py | 3 +++ networking.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/daemon.py b/daemon.py index 57df5d9..2da17e2 100644 --- a/daemon.py +++ b/daemon.py @@ -679,7 +679,7 @@ class ConnectionWizard(dbus.service.Object): ''' Cancels the wireless connection attempt ''' print 'canceling connection attempt' if not self.wifi.connecting_thread == None: - self.wifi.connecting_thread.ShouldDie = True + self.wifi.connecting_thread.should_die = True misc.Run("killall dhclient dhclient3 wpa_supplicant") #end function CancelConnect diff --git a/gui.py b/gui.py index 4059334..a87cda2 100644 --- a/gui.py +++ b/gui.py @@ -191,6 +191,7 @@ language['setting_broadcast_address'] = _('Setting broadcast address...') language['setting_static_dns'] = _('Setting static DNS servers...') language['setting_static_ip'] = _('Setting static IP addresses...') language['running_dhcp'] = _('Obtaining IP address...') +language['aborted'] = _('Connection cancelled') language['done'] = _('Done connecting...') ######################################## @@ -1168,6 +1169,8 @@ class appGui: def update_statusbar(self): #should update the status bar #every couple hundred milliseconds + if self.is_visible == False: + return True wireless_ip = wireless.GetWirelessIP() #do this so that it doesn't lock up. don't know how or why this works #but it does so we leave it alone :) wiredConnecting = wired.CheckIfWiredConnecting() diff --git a/networking.py b/networking.py index 0655285..36b3ed8 100644 --- a/networking.py +++ b/networking.py @@ -139,6 +139,17 @@ class ConnectThread(threading.Thread): self.lock.release() return message + def connect_aborted(self, reason): + """ Sets the thread status to aborted in a thread-safe way. + + Sets the status to aborted, and also delays returning for + a few seconds to make sure the message is readable + + """ + self.SetStatus(reason) + self.is_connecting = False + print 'exiting connection thread' + class Wireless(Controller): @@ -378,10 +389,18 @@ class WirelessConnectThread(ConnectThread): self.is_connecting = True + if self.should_die: + self.connect_aborted('aborted') + return + # Execute pre-connection script if necessary if self.before_script != '' and self.before_script != None: print 'Executing pre-connection script' - print misc.ExecuteScript(self.before_script) + misc.ExecuteScript(self.before_script) + + if self.should_die: + self.connect_aborted('aborted') + return # Put it down print 'Interface down' @@ -400,6 +419,11 @@ class WirelessConnectThread(ConnectThread): wiface.StopWPA() liface.StopDHCP() + if self.should_die: + wiface.Up() + self.connect_aborted('aborted') + return + # Check to see if we need to generate a PSK (only for non-ralink # cards). if self.wpa_driver != 'ralink legacy': @@ -418,6 +442,11 @@ class WirelessConnectThread(ConnectThread): print 'Attempting to authenticate...' wiface.Authenticate(self.network) + if self.should_die: + wiface.Up() + self.connect_aborted('aborted') + return + self.SetStatus('flushing_routing_table') print 'Flushing the routing table...' wiface.FlushRoutes() @@ -431,6 +460,10 @@ class WirelessConnectThread(ConnectThread): self.SetStatus('interface_up') wiface.Up() + if self.should_die: + self.connect_aborted('aborted') + return + wiface.SetMode(self.network['mode']) wiface.Associate(self.network['essid'], self.network['channel'], self.network['bssid']) @@ -446,6 +479,10 @@ class WirelessConnectThread(ConnectThread): print 'Setting the broadcast address...' + self.network['broadcast'] wiface.SetAddress(broadcast=self.network['broadcast']) + if self.should_die: + self.connect_aborted('aborted') + return + if not self.network.get('ip') == None: self.SetStatus('setting_static_ip') print 'Setting static IP : ' + self.network['ip'] @@ -470,11 +507,9 @@ class WirelessConnectThread(ConnectThread): wnettools.SetDNS(self.network.get('dns1'), self.network.get('dns2'), self.network.get('dns3')) - # Save as last used profile - print 'Saving last used profile' - config.UnsetLastUsedDefault() # Makes sure there is only one last used profile at a time - self.network.SetWiredProperty("lastused", True) - config.SaveWiredNetworkProfile(self.profilename) + if self.should_die: + self.connect_aborted('aborted') + return # Execute post-connection script if necessary if misc.Noneify(self.after_script): @@ -594,11 +629,19 @@ class WiredConnectThread(ConnectThread): self.is_connecting = True + if self.should_die: + self.connect_aborted('aborted') + return + # Execute pre-connection script if necessary if self.before_script != '' and self.before_script != None: print 'executing pre-connection script' misc.ExecuteScript(self.before_script) + if self.should_die: + self.connect_aborted('aborted') + return + # Put it down print 'Interface down' self.SetStatus('interface_down') @@ -616,6 +659,11 @@ class WiredConnectThread(ConnectThread): wiface.StopWPA() liface.StopDHCP() + if self.should_die: + liface.Up() + self.connect_aborted('aborted') + return + self.SetStatus('flushing_routing_table') print 'Flushing the routing table...' wiface.FlushRoutes() @@ -626,11 +674,19 @@ class WiredConnectThread(ConnectThread): self.SetStatus('interface_up') liface.Up() + if self.should_die: + self.connect_aborted('aborted') + return + if not self.network.get('broadcast') == None: self.SetStatus('setting_broadcast_address') print 'Setting the broadcast address...' + self.network['broadcast'] liface.SetAddress(broadcast=self.network['broadcast']) + if self.should_die: + self.connect_aborted('aborted') + return + if self.network.get('ip'): self.SetStatus('setting_static_ip') print 'Setting static IP : ' + self.network['ip'] @@ -655,6 +711,10 @@ class WiredConnectThread(ConnectThread): wnettools.SetDNS(self.network.get('dns1'), self.network.get('dns2'), self.network.get('dns3')) + if self.should_die: + self.connect_aborted('aborted') + return + # Execute post-connection script if necessary if misc.Noneify(self.after_script): print 'executing post connection script'