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.gui_open = False
self.suspended = False
self.connection_state = 0
self.connection_info = [""]
# Load the config file
self.ReadConfig()
@@ -339,6 +341,9 @@ class ConnectionWizard(dbus.service.Object):
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):
@@ -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)
@@ -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')
@@ -487,19 +493,60 @@ 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
@@ -522,38 +569,6 @@ class ConnectionWizard(dbus.service.Object):
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"""
@@ -567,10 +582,12 @@ class ConnectionWizard(dbus.service.Object):
#end function GetNumberOfNetworks
@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 '''
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')
@@ -600,10 +617,11 @@ class ConnectionWizard(dbus.service.Object):
#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."
print "Setting script properties through the daemon is not \
permitted."
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)
#end function SetProperty
@@ -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):
@@ -676,7 +694,8 @@ class ConnectionWizard(dbus.service.Object):
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')
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
@@ -791,10 +810,11 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired')
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'
@@ -806,7 +826,8 @@ class ConnectionWizard(dbus.service.Object):
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.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
@@ -820,7 +841,8 @@ class ConnectionWizard(dbus.service.Object):
@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)
#end function CheckPluggedIn
@@ -1019,7 +1041,8 @@ 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.set(self.LastScan[id]["bssid"], option,
str(self.LastScan[id][option]))
config.write(open(self.wireless_conf, "w"))
#end function SaveWirelessNetworkProperty
@@ -1144,6 +1167,7 @@ class ConnectionWizard(dbus.service.Object):
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.SetAutoReconnect(self.get_option("Settings", "auto_reconnect",
default=False))
self.SetDebugMode(self.get_option("Settings", "debug_mode",
@@ -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>

213
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()
@@ -1231,11 +1233,36 @@ class appGui:
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:
# 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 network:
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:
@@ -1250,14 +1277,7 @@ class appGui:
('$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))
return True
self.set_status(language['not_connected'])
return True
return False
def set_status(self, msg):
""" Sets the status bar message for the GUI. """
@@ -1363,7 +1383,7 @@ class appGui:
wireless.SetWirelessProperty(networkid, "gateway",
noneToString(entry.txtGateway.get_text()))
else:
#blank the values
# Blank the values
wireless.SetWirelessProperty(networkid, "ip", '')
wireless.SetWirelessProperty(networkid, "netmask", '')
wireless.SetWirelessProperty(networkid, "gateway", '')
@@ -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)

View File

@@ -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.
@@ -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):
@@ -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:

68
wicd.py
View File

@@ -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',
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
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
@@ -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

@@ -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>':