1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-23 06:37:59 +01:00

Fix some issues with the GUI statusbar being incorrect.

Make wicd-client more tolerant of dbus exceptions.
Disconnect from both managed interfaces before making a connection.
This commit is contained in:
Dan O'Reilly
2009-02-07 01:22:42 -05:00
parent 450677c83d
commit e84a637d31
6 changed files with 48 additions and 12 deletions

View File

@@ -221,11 +221,12 @@ class appGui(object):
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
"org.wicd.daemon")
self._do_statusbar_update(*daemon.GetConnectionStatus())
self.wait_for_events(0.1)
if hasattr(gobject, "timeout_add_seconds"):
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
else:
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
self._do_statusbar_update(*daemon.GetConnectionStatus())
self.refresh_clicked()
def handle_connection_results(self, results):
@@ -355,14 +356,17 @@ class appGui(object):
def update_statusbar(self):
""" Triggers a status update in wicd-monitor. """
if not self.is_visible or self.refreshing:
if not self.is_visible:
return True
daemon.UpdateState()
if self.connecting:
self._do_statusbar_update(*daemon.GetConnectionStatus())
else:
daemon.UpdateState()
return True
def _do_statusbar_update(self, state, info):
if not self.is_visible or self.refreshing:
if not self.is_visible:
return True
if state == misc.WIRED:
@@ -373,14 +377,15 @@ class appGui(object):
return self.set_connecting_state(info)
elif state in (misc.SUSPENDED, misc.NOT_CONNECTED):
return self.set_not_connected_state(info)
return True
def set_wired_state(self, info):
self._set_connected_state()
self._set_not_connecting_state()
self.set_status(language['connected_to_wired'].replace('$A', info[0]))
return True
def set_wireless_state(self, info):
self._set_connected_state()
self._set_not_connecting_state()
self.set_status(language['connected_to_wireless'].replace
('$A', info[1]).replace
('$B', daemon.FormatSignalForPrinting(info[2])).replace
@@ -389,10 +394,11 @@ class appGui(object):
def set_not_connected_state(self, info):
self.connecting = False
self._set_not_connecting_state()
self.set_status(language['not_connected'])
return True
def _set_connected_state(self):
def _set_not_connecting_state(self):
self.connecting = False
if self.pulse_active:
self.pulse_active = False

View File

@@ -647,5 +647,6 @@ def threaded(f):
wrapper.__name__ = f.__name__
wrapper.__dict__ = f.__dict__
wrapper.__doc__ = f.__doc__
wrapper.__module__ = f.__module__
return wrapper

View File

@@ -69,15 +69,16 @@ class ConnectionStatus(object):
def __init__(self):
""" Initialize variables needed for the connection status methods. """
self.last_strength = -2
self.last_state = misc.NOT_CONNECTED
self.last_reconnect_time = time.time()
self.last_network = ""
self.displayed_strength = -1
self.still_wired = False
self.network = ''
self.tried_reconnect = False
self.connection_lost_counter = 0
self.last_state = misc.NOT_CONNECTED
self.reconnecting = False
self.reconnect_tries = 0
self.last_reconnect_time = time.time()
self.signal_changed = False
self.iwconfig = ""
self.trigger_reconnect = False
@@ -155,8 +156,9 @@ class ConnectionStatus(object):
self.connection_lost_counter = 0
if (wifi_signal != self.last_strength or
self.network != wireless.GetCurrentNetwork(self.iwconfig)):
self.network != self.last_network):
self.last_strength = wifi_signal
self.last_network = self.network
self.signal_changed = True
daemon.SetCurrentInterface(daemon.GetWirelessInterface())
@@ -262,8 +264,8 @@ class ConnectionStatus(object):
daemon.SetConnectionStatus(state, info)
# Send a D-Bus signal announcing status has changed if necessary.
if state != self.last_state or \
(state == misc.WIRELESS and self.signal_changed):
if (state != self.last_state or (state == misc.WIRELESS and
self.signal_changed)):
daemon.EmitStatusChanged(state, info)
self.last_state = state
return True

View File

@@ -71,6 +71,7 @@ def abortable(func):
wrapper.__name__ = func.__name__
wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__
wrapper.__module = func.__module__
return wrapper
def get_backend_list():

View File

@@ -74,6 +74,21 @@ DBUS_AVAIL = False
language = misc.get_language_list_tray()
def catchdbus(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except DBusException, e:
print "warning: ignoring exception %s" % egg
return None
wrapper.__name__ = func.__name__
wrapper.__module__ = func.__module__
wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__
return wrapper
class NetworkMenuItem(gtk.ImageMenuItem):
def __init__(self, lbl, is_active=False):
gtk.ImageMenuItem.__init__(self)
@@ -130,6 +145,7 @@ class TrayIcon(object):
handle_no_dbus()
self.set_not_connected_state()
@catchdbus
def wired_profile_chooser(self):
""" Launch the wired profile chooser. """
gui.WiredProfileChooser()
@@ -142,6 +158,7 @@ class TrayIcon(object):
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
wired_ip))
@catchdbus
def set_wireless_state(self, info):
""" Sets the icon info for a wireless state. """
lock = ''
@@ -170,6 +187,7 @@ class TrayIcon(object):
cur_network + "...")
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
@catchdbus
def set_not_connected_state(self, info=None):
""" Set the icon info for the not connected state. """
self.tr.set_from_file(wpath.images + "no-signal.png")
@@ -182,6 +200,7 @@ class TrayIcon(object):
status = language['not_connected']
self.tr.set_tooltip(status)
@catchdbus
def update_tray_icon(self, state=None, info=None):
""" Updates the tray icon and current connection status. """
if not self.use_tray or not DBUS_AVAIL: return False
@@ -202,6 +221,7 @@ class TrayIcon(object):
return False
return True
@catchdbus
def set_signal_image(self, wireless_signal, lock):
""" Sets the tray icon image for an active wireless connection. """
if self.animate:
@@ -230,6 +250,7 @@ class TrayIcon(object):
img_file = ''.join([wpath.images, prefix, signal_img, lock, ".png"])
self.tr.set_from_file(img_file)
@catchdbus
def get_bandwidth_state(self):
""" Determines what network activity state we are in. """
transmitting = False
@@ -408,6 +429,7 @@ class TrayIcon(object):
item.set_sensitive(False)
del item
@catchdbus
def _get_img(self, net_id):
""" Determines which image to use for the wireless entries. """
def fix_strength(val, default):
@@ -441,6 +463,7 @@ class TrayIcon(object):
signal_img = 'signal-25.png'
return wpath.images + signal_img
@catchdbus
def on_net_menu_activate(self, item):
""" Trigger a background scan to populate the network menu.
@@ -464,6 +487,7 @@ class TrayIcon(object):
return True
wireless.Scan(False)
@catchdbus
def populate_network_menu(self, data=None):
""" Populates the network list submenu. """
def get_prop(net_id, prop):

View File

@@ -1120,6 +1120,7 @@ class WirelessDaemon(dbus.service.Object):
self.wifi.disconnect_script = self.GetWirelessProperty(id,
'disconnectscript')
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
self.daemon.wired_bus.DisconnectWired()
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
self.daemon.UpdateState()
@@ -1424,6 +1425,7 @@ class WiredDaemon(dbus.service.Object):
self.wired.before_script = self.GetWiredProperty("beforescript")
self.wired.after_script = self.GetWiredProperty("afterscript")
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
self.daemon.wireless_bus.DisconnectWireless()
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
self.daemon.UpdateState()