diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index ae2ac694f2..4e550de6ad 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -80,6 +80,8 @@ def _config(): help=_('Use Roman numerals for series number')) c.add_opt('sort_tags_by', default='name', help=_('Sort tags list by name, popularity, or rating')) + c.add_opt('match_tags_type', default='any', + help=_('Match tags by any or all.')) c.add_opt('cover_flow_queue_length', default=6, help=_('Number of covers to show in the cover browsing mode')) c.add_opt('LRF_conversion_defaults', default=[], diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 6b1ce2f851..f86e261443 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -158,11 +158,17 @@ class TagsView(QTreeView): # {{{ self.setContextMenuPolicy(Qt.CustomContextMenu) pop = config['sort_tags_by'] self.sort_by.setCurrentIndex(self.db.CATEGORY_SORTS.index(pop)) + try: + match_pop = self.db.MATCH_TYPE.index(config['match_tags_type']) + except ValueError: + match_pop = 0 + self.tag_match.setCurrentIndex(match_pop) if not self.made_connections: self.clicked.connect(self.toggle) self.customContextMenuRequested.connect(self.show_context_menu) self.refresh_required.connect(self.recount, type=Qt.QueuedConnection) self.sort_by.currentIndexChanged.connect(self.sort_changed) + self.tag_match.currentIndexChanged.connect(self.match_changed) self.made_connections = True self.refresh_signal_processed = True db.add_listener(self.database_changed) @@ -180,6 +186,12 @@ class TagsView(QTreeView): # {{{ config.set('sort_tags_by', self.db.CATEGORY_SORTS[pop]) self.recount() + def match_changed(self, pop): + try: + config.set('match_tags_type', self.db.MATCH_TYPE[pop]) + except: + pass + def set_search_restriction(self, s): if s: self.search_restriction = s @@ -2114,6 +2126,7 @@ class TagBrowserWidget(QWidget): # {{{ parent.sort_by.setCurrentIndex(0) self._layout.addWidget(parent.sort_by) + # Must be in the same order as db2.MATCH_TYPE parent.tag_match = QComboBox(parent) for x in (_('Match any'), _('Match all')): parent.tag_match.addItem(x) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 0cae7be2f8..042899adbe 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1228,6 +1228,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): ########## data structures for get_categories CATEGORY_SORTS = ('name', 'popularity', 'rating') + MATCH_TYPE = ('any', 'all') class TCat_Tag(object):