1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-21 13:28:08 +01:00

Refactored a few daemon methods from bring registered under the 'wireless' service to 'daemon'.

Fixed the wired autoconnect profile chooser, which was badly broken.
Added a check to GetPluggedIn() that makes sure that the wired interface is up before checking.  If it's not, it tries to put it up.  This is necessary because ethtool doesn't make this check for us, as mii-tool did.
This commit is contained in:
imdano
2008-01-22 16:05:30 +00:00
parent c83f18fd65
commit 9bd9605411
5 changed files with 69 additions and 52 deletions

View File

@@ -349,10 +349,11 @@ class ConnectionWizard(dbus.service.Object):
if fresh: if fresh:
self.Scan() self.Scan()
#self.AutoConnectScan() # Also scans for hidden networks #self.AutoConnectScan() # Also scans for hidden networks
if self.CheckPluggedIn() == True: if self.CheckPluggedIn():
if self.GetWiredAutoConnectMethod() == 2: if self.GetWiredAutoConnectMethod() == 2 and \
not self.GetNeedWiredProfileChooser():
self.LaunchChooser() self.LaunchChooser()
else: elif not self.GetWiredAutoConnectMethod != 2:
defaultNetwork = self.GetDefaultWiredNetwork() defaultNetwork = self.GetDefaultWiredNetwork()
if defaultNetwork != None: if defaultNetwork != None:
self.ReadWiredNetworkProfile(defaultNetwork) self.ReadWiredNetworkProfile(defaultNetwork)
@@ -385,7 +386,7 @@ class ConnectionWizard(dbus.service.Object):
return self.__printReturn('returning automatically reconnect when connection drops',do) return self.__printReturn('returning automatically reconnect when connection drops',do)
#end function GetAutoReconnect #end function GetAutoReconnect
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon')
def SetAutoReconnect(self, value): def SetAutoReconnect(self, value):
'''sets if wicd should try to reconnect with connection drops''' '''sets if wicd should try to reconnect with connection drops'''
print 'setting automatically reconnect when connection drops' print 'setting automatically reconnect when connection drops'
@@ -414,6 +415,16 @@ class ConnectionWizard(dbus.service.Object):
return True return True
#end function CheckIfConnecting #end function CheckIfConnecting
@dbus.service.method('org.wicd.daemon')
def CancelConnect(self):
''' Cancels the wireless connection attempt '''
print 'canceling connection attempt'
if self.wifi.connecting_thread:
self.wifi.connecting_thread.should_die = True
if self.wired.connecting_thread:
self.wired.connecting_thread.should_die = True
misc.Run("killall dhclient dhclient3 wpa_supplicant")
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetCurrentInterface(self): def GetCurrentInterface(self):
""" Returns the active interface """ """ Returns the active interface """
@@ -437,6 +448,24 @@ class ConnectionWizard(dbus.service.Object):
self.need_profile_chooser = misc.to_bool(val) self.need_profile_chooser = misc.to_bool(val)
#end function SetNeedWiredProfileChooser #end function SetNeedWiredProfileChooser
@dbus.service.method('org.wicd.daemon')
def GetForcedDisconnect(self):
''' Returns whether connection was dropped by user, or for some other reason '''
return bool(self.forced_disconnect)
#end function GetForcedDisconnect
@dbus.service.method('org.wicd.daemon')
def SetForcedDisconnect(self,value):
'''
Set to True when a user manually disconnects or cancels a connection.
It gets set to False as soon as the connection process is manually
started.
'''
self.forced_disconnect = bool(value)
#end function SetForcedDisconnect
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetGUIOpen(self): def GetGUIOpen(self):
"""Returns the value of gui_open """Returns the value of gui_open
@@ -466,7 +495,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='') @dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
def LaunchChooser(self): def LaunchChooser(self):
print 'calling wired profile chooser' print 'calling wired profile chooser'
daemon.SetNeedWiredProfileChooser(True) self.SetNeedWiredProfileChooser(True)
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='') @dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
def StatusChanged(self): def StatusChanged(self):
@@ -652,24 +681,6 @@ class ConnectionWizard(dbus.service.Object):
return self.wifi.Connect(self.LastScan[id]) return self.wifi.Connect(self.LastScan[id])
#end function Connect #end function Connect
@dbus.service.method('org.wicd.daemon.wireless')
def GetForcedDisconnect(self):
''' Returns whether wireless was dropped by user, or for some other reason '''
return bool(self.forced_disconnect)
#end function GetForcedDisconnect
@dbus.service.method('org.wicd.daemon.wireless')
def SetForcedDisconnect(self,value):
'''
Set to True when a user manually disconnects or cancels a connection.
It gets set to False as soon as the connection process is manually
started.
'''
self.forced_disconnect = bool(value)
#end function SetForcedDisconnect
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def CheckIfWirelessConnecting(self): def CheckIfWirelessConnecting(self):
''' Returns True if wireless interface is connecting, otherwise False''' ''' Returns True if wireless interface is connecting, otherwise False'''
@@ -705,15 +716,6 @@ class ConnectionWizard(dbus.service.Object):
return False return False
#end function CheckWirelessConnectingMessage #end function CheckWirelessConnectingMessage
@dbus.service.method('org.wicd.daemon.wireless')
def CancelConnect(self):
''' Cancels the wireless connection attempt '''
print 'canceling connection attempt'
if not self.wifi.connecting_thread == None:
self.wifi.connecting_thread.should_die = True
misc.Run("killall dhclient dhclient3 wpa_supplicant")
#end function CancelConnect
########## WIRED FUNCTIONS ########## WIRED FUNCTIONS
################################# #################################
@@ -817,7 +819,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CheckPluggedIn(self): def CheckPluggedIn(self):
if not self.wired.wired_interface == None and self.wired.wired_interface != "None": if self.wired.wired_interface and self.wired.wired_interface != "None":
return self.__printReturn('returning plugged in',self.wired.CheckPluggedIn()) return self.__printReturn('returning plugged in',self.wired.CheckPluggedIn())
else: else:
return self.__printReturn("returning plugged in",None) return self.__printReturn("returning plugged in",None)

