1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-20 04:48:00 +01:00

Fixed a bug that prevented unsetting the "automatically connect to this network" option.

Some formatting/docstring cleanups.
This commit is contained in:
imdano
2008-02-11 14:55:29 +00:00
parent 98069ad994
commit 44fa2ac718
6 changed files with 184 additions and 212 deletions

231
daemon.py
View File

@@ -129,7 +129,7 @@ class ConnectionWizard(dbus.service.Object):
################################# #################################
def __init__(self, bus_name, object_path='/org/wicd/daemon', def __init__(self, bus_name, object_path='/org/wicd/daemon',
auto_connect=True): auto_connect=True):
dbus.service.Object.__init__(self, bus_name, object_path) dbus.service.Object.__init__(self, bus_name, object_path)
self.app_conf = wpath.etc + 'manager-settings.conf' self.app_conf = wpath.etc + 'manager-settings.conf'
@@ -170,23 +170,21 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def Hello(self): def Hello(self):
''' Returns the version number ''' """ Returns the version number.
#returns a version number.
#this number is major-minor-micro This number is major-minor-micro. Major is only incremented if minor
#major is only incremented if minor reaches > 9. Minor is incremented if changes that break core stucture
#reaches > 9 are implemented. Micro is for everything else, and micro may be
#minor is incremented if changes anything >= 0. This number is effective starting wicd v1.2.0
#that break core stucture are implemented
#micro is for everything else. """
#and micro may be anything >= 0
#this number is effective starting wicd v1.2.0
version = '1.5.0' version = '1.5.0'
print 'returned version number', version print 'returned version number', version
return version return version
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetWiredInterface(self, interface): def SetWiredInterface(self, interface):
''' Sets the wired interface for the daemon to use ''' """ Sets the wired interface for the daemon to use. """
print "setting wired interface", str(interface) print "setting wired interface", str(interface)
self.wired.wired_interface = interface self.wired.wired_interface = interface
self.wifi.wired_interface = interface self.wifi.wired_interface = interface
@@ -197,7 +195,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetWirelessInterface(self, interface): def SetWirelessInterface(self, interface):
''' Sets the wireless interface the daemon will use ''' """ Sets the wireless interface the daemon will use. """
print "setting wireless interface" , str(interface) print "setting wireless interface" , str(interface)
self.wifi.wireless_interface = interface self.wifi.wireless_interface = interface
self.wired.wireless_interface = interface self.wired.wireless_interface = interface
@@ -209,7 +207,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetWPADriver(self, driver): def SetWPADriver(self, driver):
''' Sets the wpa driver the wpa_supplicant will use ''' """ Sets the wpa driver the wpa_supplicant will use. """
print "setting wpa driver", str(driver) print "setting wpa driver", str(driver)
self.wifi.wpa_driver = driver self.wifi.wpa_driver = driver
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@@ -217,11 +215,10 @@ class ConnectionWizard(dbus.service.Object):
config.set("Settings","wpa_driver",driver) config.set("Settings","wpa_driver",driver)
configfile = open(self.app_conf, "w") configfile = open(self.app_conf, "w")
config.write(configfile) config.write(configfile)
#end function SetWPADriver
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetUseGlobalDNS(self, use): def SetUseGlobalDNS(self, use):
''' Sets a boolean which determines if global DNS is enabled ''' """ Sets a boolean which determines if global DNS is enabled. """
print 'setting use global dns to', use print 'setting use global dns to', use
use = misc.to_bool(use) use = misc.to_bool(use)
print 'setting use global dns to boolean', use print 'setting use global dns to boolean', use
@@ -236,7 +233,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetGlobalDNS(self, dns1=None, dns2=None, dns3=None): def SetGlobalDNS(self, dns1=None, dns2=None, dns3=None):
''' Sets the global dns addresses ''' """ Sets the global dns addresses. """
print "setting global dns" print "setting global dns"
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.app_conf) config.read(self.app_conf)
@@ -255,87 +252,77 @@ class ConnectionWizard(dbus.service.Object):
print 'global dns servers are', dns1, dns2, dns3 print 'global dns servers are', dns1, dns2, dns3
configfile = open(self.app_conf, "w") configfile = open(self.app_conf, "w")
config.write(configfile) config.write(configfile)
#end function SetWirelessInterface
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetUseGlobalDNS(self): def GetUseGlobalDNS(self):
''' Returns a boolean that determines if global dns is enabled ''' """ Returns a boolean that determines if global dns is enabled. """
return bool(self.use_global_dns) return bool(self.use_global_dns)
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetWPADriver(self): def GetWPADriver(self):
''' Returns the wpa driver the daemon is using ''' """ Returns the wpa driver the daemon is using. """
return str(self.wifi.wpa_driver) return str(self.wifi.wpa_driver)
#end function GetWPADriver
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetWiredInterface(self): def GetWiredInterface(self):
''' Returns the wired interface ''' """ Returns the wired interface. """
return str(self.wired.wired_interface) return str(self.wired.wired_interface)
#end function GetWiredInterface
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetWirelessInterface(self): def GetWirelessInterface(self):
''' Returns the wireless interface the daemon is using ''' """ Returns the wireless interface the daemon is using. """
return str(self.wifi.wireless_interface) return str(self.wifi.wireless_interface)
#end function GetWirelessInterface
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetDebugMode(self, debug): def SetDebugMode(self, debug):
''' Sets if debugging mode is on or off ''' """ Sets if debugging mode is on or off. """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.app_conf) config.read(self.app_conf)
config.set("Settings", "debug_mode", debug) config.set("Settings", "debug_mode", debug)
configfile = open(self.app_conf, "w") configfile = open(self.app_conf, "w")
config.write(configfile) config.write(configfile)
self.debug_mode = misc.to_bool(debug) self.debug_mode = misc.to_bool(debug)
#end function SetDebugMode
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetDebugMode(self): def GetDebugMode(self):
''' Returns whether debugging is enabled ''' """ Returns whether debugging is enabled. """
return bool(self.debug_mode) return bool(self.debug_mode)
#end function GetDebugMode
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def Disconnect(self): def Disconnect(self):
'''disconnects all networks''' """ Disconnects all networks. """
self.SetForcedDisconnect(True) self.SetForcedDisconnect(True)
self.wifi.Disconnect() self.wifi.Disconnect()
self.wired.Disconnect() self.wired.Disconnect()
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetSignalDisplayType(self): def GetSignalDisplayType(self):
''' Returns the signal display type """ Returns the signal display type.
Returns either 0 or 1. Returns either 0 or 1.
0 for signal strength as a percentage 0 for signal strength as a percentage
1 for signal strength measured in dBm 1 for signal strength measured in dBm
''' """
return int(self.signal_display_type) return int(self.signal_display_type)
# end function GetSignalDisplayType
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetSignalDisplayType(self, value): def SetSignalDisplayType(self, value):
''' Sets the signal display type and writes it the wicd config file ''' """ Sets the signal display type and writes it the wicd config file. """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.app_conf) config.read(self.app_conf)
config.set("Settings", "signal_display_type", value) config.set("Settings", "signal_display_type", value)
configfile = open(self.app_conf, "w") configfile = open(self.app_conf, "w")
config.write(configfile) config.write(configfile)
self.signal_display_type = int(value) self.signal_display_type = int(value)
# end function SetSignalDisplayType
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def FormatSignalForPrinting(self, signal): def FormatSignalForPrinting(self, signal):
''' Returns the suffix to display after the signal strength number ''' """ Returns the suffix to display after the signal strength number. """
if self.GetSignalDisplayType() == 1: if self.GetSignalDisplayType() == 1:
return (signal + " dBm") return (signal + " dBm")
else: else:
return (signal + "%") return (signal + "%")
# End function FormatSignalForPrinting
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetSuspend(self, val): def SetSuspend(self, val):
@@ -344,13 +331,20 @@ class ConnectionWizard(dbus.service.Object):
if self.suspended: if self.suspended:
self.Disconnect() self.Disconnect()
@dbus.service.method('org.wicd.daemon')
def StartVPNSession(self):
import vpn
self.vpn_session = vpn.PPTPConnection()
self.vpn_pid = None
@dbus.service. method('org.wicd.daemon') @dbus.service. method('org.wicd.daemon')
def AutoConnect(self, fresh): def AutoConnect(self, fresh):
''' Attempts to autoconnect to a wired or wireless network. """ Attempts to autoconnect to a wired or wireless network.
Autoconnect will first try to connect to a wired network, if that Autoconnect will first try to connect to a wired network, if that
fails it tries a wireless connection. ''' fails it tries a wireless connection.
"""
if fresh: if fresh:
self.Scan() self.Scan()
#self.AutoConnectScan() # Also scans for hidden networks #self.AutoConnectScan() # Also scans for hidden networks
@@ -382,48 +376,49 @@ class ConnectionWizard(dbus.service.Object):
print "Unable to autoconnect, you'll have to manually connect" print "Unable to autoconnect, you'll have to manually connect"
else: else:
print 'autoconnect failed because wireless interface returned None' print 'autoconnect failed because wireless interface returned None'
#end function AutoConnect
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetAutoReconnect(self): def GetAutoReconnect(self):
'''returns if wicd should automatically try to reconnect is connection is lost''' """ Returns the value of self.auto_reconnect. See SetAutoReconnect. """
do = bool(self.auto_reconnect) do = bool(self.auto_reconnect)
return self.__printReturn('returning automatically reconnect when\ return self.__printReturn('returning automatically reconnect when\
connection drops', do) connection drops', do)
#end function GetAutoReconnect
@dbus.service.method('org.wicd.daemon') @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 the value of self.auto_reconnect.
If True, wicd will try to reconnect as soon as it detects that
an internet connection is lost. If False, it will do nothing,
and wait for the user to initiate reconnection.
"""
print 'setting automatically reconnect when connection drops' print 'setting automatically reconnect when connection drops'
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.app_conf) config.read(self.app_conf)
config.set("Settings", "auto_reconnect", misc.to_bool(value)) config.set("Settings", "auto_reconnect", misc.to_bool(value))
config.write(open(self.app_conf, "w")) config.write(open(self.app_conf, "w"))
self.auto_reconnect = misc.to_bool(value) self.auto_reconnect = misc.to_bool(value)
#end function SetAutoReconnect
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetGlobalDNSAddresses(self): def GetGlobalDNSAddresses(self):
'''returns the global dns addresses''' """ Returns the global dns addresses. """
print 'returning global dns addresses to client' print 'returning global dns addresses to client'
return (misc.noneToString(self.dns1), misc.noneToString(self.dns2), return (misc.noneToString(self.dns1), misc.noneToString(self.dns2),
misc.noneToString(self.dns3)) misc.noneToString(self.dns3))
#end function GetWirelessInterface
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def CheckIfConnecting(self): def CheckIfConnecting(self):
'''returns if a network connection is being made''' """ Returns if a network connection is being made. """
if self.CheckIfWiredConnecting() == False and \ if self.CheckIfWiredConnecting() == False and \
self.CheckIfWirelessConnecting() == False: self.CheckIfWirelessConnecting() == False:
return False return False
else: else:
return True return True
#end function CheckIfConnecting
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def CancelConnect(self): def CancelConnect(self):
''' Cancels the wireless connection attempt ''' """ Cancels the wireless connection attempt """
print 'canceling connection attempt' print 'canceling connection attempt'
if self.wifi.connecting_thread: if self.wifi.connecting_thread:
self.wifi.connecting_thread.should_die = True self.wifi.connecting_thread.should_die = True
@@ -452,29 +447,27 @@ class ConnectionWizard(dbus.service.Object):
""" """
self.need_profile_chooser = misc.to_bool(val) self.need_profile_chooser = misc.to_bool(val)
#end function SetNeedWiredProfileChooser
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetForcedDisconnect(self): def GetForcedDisconnect(self):
''' Returns whether connection was dropped by user, or for some other reason ''' """ Returns the forced_disconnect status. See SetForcedDisconnect. """
return bool(self.forced_disconnect) return bool(self.forced_disconnect)
#end function GetForcedDisconnect
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetForcedDisconnect(self, value): def SetForcedDisconnect(self, value):
''' """ Sets the forced_disconnect status.
Set to True when a user manually disconnects or cancels a connection. 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 It gets set to False as soon as the connection process is manually
started. started.
''' """
self.forced_disconnect = bool(value) self.forced_disconnect = bool(value)
#end function SetForcedDisconnect #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.
Returns the vlaue of gui_open, which is a boolean that keeps track Returns the vlaue of gui_open, which is a boolean that keeps track
of the state of the wicd GUI. If the GUI is open, wicd will not of the state of the wicd GUI. If the GUI is open, wicd will not
@@ -485,6 +478,8 @@ class ConnectionWizard(dbus.service.Object):
the wicd.py is not exited properly while the GUI is open. We should the wicd.py is not exited properly while the GUI is open. We should
probably implement some kind of pid system to do it properly. probably implement some kind of pid system to do it properly.
ANOTHER NOTE: This isn't implemented yet!
""" """
return bool(self.gui_open) return bool(self.gui_open)
@@ -525,14 +520,13 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def GetNeedWiredProfileChooser(self): def GetNeedWiredProfileChooser(self):
""" Returns need_profile_chooser """ Returns need_profile_chooser.
Returns a boolean specifying if the wired profile chooser needs to Returns a boolean specifying if the wired profile chooser needs to
be launched. be launched.
""" """
return bool(self.need_profile_chooser) return bool(self.need_profile_chooser)
#end function GetNeedWiredProfileChooser
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='') @dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
def LaunchChooser(self): def LaunchChooser(self):
@@ -554,18 +548,18 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def SetHiddenNetworkESSID(self, essid): def SetHiddenNetworkESSID(self, essid):
''' Sets the ESSID of a hidden network for use with Scan(). ''' """ Sets the ESSID of a hidden network for use with Scan(). """
print 'setting hidden essid: ' + str(essid) print 'setting hidden essid: ' + str(essid)
self.hidden_essid = str(misc.Noneify(essid)) self.hidden_essid = str(misc.Noneify(essid))
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def Scan(self): def Scan(self):
''' Scan for wireless networks. """ Scan for wireless networks.
Scans for wireless networks,optionally using a (hidden) essid Scans for wireless networks,optionally using a (hidden) essid
set with SetHiddenNetworkESSID. set with SetHiddenNetworkESSID.
''' """
print 'scanning start' print 'scanning start'
scan = self.wifi.Scan(str(self.hidden_essid)) scan = self.wifi.Scan(str(self.hidden_essid))
self.LastScan = scan self.LastScan = scan
@@ -581,29 +575,28 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetNumberOfNetworks(self): def GetNumberOfNetworks(self):
'''returns number of networks''' """Returns number of networks. """
print 'returned number of networks...', len(self.LastScan) if self.debug_mode:
print 'returned number of networks...', len(self.LastScan)
return len(self.LastScan) return len(self.LastScan)
#end function GetNumberOfNetworks
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused, def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
ics): ics):
''' creates an ad-hoc network using user inputted settings ''' """ Creates an ad-hoc network using user inputted settings. """
print 'attempting to create ad-hoc network...' print 'attempting to create ad-hoc network...'
self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused, self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused,
ics) ics)
#end function CreateAdHocNetwork
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetKillSwitchEnabled(self): def GetKillSwitchEnabled(self):
''' returns true if kill switch is pressed. ''' """ Returns true if kill switch is pressed. """
status = self.wifi.GetKillSwitchStatus() status = self.wifi.GetKillSwitchStatus()
return status return status
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetWirelessProperty(self, networkid, property): def GetWirelessProperty(self, networkid, property):
''' Retrieves wireless property from the network specified ''' """ Retrieves wireless property from the network specified """
value = self.LastScan[networkid].get(property) value = self.LastScan[networkid].get(property)
try: try:
value = misc.to_unicode(value) value = misc.to_unicode(value)
@@ -614,29 +607,27 @@ class ConnectionWizard(dbus.service.Object):
#print ('returned wireless network', networkid, 'property', #print ('returned wireless network', networkid, 'property',
# property, 'of type', type(value)) # property, 'of type', type(value))
return value return value
#end function GetWirelessProperty
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def SetWirelessProperty(self, networkid, property, value): def SetWirelessProperty(self, networkid, property, value):
''' Sets property to value in network specified ''' """ Sets property to value in network specified. """
#simple - set the value of the item in our current data # We don't write script settings here.
#to the value the client asked for
if (property.strip()).endswith("script"): if (property.strip()).endswith("script"):
print "Setting script properties through the daemon is not \ print "Setting script properties through the daemon is not \
permitted." permitted."
return False return False
print 'setting wireless network', networkid, 'property', property, if self.debug_mode:
'to value', value print 'setting wireless network', networkid, 'property', property,
'to value', value
self.LastScan[networkid][property] = misc.Noneify(value) self.LastScan[networkid][property] = misc.Noneify(value)
#end function SetProperty #end function SetProperty
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def DetectWirelessInterface(self): def DetectWirelessInterface(self):
''' Returns an automatically detected wireless interface ''' """ Returns an automatically detected wireless interface. """
iface = self.wifi.DetectWirelessInterface() iface = self.wifi.DetectWirelessInterface()
print 'automatically detected wireless interface', iface print 'automatically detected wireless interface', iface
return str(iface) return str(iface)
#end function DetectWirelessInterface
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetPrintableSignalStrength(self, iwconfig=None): def GetPrintableSignalStrength(self, iwconfig=None):
@@ -655,17 +646,16 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentSignalStrength(self, iwconfig=None): def GetCurrentSignalStrength(self, iwconfig=None):
''' Returns the current signal strength ''' """ Returns the current signal strength. """
try: try:
strength = int(self.wifi.GetSignalStrength(iwconfig)) strength = int(self.wifi.GetSignalStrength(iwconfig))
except: except:
strength = 0 strength = 0
return strength return strength
#end function GetCurrentSignalStrength
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentDBMStrength(self, iwconfig=None): def GetCurrentDBMStrength(self, iwconfig=None):
''' Returns the current dbm signal strength ''' """ Returns the current dbm signal strength. """
try: try:
dbm_strength = int(self.wifi.GetDBMStrength(iwconfig)) dbm_strength = int(self.wifi.GetDBMStrength(iwconfig))
except: except:
@@ -674,25 +664,23 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentNetwork(self, iwconfig=None): def GetCurrentNetwork(self, iwconfig=None):
''' Returns the current network ''' """ Returns the current network. """
current_network = str(self.wifi.GetCurrentNetwork(iwconfig)) current_network = str(self.wifi.GetCurrentNetwork(iwconfig))
return current_network return current_network
#end function GetCurrentNetwork
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentNetworkID(self, iwconfig=None): def GetCurrentNetworkID(self, iwconfig=None):
'''returns the id of the current network, or -1 if network is not found''' """ Returns the id of the current network, or -1 if its not found. """
currentESSID = self.GetCurrentNetwork(iwconfig) currentESSID = self.GetCurrentNetwork(iwconfig)
for x in xrange(0, len(self.LastScan)): for x in xrange(0, len(self.LastScan)):
if self.LastScan[x]['essid'] == currentESSID: if self.LastScan[x]['essid'] == currentESSID:
return x return x
print 'returning -1, current network not found' print 'returning -1, current network not found'
return -1 return -1
#end function GetCurrentNetwork
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def ConnectWireless(self,id): def ConnectWireless(self, id):
'''connects the the wireless network specified by id''' """ Connects the the wireless network specified by i"""
# Will returned instantly, that way we don't hold up dbus. # Will returned instantly, that way we don't hold up dbus.
# CheckIfWirelessConnecting can be used to test if the connection # CheckIfWirelessConnecting can be used to test if the connection
# is done. # is done.
@@ -703,11 +691,10 @@ class ConnectionWizard(dbus.service.Object):
'disconnectscript') 'disconnectscript')
print 'connecting to wireless network', self.LastScan[id]['essid'] print 'connecting to wireless network', self.LastScan[id]['essid']
return self.wifi.Connect(self.LastScan[id]) return self.wifi.Connect(self.LastScan[id])
#end function Connect
@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."""
if not self.wifi.connecting_thread == None: if not self.wifi.connecting_thread == None:
# If connecting_thread exists, then check for it's # If connecting_thread exists, then check for it's
# status, if it doesn't, we aren't connecting. # status, if it doesn't, we aren't connecting.
@@ -719,42 +706,38 @@ class ConnectionWizard(dbus.service.Object):
if self.debug_mode == 1: if self.debug_mode == 1:
print 'wireless connecting', False print 'wireless connecting', False
return False return False
#end function CheckIfWirelessConnecting
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetWirelessIP(self): def GetWirelessIP(self):
''' Returns the IP that the wireless interface has ''' """ Returns the IP associated with the wireless interface. """
ip = self.wifi.GetIP() ip = self.wifi.GetIP()
if self.debug_mode == 1: if self.debug_mode == 1:
print 'returning wireless ip', ip print 'returning wireless ip', ip
return ip return ip
#end function GetWirelessIP
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def CheckWirelessConnectingMessage(self): def CheckWirelessConnectingMessage(self):
''' Returns the wireless interface's status message ''' """ Returns the wireless interface's status message. """
if not self.wifi.connecting_thread == None: if not self.wifi.connecting_thread == None:
stat = self.wifi.connecting_thread.GetStatus() stat = self.wifi.connecting_thread.GetStatus()
return stat return stat
else: else:
return False return False
#end function CheckWirelessConnectingMessage
########## WIRED FUNCTIONS ########## WIRED FUNCTIONS
################################# #################################
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetWiredIP(self): def GetWiredIP(self):
'''returns the wired interface\'s ip address''' """ Returns the wired interface's ip address. """
ip = self.wired.GetIP() ip = self.wired.GetIP()
if self.debug_mode == 1: if self.debug_mode == 1:
print 'returning wired ip', ip print 'returning wired ip', ip
return ip return ip
#end function GetWiredIP
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CheckIfWiredConnecting(self): def CheckIfWiredConnecting(self):
'''returns True if wired interface is connecting, otherwise False''' """ Returns True if wired interface is connecting, otherwise False. """
if not self.wired.connecting_thread == None: if not self.wired.connecting_thread == None:
#if connecting_thread exists, then check for it's #if connecting_thread exists, then check for it's
#status, if it doesn't exist, we aren't connecting #status, if it doesn't exist, we aren't connecting
@@ -766,11 +749,10 @@ class ConnectionWizard(dbus.service.Object):
if self.debug_mode == 1: if self.debug_mode == 1:
print 'wired connecting', False print 'wired connecting', False
return False return False
#end function CheckIfWiredConnecting
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def SetWiredAutoConnectMethod(self, method): def SetWiredAutoConnectMethod(self, method):
'''sets which method the user wants to autoconnect to wired networks''' """ Sets which method to use to autoconnect to wired networks. """
# 1 = default profile # 1 = default profile
# 2 = show list # 2 = show list
# 3 = last used profile # 3 = last used profile
@@ -783,19 +765,17 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetWiredAutoConnectMethod(self): def GetWiredAutoConnectMethod(self):
'''returns the wired autoconnect method''' """ Returns the wired autoconnect method. """
return int(self.wired_connect_mode) return int(self.wired_connect_mode)
#end function GetWiredAutoConnectMethod
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CheckWiredConnectingMessage(self): def CheckWiredConnectingMessage(self):
'''returns the wired interface\'s status message''' """ Returns the wired interface\'s status message. """
if not self.wired.connecting_thread == None: if not self.wired.connecting_thread == None:
status = self.wired.connecting_thread.GetStatus() status = self.wired.connecting_thread.GetStatus()
return status return status
else: else:
return False return False
#end function CheckWiredConnectingMessage
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def SetWiredProperty(self, property, value): def SetWiredProperty(self, property, value):
@@ -811,7 +791,6 @@ class ConnectionWizard(dbus.service.Object):
else: else:
print 'WiredNetwork does not exist' print 'WiredNetwork does not exist'
return False return False
#end function SetWiredProperty
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetWiredProperty(self, property): def GetWiredProperty(self, property):
@@ -824,7 +803,6 @@ class ConnectionWizard(dbus.service.Object):
else: else:
print 'WiredNetwork does not exist' print 'WiredNetwork does not exist'
return False return False
#end function GetWiredProperty
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def SetAlwaysShowWiredInterface(self, value): def SetAlwaysShowWiredInterface(self, value):
@@ -835,13 +813,11 @@ class ConnectionWizard(dbus.service.Object):
misc.to_bool(value)) misc.to_bool(value))
config.write(open(self.app_conf, "w")) config.write(open(self.app_conf, "w"))
self.always_show_wired_interface = misc.to_bool(value) self.always_show_wired_interface = misc.to_bool(value)
#end function SetAlwaysShowWiredInterface
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetAlwaysShowWiredInterface(self): def GetAlwaysShowWiredInterface(self):
do = bool(self.always_show_wired_interface) do = bool(self.always_show_wired_interface)
return self.__printReturn('returning always show wired interface', do) return self.__printReturn('returning always show wired interface', do)
#end function GetAlwaysShowWiredInterface
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CheckPluggedIn(self): def CheckPluggedIn(self):
@@ -850,11 +826,10 @@ class ConnectionWizard(dbus.service.Object):
self.wired.CheckPluggedIn()) self.wired.CheckPluggedIn())
else: else:
return self.__printReturn("returning plugged in", None) return self.__printReturn("returning plugged in", None)
#end function CheckPluggedIn
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def ConnectWired(self): def ConnectWired(self):
'''connects to a wired network''' """connects to a wired network. """
self.wired.before_script = self.GetWiredProperty("beforescript") self.wired.before_script = self.GetWiredProperty("beforescript")
self.wired.after_script = self.GetWiredProperty("afterscript") self.wired.after_script = self.GetWiredProperty("afterscript")
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript") self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
@@ -878,7 +853,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def CreateWiredNetworkProfile(self, profilename): def CreateWiredNetworkProfile(self, profilename):
''' Creates a wired network profile ''' """ Creates a wired network profile. """
#should include: profilename, ip, netmask, gateway, dns1, dns2, dns3 #should include: profilename, ip, netmask, gateway, dns1, dns2, dns3
profilename = profilename.encode('utf-8') profilename = profilename.encode('utf-8')
print "creating profile for " + profilename print "creating profile for " + profilename
@@ -900,11 +875,10 @@ class ConnectionWizard(dbus.service.Object):
config.set(profilename, "default", False) config.set(profilename, "default", False)
config.write(open(self.wired_conf, "w")) config.write(open(self.wired_conf, "w"))
return True return True
#end function CreateWiredNetworkProfile
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def UnsetWiredLastUsed(self): def UnsetWiredLastUsed(self):
'''Unsets the last used option in the current default wired profile''' """Unsets the last used option in the current default wired profile"""
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
profileList = config.sections() profileList = config.sections()
@@ -916,11 +890,10 @@ class ConnectionWizard(dbus.service.Object):
print "removing existing lastused" print "removing existing lastused"
config.set(profile, "lastused", False) config.set(profile, "lastused", False)
self.SaveWiredNetworkProfile(profile) self.SaveWiredNetworkProfile(profile)
#end function UnsetWiredLastUsed
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def UnsetWiredDefault(self): def UnsetWiredDefault(self):
'''Unsets the default option in the current default wired profile''' """Unsets the default option in the current default wired profile"""
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
profileList = config.sections() profileList = config.sections()
@@ -932,11 +905,10 @@ class ConnectionWizard(dbus.service.Object):
print "removing existing default" print "removing existing default"
config.set(profile, "default", False) config.set(profile, "default", False)
self.SaveWiredNetworkProfile(profile) self.SaveWiredNetworkProfile(profile)
#end function UnsetWiredDefault
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def GetDefaultWiredNetwork(self): def GetDefaultWiredNetwork(self):
''' Returns the current default wired network ''' """ Returns the current default wired network """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
profileList = config.sections() profileList = config.sections()
@@ -959,7 +931,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def DeleteWiredNetworkProfile(self, profilename): def DeleteWiredNetworkProfile(self, profilename):
''' Deletes a wired network profile ''' """ Deletes a wired network profile """
profilename = profilename.encode('utf-8') profilename = profilename.encode('utf-8')
print "deleting profile for " + str(profilename) print "deleting profile for " + str(profilename)
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@@ -970,11 +942,10 @@ class ConnectionWizard(dbus.service.Object):
return "500: Profile does not exist" return "500: Profile does not exist"
config.write(open(self.wired_conf, "w")) config.write(open(self.wired_conf, "w"))
return "100: Profile Deleted" return "100: Profile Deleted"
#end function DeleteWiredNetworkProfile
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def SaveWiredNetworkProfile(self, profilename): def SaveWiredNetworkProfile(self, profilename):
''' Writes a wired network profile to disk ''' """ Writes a wired network profile to disk """
#should include: profilename,ip,netmask,gateway,dns1,dns2 #should include: profilename,ip,netmask,gateway,dns1,dns2
profilename = misc.to_unicode(profilename) profilename = misc.to_unicode(profilename)
print "setting profile for " + str(profilename) print "setting profile for " + str(profilename)
@@ -987,11 +958,10 @@ class ConnectionWizard(dbus.service.Object):
config.set(profilename, x, self.WiredNetwork[x]) config.set(profilename, x, self.WiredNetwork[x])
config.write(open(self.wired_conf, "w")) config.write(open(self.wired_conf, "w"))
return "100: Profile Written" return "100: Profile Written"
#end function SaveWiredNetworkProfile
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def ReadWiredNetworkProfile(self, profilename): def ReadWiredNetworkProfile(self, profilename):
''' Reads a wired network profile in as the currently active profile ''' """ Reads a wired network profile in as the currently active profile """
profile = {} profile = {}
profilename = misc.to_unicode(profilename) profilename = misc.to_unicode(profilename)
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@@ -1006,11 +976,10 @@ class ConnectionWizard(dbus.service.Object):
else: else:
self.WiredNetwork = None self.WiredNetwork = None
return "500: Profile Not Found" return "500: Profile Not Found"
#end function ReadWiredNetworkProfile
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def GetWiredProfileList(self): def GetWiredProfileList(self):
''' Returns a list of all wired profiles in wired-settings.conf ''' """ Returns a list of all wired profiles in wired-settings.conf """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
print config.sections() print config.sections()
@@ -1018,11 +987,10 @@ class ConnectionWizard(dbus.service.Object):
return config.sections() return config.sections()
else: else:
return None return None
#end function GetWiredProfileList
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def SaveWirelessNetworkProfile(self, id): def SaveWirelessNetworkProfile(self, id):
''' Writes a wireless profile to disk ''' """ Writes a wireless profile to disk """
print "setting network profile" print "setting network profile"
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wireless_conf) config.read(self.wireless_conf)
@@ -1034,26 +1002,26 @@ class ConnectionWizard(dbus.service.Object):
for x in self.LastScan[id]: for x in self.LastScan[id]:
config.set(self.LastScan[id]["bssid"], x, self.LastScan[id][x]) config.set(self.LastScan[id]["bssid"], x, self.LastScan[id][x])
config.write(open(self.wireless_conf, "w")) config.write(open(self.wireless_conf, "w"))
#end function SaveWirelessNetworkProfile
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def SaveWirelessNetworkProperty(self, id, option): def SaveWirelessNetworkProperty(self, id, option):
''' Writes a particular wireless property to disk ''' """ Writes a particular wireless property to disk """
if (option.strip()).endswith("script"): if (option.strip()).endswith("script"):
print 'you cannot save script information to disk through the daemon.' print 'you cannot save script information to disk through the daemon.'
return return
print "setting network option " + str(option) + " to " + str(self.LastScan[id][option])
print ("setting network option " + str(option) + " to " +
str(self.LastScan[id][option]))
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wireless_conf) config.read(self.wireless_conf)
if config.has_section(self.LastScan[id]["bssid"]): if config.has_section(self.LastScan[id]["bssid"]):
config.set(self.LastScan[id]["bssid"], option, config.set(self.LastScan[id]["bssid"], option,
str(self.LastScan[id][option])) str(self.LastScan[id][option]))
config.write(open(self.wireless_conf, "w")) config.write(open(self.wireless_conf, "w"))
#end function SaveWirelessNetworkProperty
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def ReadWirelessNetworkProfile(self, id): def ReadWirelessNetworkProfile(self, id):
''' Reads in wireless profile as the active network ''' """ Reads in wireless profile as the active network """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wireless_conf) config.read(self.wireless_conf)
print self.LastScan[id]["bssid"] print self.LastScan[id]["bssid"]
@@ -1063,7 +1031,8 @@ class ConnectionWizard(dbus.service.Object):
# Read the essid because we be needing to name those hidden # Read the essid because we be needing to name those hidden
# wireless networks now - but only read it if it is hidden. # wireless networks now - but only read it if it is hidden.
if self.LastScan[id]["hidden"] == True: if self.LastScan[id]["hidden"] == True:
self.LastScan[id]["essid"] = misc.Noneify(config.get(self.LastScan[id]["bssid"], "essid")) self.LastScan[id]["essid"] = misc.Noneify(config.get(self.LastScan[id]["bssid"],
"essid"))
for x in config.options(self.LastScan[id]["bssid"]): for x in config.options(self.LastScan[id]["bssid"]):
if self.LastScan[id].has_key(x) == False or x.endswith("script"): if self.LastScan[id].has_key(x) == False or x.endswith("script"):
self.LastScan[id][x] = misc.Noneify(config.get(self.LastScan[id]["bssid"], x)) self.LastScan[id][x] = misc.Noneify(config.get(self.LastScan[id]["bssid"], x))
@@ -1076,7 +1045,6 @@ class ConnectionWizard(dbus.service.Object):
self.LastScan[id]['use_static_dns'] = bool(self.GetUseGlobalDNS()) self.LastScan[id]['use_static_dns'] = bool(self.GetUseGlobalDNS())
self.LastScan[id]['use_global_dns'] = bool(self.GetUseGlobalDNS()) self.LastScan[id]['use_global_dns'] = bool(self.GetUseGlobalDNS())
return "500: Profile Not Found" return "500: Profile Not Found"
#end function ReadWirelessNetworkProfile
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def WriteWindowSize(self, width, height): def WriteWindowSize(self, width, height):
@@ -1123,11 +1091,10 @@ class ConnectionWizard(dbus.service.Object):
############################################# #############################################
def __printReturn(self, text, value): def __printReturn(self, text, value):
'''prints the specified text and value, then returns the value''' """prints the specified text and value, then returns the value"""
if self.debug_mode == 1: if self.debug_mode == 1:
print text, value print text, value
return value return value
#end function __printReturn
def get_option(self, section, option, default=None): def get_option(self, section, option, default=None):
""" Method for returning an option from manager-settings.conf. """ Method for returning an option from manager-settings.conf.

