A new API so that plugins are notified before the library is about to change

Fix #1977979 [Private bug](https://bugs.launchpad.net/calibre/+bug/1977979)
This commit is contained in:
Kovid Goyal 2022-06-08 19:57:18 +05:30
parent d80d0d55a9
commit 609b431c91
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 21 additions and 1 deletions

View File

@ -324,6 +324,16 @@ class InterfaceAction(QObject):
'''
pass
def library_about_to_change(self, olddb, db):
'''
Called whenever the current library is changed.
:param olddb: The LibraryDatabase corresponding to the previous library.
:param db: The LibraryDatabase corresponding to the new library.
'''
pass
def library_changed(self, db):
'''
Called whenever the current library is changed.

View File

@ -872,6 +872,12 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
return
else:
return
for action in self.iactions.values():
try:
action.library_about_to_change(olddb, db)
except Exception:
import traceback
traceback.print_exc()
self.library_path = newloc
prefs['library_path'] = self.library_path
self.book_on_device(None, reset=True)
@ -893,7 +899,11 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.apply_virtual_library(db.new_api.pref('virtual_lib_on_startup'))
self.rebuild_vl_tabs()
for action in self.iactions.values():
try:
action.library_changed(db)
except Exception:
import traceback
traceback.print_exc()
self.library_broker.gui_library_changed(db, olddb)
if self.device_connected:
self.set_books_in_library(self.booklists(), reset=True)