Add hooks to GUI plugins for the shutdown process

This commit is contained in:
Kovid Goyal 2010-08-15 11:25:19 -06:00
parent 45d20f7d7c
commit 51c56af079
2 changed files with 16 additions and 4 deletions

View File

@ -27,7 +27,8 @@ class InterfaceAction(QObject):
priority takes precedence. priority takes precedence.
Sub-classes should implement the :meth:`genesis`, :meth:`library_moved`, 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 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:: :attr:`gui` member. You can access other plugins by name, for example::
@ -122,3 +123,14 @@ class InterfaceAction(QObject):
completed. completed.
''' '''
pass 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

View File

@ -352,8 +352,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
def booklists(self): def booklists(self):
return self.memory_view.model().db, self.card_a_view.model().db, self.card_b_view.model().db return self.memory_view.model().db, self.card_a_view.model().db, self.card_b_view.model().db
def library_moved(self, newloc): def library_moved(self, newloc):
if newloc is None: return if newloc is None: return
db = LibraryDatabase2(newloc) db = LibraryDatabase2(newloc)
@ -377,7 +375,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
def set_window_title(self): def set_window_title(self):
self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name()) self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name())
def location_selected(self, location): def location_selected(self, location):
''' '''
Called when a location icon is clicked (e.g. Library) 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): def shutdown(self, write_settings=True):
for action in self.iactions.values():
if not action.shutting_down():
return
if write_settings: if write_settings:
self.write_settings() self.write_settings()
self.check_messages_timer.stop() self.check_messages_timer.stop()