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

Fixed bad except statement in misc.py.

Cleaned up formatting in gui.py.
Made glade template for preferences dialog and rewrote gui.py to use it instead of creating it explictly in the code.
Fixed a bunch indentation/whitespace problems.
Cleaned up a ton of formatting in daemon.py
Fixed a wired autoconnect bug.
Rewrote part of the connection monitoring code, further minimizing the number of external program calls, as well as number of dbus calls.
Added StatusInformation methods to daemon.py, to allow external apps to poll for the current connection status without making several dbus calls.
Fixed bad function call to GetDBMSignalStrength in daemon.py.
This commit is contained in:
imdano
2008-01-29 21:03:19 +00:00
parent 4b4bc55614
commit d46da02511
8 changed files with 866 additions and 406 deletions

View File

@@ -106,32 +106,32 @@ def get_script_info(network, network_type):
def write_scripts(network, network_type, script_info):
""" Writes script info to disk and loads it into the daemon. """
con = ConfigParser.ConfigParser()
print "writing scripts, type",network_type
print "writing scripts, type", network_type
if network_type == "wired":
con.read(wired_conf)
if con.has_section(network):
con.add_section(network)
con.set(network, "beforescript", script_info["pre_entry"])
con.set(network, "afterscript", script_info["post_entry"])
con.set(network, "beforescript", script_info["pre_entry"])
con.set(network, "afterscript", script_info["post_entry"])
con.set(network, "disconnectscript",
script_info["disconnect_entry"])
con.write(open(wired_conf, "w"))
config.ReadWiredNetworkProfile(network)
config.SaveWiredNetworkProfile(network)
con.write(open(wired_conf, "w"))
config.ReadWiredNetworkProfile(network)
config.SaveWiredNetworkProfile(network)
else:
bssid = wireless.GetWirelessProperty(int(network), "bssid")
con.read(wireless_conf)
if con.has_section(bssid):
con.add_section(bssid)
con.set(bssid, "beforescript", script_info["pre_entry"])
con.set(bssid, "afterscript", script_info["post_entry"])
con.set(bssid, "disconnectscript", script_info["disconnect_entry"])
con.write(open(wireless_conf, "w"))
config.ReadWirelessNetworkProfile(int(network))
config.SaveWirelessNetworkProfile(int(network))
con.set(bssid, "beforescript", script_info["pre_entry"])
con.set(bssid, "afterscript", script_info["post_entry"])
con.set(bssid, "disconnectscript", script_info["disconnect_entry"])
con.write(open(wireless_conf, "w"))
config.ReadWirelessNetworkProfile(int(network))
config.SaveWirelessNetworkProfile(int(network))
def main (argv):
"""Runs the script configuration dialog."""
""" Runs the script configuration dialog. """
if len(argv) < 2:
print 'Network id to configure is missing, aborting.'
sys.exit(1)

381
daemon.py
View File

