From a04171dfb4732c31daf2bbdcde22de402e74fc4f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Oct 2020 19:42:43 +0530 Subject: [PATCH] Use the all_field_names() API in a few more places --- src/calibre/gui2/convert/metadata.py | 12 ++++-------- src/calibre/gui2/dialogs/metadata_bulk.py | 18 +++++++----------- src/calibre/gui2/metadata/basic_widgets.py | 4 ++-- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/calibre/gui2/convert/metadata.py b/src/calibre/gui2/convert/metadata.py index d3e5cbf284..2f31285b51 100644 --- a/src/calibre/gui2/convert/metadata.py +++ b/src/calibre/gui2/convert/metadata.py @@ -92,7 +92,7 @@ class MetadataWidget(Widget, Ui_Form): self.author_sort.setText(mi.author_sort if mi.author_sort else '') self.author_sort.home(False) self.tags.setText(', '.join(mi.tags if mi.tags else [])) - self.tags.update_items_cache(self.db.all_tags()) + self.tags.update_items_cache(self.db.new_api.all_field_names('tags')) self.tags.home(False) self.comment.html = comments_to_html(mi.comments) if mi.comments else '' self.series.show_initial_value(mi.series if mi.series else '') @@ -141,7 +141,7 @@ class MetadataWidget(Widget, Ui_Form): self.author.set_separator('&') self.author.set_space_before_sep(True) self.author.set_add_separator(tweaks['authors_completer_append_separator']) - self.author.update_items_cache(self.db.all_author_names()) + self.author.update_items_cache(self.db.new_api.all_field_names('authors')) au = self.db.authors(self.book_id, True) if not au: @@ -151,16 +151,12 @@ class MetadataWidget(Widget, Ui_Form): self.author.home(False) def initialize_series(self): - all_series = self.db.all_series() - all_series.sort(key=lambda x : sort_key(x[1])) self.series.set_separator(None) - self.series.update_items_cache([x[1] for x in all_series]) + self.series.update_items_cache(self.db.new_api.all_field_names('series')) def initialize_publisher(self): - all_publishers = self.db.all_publishers() - all_publishers.sort(key=lambda x : sort_key(x[1])) self.publisher.set_separator(None) - self.publisher.update_items_cache([x[1] for x in all_publishers]) + self.publisher.update_items_cache(self.db.new_api.all_field_names('publisher')) def get_title_and_authors(self): title = unicode_type(self.title.text()).strip() diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index b2925fc03b..075aff3bee 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -491,7 +491,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.comments = null self.comments_button.clicked.connect(self.set_comments) - all_tags = self.db.all_tags() + all_tags = self.db.new_api.all_field_names('tags') self.tags.update_items_cache(all_tags) self.remove_tags.update_items_cache(all_tags) @@ -1094,21 +1094,16 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.authors.set_separator('&') self.authors.set_space_before_sep(True) self.authors.set_add_separator(tweaks['authors_completer_append_separator']) - self.authors.update_items_cache(self.db.all_author_names()) + self.authors.update_items_cache(self.db.new_api.all_field_names('authors')) self.authors.show_initial_value('') def initialize_series(self): - all_series = self.db.all_series() - all_series.sort(key=lambda x : sort_key(x[1])) self.series.set_separator(None) - self.series.update_items_cache([x[1] for x in all_series]) + self.series.update_items_cache(self.db.new_api.all_field_names('series')) self.series.show_initial_value('') def initialize_publisher(self): - all_publishers = self.db.all_publishers() - all_publishers.sort(key=lambda x : sort_key(x[1])) - self.publisher.set_separator(None) - self.publisher.update_items_cache([x[1] for x in all_publishers]) + self.publisher.update_items_cache(self.db.new_api.all_field_names('publisher')) self.publisher.show_initial_value('') def tag_editor(self, *args): @@ -1117,8 +1112,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): if d.result() == QDialog.Accepted: tag_string = ', '.join(d.tags) self.tags.setText(tag_string) - self.tags.update_items_cache(self.db.all_tags()) - self.remove_tags.update_items_cache(self.db.all_tags()) + all_tags = self.db.new_api.all_field_names('tags') + self.tags.update_items_cache(all_tags) + self.remove_tags.update_items_cache(all_tags) def auto_number_changed(self, state): self.series_start_number.setEnabled(bool(state)) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 5da9155a07..621588e4d1 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -1377,7 +1377,7 @@ class TagsEdit(EditWithComplete, ToMetadataMixin): # {{{ tags = db.tags(id_, index_is_id=True) tags = tags.split(',') if tags else [] self.current_val = tags - self.all_items = db.all_tag_names() + self.update_items_cache(db.new_api.all_field_names('tags')) self.original_val = self.current_val @property @@ -1401,7 +1401,7 @@ class TagsEdit(EditWithComplete, ToMetadataMixin): # {{{ d = TagEditor(self, db, id_) if d.exec_() == TagEditor.Accepted: self.current_val = d.tags - self.all_items = db.all_tags() + self.update_items_cache(db.new_api.all_field_names('tags')) def commit(self, db, id_): self.books_to_refresh |= db.set_tags(