117
gui.py
View File

@@ -26,10 +26,7 @@ Wicd user interface.
import os import os
import sys import sys
import signal
import time import time
import gettext
import locale
import gobject import gobject
import dbus import dbus
import dbus.service import dbus.service
@@ -211,7 +208,7 @@ class SmallLabel(gtk.Label):
self.set_size_request(50,-1) self.set_size_request(50,-1)
class LabelEntry(gtk.HBox): class LabelEntry(gtk.HBox):
'''a label on the left with a textbox on the right''' """ A label on the left with a textbox on the right. """
def __init__(self,text): def __init__(self,text):
gtk.HBox.__init__(self) gtk.HBox.__init__(self)
self.entry = gtk.Entry() self.entry = gtk.Entry()
@@ -254,6 +251,7 @@ class LabelEntry(gtk.HBox):
self.entry.set_visibility(False) self.entry.set_visibility(False)
class GreyLabel(gtk.Label): class GreyLabel(gtk.Label):
""" Creates a grey gtk.Label. """
def __init__(self): def __init__(self):
gtk.Label.__init__(self) gtk.Label.__init__(self)
def set_label(self,text): def set_label(self,text):
@@ -265,7 +263,7 @@ class GreyLabel(gtk.Label):
######################################## ########################################
def noneToString(text): def noneToString(text):
"""Converts a blank string to "None". """ """ Converts a blank string to "None". """
if text == "": if text == "":
return "None" return "None"
else: else:
@@ -279,17 +277,17 @@ def noneToBlankString(text):
return str(text) return str(text)
def stringToNone(text): def stringToNone(text):
'''performs opposite function of noneToString''' """ Performs opposite function of noneToString. """
if text == "" or text == "None" or text == None: if text == "" or text == "None" or text == None:
return None return None
else: else:
return str(text) return str(text)
def stringToBoolean(text): def stringToBoolean(text):
'''Turns a "True" to True or a "False" to False otherwise returns the text''' """ Turns a string representation of a bool to a boolean if needed. """
if text == "True": if text == "True" or text == "1":
return True return True
if text == "False": if text == "False" or text == "0":
return False return False
return text return text
@@ -304,7 +302,7 @@ def checkboxTextboxToggle(checkbox,textboxes):
class PrettyNetworkEntry(gtk.HBox): class PrettyNetworkEntry(gtk.HBox):
'''Adds an image and a connect button to a NetworkEntry''' """ Adds an image and a connect button to a NetworkEntry. """
def __init__(self, expander): def __init__(self, expander):
gtk.HBox.__init__(self) gtk.HBox.__init__(self)
# Add the stuff to the hbox (self) # Add the stuff to the hbox (self)
@@ -415,7 +413,7 @@ class PrettyWirelessNetworkEntry(PrettyNetworkEntry):
class NetworkEntry(gtk.Expander): class NetworkEntry(gtk.Expander):
'''The basis for the entries in the network list''' """ The basis for the entries in the network list. """
def __init__(self): def __init__(self):
# Make stuff exist, this is pretty long and boring. # Make stuff exist, this is pretty long and boring.
gtk.Expander.__init__(self) gtk.Expander.__init__(self)
@@ -440,7 +438,7 @@ class NetworkEntry(gtk.Expander):
script_image = gtk.Image() script_image = gtk.Image()
script_image.set_from_icon_name('execute', 4) script_image.set_from_icon_name('execute', 4)
script_image.set_padding(4, 0) script_image.set_padding(4, 0)
self.scriptButton.set_alignment(.5 , .5) self.scriptButton.set_alignment(.5, .5)
self.scriptButton.set_image(script_image) self.scriptButton.set_image(script_image)
self.scriptButton.set_label(language['scripts']) self.scriptButton.set_label(language['scripts'])
@@ -748,14 +746,14 @@ class WirelessNetworkEntry(NetworkEntry):
if wireless.GetWirelessProperty(networkID,'use_global_dns'): if wireless.GetWirelessProperty(networkID,'use_global_dns'):
self.checkboxGlobalDNS.set_active(True) self.checkboxGlobalDNS.set_active(True)
if wireless.GetWirelessProperty(networkID,"dns1") != None: if wireless.GetWirelessProperty(networkID, "dns1") != None:
self.txtDNS1.set_text(self.format_entry(networkID,"dns1")) self.txtDNS1.set_text(self.format_entry(networkID, "dns1"))
if wireless.GetWirelessProperty(networkID,'dns2') != None: if wireless.GetWirelessProperty(networkID, 'dns2') != None:
self.txtDNS2.set_text(self.format_entry(networkID,"dns2")) self.txtDNS2.set_text(self.format_entry(networkID, "dns2"))
if wireless.GetWirelessProperty(networkID,'dns3') != None: if wireless.GetWirelessProperty(networkID, 'dns3') != None:
self.txtDNS3.set_text(self.format_entry(networkID,"dns3")) self.txtDNS3.set_text(self.format_entry(networkID, "dns3"))
self.resetStaticCheckboxes() self.resetStaticCheckboxes()
encryptionTypes = misc.LoadEncryptionMethods() encryptionTypes = misc.LoadEncryptionMethods()
@@ -767,11 +765,12 @@ class WirelessNetworkEntry(NetworkEntry):
self.checkboxAutoConnect.set_active(True) self.checkboxAutoConnect.set_active(True)
else: else:
self.checkboxAutoConnect.set_active(False) self.checkboxAutoConnect.set_active(False)
#set it up right, with disabled stuff
# Set it up right, with disabled stuff
self.toggleEncryption() self.toggleEncryption()
#add the names to the menu # Add the names to the menu
activeID = -1 #set the menu to this item when we are done activeID = -1 # Set the menu to this item when we are done
for x in encryptionTypes: for x in encryptionTypes:
self.comboEncryption.append_text(encryptionTypes[x][0]) self.comboEncryption.append_text(encryptionTypes[x][0])
if encryptionTypes[x][1] == wireless.GetWirelessProperty(networkID, if encryptionTypes[x][1] == wireless.GetWirelessProperty(networkID,
@@ -799,13 +798,12 @@ class WirelessNetworkEntry(NetworkEntry):
def editScripts(self, widget=None, event=None): def editScripts(self, widget=None, event=None):
result = os.spawnlpe(os.P_WAIT, "gksudo", "gksudo", "./configscript.py", result = os.spawnlpe(os.P_WAIT, "gksudo", "gksudo", "./configscript.py",
str(self.networkID), "wireless", os.environ) str(self.networkID), "wireless", os.environ)
print result print result
def updateAutoConnect(self, widget=None): def updateAutoConnect(self, widget=None):
wireless.SetWirelessProperty(self.networkID, "automatic", wireless.SetWirelessProperty(self.networkID, "automatic",
noneToString(self.checkboxAutoConnect.get_active())) noneToString(self.checkboxAutoConnect.get_active()))
config.SaveWirelessNetworkProperty(self.networkID, "automatic") config.SaveWirelessNetworkProperty(self.networkID, "automatic")
def toggleEncryption(self, widget=None): def toggleEncryption(self, widget=None):
@@ -822,22 +820,23 @@ class WirelessNetworkEntry(NetworkEntry):
if ID == -1: if ID == -1:
#in case nothing is selected #in case nothing is selected
self.comboEncryption.set_active(0) self.comboEncryption.set_active(0)
ID == 0 ID = 0
for x in methods[ID][2]: opts = methods[ID][2]
for x in opts:
box = None box = None
if language.has_key(methods[ID][2][x][0]): if language.has_key(opts[x][0]):
box = LabelEntry(language[methods[ID][2][x][0].lower().replace(' ','_')]) box = LabelEntry(language[opts[x][0].lower().replace(' ','_')])
else: else:
box = LabelEntry(methods[ID][2][x][0].replace('_',' ')) box = LabelEntry(opts[x][0].replace('_',' '))
box.set_auto_hidden(True) box.set_auto_hidden(True)
self.vboxEncryptionInformation.pack_start(box) self.vboxEncryptionInformation.pack_start(box)
#add the data to any array, so that the information #add the data to any array, so that the information
#can be easily accessed by giving the name of the wanted #can be easily accessed by giving the name of the wanted
#data #data
self.encryptionInfo[methods[ID][2][x][1]] = box.entry self.encryptionInfo[opts[x][1]] = box.entry
box.entry.set_text(noneToBlankString( box.entry.set_text(noneToBlankString(
wireless.GetWirelessProperty(self.networkID,methods[ID][2][x][1]))) wireless.GetWirelessProperty(self.networkID, opts[x][1])))
self.vboxEncryptionInformation.show_all() self.vboxEncryptionInformation.show_all()
def setSignalStrength(self, strength, dbm_strength): def setSignalStrength(self, strength, dbm_strength):
@@ -996,7 +995,7 @@ class appGui:
self.toggleEncryptionCheck) self.toggleEncryptionCheck)
channelEntry.entry.set_text('3') channelEntry.entry.set_text('3')
essidEntry.entry.set_text('My_Adhoc_Network') essidEntry.entry.set_text('My_Adhoc_Network')
ipEntry.entry.set_text('169.254.12.10') #Just a random IP ipEntry.entry.set_text('169.254.12.10') # Just a random IP
vboxA = gtk.VBox(False, 0) vboxA = gtk.VBox(False, 0)
vboxA.pack_start(self.useEncryptionCheckbox, fill=False, expand=False) vboxA.pack_start(self.useEncryptionCheckbox, fill=False, expand=False)
@@ -1171,7 +1170,8 @@ class appGui:
# Should display a dialog asking # Should display a dialog asking
# for the ssid of a hidden network # for the ssid of a hidden network
# and displaying connect/cancel buttons # and displaying connect/cancel buttons
dialog = gtk.Dialog(title=language['hidden_network'], flags=gtk.DIALOG_MODAL, dialog = gtk.Dialog(title=language['hidden_network'],
flags=gtk.DIALOG_MODAL,
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)) buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2))
dialog.set_has_separator(False) dialog.set_has_separator(False)
dialog.lbl = gtk.Label(language['hidden_network_essid']) dialog.lbl = gtk.Label(language['hidden_network_essid'])
@@ -1380,35 +1380,36 @@ class appGui:
return True return True
def save_wired_settings(self, entry): def save_wired_settings(self, entry):
if entry.checkboxStaticIP.get_active(): """ Saved wired network settings. """
wired.SetWiredProperty("ip", noneToString(entry.txtIP.get_text())) if entry.checkboxStaticIP.get_active():
wired.SetWiredProperty("netmask", noneToString(entry.txtNetmask.get_text())) wired.SetWiredProperty("ip", noneToString(entry.txtIP.get_text()))
wired.SetWiredProperty("gateway", noneToString(entry.txtGateway.get_text())) wired.SetWiredProperty("netmask", noneToString(entry.txtNetmask.get_text()))
else: wired.SetWiredProperty("gateway", noneToString(entry.txtGateway.get_text()))
wired.SetWiredProperty("ip", '') else:
wired.SetWiredProperty("netmask", '') wired.SetWiredProperty("ip", '')
wired.SetWiredProperty("gateway", '') wired.SetWiredProperty("netmask", '')
wired.SetWiredProperty("gateway", '')
if entry.checkboxStaticDNS.get_active() and \ if entry.checkboxStaticDNS.get_active() and \
not entry.checkboxGlobalDNS.get_active(): not entry.checkboxGlobalDNS.get_active():
wired.SetWiredProperty('use_static_dns', True) wired.SetWiredProperty('use_static_dns', True)
wired.SetWiredProperty('use_global_dns', False) wired.SetWiredProperty('use_global_dns', False)
wired.SetWiredProperty("dns1", noneToString(entry.txtDNS1.get_text())) wired.SetWiredProperty("dns1", noneToString(entry.txtDNS1.get_text()))
wired.SetWiredProperty("dns2", noneToString(entry.txtDNS2.get_text())) wired.SetWiredProperty("dns2", noneToString(entry.txtDNS2.get_text()))
wired.SetWiredProperty("dns3", noneToString(entry.txtDNS3.get_text())) wired.SetWiredProperty("dns3", noneToString(entry.txtDNS3.get_text()))
elif entry.checkboxStaticDNS.get_active() and \ elif entry.checkboxStaticDNS.get_active() and \
entry.checkboxGlobalDNS.get_active(): entry.checkboxGlobalDNS.get_active():
wired.SetWiredProperty('use_static_dns', True) wired.SetWiredProperty('use_static_dns', True)
wired.SetWiredProperty('use_global_dns', True) wired.SetWiredProperty('use_global_dns', True)
else: else:
wired.SetWiredProperty('use_static_dns', False) wired.SetWiredProperty('use_static_dns', False)
wired.SetWiredProperty("dns1", '') wired.SetWiredProperty("dns1", '')
wired.SetWiredProperty("dns2", '') wired.SetWiredProperty("dns2", '')
wired.SetWiredProperty("dns3", '') wired.SetWiredProperty("dns3", '')
config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text()) config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text())
def save_wireless_settings(self, networkid, entry): def save_wireless_settings(self, networkid, entry):
print 'networkid', networkid """ Save wireless network settings. """
wireless.SetWirelessProperty(networkid, "automatic", wireless.SetWirelessProperty(networkid, "automatic",
noneToString(entry.checkboxAutoConnect.get_active())) noneToString(entry.checkboxAutoConnect.get_active()))

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
""" networking - Provides wrappers for common network operations """ networking - Provides wrappers for common network operations
This module provides wrappers of the common network tasks as well as This module provides wrappers of the common network tasks as well as

