mirror of
https://github.com/gryf/wicd.git
synced 2025-12-22 14:07:59 +01:00
Rather than polling for network status in the GUI, just have the monitor run an on-demand pull and get the results from the daemon. Should reduce iwconfig/ifconfig calls while the GUI is open and make for nicer looking code.
This commit is contained in:
113
wicd/gui.py
113
wicd/gui.py
@@ -358,31 +358,38 @@ class appGui(object):
|
|||||||
if not self.is_visible or self.refreshing:
|
if not self.is_visible or self.refreshing:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
fast = not daemon.NeedsExternalCalls()
|
daemon.UpdateState()
|
||||||
wired_connecting = wired.CheckIfWiredConnecting()
|
[state, info] = daemon.GetConnectionStatus()
|
||||||
wireless_connecting = wireless.CheckIfWirelessConnecting()
|
|
||||||
self.connecting = wired_connecting or wireless_connecting
|
|
||||||
|
|
||||||
if self.connecting:
|
if state == misc.WIRED:
|
||||||
if not self.pulse_active:
|
return self.set_wired_state(info)
|
||||||
self.pulse_active = True
|
elif state == misc.WIRELESS:
|
||||||
gobject.timeout_add(100, self.pulse_progress_bar)
|
return self.set_wireless_state(info)
|
||||||
gobject.idle_add(self.network_list.set_sensitive, False)
|
elif state == misc.CONNECTING:
|
||||||
gobject.idle_add(self.status_area.show_all)
|
return self.set_connecting_state(info)
|
||||||
if self.statusID:
|
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
|
||||||
gobject.idle_add(self.status_bar.remove, 1, self.statusID)
|
return self.set_not_connected_state(info)
|
||||||
if wireless_connecting:
|
|
||||||
if not fast:
|
def set_wired_state(self, info):
|
||||||
iwconfig = wireless.GetIwconfig()
|
self._set_connected_state()
|
||||||
else:
|
self.set_status(language['connected_to_wired'].replace('$A', info[0]))
|
||||||
iwconfig = ''
|
|
||||||
gobject.idle_add(self.set_status, wireless.GetCurrentNetwork(iwconfig) + ': ' +
|
|
||||||
language[str(wireless.CheckWirelessConnectingMessage())])
|
|
||||||
if wired_connecting:
|
|
||||||
gobject.idle_add(self.set_status, language['wired_network'] + ': ' +
|
|
||||||
language[str(wired.CheckWiredConnectingMessage())])
|
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
|
def set_wireless_state(self, info):
|
||||||
|
self._set_connected_state()
|
||||||
|
self.set_status(language['connected_to_wireless'].replace
|
||||||
|
('$A', info[1]).replace
|
||||||
|
('$B', daemon.FormatSignalForPrinting(info[2])).replace
|
||||||
|
('$C', info[0]))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def set_not_connected_state(self, info):
|
||||||
|
self.connecting = False
|
||||||
|
self.set_status(language['not_connected'])
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _set_connected_state(self):
|
||||||
|
self.connecting = False
|
||||||
if self.pulse_active:
|
if self.pulse_active:
|
||||||
self.pulse_active = False
|
self.pulse_active = False
|
||||||
gobject.idle_add(self.network_list.set_sensitive, True)
|
gobject.idle_add(self.network_list.set_sensitive, True)
|
||||||
@@ -391,16 +398,21 @@ class appGui(object):
|
|||||||
if self.statusID:
|
if self.statusID:
|
||||||
gobject.idle_add(self.status_bar.remove, 1, self.statusID)
|
gobject.idle_add(self.status_bar.remove, 1, self.statusID)
|
||||||
|
|
||||||
# Determine connection status.
|
def set_connecting_state(self, info):
|
||||||
if self.check_for_wired(wired.GetWiredIP("")):
|
self.connecting = True
|
||||||
return True
|
if not self.pulse_active:
|
||||||
if not fast:
|
self.pulse_active = True
|
||||||
iwconfig = wireless.GetIwconfig()
|
gobject.timeout_add(100, self.pulse_progress_bar)
|
||||||
else:
|
gobject.idle_add(self.network_list.set_sensitive, False)
|
||||||
iwconfig = ''
|
gobject.idle_add(self.status_area.show_all)
|
||||||
if self.check_for_wireless(iwconfig, wireless.GetWirelessIP("")):
|
if self.statusID:
|
||||||
return True
|
gobject.idle_add(self.status_bar.remove, 1, self.statusID)
|
||||||
self.set_status(language['not_connected'])
|
if info[0] == "wireless":
|
||||||
|
gobject.idle_add(self.set_status, str(info[1]) + ': ' +
|
||||||
|
language[str(wireless.CheckWirelessConnectingMessage())])
|
||||||
|
elif info[0] == "wired":
|
||||||
|
gobject.idle_add(self.set_status, language['wired_network'] + ': ' +
|
||||||
|
language[str(wired.CheckWiredConnectingMessage())])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update_connect_buttons(self, state=None, x=None, force_check=False):
|
def update_connect_buttons(self, state=None, x=None, force_check=False):
|
||||||
@@ -421,41 +433,6 @@ class appGui(object):
|
|||||||
entry.update_connect_button(state, apbssid)
|
entry.update_connect_button(state, apbssid)
|
||||||
self.prev_state = state
|
self.prev_state = state
|
||||||
|
|
||||||
def check_for_wired(self, wired_ip):
|
|
||||||
""" Determine if wired is active, and if yes, set the status. """
|
|
||||||
if wired_ip and wired.CheckPluggedIn():
|
|
||||||
self.set_status(
|
|
||||||
language['connected_to_wired'].replace('$A',wired_ip)
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_for_wireless(self, iwconfig, wireless_ip):
|
|
||||||
""" Determine if wireless is active, and if yes, set the status. """
|
|
||||||
if not wireless_ip:
|
|
||||||
return False
|
|
||||||
|
|
||||||
network = wireless.GetCurrentNetwork(iwconfig)
|
|
||||||
if not network:
|
|
||||||
return False
|
|
||||||
|
|
||||||
network = str(network)
|
|
||||||
if daemon.GetSignalDisplayType() == 0:
|
|
||||||
strength = wireless.GetCurrentSignalStrength(iwconfig)
|
|
||||||
else:
|
|
||||||
strength = wireless.GetCurrentDBMStrength(iwconfig)
|
|
||||||
|
|
||||||
if strength is None:
|
|
||||||
return False
|
|
||||||
strength = str(strength)
|
|
||||||
ip = str(wireless_ip)
|
|
||||||
self.set_status(language['connected_to_wireless'].replace
|
|
||||||
('$A', network).replace
|
|
||||||
('$B', daemon.FormatSignalForPrinting(strength)).replace
|
|
||||||
('$C', wireless_ip))
|
|
||||||
return True
|
|
||||||
|
|
||||||
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. """
|
||||||
self.statusID = self.status_bar.push(1, msg)
|
self.statusID = self.status_bar.push(1, msg)
|
||||||
|
|||||||
@@ -787,6 +787,7 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
def ConnectResultsSent(self, result):
|
def ConnectResultsSent(self, result):
|
||||||
print "Sending connection attempt result %s" % result
|
print "Sending connection attempt result %s" % result
|
||||||
|
|
||||||
|
@dbus.service.method("org.wicd.daemon")
|
||||||
@dbus.service.signal(dbus_interface="org.wicd.daemon", signature='')
|
@dbus.service.signal(dbus_interface="org.wicd.daemon", signature='')
|
||||||
def UpdateState(self):
|
def UpdateState(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user