mirror of
https://github.com/gryf/wicd.git
synced 2025-12-22 05:48:03 +01:00
More work on making the client handle a daemon restart
This commit is contained in:
27
wicd/gui.py
27
wicd/gui.py
@@ -52,10 +52,10 @@ except:
|
|||||||
|
|
||||||
proxy_obj = daemon = wireless = wired = bus = None
|
proxy_obj = daemon = wireless = wired = bus = None
|
||||||
language = misc.get_language_list_gui()
|
language = misc.get_language_list_gui()
|
||||||
|
DBUS_AVAIL = False
|
||||||
|
|
||||||
def setup_dbus(force=True):
|
def setup_dbus(force=True):
|
||||||
global bus, daemon, wireless, wired
|
global bus, daemon, wireless, wired, DBUS_AVAIL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dbusmanager.connect_to_dbus()
|
dbusmanager.connect_to_dbus()
|
||||||
except DBusException:
|
except DBusException:
|
||||||
@@ -70,25 +70,36 @@ def setup_dbus(force=True):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
bus = dbusmanager.get_bus()
|
bus = dbusmanager.get_bus()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||||
daemon = dbus_ifaces['daemon']
|
daemon = dbus_ifaces['daemon']
|
||||||
wireless = dbus_ifaces['wireless']
|
wireless = dbus_ifaces['wireless']
|
||||||
wired = dbus_ifaces['wired']
|
wired = dbus_ifaces['wired']
|
||||||
|
DBUS_AVAIL = True
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@misc.threaded
|
def handle_no_dbus(from_tray=False):
|
||||||
def handle_no_dbus():
|
global DBUS_AVAIL
|
||||||
|
DBUS_AVAIL = False
|
||||||
|
if from_tray: return False
|
||||||
print "Wicd daemon is shutting down!"
|
print "Wicd daemon is shutting down!"
|
||||||
error(None, "The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
error(None, "The wicd daemon has shut down, the UI will not function properly until it is restarted.")
|
||||||
|
_wait_for_dbus()
|
||||||
|
return False
|
||||||
|
|
||||||
|
@misc.threaded
|
||||||
|
def _wait_for_dbus():
|
||||||
|
global DBUS_AVAIL
|
||||||
while True:
|
while True:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
print "Trying to reconnect.."
|
print "Trying to reconnect.."
|
||||||
if not setup_dbus(force=False):
|
if not setup_dbus(force=False):
|
||||||
print "Failed to reconnect to the daemon."
|
print "Failed to reconnect to the daemon."
|
||||||
|
else:
|
||||||
|
print "Successfully reconnected to the daemon."
|
||||||
|
DBUS_AVAIL = True
|
||||||
|
return
|
||||||
|
|
||||||
def error(parent, message):
|
def error(parent, message):
|
||||||
""" Shows an error dialog """
|
""" Shows an error dialog """
|
||||||
@@ -481,6 +492,7 @@ class appGui(object):
|
|||||||
current network state is the same as the previous.
|
current network state is the same as the previous.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not DBUS_AVAIL: return
|
||||||
if not state:
|
if not state:
|
||||||
state, x = daemon.GetConnectionStatus()
|
state, x = daemon.GetConnectionStatus()
|
||||||
|
|
||||||
@@ -536,15 +548,18 @@ class appGui(object):
|
|||||||
This method is called after a wireless scan is completed.
|
This method is called after a wireless scan is completed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not DBUS_AVAIL: return
|
||||||
if not self.connecting:
|
if not self.connecting:
|
||||||
gobject.idle_add(self.refresh_networks, None, False, None)
|
gobject.idle_add(self.refresh_networks, None, False, None)
|
||||||
|
|
||||||
def dbus_scan_started(self):
|
def dbus_scan_started(self):
|
||||||
""" Called when a wireless scan starts. """
|
""" Called when a wireless scan starts. """
|
||||||
|
if not DBUS_AVAIL: return
|
||||||
self.network_list.set_sensitive(False)
|
self.network_list.set_sensitive(False)
|
||||||
|
|
||||||
def refresh_clicked(self, widget=None):
|
def refresh_clicked(self, widget=None):
|
||||||
""" Kick off an asynchronous wireless scan. """
|
""" Kick off an asynchronous wireless scan. """
|
||||||
|
if not DBUS_AVAIL: return
|
||||||
self.refreshing = True
|
self.refreshing = True
|
||||||
wireless.Scan(reply_handler=None, error_handler=None)
|
wireless.Scan(reply_handler=None, error_handler=None)
|
||||||
|
|
||||||
|
|||||||
@@ -535,6 +535,7 @@ def get_language_list_tray():
|
|||||||
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
|
language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \
|
||||||
"This typically means there was a problem starting the daemon." + \
|
"This typically means there was a problem starting the daemon." + \
|
||||||
"Check the wicd log for more info")
|
"Check the wicd log for more info")
|
||||||
|
language['no_daemon_tooltip'] = _("Wicd daemon unreachable")
|
||||||
return language
|
return language
|
||||||
|
|
||||||
def noneToBlankString(text):
|
def noneToBlankString(text):
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ class TrayIcon(object):
|
|||||||
self.update_tray_icon()
|
self.update_tray_icon()
|
||||||
else:
|
else:
|
||||||
handle_no_dbus()
|
handle_no_dbus()
|
||||||
|
self.set_not_connected_state()
|
||||||
|
|
||||||
def wired_profile_chooser(self):
|
def wired_profile_chooser(self):
|
||||||
""" Launch the wired profile chooser. """
|
""" Launch the wired profile chooser. """
|
||||||
@@ -138,7 +139,7 @@ class TrayIcon(object):
|
|||||||
def set_wired_state(self, info):
|
def set_wired_state(self, info):
|
||||||
""" Sets the icon info for a wired state. """
|
""" Sets the icon info for a wired state. """
|
||||||
wired_ip = info[0]
|
wired_ip = info[0]
|
||||||
self.tr.set_from_file(wpath.images + "wired.png")
|
self.tr.set_from_file(os.path.join(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))
|
wired_ip))
|
||||||
|
|
||||||
@@ -168,12 +169,14 @@ class TrayIcon(object):
|
|||||||
cur_network = info[1]
|
cur_network = info[1]
|
||||||
self.tr.set_tooltip(language['connecting'] + " to " +
|
self.tr.set_tooltip(language['connecting'] + " to " +
|
||||||
cur_network + "...")
|
cur_network + "...")
|
||||||
self.tr.set_from_file(wpath.images + "no-signal.png")
|
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
|
||||||
|
|
||||||
def set_not_connected_state(self, info):
|
def set_not_connected_state(self, info=None):
|
||||||
""" Set the icon info for the not connected state. """
|
""" Set the icon info for the not connected state. """
|
||||||
self.tr.set_from_file(wpath.images + "no-signal.png")
|
self.tr.set_from_file(wpath.images + "no-signal.png")
|
||||||
if wireless.GetKillSwitchEnabled():
|
if not DBUS_AVAIL:
|
||||||
|
status = language['no_daemon_tooltip']
|
||||||
|
elif wireless.GetKillSwitchEnabled():
|
||||||
status = (language['not_connected'] + " (" +
|
status = (language['not_connected'] + " (" +
|
||||||
language['killswitch_enabled'] + ")")
|
language['killswitch_enabled'] + ")")
|
||||||
else:
|
else:
|
||||||
@@ -182,7 +185,7 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def update_tray_icon(self, state=None, info=None):
|
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 not self.use_tray: return False
|
if not self.use_tray or not DBUS_AVAIL: return False
|
||||||
|
|
||||||
if not state or not info:
|
if not state or not info:
|
||||||
[state, info] = daemon.GetConnectionStatus()
|
[state, info] = daemon.GetConnectionStatus()
|
||||||
@@ -345,11 +348,13 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def tray_scan_started(self):
|
def tray_scan_started(self):
|
||||||
""" Callback for when a wireless scan is started. """
|
""" Callback for when a wireless scan is started. """
|
||||||
|
if not DBUS_AVAIL: return
|
||||||
self._is_scanning = True
|
self._is_scanning = True
|
||||||
self.init_network_menu()
|
self.init_network_menu()
|
||||||
|
|
||||||
def tray_scan_ended(self):
|
def tray_scan_ended(self):
|
||||||
""" Callback for when a wireless scan finishes. """
|
""" Callback for when a wireless scan finishes. """
|
||||||
|
if not DBUS_AVAIL: return
|
||||||
self._is_scanning = False
|
self._is_scanning = False
|
||||||
self.populate_network_menu()
|
self.populate_network_menu()
|
||||||
|
|
||||||
@@ -468,6 +473,9 @@ class TrayIcon(object):
|
|||||||
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/")
|
||||||
submenu = net_menuitem.get_submenu()
|
submenu = net_menuitem.get_submenu()
|
||||||
self._clear_menu(submenu)
|
self._clear_menu(submenu)
|
||||||
|
if not DBUS_AVAIL:
|
||||||
|
net_menuitem.show()
|
||||||
|
return
|
||||||
|
|
||||||
is_connecting = daemon.CheckIfConnecting()
|
is_connecting = daemon.CheckIfConnecting()
|
||||||
num_networks = wireless.GetNumberOfNetworks()
|
num_networks = wireless.GetNumberOfNetworks()
|
||||||
@@ -659,21 +667,29 @@ def setup_dbus(force=True):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@misc.threaded
|
|
||||||
def handle_no_dbus():
|
def handle_no_dbus():
|
||||||
global DBUS_AVAIL
|
global DBUS_AVAIL
|
||||||
|
DBUS_AVAIL = False
|
||||||
|
gui.handle_no_dbus(from_tray=True)
|
||||||
print "Wicd daemon is shutting down!"
|
print "Wicd daemon is shutting down!"
|
||||||
gui.error(None, "The wicd daemon has shut down, the UI will not function " +
|
gui.error(None, "The wicd daemon has shut down, the UI will not function " +
|
||||||
"properly until it is restarted.")
|
"properly until it is restarted.")
|
||||||
|
_wait_for_dbus()
|
||||||
|
return False
|
||||||
|
|
||||||
|
@misc.threaded
|
||||||
|
def _wait_for_dbus():
|
||||||
|
global DBUS_AVAIL
|
||||||
while True:
|
while True:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
print "Trying to reconnect.."
|
print "Trying to reconnect.."
|
||||||
if not setup_dbus(force=False):
|
if not setup_dbus(force=False):
|
||||||
print "Failed to reconnect to the daemon."
|
print "Failed to reconnect to the daemon."
|
||||||
else:
|
else:
|
||||||
|
print "Successfully reconnected to the daemon."
|
||||||
gui.setup_dbus(force=False)
|
gui.setup_dbus(force=False)
|
||||||
DBUS_AVAIL = True
|
DBUS_AVAIL = True
|
||||||
return True
|
return
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
""" The main frontend program.
|
""" The main frontend program.
|
||||||
@@ -732,7 +748,8 @@ def main(argv):
|
|||||||
'org.wicd.daemon.wireless')
|
'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
bus.add_signal_receiver(tray_icon.tr.tray_scan_started,
|
||||||
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
'SendStartScanSignal', 'org.wicd.daemon.wireless')
|
||||||
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing", 'org.wicd.daemon')
|
bus.add_signal_receiver(lambda: handle_no_dbus() or tray_icon.icon_info.set_not_connected_state(),
|
||||||
|
"DaemonClosing", 'org.wicd.daemon')
|
||||||
print 'Done.'
|
print 'Done.'
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
mainloop.run()
|
mainloop.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user