View File

@@ -3,7 +3,9 @@
""" Suspends the wicd daemon. """ Suspends the wicd daemon.
Sets a flag in the daemon that will stop it from monitoring networkg status. Sets a flag in the daemon that will stop it from monitoring networkg status.
Used for when a laptop enters hibernation/suspension. """ Used for when a laptop enters hibernation/suspension.
"""
# #
# Copyright (C) 2007 Adam Blackburn # Copyright (C) 2007 Adam Blackburn

38
wicd.py
View File

@@ -107,7 +107,7 @@ language['connecting'] = _('Connecting')
language['wired'] = _('Wired Network') language['wired'] = _('Wired Network')
class TrayIcon(): class TrayIcon():
"""Base Tray Icon class """ Base Tray Icon class.
Base Class for implementing a tray icon to display network status. Base Class for implementing a tray icon to display network status.
@@ -121,9 +121,9 @@ class TrayIcon():
class TrayConnectionInfo(): class TrayConnectionInfo():
"""Class for updating the tray icon status""" """ Class for updating the tray icon status. """
def __init__(self, tr, use_tray=True): def __init__(self, tr, use_tray=True):
"""Initialize variables needed for the icon status methods.""" """ Initialize variables needed for the icon status methods. """
self.last_strength = -2 self.last_strength = -2
self.still_wired = False self.still_wired = False
self.network = '' self.network = ''
@@ -139,7 +139,7 @@ class TrayIcon():
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
def update_tray_icon(self, state=None, info=None): def update_tray_icon(self, state=None, info=None):
"""Updates the tray icon and current connection status""" """ Updates the tray icon and current connection status. """
if self.use_tray == False: return False if self.use_tray == False: return False
if not state or not info: if not state or not info:
@@ -192,7 +192,7 @@ class TrayIcon():
return True return True
def set_signal_image(self, wireless_signal, lock): def set_signal_image(self, wireless_signal, lock):
"""Sets the tray icon image for an active wireless connection""" """ Sets the tray icon image for an active wireless connection. """
if daemon.GetSignalDisplayType() == 0: if daemon.GetSignalDisplayType() == 0:
if wireless_signal > 75: if wireless_signal > 75:
signal_img = "high-signal" signal_img = "high-signal"
@@ -217,7 +217,7 @@ class TrayIcon():
class TrayIconGUI(): class TrayIconGUI():
"""Base Tray Icon class """ Base Tray Icon class.
Implements methods and variables used by both egg/StatusIcon Implements methods and variables used by both egg/StatusIcon
tray icons. tray icons.
@@ -257,19 +257,19 @@ class TrayIcon():
self.use_tray = use_tray self.use_tray = use_tray
def on_activate(self, data=None): def on_activate(self, data=None):
"""Opens the wicd GUI""" """ Opens the wicd GUI. """
self.toggle_wicd_gui() self.toggle_wicd_gui()
def on_quit(self, widget=None): def on_quit(self, widget=None):
"""Closes the tray icon""" """ Closes the tray icon. """
sys.exit(0) sys.exit(0)
def on_preferences(self, data=None): def on_preferences(self, data=None):
"""Opens the wicd GUI """ """ Opens the wicd GUI. """
self.toggle_wicd_gui() self.toggle_wicd_gui()
def on_about(self, data = None): def on_about(self, data = None):
"""Opens the About Dialog""" """ Opens the About Dialog. """
dialog = gtk.AboutDialog() dialog = gtk.AboutDialog()
dialog.set_name('wicd tray icon') dialog.set_name('wicd tray icon')
dialog.set_version('1.0') dialog.set_version('1.0')
@@ -279,7 +279,7 @@ class TrayIcon():
dialog.destroy() dialog.destroy()
def toggle_wicd_gui(self): def toggle_wicd_gui(self):
"""Toggles the wicd GUI""" """ Toggles the wicd GUI. """
if self.gui_win == None: if self.gui_win == None:
self.gui_win = gui.appGui() self.gui_win = gui.appGui()
elif self.gui_win.is_visible == False: elif self.gui_win.is_visible == False:
@@ -290,7 +290,7 @@ class TrayIcon():
class EggTrayIconGUI(TrayIconGUI): class EggTrayIconGUI(TrayIconGUI):
"""Tray Icon for gtk < 2.10 """ Tray Icon for gtk < 2.10.
Uses the deprecated egg.trayicon module to implement the tray icon. Uses the deprecated egg.trayicon module to implement the tray icon.
@@ -316,19 +316,19 @@ class TrayIcon():
self.tray.show_all() self.tray.show_all()
def tray_clicked(self, widget, event): def tray_clicked(self, widget, event):
"""Handles tray mouse click events""" """ Handles tray mouse click events. """
if event.button == 1: if event.button == 1:
self.toggle_wicd_gui() self.toggle_wicd_gui()
if event.button == 3: if event.button == 3:
self.menu.popup(None, None, None, event.button, event.time) self.menu.popup(None, None, None, event.button, event.time)
def set_from_file(self, val=None): def set_from_file(self, val=None):
"""Calls set_from_file on the gtk.Image for the tray icon""" """ Calls set_from_file on the gtk.Image for the tray icon. """
if not self.use_tray: return if not self.use_tray: return
self.pic.set_from_file(val) self.pic.set_from_file(val)
def set_tooltip(self, val): def set_tooltip(self, val):
""" """ Set the tooltip for this tray icon.
Sets the tooltip for the gtk.ToolTips associated with this Sets the tooltip for the gtk.ToolTips associated with this
tray icon. tray icon.
@@ -339,7 +339,7 @@ class TrayIcon():
class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI): class StatusTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
"""Class for creating the wicd tray icon on gtk > 2.10 """ Class for creating the wicd tray icon on gtk > 2.10.
Uses gtk.StatusIcon to implement a tray icon. Uses gtk.StatusIcon to implement a tray icon.
@@ -362,11 +362,11 @@ class TrayIcon():
self.set_tooltip("Initializing wicd...") self.set_tooltip("Initializing wicd...")
def on_popup_menu(self, status, button, timestamp): def on_popup_menu(self, status, button, timestamp):
"""Opens the right click menu for the tray icon""" """ Opens the right click menu for the tray icon. """
self.menu.popup(None, None, None, button, timestamp) self.menu.popup(None, None, None, button, timestamp)
def set_from_file(self, path = None): def set_from_file(self, path = None):
"""Sets a new tray icon picture""" """ Sets a new tray icon picture. """
if not self.use_tray: return if not self.use_tray: return
if path != self.current_icon_path: if path != self.current_icon_path:
self.current_icon_path = path self.current_icon_path = path
@@ -374,7 +374,7 @@ class TrayIcon():
def usage(): def usage():
"""Print usage information.""" """ Print usage information. """
print """ print """
wicd 1.40 wicd 1.40
wireless (and wired) connection daemon front-end. wireless (and wired) connection daemon front-end.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
""" Network interface control tools for wicd. """ Network interface control tools for wicd.
This module implements functions to control and obtain information from This module implements functions to control and obtain information from