From a461074da26c46a38fcf5ce4343b267bb3038f58 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 21 Jan 2008 09:54:03 +0000 Subject: [PATCH] Catch signals and KeyboardInterrupt and shutdown properly in GtkUI. --- deluge/ui/gtkui/gtkui.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index 3899e03e9..7f7e473f3 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -41,6 +41,7 @@ import gtk, gtk.glade import gettext import locale import pkg_resources +import signal import deluge.component as component import deluge.ui.client as client @@ -114,8 +115,18 @@ class GtkUI: pkg_resources.resource_filename( "deluge", "i18n")) + # Setup signals + try: + import gnome.ui + self.gnome_client = gnome.ui.Client() + self.gnome_client.connect("die", self.shutdown) + except: + pass + signal.signal(signal.SIGINT, self.shutdown) + signal.signal(signal.SIGTERM, self.shutdown) + # Make sure gtkui.conf has at least the defaults set - config = ConfigManager("gtkui.conf", DEFAULT_PREFS) + self.config = ConfigManager("gtkui.conf", DEFAULT_PREFS) # Start the Dbus Interface before anything else.. Just in case we are # already running. @@ -145,16 +156,22 @@ class GtkUI: # Show the connection manager self.connectionmanager = ConnectionManager() - if config["show_connection_manager_on_start"]: + if self.config["show_connection_manager_on_start"]: self.connectionmanager.show() # Start the gtk main loop - gtk.main() - + try: + gtk.main() + except KeyboardInterrupt: + self.shutdown() + else: + self.shutdown() + + def shutdown(self, data=None): log.debug("gtkui shutting down..") # Make sure the config is saved. - config.save() + self.config.save() # Shutdown all components component.shutdown()