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

147
daemon.py
View File

@@ -144,6 +144,8 @@ class ConnectionWizard(dbus.service.Object):
self.vpn_session = None self.vpn_session = None
self.gui_open = False self.gui_open = False
self.suspended = False self.suspended = False
self.connection_state = 0
self.connection_info = [""]
# Load the config file # Load the config file
self.ReadConfig() self.ReadConfig()
@@ -339,6 +341,9 @@ class ConnectionWizard(dbus.service.Object):
def SetSuspend(self, val): def SetSuspend(self, val):
""" Toggles whether or not monitoring connection status is suspended """ """ Toggles whether or not monitoring connection status is suspended """
self.suspended = val self.suspended = val
if self.suspended:
self.Disconnect()
@dbus.service. method('org.wicd.daemon') @dbus.service. method('org.wicd.daemon')
def AutoConnect(self, fresh): def AutoConnect(self, fresh):
@@ -353,7 +358,7 @@ class ConnectionWizard(dbus.service.Object):
if self.GetWiredAutoConnectMethod() == 2 and \ if self.GetWiredAutoConnectMethod() == 2 and \
not self.GetNeedWiredProfileChooser(): not self.GetNeedWiredProfileChooser():
self.LaunchChooser() self.LaunchChooser()
elif not self.GetWiredAutoConnectMethod != 2: elif self.GetWiredAutoConnectMethod != 2:
defaultNetwork = self.GetDefaultWiredNetwork() defaultNetwork = self.GetDefaultWiredNetwork()
if defaultNetwork != None: if defaultNetwork != None:
self.ReadWiredNetworkProfile(defaultNetwork) self.ReadWiredNetworkProfile(defaultNetwork)
@@ -383,7 +388,8 @@ class ConnectionWizard(dbus.service.Object):
def GetAutoReconnect(self): def GetAutoReconnect(self):
'''returns if wicd should automatically try to reconnect is connection is lost''' '''returns if wicd should automatically try to reconnect is connection is lost'''
do = bool(self.auto_reconnect) 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 #end function GetAutoReconnect
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
@@ -487,19 +493,60 @@ class ConnectionWizard(dbus.service.Object):
""" Sets the value of gui_open. """ """ Sets the value of gui_open. """
self.gui_open = bool(val) 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') @dbus.service.method('org.wicd.daemon')
def GetNeedWiredProfileChooser(self): 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) return bool(self.need_profile_chooser)
#end function GetNeedWiredProfileChooser #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):
""" Emits the wired profile chooser dbus signal. """
print 'calling wired profile chooser' print 'calling wired profile chooser'
self.SetNeedWiredProfileChooser(True) self.SetNeedWiredProfileChooser(True)
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='') @dbus.service.signal(dbus_interface='org.wicd.daemon', signature='uav')
def StatusChanged(self): def StatusChanged(self, state, info):
""" Called when the current connection status has changed """ """ Emits a "status changed" dbus signal.
This D-Bus signal is emitted when the connection status changes.
"""
pass pass
########## WIRELESS FUNCTIONS ########## WIRELESS FUNCTIONS
@@ -522,38 +569,6 @@ class ConnectionWizard(dbus.service.Object):
for i, network in enumerate(scan): for i, network in enumerate(scan):
self.ReadWirelessNetworkProfile(i) 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') @dbus.service.method('org.wicd.daemon.wireless')
def GetIwconfig(self): def GetIwconfig(self):
""" Calls and returns the output of iwconfig""" """ Calls and returns the output of iwconfig"""
@@ -567,10 +582,12 @@ class ConnectionWizard(dbus.service.Object):
#end function GetNumberOfNetworks #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,ics): def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused,
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,ics) self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused,
ics)
#end function CreateAdHocNetwork #end function CreateAdHocNetwork
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
@@ -600,10 +617,11 @@ class ConnectionWizard(dbus.service.Object):
#simple - set the value of the item in our current data #simple - set the value of the item in our current data
#to the value the client asked for #to the value the client asked for
if (property.strip()).endswith("script"): if (property.strip()).endswith("script"):
print "Setting script properties through the daemon \ print "Setting script properties through the daemon is not \
is not permitted." permitted."
return False return False
print 'setting wireless network',networkid,'property',property,'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
@@ -628,7 +646,7 @@ class ConnectionWizard(dbus.service.Object):
if self.GetSignalDisplayType() == 0: if self.GetSignalDisplayType() == 0:
return self.GetCurrentSignalStrength(iwconfig) return self.GetCurrentSignalStrength(iwconfig)
else: else:
return GetCurrentDBMStrength(iwconfig) return self.GetCurrentDBMStrength(iwconfig)
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def GetCurrentSignalStrength(self, iwconfig=None): def GetCurrentSignalStrength(self, iwconfig=None):
@@ -676,7 +694,8 @@ class ConnectionWizard(dbus.service.Object):
self.SetForcedDisconnect(False) self.SetForcedDisconnect(False)
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript') self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript') self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
self.wifi.disconnect_script = self.GetWirelessProperty(id,'disconnectscript') self.wifi.disconnect_script = self.GetWirelessProperty(id,
'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 #end function Connect
@@ -791,10 +810,11 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetWiredProperty(self, property): def GetWiredProperty(self, property):
""" Returns the requested wired property. """
if self.WiredNetwork: if self.WiredNetwork:
value = self.WiredNetwork.get(property) value = self.WiredNetwork.get(property)
if self.debug_mode == 1: 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 return value
else: else:
print 'WiredNetwork does not exist' print 'WiredNetwork does not exist'
@@ -806,7 +826,8 @@ class ConnectionWizard(dbus.service.Object):
print 'Setting always show wired interface' print 'Setting always show wired interface'
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.app_conf) config.read(self.app_conf)
config.set("Settings","always_show_wired_interface",misc.to_bool(value)) config.set("Settings", "always_show_wired_interface",
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 #end function SetAlwaysShowWiredInterface
@@ -820,7 +841,8 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CheckPluggedIn(self): def CheckPluggedIn(self):
if self.wired.wired_interface and self.wired.wired_interface != "None": if self.wired.wired_interface and self.wired.wired_interface != "None":
return self.__printReturn('returning plugged in',self.wired.CheckPluggedIn()) return self.__printReturn('returning plugged in',
self.wired.CheckPluggedIn())
else: else:
return self.__printReturn("returning plugged in", None) return self.__printReturn("returning plugged in", None)
#end function CheckPluggedIn #end function CheckPluggedIn
@@ -1019,7 +1041,8 @@ class ConnectionWizard(dbus.service.Object):
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,str(self.LastScan[id][option])) config.set(self.LastScan[id]["bssid"], option,
str(self.LastScan[id][option]))
config.write(open(self.wireless_conf, "w")) config.write(open(self.wireless_conf, "w"))
#end function SaveWirelessNetworkProperty #end function SaveWirelessNetworkProperty
@@ -1144,6 +1167,7 @@ class ConnectionWizard(dbus.service.Object):
dns2 = self.get_option("Settings", "global_dns_2", default='None') dns2 = self.get_option("Settings", "global_dns_2", default='None')
dns3 = self.get_option("Settings", "global_dns_3", 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", self.SetAutoReconnect(self.get_option("Settings", "auto_reconnect",
default=False)) default=False))
self.SetDebugMode(self.get_option("Settings", "debug_mode", self.SetDebugMode(self.get_option("Settings", "debug_mode",
@@ -1240,6 +1264,7 @@ class ConnectionStatus():
self.connection_lost_counter = 0 self.connection_lost_counter = 0
self.conn = connection self.conn = connection
self.status_changed = False self.status_changed = False
self.state = 0
def check_for_wired_connection(self, wired_ip): def check_for_wired_connection(self, wired_ip):
""" Checks for an active wired connection. """ Checks for an active wired connection.
@@ -1255,6 +1280,7 @@ class ConnectionStatus():
conn.SetCurrentInterface(conn.GetWiredInterface()) conn.SetCurrentInterface(conn.GetWiredInterface())
self.still_wired = True self.still_wired = True
self.status_changed = True self.status_changed = True
self.state = misc.WIRED
return True return True
# Wired connection isn't active # Wired connection isn't active
self.still_wired = False self.still_wired = False
@@ -1306,6 +1332,7 @@ class ConnectionStatus():
self.last_strength = wifi_signal self.last_strength = wifi_signal
self.status_changed = True self.status_changed = True
conn.SetCurrentInterface(conn.GetWirelessInterface()) conn.SetCurrentInterface(conn.GetWirelessInterface())
self.state = misc.WIRELESS
return True return True
@@ -1323,6 +1350,7 @@ class ConnectionStatus():
print "Suspended." print "Suspended."
return True return True
# Determine what our current state is.
self.iwconfig = conn.GetIwconfig() self.iwconfig = conn.GetIwconfig()
wired_ip = conn.GetWiredIP() wired_ip = conn.GetWiredIP()
wired_found = self.check_for_wired_connection(wired_ip) wired_found = self.check_for_wired_connection(wired_ip)
@@ -1332,13 +1360,34 @@ class ConnectionStatus():
wireless_found = self.check_for_wireless_connection(wifi_ip) wireless_found = self.check_for_wireless_connection(wifi_ip)
if not wireless_found: # No connection at all if not wireless_found: # No connection at all
if not conn.CheckIfConnecting(): if not conn.CheckIfConnecting():
self.state = misc.NOT_CONNECTED
self.auto_reconnect() self.auto_reconnect()
else: else:
self.state = misc.CONNECTING
self.status_changed = True 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. # Send a D-Bus signal announcing status has changed if necessary.
if self.status_changed: if self.status_changed:
conn.StatusChanged() conn.StatusChanged(self.state, info)
self.status_changed = False self.status_changed = False
return True return True

View File

@@ -380,4 +380,397 @@
</widget> </widget>
</child> </child>
</widget> </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> </glade-interface>

213
gui.py
View File

@@ -1,5 +1,12 @@
#!/usr/bin/python #!/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 Adam Blackburn
# Copyright (C) 2007 Dan O'Reilly # Copyright (C) 2007 Dan O'Reilly
@@ -667,7 +674,8 @@ class WiredNetworkEntry(NetworkEntry):
print 'unsetting previous default profile...' print 'unsetting previous default profile...'
# Make sure there is only one default profile at a time # Make sure there is only one default profile at a time
config.UnsetWiredDefault() config.UnsetWiredDefault()
wired.SetWiredProperty("default",self.checkboxDefaultProfile.get_active()) wired.SetWiredProperty("default",
self.checkboxDefaultProfile.get_active())
config.SaveWiredNetworkProfile(self.comboProfileNames.get_active_text()) config.SaveWiredNetworkProfile(self.comboProfileNames.get_active_text())
def changeProfile(self,widget): def changeProfile(self,widget):
@@ -940,10 +948,8 @@ class appGui:
probar = self.wTree.get_widget("progressbar") probar = self.wTree.get_widget("progressbar")
probar.set_text(language['connecting']) 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.network_list = self.wTree.get_widget("network_list_vbox")
self.status_area = self.wTree.get_widget("connecting_hbox") self.status_area = self.wTree.get_widget("connecting_hbox")
self.status_bar = self.wTree.get_widget("statusbar") self.status_bar = self.wTree.get_widget("statusbar")
@@ -952,7 +958,7 @@ class appGui:
self.status_area.hide_all() self.status_area.hide_all()
self.statusID = None self.statusID = None
self.first_dialog_load = False
self.vpn_connection_pipe = None self.vpn_connection_pipe = None
self.is_visible = True self.is_visible = True
@@ -986,7 +992,8 @@ class appGui:
useICSCheckbox = gtk.CheckButton(language['use_ics']) useICSCheckbox = gtk.CheckButton(language['use_ics'])
self.useEncryptionCheckbox.connect("toggled",self.toggleEncryptionCheck) self.useEncryptionCheckbox.connect("toggled",
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
@@ -1032,123 +1039,115 @@ class appGui:
def settings_dialog(self,widget,event=None): def settings_dialog(self,widget,event=None):
""" Displays a general settings dialog. """ """ Displays a general settings dialog. """
dialog = gtk.Dialog(title=language['preferences'], dialog = self.wTree.get_widget("pref_dialog")
flags=gtk.DIALOG_MODAL, dialog.set_title(language['preferences'])
buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2)) wiredcheckbox = self.wTree.get_widget("pref_always_check")
dialog.set_has_separator(False) wiredcheckbox.set_label(language['wired_always_on'])
dialog.set_size_request(465,-1)
wiredcheckbox = gtk.CheckButton(language['wired_always_on'])
wiredcheckbox.set_active(wired.GetAlwaysShowWiredInterface()) 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()) 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()) 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()) displaytypecheckbox.set_active(daemon.GetSignalDisplayType())
sepline = gtk.HSeparator()
usedefaultradiobutton = gtk.RadioButton(None, entryWiredAutoMethod = self.wTree.get_widget("pref_wired_auto_label")
language['use_default_profile'], entryWiredAutoMethod.set_label('Wired Autoconnect Setting:')
False) usedefaultradiobutton = self.wTree.get_widget("pref_use_def_radio")
showlistradiobutton = gtk.RadioButton(usedefaultradiobutton, usedefaultradiobutton.set_label(language['use_default_profile'])
language['show_wired_list'], showlistradiobutton = self.wTree.get_widget("pref_prompt_radio")
False) showlistradiobutton.set_label(language['show_wired_list'])
lastusedradiobutton = gtk.RadioButton(usedefaultradiobutton, lastusedradiobutton = self.wTree.get_widget("pref_use_last_radio")
language['use_last_used_profile'], lastusedradiobutton.set_label(language['use_last_used_profile'])
False)
if wired.GetWiredAutoConnectMethod() == 1: if wired.GetWiredAutoConnectMethod() == 1:
usedefaultradiobutton.set_active(True) usedefaultradiobutton.set_active(True)
print 'use default profile'
elif wired.GetWiredAutoConnectMethod() == 2: elif wired.GetWiredAutoConnectMethod() == 2:
print 'show list'
showlistradiobutton.set_active(True) showlistradiobutton.set_active(True)
elif wired.GetWiredAutoConnectMethod() == 3: elif wired.GetWiredAutoConnectMethod() == 3:
print 'use last used profile'
lastusedradiobutton.set_active(True) 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 = gtk.combo_box_new_text()
wpadrivercombo.set_size_request(50,-1) wpa_hbox.pack_end(wpadrivercombo)
wpadrivers = ["hostap","hermes","madwifi","atmel","wext","ndiswrapper",
"broadcom","ipw","ralink legacy"] wpadrivers = ["hostap", "hermes", "madwifi", "atmel", "wext",
"ndiswrapper", "broadcom", "ipw", "ralink legacy"]
i = 0 i = 0
found = False found = False
for x in wpadrivers: for x in wpadrivers:
if x == daemon.GetWPADriver() and found == False: if x == daemon.GetWPADriver() and not found:
found = True found = True
else: elif not found:
if found == False:
i+=1 i+=1
wpadrivercombo.append_text(x) wpadrivercombo.append_text(x)
# Set active here.
# If we set active an item to active, then add more items # Set the active choice here. Doing it before all the items are
# it loses the activeness. # added the combobox causes the choice to be reset.
wpadrivercombo.set_active(i) wpadrivercombo.set_active(i)
# Select wext as the default driver, because it works for most cards if not found:
wpabox = gtk.HBox(False,1) # Use wext as default, since normally it is the correct driver.
wpabox.pack_start(wpadriverlabel) wpadrivercombo.set_active(4)
wpabox.pack_start(wpadrivercombo)
entryWirelessInterface = LabelEntry(language['wireless_interface'] + ':') self.set_label("pref_wifi_label", language['wireless_interface'] + ':')
entryWiredInterface = LabelEntry(language['wired_interface'] + ':') self.set_label("pref_wired_label", language['wired_interface'] + ':')
entryWirelessInterface.label.set_size_request(260,-1)
entryWiredInterface.label.set_size_request(260,-1)
entryWiredAutoMethod = gtk.Label('Wired Autoconnect Setting:')
entryWirelessInterface.entry.set_text(daemon.GetWirelessInterface()) entryWirelessInterface = self.wTree.get_widget("pref_wifi_entry")
entryWiredInterface.entry.set_text(daemon.GetWiredInterface()) entryWirelessInterface.set_text(daemon.GetWirelessInterface())
useGlobalDNSCheckbox = gtk.CheckButton(language['use_global_dns']) entryWiredInterface = self.wTree.get_widget("pref_wired_entry")
dns1Entry = LabelEntry(language['dns'] + ' ' + language['1']) entryWiredInterface.set_text(daemon.GetWiredInterface())
dns2Entry = LabelEntry(language['dns'] + ' ' + language['2'])
dns3Entry = LabelEntry(language['dns'] + ' ' + language['3']) # 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, useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
(dns1Entry, dns2Entry, dns3Entry)) (dns1Entry, dns2Entry, dns3Entry))
dns_addresses = daemon.GetGlobalDNSAddresses() dns_addresses = daemon.GetGlobalDNSAddresses()
useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS()) useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
dns1Entry.set_text(noneToBlankString(dns_addresses[0])) dns1Entry.set_text(noneToBlankString(dns_addresses[0]))
dns2Entry.set_text(noneToBlankString(dns_addresses[1])) dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
dns3Entry.set_text(noneToBlankString(dns_addresses[2])) dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
if not daemon.GetUseGlobalDNS(): if not daemon.GetUseGlobalDNS():
dns1Entry.set_sensitive(False) dns1Entry.set_sensitive(False)
dns2Entry.set_sensitive(False) dns2Entry.set_sensitive(False)
dns3Entry.set_sensitive(False) dns3Entry.set_sensitive(False)
# Bold/Align the Wired Autoconnect label.
entryWiredAutoMethod.set_alignment(0,0) entryWiredAutoMethod.set_alignment(0,0)
sepline.set_size_request(2,8)
atrlist = pango.AttrList() atrlist = pango.AttrList()
atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD,0,50)) atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD,0,50))
entryWiredAutoMethod.set_attributes(atrlist) 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() dialog.show_all()
response = dialog.run() response = dialog.run()
if response == 1: if response == 1:
daemon.SetUseGlobalDNS(useGlobalDNSCheckbox.get_active()) daemon.SetUseGlobalDNS(useGlobalDNSCheckbox.get_active())
daemon.SetGlobalDNS(dns1Entry.get_text(),dns2Entry.get_text(),dns3Entry.get_text()) daemon.SetGlobalDNS(dns1Entry.get_text(), dns2Entry.get_text(),
daemon.SetWirelessInterface(entryWirelessInterface.entry.get_text()) dns3Entry.get_text())
daemon.SetWiredInterface(entryWiredInterface.entry.get_text()) daemon.SetWirelessInterface(entryWirelessInterface.get_text())
daemon.SetWiredInterface(entryWiredInterface.get_text())
print "setting: " + wpadrivers[wpadrivercombo.get_active()] print "setting: " + wpadrivers[wpadrivercombo.get_active()]
daemon.SetWPADriver(wpadrivers[wpadrivercombo.get_active()]) daemon.SetWPADriver(wpadrivers[wpadrivercombo.get_active()])
wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active()) wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active())
@@ -1161,10 +1160,11 @@ class appGui:
wired.SetWiredAutoConnectMethod(3) wired.SetWiredAutoConnectMethod(3)
else: else:
wired.SetWiredAutoConnectMethod(1) wired.SetWiredAutoConnectMethod(1)
dialog.hide()
dialog.destroy() def set_label(self, glade_str, label):
else: """ Sets the label for the given widget in wicd.glade. """
dialog.destroy() self.wTree.get_widget(glade_str).set_label(label)
def connect_hidden(self,widget): def connect_hidden(self,widget):
""" Prompts the user for a hidden network, then scans for it. """ """ Prompts the user for a hidden network, then scans for it. """
@@ -1199,6 +1199,8 @@ class appGui:
def pulse_progress_bar(self): def pulse_progress_bar(self):
""" Pulses the progress bar while connecting to a network. """ """ Pulses the progress bar while connecting to a network. """
if not self.is_visible:
return True
try: try:
self.wTree.get_widget("progressbar").pulse() self.wTree.get_widget("progressbar").pulse()
except: except:
@@ -1207,9 +1209,9 @@ class appGui:
def update_statusbar(self): def update_statusbar(self):
""" Updates the status bar. """ """ Updates the status bar. """
# Update the status bar every couple hundred milliseconds.
if self.is_visible == False: if self.is_visible == False:
return True return True
iwconfig = wireless.GetIwconfig() iwconfig = wireless.GetIwconfig()
wireless_ip = wireless.GetWirelessIP() wireless_ip = wireless.GetWirelessIP()
wiredConnecting = wired.CheckIfWiredConnecting() wiredConnecting = wired.CheckIfWiredConnecting()
@@ -1231,11 +1233,36 @@ class appGui:
self.status_area.hide_all() self.status_area.hide_all()
if self.statusID: if self.statusID:
self.status_bar.remove(1, 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 # Determine connection status.
if wireless_ip: 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) network = wireless.GetCurrentNetwork(iwconfig)
if network: if not network:
return False
strength = wireless.GetCurrentSignalStrength(iwconfig) strength = wireless.GetCurrentSignalStrength(iwconfig)
dbm_strength = wireless.GetCurrentDBMStrength(iwconfig) dbm_strength = wireless.GetCurrentDBMStrength(iwconfig)
if strength is not None and dbm_strength is not None: if strength is not None and dbm_strength is not None:
@@ -1250,14 +1277,7 @@ class appGui:
('$B', daemon.FormatSignalForPrinting(strength)).replace ('$B', daemon.FormatSignalForPrinting(strength)).replace
('$C', wireless_ip)) ('$C', wireless_ip))
return True return True
wired_ip = wired.GetWiredIP() return False
if wired_ip:
if wired.CheckPluggedIn():
self.set_status(language['connected_to_wired'].replace('$A',
wired_ip))
return True
self.set_status(language['not_connected'])
return True
def set_status(self, msg): def set_status(self, msg):
""" Sets the status bar message for the GUI. """ """ Sets the status bar message for the GUI. """
@@ -1363,7 +1383,7 @@ class appGui:
wireless.SetWirelessProperty(networkid, "gateway", wireless.SetWirelessProperty(networkid, "gateway",
noneToString(entry.txtGateway.get_text())) noneToString(entry.txtGateway.get_text()))
else: else:
#blank the values # Blank the values
wireless.SetWirelessProperty(networkid, "ip", '') wireless.SetWirelessProperty(networkid, "ip", '')
wireless.SetWirelessProperty(networkid, "netmask", '') wireless.SetWirelessProperty(networkid, "netmask", '')
wireless.SetWirelessProperty(networkid, "gateway", '') wireless.SetWirelessProperty(networkid, "gateway", '')
@@ -1473,6 +1493,7 @@ class appGui:
return True return True
def connect(self, widget, event, type, networkid, networkentry): def connect(self, widget, event, type, networkid, networkentry):
""" Initiates the connection process in the daemon. """
cancelButton = self.wTree.get_widget("cancel_button") cancelButton = self.wTree.get_widget("cancel_button")
cancelButton.set_sensitive(True) cancelButton.set_sensitive(True)