@@ -42,7 +42,7 @@ import ConfigParser
import gobject
import dbus
import dbus.service
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
if getattr(dbus, 'version', (0, 0, 0)) >= (0, 41, 0):
import dbus.glib
# wicd specific libraries
import wpath
@@ -67,7 +67,7 @@ logging_enabled = True
class LogWriter:
""" A class to provide timestamped logging. """
def __init__(self):
self.file = open(wpath.log + 'wicd.log','a')
self.file = open(wpath.log + 'wicd.log', 'a')
self.eol = True
@@ -118,9 +118,9 @@ class LogWriter:
"""
x = time.localtime()
return ''.join([
str(x[0]).rjust(4,'0'), '/', str(x[1]).rjust(2,'0'), '/',
str(x[2]).rjust(2,'0'), ' ', str(x[3]).rjust(2,'0'), ':',
str(x[4]).rjust(2,'0'), ':', str(x[5]).rjust(2,'0')])
str(x[0]).rjust(4, '0'), '/', str(x[1]).rjust(2, '0'), '/',
str(x[2]).rjust(2, '0'), ' ', str(x[3]).rjust(2, '0'), ':',
str(x[4]).rjust(2, '0'), ':', str(x[5]).rjust(2, '0')])
class ConnectionWizard(dbus.service.Object):
@@ -144,6 +144,8 @@ class ConnectionWizard(dbus.service.Object):
self.vpn_session = None
self.gui_open = False
self.suspended = False
self.connection_state = 0
self.connection_info = [""]
# Load the config file
self.ReadConfig()
@@ -158,7 +160,7 @@ class ConnectionWizard(dbus.service.Object):
# Scan since we just got started
if auto_connect:
print "autoconnecting...",str(self.GetWirelessInterface()[5:])
print "autoconnecting...", str(self.GetWirelessInterface()[5:])
self.AutoConnect(True)
else:
print "--no-scan detected, not autoconnecting..."
@@ -179,79 +181,79 @@ class ConnectionWizard(dbus.service.Object):
#and micro may be anything >= 0
#this number is effective starting wicd v1.2.0
version = '1.5.0'
print 'returned version number',version
print 'returned version number', version
return version
@dbus.service.method('org.wicd.daemon')
def SetWiredInterface(self,interface):
def SetWiredInterface(self, interface):
''' 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.wifi.wired_interface = interface
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","wired_interface",interface)
config.write(open(self.app_conf,"w"))
config.set("Settings","wired_interface", interface)
config.write(open(self.app_conf, "w"))
@dbus.service.method('org.wicd.daemon')
def SetWirelessInterface(self,interface):
def SetWirelessInterface(self, interface):
''' Sets the wireless interface the daemon will use '''
print "setting wireless interface" , str(interface)
self.wifi.wireless_interface = interface
self.wired.wireless_interface = interface
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","wireless_interface",interface)
configfile = open(self.app_conf,"w")
config.set("Settings","wireless_interface", interface)
configfile = open(self.app_conf, "w")
config.write(configfile)
@dbus.service.method('org.wicd.daemon')
def SetWPADriver(self,driver):
def SetWPADriver(self, driver):
''' 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
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","wpa_driver",driver)
configfile = open(self.app_conf,"w")
configfile = open(self.app_conf, "w")
config.write(configfile)
#end function SetWPADriver
@dbus.service.method('org.wicd.daemon')
def SetUseGlobalDNS(self,use):
def SetUseGlobalDNS(self, use):
''' 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)
print 'setting use global dns to boolean',use
print 'setting use global dns to boolean', use
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","use_global_dns", use)
config.set("Settings", "use_global_dns", use)
self.use_global_dns = use
self.wifi.use_global_dns = use
self.wired.use_global_dns = use
configfile = open(self.app_conf,"w")
configfile = open(self.app_conf, "w")
config.write(configfile)
@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 '''
print "setting global dns"
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","global_dns_1",misc.noneToString(dns1))
config.set("Settings", "global_dns_1", misc.noneToString(dns1))
self.dns1 = dns1
self.wifi.global_dns_1 = dns1
self.wired.global_dns_1 = dns1
config.set("Settings","global_dns_2",misc.noneToString(dns2))
config.set("Settings", "global_dns_2", misc.noneToString(dns2))
self.dns2 = dns2
self.wifi.global_dns_2 = dns2
self.wired.global_dns_2 = dns2
config.set("Settings","global_dns_3",misc.noneToString(dns3))
config.set("Settings", "global_dns_3", misc.noneToString(dns3))
self.dns3 = dns3
self.wifi.global_dns_3 = dns3
self.wired.global_dns_3 = dns3
print 'global dns servers are',dns1,dns2,dns3
configfile = open(self.app_conf,"w")
print 'global dns servers are', dns1, dns2, dns3
configfile = open(self.app_conf, "w")
config.write(configfile)
#end function SetWirelessInterface
@@ -284,8 +286,8 @@ class ConnectionWizard(dbus.service.Object):
''' Sets if debugging mode is on or off '''
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","debug_mode",debug)
configfile = open(self.app_conf,"w")
config.set("Settings", "debug_mode", debug)
configfile = open(self.app_conf, "w")
config.write(configfile)
self.debug_mode = misc.to_bool(debug)
#end function SetDebugMode
@@ -320,8 +322,8 @@ class ConnectionWizard(dbus.service.Object):
''' Sets the signal display type and writes it the wicd config file '''
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","signal_display_type",value)
configfile = open(self.app_conf,"w")
config.set("Settings", "signal_display_type", value)
configfile = open(self.app_conf, "w")
config.write(configfile)
self.signal_display_type = int(value)
# end function SetSignalDisplayType
@@ -335,13 +337,16 @@ class ConnectionWizard(dbus.service.Object):
return (signal + "%")
# End function FormatSignalForPrinting
@dbus.service. method('org.wicd.daemon')
@dbus.service.method('org.wicd.daemon')
def SetSuspend(self, val):
""" Toggles whether or not monitoring connection status is suspended """
self.suspended = val
if self.suspended:
self.Disconnect()
@dbus.service. method('org.wicd.daemon')
def AutoConnect(self,fresh):
def AutoConnect(self, fresh):
''' Attempts to autoconnect to a wired or wireless network.
Autoconnect will first try to connect to a wired network, if that
@@ -353,7 +358,7 @@ class ConnectionWizard(dbus.service.Object):
if self.GetWiredAutoConnectMethod() == 2 and \
not self.GetNeedWiredProfileChooser():
self.LaunchChooser()
elif not self.GetWiredAutoConnectMethod != 2:
elif self.GetWiredAutoConnectMethod != 2:
defaultNetwork = self.GetDefaultWiredNetwork()
if defaultNetwork != None:
self.ReadWiredNetworkProfile(defaultNetwork)
@@ -370,7 +375,7 @@ class ConnectionWizard(dbus.service.Object):
if bool(self.LastScan[x]["has_profile"]):
print self.LastScan[x]["essid"] + ' has profile'
if bool(self.LastScan[x].get('automatic')):
print 'trying to automatically connect to...',self.LastScan[x]["essid"]
print 'trying to automatically connect to...', self.LastScan[x]["essid"]
self.ConnectWireless(x)
time.sleep(1)
return
@@ -383,7 +388,8 @@ class ConnectionWizard(dbus.service.Object):
def GetAutoReconnect(self):
'''returns if wicd should automatically try to reconnect is connection is lost'''
do = bool(self.auto_reconnect)
return self.__printReturn('returning automatically reconnect when connection drops',do)
return self.__printReturn('returning automatically reconnect when\
connection drops', do)
#end function GetAutoReconnect
@dbus.service.method('org.wicd.daemon')
@@ -392,8 +398,8 @@ class ConnectionWizard(dbus.service.Object):
print 'setting automatically reconnect when connection drops'
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","auto_reconnect",misc.to_bool(value))
config.write(open(self.app_conf,"w"))
config.set("Settings", "auto_reconnect", misc.to_bool(value))
config.write(open(self.app_conf, "w"))
self.auto_reconnect = misc.to_bool(value)
#end function SetAutoReconnect
@@ -436,7 +442,7 @@ class ConnectionWizard(dbus.service.Object):
self.current_interface = str(iface)
@dbus.service.method('org.wicd.daemon')
def SetNeedWiredProfileChooser(self,val):
def SetNeedWiredProfileChooser(self, val):
""" Sets the need_wired_profile_chooser variable.
If set to True, that alerts the wicd frontend to display the chooser,
@@ -455,7 +461,7 @@ class ConnectionWizard(dbus.service.Object):
#end function GetForcedDisconnect
@dbus.service.method('org.wicd.daemon')
def SetForcedDisconnect(self,value):
def SetForcedDisconnect(self, value):
'''
Set to True when a user manually disconnects or cancels a connection.
@@ -487,26 +493,67 @@ class ConnectionWizard(dbus.service.Object):
""" Sets the value of gui_open. """
self.gui_open = bool(val)
@dbus.service.method('org.wicd.daemon')
def SetConnectionStatus(self, state, info):
""" Sets the connection status.
Keyword arguments:
state - An int representing the state of the connection as defined
in misc.py.
info - a list of strings containing data about the connection state.
The contents of this list are dependent on the connection state.
state - info contents:
NOT_CONNECTED - info[0] = ""
CONNECTING - info[0] = "wired" or "wireless"
info[1] = None for wired, essid for wireless
WIRED - info[0] = IP Adresss
WIRELESS - info[0] = IP Address
info[1] = essid
info[2] = signal strength
info[3] = internal networkid
"""
self.connection_state = state
self.connection_info = info
@dbus.service.method('org.wicd.daemon', out_signature='(uas)')
def GetConnectionStatus(self):
return [self.connection_state, self.connection_info]
@dbus.service.method('org.wicd.daemon')
def GetNeedWiredProfileChooser(self):
""" Returns need_profile_chooser
Returns a boolean specifying if the wired profile chooser needs to
be launched.
"""
return bool(self.need_profile_chooser)
#end function GetNeedWiredProfileChooser
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
def LaunchChooser(self):
""" Emits the wired profile chooser dbus signal. """
print 'calling wired profile chooser'
self.SetNeedWiredProfileChooser(True)
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
def StatusChanged(self):
""" Called when the current connection status has changed """
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='uav')
def StatusChanged(self, state, info):
""" Emits a "status changed" dbus signal.
This D-Bus signal is emitted when the connection status changes.
"""
pass
########## WIRELESS FUNCTIONS
#################################
@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 ConnectionWizard.Scan'''
print 'setting hidden essid: ' + str(essid)
self.hidden_essid = str(misc.Noneify(essid))
@@ -518,42 +565,10 @@ class ConnectionWizard(dbus.service.Object):
scan = self.wifi.Scan(str(self.hidden_essid))
self.LastScan = scan
print 'scanning done'
print 'found',str(len(scan)),'networks:',
print 'found', str(len(scan)), 'networks:',
for i, network in enumerate(scan):
self.ReadWirelessNetworkProfile(i)
# This is unfinished so not on dbus yet
def AutoConnectScan(self):
''' Scan for networks and for known hidden networks
Scans for wireless networks and also for hidden networks defined in
wireless-settings.conf
'''
hidden_network_list = self.GetHiddenNetworkList()
master_scan = self.Scan()
if hidden_network_list is None:
return
else:
# If we find hidden networks, run a scan for each one found,
# parsing out the hidden network info if it's in the scan
# results, and appending it to a master scan list
for hidden_network in hidden_network_list:
print 'Scanning for hidden network:', hidden_network
self.SetHiddenESSID(hidden_network['essid'])
temp_scan = self.Scan()
for i, network in enumerate(temp_scan):
print 'Searching scan results for ' + hidden_network['essid']
# Make sure both the essid and bssid match
if temp_scan[i]['essid'] == hidden_network['essid'] and \
temp_scan[i]['bssid'] == hidden_network['bssid']:
print 'Hidden network found, adding to master list'
master_scan[len(master_scan)] = temp_scan[i]
# Break once the network is found
break
self.LastScan = master_scan
@dbus.service.method('org.wicd.daemon.wireless')
def GetIwconfig(self):
""" Calls and returns the output of iwconfig"""
@@ -562,15 +577,17 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wireless')
def GetNumberOfNetworks(self):
'''returns number of networks'''
print 'returned number of networks...',len(self.LastScan)
print 'returned number of networks...', len(self.LastScan)
return len(self.LastScan)
#end function GetNumberOfNetworks
@dbus.service.method('org.wicd.daemon.wireless')
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused,ics):
'''creates an ad-hoc network using user inputted settings'''
def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
ics):
''' creates an ad-hoc network using user inputted settings '''
print 'attempting to create ad-hoc network...'
self.wifi.CreateAdHocNetwork(essid,channel,ip,enctype,key,encused,ics)
self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused,
ics)
#end function CreateAdHocNetwork
@dbus.service.method('org.wicd.daemon.wireless')
@@ -580,7 +597,7 @@ class ConnectionWizard(dbus.service.Object):
return status
@dbus.service.method('org.wicd.daemon.wireless')
def GetWirelessProperty(self,networkid,property):
def GetWirelessProperty(self, networkid, property):
''' Retrieves wireless property from the network specified '''
value = self.LastScan[networkid].get(property)
try:
@@ -589,21 +606,22 @@ class ConnectionWizard(dbus.service.Object):
pass
#if self.debug_mode == 1:
#return type instead of value for security
#print ('returned wireless network',networkid,'property',
# property,'of type',type(value))
#print ('returned wireless network', networkid, 'property',
# property, 'of type', type(value))
return value
#end function GetWirelessProperty
@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 '''
#simple - set the value of the item in our current data
#to the value the client asked for
if (property.strip()).endswith("script"):
print "Setting script properties through the daemon \
is not permitted."
return False
print 'setting wireless network',networkid,'property',property,'to value',value
print "Setting script properties through the daemon is not \
permitted."
return False
print 'setting wireless network', networkid, 'property', property,
'to value', value
self.LastScan[networkid][property] = misc.Noneify(value)
#end function SetProperty
@@ -611,7 +629,7 @@ class ConnectionWizard(dbus.service.Object):
def DetectWirelessInterface(self):
''' Returns an automatically detected wireless interface '''
iface = self.wifi.DetectWirelessInterface()
print 'automatically detected wireless interface',iface
print 'automatically detected wireless interface', iface
return str(iface)
#end function DetectWirelessInterface
@@ -628,7 +646,7 @@ class ConnectionWizard(dbus.service.Object):
if self.GetSignalDisplayType() == 0:
return self.GetCurrentSignalStrength(iwconfig)
else:
return GetCurrentDBMStrength(iwconfig)
return self.GetCurrentDBMStrength(iwconfig)
@dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentSignalStrength(self, iwconfig=None):
@@ -660,7 +678,7 @@ class ConnectionWizard(dbus.service.Object):
def GetCurrentNetworkID(self, iwconfig=None):
'''returns the id of the current network, or -1 if network is not found'''
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:
return x
print 'returning -1, current network not found'
@@ -674,10 +692,11 @@ class ConnectionWizard(dbus.service.Object):
# CheckIfWirelessConnecting can be used to test if the connection
# is done.
self.SetForcedDisconnect(False)
self.wifi.before_script = self.GetWirelessProperty(id,'beforescript')
self.wifi.after_script = self.GetWirelessProperty(id,'afterscript')
self.wifi.disconnect_script = self.GetWirelessProperty(id,'disconnectscript')
print 'connecting to wireless network',self.LastScan[id]['essid']
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
self.wifi.disconnect_script = self.GetWirelessProperty(id,
'disconnectscript')
print 'connecting to wireless network', self.LastScan[id]['essid']
return self.wifi.Connect(self.LastScan[id])
#end function Connect
@@ -689,11 +708,11 @@ class ConnectionWizard(dbus.service.Object):
# status, if it doesn't, we aren't connecting.
status = self.wifi.connecting_thread.is_connecting
if self.debug_mode == 1:
print 'wireless connecting',status
print 'wireless connecting', status
return status
else:
if self.debug_mode == 1:
print 'wireless connecting',False
print 'wireless connecting', False
return False
#end function CheckIfWirelessConnecting
@@ -702,7 +721,7 @@ class ConnectionWizard(dbus.service.Object):
''' Returns the IP that the wireless interface has '''
ip = self.wifi.GetIP()
if self.debug_mode == 1:
print 'returning wireless ip',ip
print 'returning wireless ip', ip
return ip
#end function GetWirelessIP
@@ -724,7 +743,7 @@ class ConnectionWizard(dbus.service.Object):
'''returns the wired interface\'s ip address'''
ip = self.wired.GetIP()
if self.debug_mode == 1:
print 'returning wired ip',ip
print 'returning wired ip', ip
return ip
#end function GetWiredIP
@@ -736,25 +755,25 @@ class ConnectionWizard(dbus.service.Object):
#status, if it doesn't exist, we aren't connecting
status = self.wired.connecting_thread.is_connecting
if self.debug_mode == 1:
print 'wired connecting',status
print 'wired connecting', status
return status
else:
if self.debug_mode == 1:
print 'wired connecting',False
print 'wired connecting', False
return False
#end function CheckIfWiredConnecting
@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'''
# 1 = default profile
# 2 = show list
# 3 = last used profile
print 'wired autoconnection method is',method
print 'wired autoconnection method is', method
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","wired_connect_mode",int(method))
config.write(open(self.app_conf,"w"))
config.set("Settings","wired_connect_mode", int(method))
config.write(open(self.app_conf, "w"))
self.wired_connect_mode = int(method)
@dbus.service.method('org.wicd.daemon.wired')
@@ -774,7 +793,7 @@ class ConnectionWizard(dbus.service.Object):
#end function CheckWiredConnectingMessage
@dbus.service.method('org.wicd.daemon.wired')
def SetWiredProperty(self,property,value):
def SetWiredProperty(self, property, value):
if self.WiredNetwork:
if (property.strip()).endswith("script"):
print "Setting script properties through the daemon \
@@ -782,7 +801,7 @@ class ConnectionWizard(dbus.service.Object):
return False
self.WiredNetwork[property] = misc.Noneify(value)
if self.debug_mode == 1:
print 'set',property,'to',misc.Noneify(value)
print 'set', property, 'to', misc.Noneify(value)
return True
else:
print 'WiredNetwork does not exist'
@@ -790,11 +809,12 @@ class ConnectionWizard(dbus.service.Object):
#end function SetWiredProperty
@dbus.service.method('org.wicd.daemon.wired')
def GetWiredProperty(self,property):
def GetWiredProperty(self, property):
""" Returns the requested wired property. """
if self.WiredNetwork:
value = self.WiredNetwork.get(property)
if self.debug_mode == 1:
print 'returned',property,'with value of',value,'to client...'
print 'returned', property, 'with value of', value, 'to client'
return value
else:
print 'WiredNetwork does not exist'
@@ -802,27 +822,29 @@ class ConnectionWizard(dbus.service.Object):
#end function GetWiredProperty
@dbus.service.method('org.wicd.daemon.wired')
def SetAlwaysShowWiredInterface(self,value):
def SetAlwaysShowWiredInterface(self, value):
print 'Setting always show wired interface'
config = ConfigParser.ConfigParser()
config.read(self.app_conf)
config.set("Settings","always_show_wired_interface",misc.to_bool(value))
config.write(open(self.app_conf,"w"))
config.set("Settings", "always_show_wired_interface",
misc.to_bool(value))
config.write(open(self.app_conf, "w"))
self.always_show_wired_interface = misc.to_bool(value)
#end function SetAlwaysShowWiredInterface
@dbus.service.method('org.wicd.daemon.wired')
def GetAlwaysShowWiredInterface(self):
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')
def CheckPluggedIn(self):
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:
return self.__printReturn("returning plugged in",None)
return self.__printReturn("returning plugged in", None)
#end function CheckPluggedIn
@dbus.service.method('org.wicd.daemon.wired')
@@ -850,9 +872,9 @@ class ConnectionWizard(dbus.service.Object):
#################################
@dbus.service.method('org.wicd.daemon.config')
def CreateWiredNetworkProfile(self,profilename):
def CreateWiredNetworkProfile(self, profilename):
''' 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')
print "creating profile for " + profilename
config = ConfigParser.ConfigParser()
@@ -860,18 +882,18 @@ class ConnectionWizard(dbus.service.Object):
if config.has_section(profilename):
return False
config.add_section(profilename)
config.set(profilename,"ip",None)
config.set(profilename,"broadcast",None)
config.set(profilename,"netmask",None)
config.set(profilename,"gateway",None)
config.set(profilename,"dns1",None)
config.set(profilename,"dns2",None)
config.set(profilename,"dns3",None)
config.set(profilename,"beforescript",None)
config.set(profilename,"afterscript",None)
config.set(profilename,"disconnectscript",None)
config.set(profilename,"default",False)
config.write( open(self.wired_conf,"w"))
config.set(profilename, "ip", None)
config.set(profilename, "broadcast", None)
config.set(profilename, "netmask", None)
config.set(profilename, "gateway", None)
config.set(profilename, "dns1", None)
config.set(profilename, "dns2", None)
config.set(profilename, "dns3", None)
config.set(profilename, "beforescript", None)
config.set(profilename, "afterscript", None)
config.set(profilename, "disconnectscript", None)
config.set(profilename, "default", False)
config.write(open(self.wired_conf, "w"))
return True
#end function CreateWiredNetworkProfile
@@ -881,13 +903,13 @@ class ConnectionWizard(dbus.service.Object):
config = ConfigParser.ConfigParser()
config.read(self.wired_conf)
profileList = config.sections()
print "profileList = ",profileList
print "profileList = ", profileList
for profile in profileList:
print "profile = ", profile
if config.has_option(profile,"lastused"):
if config.get(profile,"lastused") == "True":
if config.get(profile, "lastused") == "True":
print "removing existing lastused"
config.set(profile,"lastused", False)
config.set(profile, "lastused", False)
self.SaveWiredNetworkProfile(profile)
#end function UnsetWiredLastUsed
@@ -897,13 +919,13 @@ class ConnectionWizard(dbus.service.Object):
config = ConfigParser.ConfigParser()
config.read(self.wired_conf)
profileList = config.sections()
print "profileList = ",profileList
print "profileList = ", profileList
for profile in profileList:
print "profile = ", profile
if config.has_option(profile,"default"):
if config.get(profile,"default") == "True":
if config.has_option(profile, "default"):
if config.get(profile, "default") == "True":
print "removing existing default"
config.set(profile,"default", False)
config.set(profile, "default", False)
self.SaveWiredNetworkProfile(profile)
#end function UnsetWiredDefault
@@ -914,8 +936,8 @@ class ConnectionWizard(dbus.service.Object):
config.read(self.wired_conf)
profileList = config.sections()
for profile in profileList:
if config.has_option(profile,"default"):
if config.get(profile,"default") == "True":
if config.has_option(profile, "default"):
if config.get(profile, "default") == "True":
return profile
return None
@@ -931,7 +953,7 @@ class ConnectionWizard(dbus.service.Object):
return None
@dbus.service.method('org.wicd.daemon.config')
def DeleteWiredNetworkProfile(self,profilename):
def DeleteWiredNetworkProfile(self, profilename):
''' Deletes a wired network profile '''
profilename = profilename.encode('utf-8')
print "deleting profile for " + str(profilename)
@@ -941,12 +963,12 @@ class ConnectionWizard(dbus.service.Object):
config.remove_section(profilename)
else:
return "500: Profile does not exist"
config.write( open(self.wired_conf,"w"))
config.write(open(self.wired_conf, "w"))
return "100: Profile Deleted"
#end function DeleteWiredNetworkProfile
@dbus.service.method('org.wicd.daemon.config')
def SaveWiredNetworkProfile(self,profilename):
def SaveWiredNetworkProfile(self, profilename):
''' Writes a wired network profile to disk '''
#should include: profilename,ip,netmask,gateway,dns1,dns2
profilename = misc.to_unicode(profilename)
@@ -957,13 +979,13 @@ class ConnectionWizard(dbus.service.Object):
config.remove_section(profilename)
config.add_section(profilename)
for x in self.WiredNetwork:
config.set(profilename,x,self.WiredNetwork[x])
config.write( open(self.wired_conf,"w"))
config.set(profilename, x, self.WiredNetwork[x])
config.write(open(self.wired_conf, "w"))
return "100: Profile Written"
#end function SaveWiredNetworkProfile
@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 '''
profile = {}
profilename = misc.to_unicode(profilename)
@@ -971,7 +993,7 @@ class ConnectionWizard(dbus.service.Object):
config.read(self.wired_conf)
if config.has_section(profilename) == True:
for x in config.options(profilename):
profile[x] = misc.Noneify(config.get(profilename,x))
profile[x] = misc.Noneify(config.get(profilename, x))
profile['use_global_dns'] = bool(profile.get('use_global_dns'))
profile['use_static_dns'] = bool(profile.get('use_static_dns'))
self.WiredNetwork = profile
@@ -994,7 +1016,7 @@ class ConnectionWizard(dbus.service.Object):
#end function GetWiredProfileList
@dbus.service.method('org.wicd.daemon.config')
def SaveWirelessNetworkProfile(self,id):
def SaveWirelessNetworkProfile(self, id):
''' Writes a wireless profile to disk '''
print "setting network profile"
config = ConfigParser.ConfigParser()
@@ -1006,11 +1028,11 @@ class ConnectionWizard(dbus.service.Object):
#out which network is which. it will not be read
for x in self.LastScan[id]:
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')
def SaveWirelessNetworkProperty(self,id,option):
def SaveWirelessNetworkProperty(self, id, option):
''' Writes a particular wireless property to disk '''
if (option.strip()).endswith("script"):
print 'you cannot save script information to disk through the daemon.'
@@ -1019,12 +1041,13 @@ class ConnectionWizard(dbus.service.Object):
config = ConfigParser.ConfigParser()
config.read(self.wireless_conf)
if config.has_section(self.LastScan[id]["bssid"]):
config.set(self.LastScan[id]["bssid"],option,str(self.LastScan[id][option]))
config.write(open(self.wireless_conf,"w"))
config.set(self.LastScan[id]["bssid"], option,
str(self.LastScan[id][option]))
config.write(open(self.wireless_conf, "w"))
#end function SaveWirelessNetworkProperty
@dbus.service.method('org.wicd.daemon.config')
def ReadWirelessNetworkProfile(self,id):
def ReadWirelessNetworkProfile(self, id):
''' Reads in wireless profile as the active network '''
config = ConfigParser.ConfigParser()
config.read(self.wireless_conf)
@@ -1094,10 +1117,10 @@ class ConnectionWizard(dbus.service.Object):
# then be SURE YOU CHANGE IT #
#############################################
def __printReturn(self,text,value):
def __printReturn(self, text, value):
'''prints the specified text and value, then returns the value'''
if self.debug_mode == 1:
print text,value
print text, value
return value
#end function __printReturn
@@ -1122,7 +1145,7 @@ class ConnectionWizard(dbus.service.Object):
return ret
def ReadConfig(self):
if os.path.isfile( self.app_conf ):
if os.path.isfile(self.app_conf):
iface = self.DetectWirelessInterface()
if not iface:
iface = "wlan0"
@@ -1143,7 +1166,8 @@ class ConnectionWizard(dbus.service.Object):
dns1 = self.get_option("Settings", "global_dns_1", default='None')
dns2 = self.get_option("Settings", "global_dns_2", default='None')
dns3 = self.get_option("Settings", "global_dns_3", default='None')
self.SetGlobalDNS(dns1,dns2,dns3)
self.SetGlobalDNS(dns1, dns2, dns3)
self.SetAutoReconnect(self.get_option("Settings", "auto_reconnect",
default=False))
self.SetDebugMode(self.get_option("Settings", "debug_mode",
@@ -1174,7 +1198,7 @@ class ConnectionWizard(dbus.service.Object):
config.set("Settings", "dns3", "None")
iface = self.DetectWirelessInterface()
if iface is not None:
config.set("Settings","wireless_interface", iface)
config.set("Settings", "wireless_interface", iface)
else:
print "couldn't detect a wireless interface, using wlan0..."
config.set("Settings", "wireless_interface", "wlan0")
@@ -1194,23 +1218,23 @@ class ConnectionWizard(dbus.service.Object):
self.SetUseGlobalDNS(False)
self.SetGlobalDNS(None, None, None)
if os.path.isfile( self.wireless_conf ):
if os.path.isfile(self.wireless_conf):
print "wireless configuration file found..."
# Don't do anything since it is there
pass
else:
# We don't need to put anything in it, so just make it
print "wireless configuration file not found, creating..."
open( self.wireless_conf, "w" ).close()
open(self.wireless_conf, "w").close()
if os.path.isfile( self.wired_conf ):
if os.path.isfile(self.wired_conf):
print "wired configuration file found..."
# Don't do anything since it is there
pass
else:
print "wired configuration file not found, creating a default..."
# Create the file and a default profile
open( self.wired_conf, "w" ).close()
open(self.wired_conf, "w").close()
self.CreateWiredNetworkProfile("wired-default")
# Hide the files, so the keys aren't exposed.
@@ -1225,14 +1249,14 @@ class ConnectionWizard(dbus.service.Object):
os.chown(self.wireless_conf, 0, 0)
os.chown(self.wired_conf, 0, 0)
print "autodetected wireless interface...",self.DetectWirelessInterface()
print "using wireless interface...",self.GetWirelessInterface()[5:]
print "autodetected wireless interface...", self.DetectWirelessInterface()
print "using wireless interface...", self.GetWirelessInterface()[5:]
class ConnectionStatus():
""" Class for monitoring the computer's connection status. """
def __init__(self, connection):
"""Initialize variables needed for the connection status methods."""
""" Initialize variables needed for the connection status methods. """
self.last_strength = -2
self.still_wired = False
self.network = ''
@@ -1240,6 +1264,7 @@ class ConnectionStatus():
self.connection_lost_counter = 0
self.conn = connection
self.status_changed = False
self.state = 0
def check_for_wired_connection(self, wired_ip):
""" Checks for an active wired connection.
@@ -1255,6 +1280,7 @@ class ConnectionStatus():
conn.SetCurrentInterface(conn.GetWiredInterface())
self.still_wired = True
self.status_changed = True
self.state = misc.WIRED
return True
# Wired connection isn't active
self.still_wired = False
@@ -1306,6 +1332,7 @@ class ConnectionStatus():
self.last_strength = wifi_signal
self.status_changed = True
conn.SetCurrentInterface(conn.GetWirelessInterface())
self.state = misc.WIRELESS
return True
@@ -1323,6 +1350,7 @@ class ConnectionStatus():
print "Suspended."
return True
# Determine what our current state is.
self.iwconfig = conn.GetIwconfig()
wired_ip = conn.GetWiredIP()
wired_found = self.check_for_wired_connection(wired_ip)
@@ -1332,13 +1360,34 @@ class ConnectionStatus():
wireless_found = self.check_for_wireless_connection(wifi_ip)
if not wireless_found: # No connection at all
if not conn.CheckIfConnecting():
self.state = misc.NOT_CONNECTED
self.auto_reconnect()
else:
self.state = misc.CONNECTING
self.status_changed = True
# Set our connection state/info.
if self.state == misc.NOT_CONNECTED:
info = [""]
elif self.state == misc.CONNECTING:
if conn.CheckIfWiredConnecting():
info = ["wired"]
else:
info = ["wireless", conn.GetCurrentNetwork(self.iwconfig)]
elif self.state == misc.WIRELESS:
info = [wifi_ip, conn.GetCurrentNetwork(self.iwconfig),
str(conn.GetPrintableSignalStrength(self.iwconfig)),
str(conn.GetCurrentNetworkID(self.iwconfig))]
elif self.state == misc.WIRED:
info = [wired_ip]
else:
print 'ERROR: Invalid state!'
return True
conn.SetConnectionStatus(self.state, info)
# Send a D-Bus signal announcing status has changed if necessary.
if self.status_changed:
conn.StatusChanged()
conn.StatusChanged(self.state, info)
self.status_changed = False
return True

View File

@@ -380,4 +380,397 @@
</widget>
</child>
</widget>
<widget class="GtkDialog" id="pref_dialog">
<property name="width_request">465</property>
<property name="height_request">525</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Wicd Preferences</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">5</property>
<child>
<widget class="GtkHBox" id="hbox_wpa">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="pref_driver_label">
<property name="width_request">75</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">WPA Supplicant Driver:</property>
</widget>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">1</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox11">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="pref_wifi_label">
<property name="width_request">260</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Wireless Interface:</property>
</widget>
</child>
<child>
<widget class="GtkEntry" id="pref_wifi_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox12">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="pref_wired_label">
<property name="width_request">260</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Wired Interface:</property>
</widget>
</child>
<child>
<widget class="GtkEntry" id="pref_wired_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="pref_global_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Use global DNS servers</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox13">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="pref_dns1_label">
<property name="width_request">170</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">DNS 1</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="pref_dns1_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox14">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="pref_dns2_label">
<property name="width_request">170</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">DNS 2</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="pref_dns2_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">6</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox15">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="pref_dns3_label">
<property name="width_request">170</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">DNS 3</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="pref_dns3_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">7</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="pref_always_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Always show wired interface</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">8</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="pref_auto_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Automatically reconnect on connection loss</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">9</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="pref_debug_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Enable Debug Mode</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">10</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="pref_dbm_check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Use dBm to measure signal strength</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">11</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator3">
<property name="width_request">2</property>
<property name="height_request">8</property>
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">12</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="pref_wired_auto_label">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Wired Autoconnect Setting:</property>
<property name="single_line_mode">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">13</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="pref_use_def_radio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Use default profile on wired autoconnect</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">14</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="pref_prompt_radio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Prompt for profile on wired autoconnect</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">pref_use_def_radio</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">15</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="pref_use_last_radio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Use last profile on wired autoconnect</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">pref_use_def_radio</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">16</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">1</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="button6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">2</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

281
gui.py
View File

@@ -1,5 +1,12 @@
#!/usr/bin/python
""" Wicd GUI module.
Module containg all the code (other than the tray icon) related to the
Wicd user interface.
"""
#
# Copyright (C) 2007 Adam Blackburn
# Copyright (C) 2007 Dan O'Reilly
@@ -667,7 +674,8 @@ class WiredNetworkEntry(NetworkEntry):
print 'unsetting previous default profile...'
# Make sure there is only one default profile at a time
config.UnsetWiredDefault()
wired.SetWiredProperty("default",self.checkboxDefaultProfile.get_active())
wired.SetWiredProperty("default",
self.checkboxDefaultProfile.get_active())
config.SaveWiredNetworkProfile(self.comboProfileNames.get_active_text())
def changeProfile(self,widget):
@@ -940,10 +948,8 @@ class appGui:
probar = self.wTree.get_widget("progressbar")
probar.set_text(language['connecting'])
# self.entry.set_visibility(False)
# probar.set_visiblity(False)
self.window = self.wTree.get_widget("window1")
self.window = self.wTree.get_widget("window1")
self.network_list = self.wTree.get_widget("network_list_vbox")
self.status_area = self.wTree.get_widget("connecting_hbox")
self.status_bar = self.wTree.get_widget("statusbar")
@@ -952,7 +958,7 @@ class appGui:
self.status_area.hide_all()
self.statusID = None
self.first_dialog_load = False
self.vpn_connection_pipe = None
self.is_visible = True
@@ -986,7 +992,8 @@ class appGui:
useICSCheckbox = gtk.CheckButton(language['use_ics'])
self.useEncryptionCheckbox.connect("toggled",self.toggleEncryptionCheck)
self.useEncryptionCheckbox.connect("toggled",
self.toggleEncryptionCheck)
channelEntry.entry.set_text('3')
essidEntry.entry.set_text('My_Adhoc_Network')
ipEntry.entry.set_text('169.254.12.10') #Just a random IP
@@ -1032,123 +1039,115 @@ class appGui:
def settings_dialog(self,widget,event=None):
""" Displays a general settings dialog. """
dialog = gtk.Dialog(title=language['preferences'],
flags=gtk.DIALOG_MODAL,
buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2))
dialog.set_has_separator(False)
dialog.set_size_request(465,-1)
wiredcheckbox = gtk.CheckButton(language['wired_always_on'])
dialog = self.wTree.get_widget("pref_dialog")
dialog.set_title(language['preferences'])
wiredcheckbox = self.wTree.get_widget("pref_always_check")
wiredcheckbox.set_label(language['wired_always_on'])
wiredcheckbox.set_active(wired.GetAlwaysShowWiredInterface())
reconnectcheckbox = gtk.CheckButton(language['auto_reconnect'])
reconnectcheckbox = self.wTree.get_widget("pref_auto_check")
reconnectcheckbox.set_label(language['auto_reconnect'])
reconnectcheckbox.set_active(daemon.GetAutoReconnect())
debugmodecheckbox = gtk.CheckButton(language['use_debug_mode'])
debugmodecheckbox = self.wTree.get_widget("pref_debug_check")
debugmodecheckbox.set_label(language['use_debug_mode'])
debugmodecheckbox.set_active(daemon.GetDebugMode())
displaytypecheckbox = gtk.CheckButton(language['display_type_dialog'])
displaytypecheckbox = self.wTree.get_widget("pref_dbm_check")
displaytypecheckbox.set_label(language['display_type_dialog'])
displaytypecheckbox.set_active(daemon.GetSignalDisplayType())
sepline = gtk.HSeparator()
usedefaultradiobutton = gtk.RadioButton(None,
language['use_default_profile'],
False)
showlistradiobutton = gtk.RadioButton(usedefaultradiobutton,
language['show_wired_list'],
False)
lastusedradiobutton = gtk.RadioButton(usedefaultradiobutton,
language['use_last_used_profile'],
False)
entryWiredAutoMethod = self.wTree.get_widget("pref_wired_auto_label")
entryWiredAutoMethod.set_label('Wired Autoconnect Setting:')
usedefaultradiobutton = self.wTree.get_widget("pref_use_def_radio")
usedefaultradiobutton.set_label(language['use_default_profile'])
showlistradiobutton = self.wTree.get_widget("pref_prompt_radio")
showlistradiobutton.set_label(language['show_wired_list'])
lastusedradiobutton = self.wTree.get_widget("pref_use_last_radio")
lastusedradiobutton.set_label(language['use_last_used_profile'])
if wired.GetWiredAutoConnectMethod() == 1:
usedefaultradiobutton.set_active(True)
print 'use default profile'
elif wired.GetWiredAutoConnectMethod() == 2:
print 'show list'
showlistradiobutton.set_active(True)
elif wired.GetWiredAutoConnectMethod() == 3:
print 'use last used profile'
lastusedradiobutton.set_active(True)
wpadriverlabel = SmallLabel(language['wpa_supplicant_driver'] + ':')
wpadriverlabel.set_size_request(75,-1)
self.set_label("pref_driver_label", language['wpa_supplicant_driver'] +
':')
# Hack to get the combo box we need, which you can't do with glade.
if not self.first_dialog_load:
self.first_dialog_load = True
wpa_hbox = self.wTree.get_widget("hbox_wpa")
wpadrivercombo = gtk.combo_box_new_text()
wpadrivercombo.set_size_request(50,-1)
wpadrivers = ["hostap","hermes","madwifi","atmel","wext","ndiswrapper",
"broadcom","ipw","ralink legacy"]
wpa_hbox.pack_end(wpadrivercombo)
wpadrivers = ["hostap", "hermes", "madwifi", "atmel", "wext",
"ndiswrapper", "broadcom", "ipw", "ralink legacy"]
i = 0
found = False
for x in wpadrivers:
if x == daemon.GetWPADriver() and found == False:
if x == daemon.GetWPADriver() and not found:
found = True
else:
if found == False:
elif not found:
i+=1
wpadrivercombo.append_text(x)
# Set active here.
# If we set active an item to active, then add more items
# it loses the activeness.
# Set the active choice here. Doing it before all the items are
# added the combobox causes the choice to be reset.
wpadrivercombo.set_active(i)
# Select wext as the default driver, because it works for most cards
wpabox = gtk.HBox(False,1)
wpabox.pack_start(wpadriverlabel)
wpabox.pack_start(wpadrivercombo)
if not found:
# Use wext as default, since normally it is the correct driver.
wpadrivercombo.set_active(4)
entryWirelessInterface = LabelEntry(language['wireless_interface'] + ':')
entryWiredInterface = LabelEntry(language['wired_interface'] + ':')
entryWirelessInterface.label.set_size_request(260,-1)
entryWiredInterface.label.set_size_request(260,-1)
entryWiredAutoMethod = gtk.Label('Wired Autoconnect Setting:')
self.set_label("pref_wifi_label", language['wireless_interface'] + ':')
self.set_label("pref_wired_label", language['wired_interface'] + ':')
entryWirelessInterface.entry.set_text(daemon.GetWirelessInterface())
entryWiredInterface.entry.set_text(daemon.GetWiredInterface())
entryWirelessInterface = self.wTree.get_widget("pref_wifi_entry")
entryWirelessInterface.set_text(daemon.GetWirelessInterface())
useGlobalDNSCheckbox = gtk.CheckButton(language['use_global_dns'])
dns1Entry = LabelEntry(language['dns'] + ' ' + language['1'])
dns2Entry = LabelEntry(language['dns'] + ' ' + language['2'])
dns3Entry = LabelEntry(language['dns'] + ' ' + language['3'])
entryWiredInterface = self.wTree.get_widget("pref_wired_entry")
entryWiredInterface.set_text(daemon.GetWiredInterface())
# Set up global DNS stuff
useGlobalDNSCheckbox = self.wTree.get_widget("pref_global_check")
useGlobalDNSCheckbox.set_label(language['use_global_dns'])
dns1Entry = self.wTree.get_widget("pref_dns1_entry")
dns2Entry = self.wTree.get_widget("pref_dns2_entry")
dns3Entry = self.wTree.get_widget("pref_dns3_entry")
self.set_label("pref_dns1_label", language['dns'] + ' ' + language['1'])
self.set_label("pref_dns2_label", language['dns'] + ' ' + language['2'])
self.set_label("pref_dns3_label", language['dns'] + ' ' + language['3'])
useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
(dns1Entry, dns2Entry, dns3Entry))
dns_addresses = daemon.GetGlobalDNSAddresses()
useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
dns1Entry.set_text(noneToBlankString(dns_addresses[0]))
dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
if not daemon.GetUseGlobalDNS():
dns1Entry.set_sensitive(False)
dns2Entry.set_sensitive(False)
dns3Entry.set_sensitive(False)
# Bold/Align the Wired Autoconnect label.
entryWiredAutoMethod.set_alignment(0,0)
sepline.set_size_request(2,8)
atrlist = pango.AttrList()
atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD,0,50))
entryWiredAutoMethod.set_attributes(atrlist)
dialog.vbox.pack_start(wpabox)
dialog.vbox.pack_start(entryWirelessInterface)
dialog.vbox.pack_start(entryWiredInterface)
dialog.vbox.pack_start(useGlobalDNSCheckbox)
dialog.vbox.pack_start(dns1Entry)
dialog.vbox.pack_start(dns2Entry)
dialog.vbox.pack_start(dns3Entry)
dialog.vbox.pack_start(wiredcheckbox)
dialog.vbox.pack_start(reconnectcheckbox)
dialog.vbox.pack_start(debugmodecheckbox)
dialog.vbox.pack_start(displaytypecheckbox)
dialog.vbox.pack_start(sepline)
dialog.vbox.pack_start(entryWiredAutoMethod)
dialog.vbox.pack_start(usedefaultradiobutton)
dialog.vbox.pack_start(showlistradiobutton)
dialog.vbox.pack_start(lastusedradiobutton)
dialog.vbox.set_spacing(5)
dialog.show_all()
response = dialog.run()
if response == 1:
daemon.SetUseGlobalDNS(useGlobalDNSCheckbox.get_active())
daemon.SetGlobalDNS(dns1Entry.get_text(),dns2Entry.get_text(),dns3Entry.get_text())
daemon.SetWirelessInterface(entryWirelessInterface.entry.get_text())
daemon.SetWiredInterface(entryWiredInterface.entry.get_text())
daemon.SetGlobalDNS(dns1Entry.get_text(), dns2Entry.get_text(),
dns3Entry.get_text())
daemon.SetWirelessInterface(entryWirelessInterface.get_text())
daemon.SetWiredInterface(entryWiredInterface.get_text())
print "setting: " + wpadrivers[wpadrivercombo.get_active()]
daemon.SetWPADriver(wpadrivers[wpadrivercombo.get_active()])
wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active())
@@ -1161,10 +1160,11 @@ class appGui:
wired.SetWiredAutoConnectMethod(3)
else:
wired.SetWiredAutoConnectMethod(1)
dialog.hide()
dialog.destroy()
else:
dialog.destroy()
def set_label(self, glade_str, label):
""" Sets the label for the given widget in wicd.glade. """
self.wTree.get_widget(glade_str).set_label(label)
def connect_hidden(self,widget):
""" Prompts the user for a hidden network, then scans for it. """
@@ -1199,6 +1199,8 @@ class appGui:
def pulse_progress_bar(self):
""" Pulses the progress bar while connecting to a network. """
if not self.is_visible:
return True
try:
self.wTree.get_widget("progressbar").pulse()
except:
@@ -1207,9 +1209,9 @@ class appGui:
def update_statusbar(self):
""" Updates the status bar. """
# Update the status bar every couple hundred milliseconds.
if self.is_visible == False:
return True
iwconfig = wireless.GetIwconfig()
wireless_ip = wireless.GetWirelessIP()
wiredConnecting = wired.CheckIfWiredConnecting()
@@ -1219,51 +1221,69 @@ class appGui:
self.network_list.set_sensitive(False)
self.status_area.show_all()
if self.statusID:
self.status_bar.remove(1,self.statusID)
self.status_bar.remove(1, self.statusID)
if wirelessConnecting:
self.set_status(wireless.GetCurrentNetwork(iwconfig) + ': ' +
language[str(wireless.CheckWirelessConnectingMessage())])
language[str(wireless.CheckWirelessConnectingMessage())])
if wiredConnecting:
self.set_status(language['wired_network'] + ': ' +
language[str(wired.CheckWiredConnectingMessage())])
language[str(wired.CheckWiredConnectingMessage())])
else:
self.network_list.set_sensitive(True)
self.status_area.hide_all()
if self.statusID:
self.status_bar.remove(1,self.statusID)
#use the chain approach to save calls to external programs
#external programs are quite CPU intensive
if wireless_ip:
network = wireless.GetCurrentNetwork(iwconfig)
if network:
strength = wireless.GetCurrentSignalStrength(iwconfig)
dbm_strength = wireless.GetCurrentDBMStrength(iwconfig)
if strength is not None and dbm_strength is not None:
network = str(network)
if daemon.GetSignalDisplayType() == 0:
strength = str(strength)
else:
strength = str(dbm_strength)
ip = str(wireless_ip)
self.set_status(language['connected_to_wireless'].replace
('$A',network).replace
('$B',daemon.FormatSignalForPrinting(strength)).replace
('$C',wireless_ip))
return True
wired_ip = wired.GetWiredIP()
if wired_ip:
if wired.CheckPluggedIn():
self.set_status(language['connected_to_wired'].replace('$A',
wired_ip))
self.status_bar.remove(1, self.statusID)
# Determine connection status.
if self.check_for_wireless(iwconfig, wireless_ip):
return True
wired_ip = wired.GetWiredIP()
if self.check_for_wired(wired_ip):
return True
self.set_status(language['not_connected'])
return True
def check_for_wired(self, wired_ip):
""" Determine if wired is active, and if yes, set the status. """
if wired_ip and wired.CheckPluggedIn():
self.set_status(language['connected_to_wired'].replace('$A',
wired_ip))
return True
else:
return False
def check_for_wireless(self, iwconfig, wireless_ip):
""" Determine if wireless is active, and if yes, set the status. """
if not wireless_ip:
return False
network = wireless.GetCurrentNetwork(iwconfig)
if not network:
return False
strength = wireless.GetCurrentSignalStrength(iwconfig)
dbm_strength = wireless.GetCurrentDBMStrength(iwconfig)
if strength is not None and dbm_strength is not None:
network = str(network)
if daemon.GetSignalDisplayType() == 0:
strength = str(strength)
else:
strength = str(dbm_strength)
ip = str(wireless_ip)
self.set_status(language['connected_to_wireless'].replace
('$A', network).replace
('$B', daemon.FormatSignalForPrinting(strength)).replace
('$C', wireless_ip))
return True
return False
def set_status(self, msg):
""" Sets the status bar message for the GUI. """
self.statusID = self.status_bar.push(1, msg)
def refresh_networks(self,widget=None,fresh=True,hidden=None):
def refresh_networks(self, widget=None, fresh=True, hidden=None):
""" Refreshes the network list.
If fresh=True, scans for wireless networks and displays the results.
@@ -1300,7 +1320,7 @@ class appGui:
instructLabel = self.wTree.get_widget("label_instructions")
if num_networks > 0:
instructLabel.show()
for x in range(0,num_networks):
for x in range(0, num_networks):
if printLine:
sep = gtk.HSeparator()
self.network_list.pack_start(sep, padding=10, expand=False,
@@ -1312,7 +1332,7 @@ class appGui:
tempnet.show_all()
self.network_list.pack_start(tempnet, expand=False, fill=False)
tempnet.connectButton.connect("button-press-event",
self.connect, "wireless", x,
self.connect, "wireless", x,
tempnet)
tempnet.expander.advancedButton.connect("button-press-event",
self.edit_advanced,
@@ -1322,7 +1342,7 @@ class appGui:
if wireless.GetKillSwitchEnabled():
label = gtk.Label(language['killswitch_enabled'] + ".")
else:
label = gtk.Label(language['no_wireless_networks_found'])
label = gtk.Label(language['no_wireless_networks_found'])
self.network_list.pack_start(label)
label.show()
@@ -1363,15 +1383,15 @@ class appGui:
wireless.SetWirelessProperty(networkid, "gateway",
noneToString(entry.txtGateway.get_text()))
else:
#blank the values
wireless.SetWirelessProperty(networkid,"ip",'')
wireless.SetWirelessProperty(networkid,"netmask",'')
wireless.SetWirelessProperty(networkid,"gateway",'')
# Blank the values
wireless.SetWirelessProperty(networkid, "ip", '')
wireless.SetWirelessProperty(networkid, "netmask", '')
wireless.SetWirelessProperty(networkid, "gateway", '')
if entry.checkboxStaticDNS.get_active() and \
not entry.checkboxGlobalDNS.get_active():
wireless.SetWirelessProperty(networkid,'use_static_dns',True)
wireless.SetWirelessProperty(networkid,'use_global_dns',False)
wireless.SetWirelessProperty(networkid, 'use_static_dns', True)
wireless.SetWirelessProperty(networkid, 'use_global_dns', False)
wireless.SetWirelessProperty(networkid, 'dns1',
noneToString(entry.txtDNS1.get_text()))
wireless.SetWirelessProperty(networkid, 'dns2',
@@ -1380,8 +1400,8 @@ class appGui:
noneToString(entry.txtDNS3.get_text()))
elif entry.checkboxStaticDNS.get_active() and \
entry.checkboxGlobalDNS.get_active():
wireless.SetWirelessProperty(networkid,'use_static_dns',True)
wireless.SetWirelessProperty(networkid,'use_global_dns',True)
wireless.SetWirelessProperty(networkid, 'use_static_dns', True)
wireless.SetWirelessProperty(networkid, 'use_global_dns', True)
else:
wireless.SetWirelessProperty(networkid, 'use_static_dns', False)
wireless.SetWirelessProperty(networkid, 'use_global_dns', False)
@@ -1397,7 +1417,7 @@ class appGui:
encrypt_methods[entry.comboEncryption.
get_active()][1])
for x in encryptionInfo:
wireless.SetWirelessProperty(networkid,x,
wireless.SetWirelessProperty(networkid, x,
noneToString(encryptionInfo[x].get_text()))
else:
print "no encryption specified..."
@@ -1411,9 +1431,9 @@ class appGui:
wired.SetWiredProperty("netmask", noneToString(entry.txtNetmask.get_text()))
wired.SetWiredProperty("gateway", noneToString(entry.txtGateway.get_text()))
else:
wired.SetWiredProperty("ip",'')
wired.SetWiredProperty("netmask",'')
wired.SetWiredProperty("gateway",'')
wired.SetWiredProperty("ip", '')
wired.SetWiredProperty("netmask", '')
wired.SetWiredProperty("gateway", '')
if entry.checkboxStaticDNS.get_active() and \
not entry.checkboxGlobalDNS.get_active():
@@ -1428,9 +1448,9 @@ class appGui:
wireless.SetWiredProperty('use_global_dns', True)
else:
wired.SetWiredProperty('use_static_dns', False)
wired.SetWiredProperty("dns1",'')
wired.SetWiredProperty("dns2",'')
wired.SetWiredProperty("dns3",'')
wired.SetWiredProperty("dns1", '')
wired.SetWiredProperty("dns2", '')
wired.SetWiredProperty("dns3", '')
config.SaveWiredNetworkProfile(entry.comboProfileNames.get_active_text())
return True
@@ -1473,6 +1493,7 @@ class appGui:
return True
def connect(self, widget, event, type, networkid, networkentry):
""" Initiates the connection process in the daemon. """
cancelButton = self.wTree.get_widget("cancel_button")
cancelButton.set_sensitive(True)

15
misc.py
View File

@@ -1,7 +1,7 @@
""" Misc - miscellaneous functions for wicd """
#
# Copyright (C) 2007 Adam Blackburn
# Copyright (C) 2007 Adam Blackburn
# Copyright (C) 2007 Dan O'Reilly
#
# This program is free software; you can redistribute it and/or modify
@@ -29,6 +29,11 @@ from subprocess import *
if __name__ == '__main__':
wpath.chdir(__file__)
NOT_CONNECTED = 0
CONNECTING = 1
WIRELESS = 2
WIRED = 3
def Run(cmd, include_stderr=False, return_pipe=False):
""" Run a command.
@@ -69,7 +74,7 @@ def IsValidIP(ip):
for number in ipNumbers:
if not number.isdigit() or int(number) > 255:
return False
return ipNumbers
return ipNumbers
return False
def PromptToStartDaemon():
@@ -232,7 +237,8 @@ def get_gettext():
# Translation stuff
# borrowed from an excellent post on how to do this on
# http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/
local_path = os.path.realpath(os.path.dirname(sys.argv[0])) + '/translations'
local_path = os.path.realpath(os.path.dirname(sys.argv[0])) + \
'/translations'
langs = []
lc, encoding = locale.getdefaultlocale()
if (lc):
@@ -242,7 +248,7 @@ def get_gettext():
langs += osLanguage.split(":")
langs += ["en_US"]
lang = gettext.translation('wicd', local_path, languages=langs,
fallback = True)
fallback=True)
_ = lang.gettext
return _
@@ -252,6 +258,7 @@ def to_unicode(x):
try: # This may never fail, but let's be safe
default_encoding = locale.getpreferredencoding()
except:
print 'Could not get default encoding'
default_encoding = None
if default_encoding:

76
wicd.py
View File

@@ -90,7 +90,7 @@ except Exception:
print 'Success.'
except:
print 'Failed to start daemon. Aborting.'
sys.exit(1)
sys.exit(1)
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
@@ -138,52 +138,46 @@ class TrayIcon():
gui.WiredProfileChooser()
daemon.SetNeedWiredProfileChooser(False)
def update_tray_icon(self):
def update_tray_icon(self, state=None, info=None):
"""Updates the tray icon and current connection status"""
if self.use_tray == False: return False
iwconfig = wireless.GetIwconfig()
# If we're currently connecting, we can shortcut all other checks
if daemon.CheckIfConnecting():
if wireless.CheckIfWirelessConnecting():
cur_network = wireless.GetCurrentNetwork(iwconfig)
else:
cur_network = language['wired']
self.tr.set_tooltip(language['connecting'] + " to " +
cur_network + "...")
self.tr.set_from_file(wpath.images + "no-signal.png")
return True
if not state or not info:
[state, info] = daemon.GetConnectionStatus()
cur_iface = daemon.GetCurrentInterface()
wifi_iface = daemon.GetWirelessInterface()
wire_iface = daemon.GetWiredInterface()
# Check for a wired connection
if cur_iface == wire_iface:
wired_ip = wired.GetWiredIP()
if state == misc.WIRED:
wired_ip = info[0]
self.tr.set_from_file(wpath.images + "wired.png")
self.tr.set_tooltip(language['connected_to_wired'].
replace('$A',
wired_ip))
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
wired_ip))
# Check for a wireless connection
elif cur_iface == wifi_iface:
cur_net_id = wireless.GetCurrentNetworkID(iwconfig)
elif state == misc.WIRELESS:
lock = ''
wireless_ip = info[0]
self.network = info[1]
strength = info[2]
cur_net_id = int(info[3])
sig_string = daemon.FormatSignalForPrinting(str(strength))
if wireless.GetWirelessProperty(cur_net_id, "encryption"):
lock = "-lock"
strength = wireless.GetPrintableSignalStrength(iwconfig)
self.network = str(wireless.GetCurrentNetwork(iwconfig))
sig_string = daemon.FormatSignalForPrinting(str(strength))
wireless_ip = wireless.GetWirelessIP()
self.tr.set_tooltip(language['connected_to_wireless']
.replace('$A', self.network)
.replace('$B', sig_string)
.replace('$C', str(wireless_ip)))
self.set_signal_image(strength, lock)
# If we made it here, we don't have a connection
else:
elif state == misc.CONNECTING:
if info[0] == 'wired' and len(info) == 1:
cur_network = language['wired']
else:
cur_network = info[1]
self.tr.set_tooltip(language['connecting'] + " to " +
cur_network + "...")
self.tr.set_from_file(wpath.images + "no-signal.png")
elif state == misc.NOT_CONNECTED:
self.tr.set_from_file(wpath.images + "no-signal.png")
if wireless.GetKillSwitchEnabled():
status = (language['not_connected'] + " (" +
@@ -191,6 +185,9 @@ class TrayIcon():
else:
status = language['not_connected']
self.tr.set_tooltip(status)
else:
print 'Invalid state returned!!!'
return False
return True
@@ -254,7 +251,7 @@ class TrayIcon():
self.manager.insert_action_group(actg, 0)
self.manager.add_ui_from_string(menu)
self.menu = (self.manager.get_widget('/Menubar/Menu/About').
props.parent)
props.parent)
self.gui_win = None
self.current_icon_path = None
self.use_tray = use_tray
@@ -281,13 +278,6 @@ class TrayIcon():
dialog.run()
dialog.destroy()
def set_from_file(self, path = None):
"""Sets a new tray icon picture"""
if not self.use_tray: return
if path != self.current_icon_path:
self.current_icon_path = path
gtk.StatusIcon.set_from_file(self, path)
def toggle_wicd_gui(self):
"""Toggles the wicd GUI"""
if self.gui_win == None:
@@ -332,7 +322,7 @@ class TrayIcon():
if event.button == 3:
self.menu.popup(None, None, None, event.button, event.time)
def set_from_file(self, val):
def set_from_file(self, val=None):
"""Calls set_from_file on the gtk.Image for the tray icon"""
if not self.use_tray: return
self.pic.set_from_file(val)
@@ -371,9 +361,9 @@ class TrayIcon():
self.set_from_file(wpath.images + "no-signal.png")
self.set_tooltip("Initializing wicd...")
def on_popup_menu(self, status, button, time):
def on_popup_menu(self, status, button, timestamp):
"""Opens the right click menu for the tray icon"""
self.menu.popup(None, None, None, button, time)
self.menu.popup(None, None, None, button, timestamp)
def set_from_file(self, path = None):
"""Sets a new tray icon picture"""

View File

@@ -48,7 +48,7 @@ altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)', re.I | re.M | re
signaldbm_pattern = re.compile('.*Signal level:?=? ?(-\d\d*)', re.I | re.M | re.S)
mode_pattern = re.compile('.*Mode:(.*?)\n', re.I | re.M | re.S)
freq_pattern = re.compile('.*Frequency:(.*?)\n', re.I | re.M | re.S)
ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)',re.S)
ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)', re.S)
wep_pattern = re.compile('.*Encryption key:(.*?)\n', re.I | re.M | re.S)
altwpa_pattern = re.compile('(wpa_ie)', re.I | re.M | re.S)
@@ -238,7 +238,7 @@ class Interface(object):
cmd = 'ifconfig ' + self.iface
#if self.verbose: print cmd
output = misc.Run(cmd)
return misc.RunRegex(ip_pattern,output)
return misc.RunRegex(ip_pattern, output)
class WiredInterface(Interface):
@@ -292,7 +292,7 @@ class WiredInterface(Interface):
if line.strip().startswith('UP'):
return True
return False
return False
class WirelessInterface(Interface):
@@ -440,7 +440,7 @@ class WirelessInterface(Interface):
ap['essid'] = misc.RunRegex(essid_pattern, cell)
try:
ap['essid'] = misc.to_unicode(ap['essid'])
except UnicodeDecodeError, UnicodeEncodeError:
except (UnicodeDecodeError, UnicodeEncodeError):
print 'Unicode problem with current network essid, ignoring!!'
return None
if ap['essid'] == '<hidden>':
@@ -470,13 +470,13 @@ class WirelessInterface(Interface):
ap['encryption'] = True
ap['encryption_method'] = 'WEP'
if misc.RunRegex(wpa1_pattern,cell) == 'WPA Version 1':
if misc.RunRegex(wpa1_pattern, cell) == 'WPA Version 1':
ap['encryption_method'] = 'WPA'
if misc.RunRegex(altwpa_pattern,cell) == 'wpa_ie':
if misc.RunRegex(altwpa_pattern, cell) == 'wpa_ie':
ap['encryption_method'] = 'WPA'
if misc.RunRegex(wpa2_pattern,cell) == 'WPA2':
if misc.RunRegex(wpa2_pattern, cell) == 'WPA2':
ap['encryption_method'] = 'WPA2'
else:
ap['encryption'] = False
@@ -493,7 +493,7 @@ class WirelessInterface(Interface):
else:
ap["quality"] = int(strength)
elif misc.RunRegex(altstrength_pattern,cell):
ap['quality'] = misc.RunRegex(altstrength_pattern,cell)
ap['quality'] = misc.RunRegex(altstrength_pattern, cell)
else:
ap['quality'] = -1
@@ -636,7 +636,7 @@ class WirelessInterface(Interface):
result = misc.RunRegex(auth_pattern, output)
if result == "COMPLETED":
return True
elif result =="DISCONNECTED":
elif result == "DISCONNECTED":
# Force a rescan to get wpa_supplicant moving again.
self._ForceSupplicantScan()
return self.ValidateAuthentication()
@@ -726,9 +726,9 @@ class WirelessInterface(Interface):
"""
if not iwconfig:
cmd = 'iwconfig ' + self.iface
# if self.verbose: print cmd
output = misc.Run(cmd)
cmd = 'iwconfig ' + self.iface
# if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
# implemented the patch provided in
@@ -743,7 +743,7 @@ class WirelessInterface(Interface):
return 100 * int(strength) / int(max_strength)
if strength == None:
strength = misc.RunRegex(altstrength_pattern,output)
strength = misc.RunRegex(altstrength_pattern, output)
return strength
@@ -755,12 +755,12 @@ class WirelessInterface(Interface):
"""
if iwconfig:
cmd = 'iwconfig ' + self.iface
# if self.verbose: print cmd
output = misc.Run(cmd)
cmd = 'iwconfig ' + self.iface
# if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
dbm_strength = misc.RunRegex(signaldbm_pattern,output)
dbm_strength = misc.RunRegex(signaldbm_pattern, output)
return dbm_strength
@@ -772,9 +772,9 @@ class WirelessInterface(Interface):
"""
if not iwconfig:
cmd = 'iwconfig ' + self.iface
# if self.verbose: print cmd
output = misc.Run(cmd)
cmd = 'iwconfig ' + self.iface
# if self.verbose: print cmd
output = misc.Run(cmd)
else:
output = iwconfig
network = misc.RunRegex(re.compile('.*ESSID:"(.*?)"',