From 51c56af0797a967b8b426b0e4f1135cb3e19bbff Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Aug 2010 11:25:19 -0600 Subject: [PATCH] Add hooks to GUI plugins for the shutdown process --- src/calibre/gui2/actions/__init__.py | 14 +++++++++++++- src/calibre/gui2/ui.py | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index bce1f283aa..9c20f2adef 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -27,7 +27,8 @@ class InterfaceAction(QObject): priority takes precedence. Sub-classes should implement the :meth:`genesis`, :meth:`library_moved`, - :meth:`location_selected` and :meth:`initialization_complete` methods. + :meth:`location_selected` :meth:`shutting_down` + and :meth:`initialization_complete` methods. Once initialized, this plugin has access to the main calibre GUI via the :attr:`gui` member. You can access other plugins by name, for example:: @@ -122,3 +123,14 @@ class InterfaceAction(QObject): completed. ''' pass + + def shutting_down(self): + ''' + Called once per plugin when the main GUI is in the process of shutting + down. Release any used resources, but try not to block the shutdown for + long periods of time. + + :return: False to halt the shutdown. You are responsible for telling + the user why the shutdown was halted. + ''' + return True diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 01e9d959f9..1b918e679e 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -352,8 +352,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ def booklists(self): return self.memory_view.model().db, self.card_a_view.model().db, self.card_b_view.model().db - - def library_moved(self, newloc): if newloc is None: return db = LibraryDatabase2(newloc) @@ -377,7 +375,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ def set_window_title(self): self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name()) - def location_selected(self, location): ''' Called when a location icon is clicked (e.g. Library) @@ -517,6 +514,9 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ def shutdown(self, write_settings=True): + for action in self.iactions.values(): + if not action.shutting_down(): + return if write_settings: self.write_settings() self.check_messages_timer.stop()