diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index e676f76b2..8834a5ee3 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -257,12 +257,17 @@ class GtkUI(object): # Shut down components yield self.shutdown() - # Modal dialogs can prevent the application exiting so destroy mainwindow - # Must do this here to avoid hang when closing with SIGINT (CTRL-C) + # The gtk modal dialogs (e.g. Preferences) can prevent the application + # quitting, so force exiting by destroying MainWindow. Must be done here + # to avoid hanging when quitting with SIGINT (CTRL-C). self.mainwindow.window.destroy() reactor.stop() + # Restart the application after closing if MainWindow attribute set. + if component.get('MainWindow').restart: + os.execv(sys.argv[0], sys.argv) + def print_rpc_stats(self): if not client.connected(): return diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index a02a2dd06..d40b9e01e 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -107,6 +107,7 @@ class MainWindow(component.Component): # Keep track of window's minimization state so that we don't update the # UI when it is minimized. self.is_minimized = False + self.restart = False self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/uri-list', 0, 80)], gtk.gdk.ACTION_COPY) @@ -200,15 +201,18 @@ class MainWindow(component.Component): """Returns a reference to the main window GTK builder object.""" return self.main_builder - def quit(self, shutdown=False): - """ - Quits the GtkUI + def quit(self, shutdown=False, restart=False): + """Quits the GtkUI application. + + Args: + shutdown (bool): Whether or not to shutdown the daemon as well. + restart (bool): Whether or not to restart the application after closing. - :param shutdown: whether or not to shutdown the daemon as well - :type shutdown: boolean """ + def quit_gtkui(): def stop_gtk_reactor(result=None): + self.restart = restart try: reactor.callLater(0, reactor.fireSystemEvent, 'gtkui_close') except ReactorNotRunning: diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 5c348a412..10d1c4175 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -701,16 +701,17 @@ class Preferences(component.Component): shutdown_daemon = (not client.is_standalone() and client.connected() and client.is_localhost()) - component.get('MainWindow').quit(shutdown=shutdown_daemon) + component.get('MainWindow').quit(shutdown=shutdown_daemon, restart=True) else: self.gtkui_config['standalone'] = not new_gtkui_standalone self.builder.get_object('radio_standalone').set_active( self.gtkui_config['standalone']) self.builder.get_object('radio_thinclient').set_active( not self.gtkui_config['standalone']) + mode = 'Thinclient' if was_standalone else 'Standalone' dialog = YesNoDialog( - _('Switching client mode...'), - _('Your current session will be stopped. Do you wish to continue?') + _('Switching Deluge Client Mode...'), + _('Do you want to restart to use %s mode?' % mode) ) dialog.run().addCallback(on_response)