22
gui.py
View File

@@ -595,7 +595,7 @@ class WiredNetworkEntry(NetworkEntry):
if self.profileList: # Make sure there is something in it... if self.profileList: # Make sure there is something in it...
for x in config.GetWiredProfileList(): # Add all the names to the combobox for x in config.GetWiredProfileList(): # Add all the names to the combobox
self.comboProfileNames.append_text(x) self.comboProfileNames.append_text(x)
hboxTemp = gtk.HBox(False,0) self.hboxTemp = gtk.HBox(False,0)
hboxDef = gtk.HBox(False,0) hboxDef = gtk.HBox(False,0)
buttonAdd = gtk.Button(stock=gtk.STOCK_ADD) buttonAdd = gtk.Button(stock=gtk.STOCK_ADD)
buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE) buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE)
@@ -606,9 +606,9 @@ class WiredNetworkEntry(NetworkEntry):
self.profileHelp.set_line_wrap(True) self.profileHelp.set_line_wrap(True)
self.vboxTop.pack_start(self.profileHelp,fill=True,expand=True) self.vboxTop.pack_start(self.profileHelp,fill=True,expand=True)
hboxTemp.pack_start(self.comboProfileNames, fill=True, expand=True) self.hboxTemp.pack_start(self.comboProfileNames, fill=True, expand=True)
hboxTemp.pack_start(buttonAdd, fill=False, expand=False) self.hboxTemp.pack_start(buttonAdd, fill=False, expand=False)
hboxTemp.pack_start(buttonDelete, fill=False, expand=False) self.hboxTemp.pack_start(buttonDelete, fill=False, expand=False)
hboxDef.pack_start(self.checkboxDefaultProfile,fill=False,expand=False) hboxDef.pack_start(self.checkboxDefaultProfile,fill=False,expand=False)
buttonAdd.connect("clicked", self.addProfile) buttonAdd.connect("clicked", self.addProfile)
@@ -616,7 +616,7 @@ class WiredNetworkEntry(NetworkEntry):
self.comboProfileNames.connect("changed",self.changeProfile) self.comboProfileNames.connect("changed",self.changeProfile)
self.scriptButton.connect("button-press-event", self.editScripts) self.scriptButton.connect("button-press-event", self.editScripts)
self.vboxTop.pack_start(hboxDef) self.vboxTop.pack_start(hboxDef)
self.vboxTop.pack_start(hboxTemp) self.vboxTop.pack_start(self.hboxTemp)
if stringToBoolean(wired.GetWiredProperty("default")): if stringToBoolean(wired.GetWiredProperty("default")):
self.checkboxDefaultProfile.set_active(True) self.checkboxDefaultProfile.set_active(True)
@@ -844,7 +844,8 @@ class WirelessNetworkEntry(NetworkEntry):
#data #data
self.encryptionInfo[methods[ID][2][x][1]] = box.entry self.encryptionInfo[methods[ID][2][x][1]] = box.entry
box.entry.set_text(noneToBlankString(wireless.GetWirelessProperty(self.networkID,methods[ID][2][x][1]))) box.entry.set_text(noneToBlankString(
wireless.GetWirelessProperty(self.networkID,methods[ID][2][x][1])))
self.vboxEncryptionInformation.show_all() self.vboxEncryptionInformation.show_all()
def setSignalStrength(self,strength, dbm_strength): def setSignalStrength(self,strength, dbm_strength):
@@ -879,7 +880,7 @@ class WiredProfileChooser:
# Import and init WiredNetworkEntry to steal some of the # Import and init WiredNetworkEntry to steal some of the
# functions and widgets it uses. # functions and widgets it uses.
wiredNetEntry = WiredNetworkEntry() wiredNetEntry = WiredNetworkEntry()
wiredNetEntry.__init__() #wiredNetEntry.__init__()
dialog = gtk.Dialog(title = language['wired_network_found'], dialog = gtk.Dialog(title = language['wired_network_found'],
flags = gtk.DIALOG_MODAL, flags = gtk.DIALOG_MODAL,
@@ -921,8 +922,7 @@ class WiredProfileChooser:
wired.ConnectWired() wired.ConnectWired()
else: else:
if stoppopcheckbox.get_active() == True: if stoppopcheckbox.get_active() == True:
# Stops the pop-up from reappearing if cancelled daemon.SetForcedDisconnect(True)
wired.use_default_profile = 1
dialog.destroy() dialog.destroy()
@@ -1191,9 +1191,9 @@ class appGui:
#is one in progress #is one in progress
cancelButton = self.wTree.get_widget("cancel_button") cancelButton = self.wTree.get_widget("cancel_button")
cancelButton.set_sensitive(False) cancelButton.set_sensitive(False)
wireless.CancelConnect() daemon.CancelConnect()
# Prevents automatic reconnecting if that option is enabled # Prevents automatic reconnecting if that option is enabled
wireless.SetForcedDisconnect(True) daemon.SetForcedDisconnect(True)
def pulse_progress_bar(self): def pulse_progress_bar(self):
try: try:

View File

@@ -346,6 +346,7 @@ class Wireless(Controller):
wiface.SetAddress('0.0.0.0') wiface.SetAddress('0.0.0.0')
wiface.Down() wiface.Down()
wiface.Up()
class WirelessConnectThread(ConnectThread): class WirelessConnectThread(ConnectThread):
""" A thread class to perform the connection to a wireless network. """ A thread class to perform the connection to a wireless network.
@@ -604,6 +605,7 @@ class Wired(Controller):
liface.SetAddress('0.0.0.0') liface.SetAddress('0.0.0.0')
liface.Down() liface.Down()
liface.Up()
class WiredConnectThread(ConnectThread): class WiredConnectThread(ConnectThread):

View File

@@ -135,8 +135,8 @@ class TrayIcon():
def wired_profile_chooser(self): def wired_profile_chooser(self):
"""Launch the wired profile chooser.""" """Launch the wired profile chooser."""
daemon.SetNeedWiredProfileChooser(False)
gui.WiredProfileChooser() gui.WiredProfileChooser()
daemon.SetNeedWiredProfileChooser(False)
def update_tray_icon(self): def update_tray_icon(self):
"""Updates the tray icon and current connection status""" """Updates the tray icon and current connection status"""
@@ -364,7 +364,7 @@ class TrayIcon():
gtk.StatusIcon.__init__(self) gtk.StatusIcon.__init__(self)
self.current_icon_path = '' self.current_icon_path = ''
wireless.SetForcedDisconnect(False) daemon.SetForcedDisconnect(False)
self.set_visible(True) self.set_visible(True)
self.connect('activate', self.on_activate) self.connect('activate', self.on_activate)
self.connect('popup-menu', self.on_popup_menu) self.connect('popup-menu', self.on_popup_menu)

View File

@@ -262,6 +262,10 @@ class WiredInterface(Interface):
""" """
link_tool = 'ethtool' link_tool = 'ethtool'
if not self.IsUp():
print 'Wired Interface is down, putting it up'
self.Up()
time.sleep(6)
tool_data = misc.Run(link_tool + ' ' + self.iface, True) tool_data = misc.Run(link_tool + ' ' + self.iface, True)
if misc.RunRegex(re.compile('(Operation not supported)|\ if misc.RunRegex(re.compile('(Operation not supported)|\
(ethtool: command not found)', re.I), (ethtool: command not found)', re.I),
@@ -269,17 +273,26 @@ class WiredInterface(Interface):
print "ethtool check failed, falling back to mii-tool" print "ethtool check failed, falling back to mii-tool"
link_tool = 'mii-tool' link_tool = 'mii-tool'
if misc.RunRegex(re.compile('(Invalid argument)', re.I | re.M | re.S), tool_data = misc.Run(link_tool + ' ' + self.iface, True)
tool_data) is not None:
print 'wired interface appears down, putting up for mii-tool check'
self.Up()
tool_data = misc.Run(link_tool + ' ' + self.iface)
if misc.RunRegex(re.compile('(Link detected: yes)|(link ok)', if misc.RunRegex(re.compile('(Link detected: yes)|(link ok)',
re.I | re.M | re.S), tool_data) is not None: re.I | re.M | re.S), tool_data) is not None:
return True return True
else: else:
return False return False
def IsUp(self):
""" Determines if the interface is up. """
cmd = "ifconfig " + self.iface
output = misc.Run(cmd)
lines = output.split('\n')
if len(lines) < 5:
return False
for line in lines[1:4]:
if line.strip().startswith('UP'):
return True
return False
class WirelessInterface(Interface): class WirelessInterface(Interface):