View File

@@ -29,6 +29,11 @@ from subprocess import *
if __name__ == '__main__': if __name__ == '__main__':
wpath.chdir(__file__) wpath.chdir(__file__)
NOT_CONNECTED = 0
CONNECTING = 1
WIRELESS = 2
WIRED = 3
def Run(cmd, include_stderr=False, return_pipe=False): def Run(cmd, include_stderr=False, return_pipe=False):
""" Run a command. """ Run a command.
@@ -232,7 +237,8 @@ def get_gettext():
# Translation stuff # Translation stuff
# borrowed from an excellent post on how to do this on # borrowed from an excellent post on how to do this on
# http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/ # 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 = [] langs = []
lc, encoding = locale.getdefaultlocale() lc, encoding = locale.getdefaultlocale()
if (lc): if (lc):
@@ -252,6 +258,7 @@ def to_unicode(x):
try: # This may never fail, but let's be safe try: # This may never fail, but let's be safe
default_encoding = locale.getpreferredencoding() default_encoding = locale.getpreferredencoding()
except: except:
print 'Could not get default encoding'
default_encoding = None default_encoding = None
if default_encoding: if default_encoding:

68
wicd.py
View File

@@ -138,52 +138,46 @@ class TrayIcon():
gui.WiredProfileChooser() gui.WiredProfileChooser()
daemon.SetNeedWiredProfileChooser(False) 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""" """Updates the tray icon and current connection status"""
if self.use_tray == False: return False if self.use_tray == False: return False
iwconfig = wireless.GetIwconfig() if not state or not info:
# If we're currently connecting, we can shortcut all other checks [state, info] = daemon.GetConnectionStatus()
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
cur_iface = daemon.GetCurrentInterface() if state == misc.WIRED:
wifi_iface = daemon.GetWirelessInterface() wired_ip = info[0]
wire_iface = daemon.GetWiredInterface()
# Check for a wired connection
if cur_iface == wire_iface:
wired_ip = wired.GetWiredIP()
self.tr.set_from_file(wpath.images + "wired.png") self.tr.set_from_file(wpath.images + "wired.png")
self.tr.set_tooltip(language['connected_to_wired']. self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
replace('$A',
wired_ip)) wired_ip))
# Check for a wireless connection elif state == misc.WIRELESS:
elif cur_iface == wifi_iface:
cur_net_id = wireless.GetCurrentNetworkID(iwconfig)
lock = '' 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"): if wireless.GetWirelessProperty(cur_net_id, "encryption"):
lock = "-lock" 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'] self.tr.set_tooltip(language['connected_to_wireless']
.replace('$A', self.network) .replace('$A', self.network)
.replace('$B', sig_string) .replace('$B', sig_string)
.replace('$C', str(wireless_ip))) .replace('$C', str(wireless_ip)))
self.set_signal_image(strength, lock) self.set_signal_image(strength, lock)
# If we made it here, we don't have a connection elif state == misc.CONNECTING:
if info[0] == 'wired' and len(info) == 1:
cur_network = language['wired']
else: 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") self.tr.set_from_file(wpath.images + "no-signal.png")
if wireless.GetKillSwitchEnabled(): if wireless.GetKillSwitchEnabled():
status = (language['not_connected'] + " (" + status = (language['not_connected'] + " (" +
@@ -191,6 +185,9 @@ class TrayIcon():
else: else:
status = language['not_connected'] status = language['not_connected']
self.tr.set_tooltip(status) self.tr.set_tooltip(status)
else:
print 'Invalid state returned!!!'
return False
return True return True
@@ -281,13 +278,6 @@ class TrayIcon():
dialog.run() dialog.run()
dialog.destroy() 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): def toggle_wicd_gui(self):
"""Toggles the wicd GUI""" """Toggles the wicd GUI"""
if self.gui_win == None: if self.gui_win == None:
@@ -332,7 +322,7 @@ class TrayIcon():
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): 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)
@@ -371,9 +361,9 @@ class TrayIcon():
self.set_from_file(wpath.images + "no-signal.png") self.set_from_file(wpath.images + "no-signal.png")
self.set_tooltip("Initializing wicd...") 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""" """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): def set_from_file(self, path = None):
"""Sets a new tray icon picture""" """Sets a new tray icon picture"""

View File

@@ -440,7 +440,7 @@ class WirelessInterface(Interface):
ap['essid'] = misc.RunRegex(essid_pattern, cell) ap['essid'] = misc.RunRegex(essid_pattern, cell)
try: try:
ap['essid'] = misc.to_unicode(ap['essid']) ap['essid'] = misc.to_unicode(ap['essid'])
except UnicodeDecodeError, UnicodeEncodeError: except (UnicodeDecodeError, UnicodeEncodeError):
print 'Unicode problem with current network essid, ignoring!!' print 'Unicode problem with current network essid, ignoring!!'
return None return None
if ap['essid'] == '<hidden>': if ap['essid'] == '<hidden>':