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:
68
daemon.py
68
daemon.py
@@ -349,10 +349,11 @@ class ConnectionWizard(dbus.service.Object):
|
||||
if fresh:
|
||||
self.Scan()
|
||||
#self.AutoConnectScan() # Also scans for hidden networks
|
||||
if self.CheckPluggedIn() == True:
|
||||
if self.GetWiredAutoConnectMethod() == 2:
|
||||
if self.CheckPluggedIn():
|
||||
if self.GetWiredAutoConnectMethod() == 2 and \
|
||||
not self.GetNeedWiredProfileChooser():
|
||||
self.LaunchChooser()
|
||||
else:
|
||||
elif not self.GetWiredAutoConnectMethod != 2:
|
||||
defaultNetwork = self.GetDefaultWiredNetwork()
|
||||
if defaultNetwork != None:
|
||||
self.ReadWiredNetworkProfile(defaultNetwork)
|
||||
@@ -385,7 +386,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
return self.__printReturn('returning automatically reconnect when connection drops',do)
|
||||
#end function GetAutoReconnect
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetAutoReconnect(self, value):
|
||||
'''sets if wicd should try to reconnect with connection drops'''
|
||||
print 'setting automatically reconnect when connection drops'
|
||||
@@ -414,6 +415,16 @@ class ConnectionWizard(dbus.service.Object):
|
||||
return True
|
||||
#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')
|
||||
def GetCurrentInterface(self):
|
||||
""" Returns the active interface """
|
||||
@@ -437,6 +448,24 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.need_profile_chooser = misc.to_bool(val)
|
||||
#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')
|
||||
def GetGUIOpen(self):
|
||||
"""Returns the value of gui_open
|
||||
@@ -466,7 +495,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
||||
def LaunchChooser(self):
|
||||
print 'calling wired profile chooser'
|
||||
daemon.SetNeedWiredProfileChooser(True)
|
||||
self.SetNeedWiredProfileChooser(True)
|
||||
|
||||
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
||||
def StatusChanged(self):
|
||||
@@ -652,24 +681,6 @@ class ConnectionWizard(dbus.service.Object):
|
||||
return self.wifi.Connect(self.LastScan[id])
|
||||
#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')
|
||||
def CheckIfWirelessConnecting(self):
|
||||
''' Returns True if wireless interface is connecting, otherwise False'''
|
||||
@@ -705,15 +716,6 @@ class ConnectionWizard(dbus.service.Object):
|
||||
return False
|
||||
#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
|
||||
#################################
|
||||
|
||||
@@ -817,7 +819,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
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())
|
||||
else:
|
||||
return self.__printReturn("returning plugged in",None)
|
||||
|
||||
22
gui.py
22
gui.py
@@ -595,7 +595,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
if self.profileList: # Make sure there is something in it...
|
||||
for x in config.GetWiredProfileList(): # Add all the names to the combobox
|
||||
self.comboProfileNames.append_text(x)
|
||||
hboxTemp = gtk.HBox(False,0)
|
||||
self.hboxTemp = gtk.HBox(False,0)
|
||||
hboxDef = gtk.HBox(False,0)
|
||||
buttonAdd = gtk.Button(stock=gtk.STOCK_ADD)
|
||||
buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE)
|
||||
@@ -606,9 +606,9 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.profileHelp.set_line_wrap(True)
|
||||
|
||||
self.vboxTop.pack_start(self.profileHelp,fill=True,expand=True)
|
||||
hboxTemp.pack_start(self.comboProfileNames, fill=True, expand=True)
|
||||
hboxTemp.pack_start(buttonAdd, fill=False, expand=False)
|
||||
hboxTemp.pack_start(buttonDelete, fill=False, expand=False)
|
||||
self.hboxTemp.pack_start(self.comboProfileNames, fill=True, expand=True)
|
||||
self.hboxTemp.pack_start(buttonAdd, fill=False, expand=False)
|
||||
self.hboxTemp.pack_start(buttonDelete, fill=False, expand=False)
|
||||
hboxDef.pack_start(self.checkboxDefaultProfile,fill=False,expand=False)
|
||||
|
||||
buttonAdd.connect("clicked", self.addProfile)
|
||||
@@ -616,7 +616,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.comboProfileNames.connect("changed",self.changeProfile)
|
||||
self.scriptButton.connect("button-press-event", self.editScripts)
|
||||
self.vboxTop.pack_start(hboxDef)
|
||||
self.vboxTop.pack_start(hboxTemp)
|
||||
self.vboxTop.pack_start(self.hboxTemp)
|
||||
|
||||
if stringToBoolean(wired.GetWiredProperty("default")):
|
||||
self.checkboxDefaultProfile.set_active(True)
|
||||
@@ -844,7 +844,8 @@ class WirelessNetworkEntry(NetworkEntry):
|
||||
#data
|
||||
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()
|
||||
|
||||
def setSignalStrength(self,strength, dbm_strength):
|
||||
@@ -879,7 +880,7 @@ class WiredProfileChooser:
|
||||
# Import and init WiredNetworkEntry to steal some of the
|
||||
# functions and widgets it uses.
|
||||
wiredNetEntry = WiredNetworkEntry()
|
||||
wiredNetEntry.__init__()
|
||||
#wiredNetEntry.__init__()
|
||||
|
||||
dialog = gtk.Dialog(title = language['wired_network_found'],
|
||||
flags = gtk.DIALOG_MODAL,
|
||||
@@ -921,8 +922,7 @@ class WiredProfileChooser:
|
||||
wired.ConnectWired()
|
||||
else:
|
||||
if stoppopcheckbox.get_active() == True:
|
||||
# Stops the pop-up from reappearing if cancelled
|
||||
wired.use_default_profile = 1
|
||||
daemon.SetForcedDisconnect(True)
|
||||
dialog.destroy()
|
||||
|
||||
|
||||
@@ -1191,9 +1191,9 @@ class appGui:
|
||||
#is one in progress
|
||||
cancelButton = self.wTree.get_widget("cancel_button")
|
||||
cancelButton.set_sensitive(False)
|
||||
wireless.CancelConnect()
|
||||
daemon.CancelConnect()
|
||||
# Prevents automatic reconnecting if that option is enabled
|
||||
wireless.SetForcedDisconnect(True)
|
||||
daemon.SetForcedDisconnect(True)
|
||||
|
||||
def pulse_progress_bar(self):
|
||||
try:
|
||||
|
||||
@@ -346,6 +346,7 @@ class Wireless(Controller):
|
||||
|
||||
wiface.SetAddress('0.0.0.0')
|
||||
wiface.Down()
|
||||
wiface.Up()
|
||||
|
||||
class WirelessConnectThread(ConnectThread):
|
||||
""" 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.Down()
|
||||
liface.Up()
|
||||
|
||||
|
||||
class WiredConnectThread(ConnectThread):
|
||||
|
||||
4
wicd.py
4
wicd.py
@@ -135,8 +135,8 @@ class TrayIcon():
|
||||
|
||||
def wired_profile_chooser(self):
|
||||
"""Launch the wired profile chooser."""
|
||||
daemon.SetNeedWiredProfileChooser(False)
|
||||
gui.WiredProfileChooser()
|
||||
daemon.SetNeedWiredProfileChooser(False)
|
||||
|
||||
def update_tray_icon(self):
|
||||
"""Updates the tray icon and current connection status"""
|
||||
@@ -364,7 +364,7 @@ class TrayIcon():
|
||||
gtk.StatusIcon.__init__(self)
|
||||
|
||||
self.current_icon_path = ''
|
||||
wireless.SetForcedDisconnect(False)
|
||||
daemon.SetForcedDisconnect(False)
|
||||
self.set_visible(True)
|
||||
self.connect('activate', self.on_activate)
|
||||
self.connect('popup-menu', self.on_popup_menu)
|
||||
|
||||
25
wnettools.py
25
wnettools.py
@@ -262,6 +262,10 @@ class WiredInterface(Interface):
|
||||
|
||||
"""
|
||||
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)
|
||||
if misc.RunRegex(re.compile('(Operation not supported)|\
|
||||
(ethtool: command not found)', re.I),
|
||||
@@ -269,18 +273,27 @@ class WiredInterface(Interface):
|
||||
print "ethtool check failed, falling back to mii-tool"
|
||||
link_tool = 'mii-tool'
|
||||
|
||||
if misc.RunRegex(re.compile('(Invalid argument)', re.I | re.M | re.S),
|
||||
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)
|
||||
tool_data = misc.Run(link_tool + ' ' + self.iface, True)
|
||||
if misc.RunRegex(re.compile('(Link detected: yes)|(link ok)',
|
||||
re.I | re.M | re.S), tool_data) is not None:
|
||||
return True
|
||||
else:
|
||||
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):
|
||||
""" Control a wireless network interface. """
|
||||
|
||||
Reference in New Issue
Block a user