diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index 8e9fca718e..f8177b7680 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -98,7 +98,7 @@ class MyBlockingBusy(QDialog): return self.accept() def do_one(self, id): - remove, add, au, aus, do_aus, rating, pub, do_series, \ + remove_all, remove, add, au, aus, do_aus, rating, pub, do_series, \ do_autonumber, do_remove_format, remove_format, do_swap_ta, \ do_remove_conv, do_auto_author, series, do_series_restart, \ series_start_value, do_title_case, clear_series = self.args @@ -168,6 +168,8 @@ class MyBlockingBusy(QDialog): # both of these are fast enough to just do them all for w in self.cc_widgets: w.commit(self.ids) + if remove_all: + self.db.remove_all_tags(self.ids) self.db.bulk_modify_tags(self.ids, add=add, remove=remove, notify=False) self.current_index = len(self.ids) @@ -640,9 +642,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): for w in getattr(self, 'custom_column_widgets', []): w.gui_val - if self.remove_all_tags.isChecked(): - remove = self.db.all_tags() - else: + remove_all = self.remove_all_tags.isChecked() + remove = [] + if not remove_all: remove = unicode(self.remove_tags.text()).strip().split(',') add = unicode(self.tags.text()).strip().split(',') au = unicode(self.authors.text()) @@ -663,7 +665,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): do_auto_author = self.auto_author_sort.isChecked() do_title_case = self.change_title_to_title_case.isChecked() - args = (remove, add, au, aus, do_aus, rating, pub, do_series, + args = (remove_all, remove, add, au, aus, do_aus, rating, pub, do_series, do_autonumber, do_remove_format, remove_format, do_swap_ta, do_remove_conv, do_auto_author, series, do_series_restart, series_start_value, do_title_case, clear_series) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index efe92d3c63..c4d11beb58 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1759,6 +1759,18 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): ans.append(tag) return ans + def remove_all_tags(self, ids, notify=False, commit=True): + self.conn.executemany( + 'DELETE FROM books_tags_link WHERE book=?', [(x,) for x in ids]) + self.dirtied(ids, commit=False) + if commit: + self.conn.commit() + + for x in ids: + self.data.set(x, self.FIELD_MAP['tags'], '', row_is_id=True) + if notify: + self.notify('metadata', ids) + def bulk_modify_tags(self, ids, add=[], remove=[], notify=False): add = self.cleanup_tags(add) remove = self.cleanup_tags(remove)