diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index fd71d1c8fe..05bf3dfcc5 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -716,7 +716,9 @@ class Cache: references resources their hashes must be present in resource_hashes. Set remove_unused_resources to True to cleanup unused resources, note that updating a note automatically cleans up resources pertaining to that note anyway. ''' - return self.backend.set_notes_for(field, item_id, doc, searchable_text, resource_hashes, remove_unused_resources) + ans = self.backend.set_notes_for(field, item_id, doc, searchable_text, resource_hashes, remove_unused_resources) + self.event_dispatcher(EventType.notes_changed, field, item_id) + return ans @write_api def add_notes_resource(self, path_or_stream_or_data, name: str, mtime: float = None) -> int: @@ -736,7 +738,9 @@ class Cache: @write_api def unretire_note_for(self, field, item_id) -> int: ' Unretire a previously retired note for the specified item. Notes are retired when an item is removed from the database ' - return self.backend.unretire_note_for(field, item_id) + ans = self.backend.unretire_note_for(field, item_id) + self.event_dispatcher(EventType.notes_changed, field, item_id) + return ans @read_api def export_note(self, field, item_id) -> str: @@ -756,7 +760,9 @@ class Cache: st = os.stat(f.fileno()) ctime, mtime = st.st_ctime, st.st_mtime basedir = os.path.dirname(os.path.abspath(path_to_html_file)) - return self.backend.import_note(field, item_id, html, basedir, ctime, mtime) + ans = self.backend.import_note(field, item_id, html, basedir, ctime, mtime) + self.event_dispatcher(EventType.notes_changed, field, item_id) + return ans @write_api # we need to use write locking as SQLITE gives a locked table error if multiple FTS queries are made at the same time def search_notes( diff --git a/src/calibre/db/listeners.py b/src/calibre/db/listeners.py index b6e2fb2850..a372aa41c6 100644 --- a/src/calibre/db/listeners.py +++ b/src/calibre/db/listeners.py @@ -43,6 +43,9 @@ class EventType(Enum): #: When the indexing progress changes indexing_progress_changed = auto() + #: When the notes associated with an item are changed, with arguments: (field_name, item_id) + notes_changed = auto() + class EventDispatcher(Thread):