diff --git a/src/calibre/gui2/tags.py b/src/calibre/gui2/tags.py index 0a08411056..167236c960 100644 --- a/src/calibre/gui2/tags.py +++ b/src/calibre/gui2/tags.py @@ -39,8 +39,8 @@ class TagsView(QTreeView): class TagsModel(QAbstractItemModel): - categories = [_('Authors'), _('Series'), _('Formats'), _('Publishers'), _('Tags')] - row_map = {0: 'author', 1:'series', 2:'format', 3:'publisher', 4:'tag'} + categories = [_('Authors'), _('Series'), _('Formats'), _('Publishers'), _('News'), _('Tags')] + row_map = {0: 'author', 1:'series', 2:'format', 3:'publisher', 4:'news', 5:'tag'} def __init__(self, db): QAbstractItemModel.__init__(self) @@ -53,7 +53,7 @@ class TagsModel(QAbstractItemModel): self.bold_font = QVariant(self.bold_font) self.status_map = [QColor(200,200,200, 0), QIcon(':/images/plus.svg'), QIcon(':/images/minus.svg')] self.status_map = list(map(QVariant, self.status_map)) - self.cmap = [QIcon(':/images/user_profile.svg'), QIcon(':/images/series.svg'), QIcon(':/images/book.svg'), QIcon(':/images/publisher.png'), QIcon(':/images/tags.svg')] + self.cmap = [QIcon(':/images/user_profile.svg'), QIcon(':/images/series.svg'), QIcon(':/images/book.svg'), QIcon(':/images/publisher.png'), QIcon(':/images/news.svg'), QIcon(':/images/tags.svg')] self.cmap = list(map(QVariant, self.cmap)) self.db.add_listener(self.database_changed) @@ -95,9 +95,10 @@ class TagsModel(QAbstractItemModel): ans = [] for key in self.row_map.values(): for tag in self._data[key]: + category = key if key != 'news' else 'tag' if tag.state > 0: prefix = ' not ' if tag.state == 2 else '' - ans.append('%s%s:"%s"'%(prefix, key, tag)) + ans.append('%s%s:"%s"'%(prefix, category, tag)) return ans def index(self, row, col, parent=QModelIndex()): diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index faf0b560eb..35a7ad1c3a 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -746,6 +746,16 @@ class LibraryDatabase2(LibraryDatabase): ('series', 'series')): get(*x) get('data', 'format', 'format') + + categories['news'] = [] + newspapers = self.conn.get('SELECT name FROM tags WHERE id IN (SELECT DISTINCT tag FROM books_tags_link WHERE book IN (select book from books_tags_link where tag IN (SELECT id FROM tags WHERE name=?)))', (_('News'),)) + if newspapers: + newspapers = [f[0] for f in newspapers] + newspapers.remove(_('News')) + categories['news'] = list(map(Tag, newspapers)) + for tag in categories['news']: + tag.count = self.conn.get('SELECT COUNT(id) FROM books_tags_link WHERE tag IN (SELECT DISTINCT id FROM tags WHERE name=?)', (tag,), all=False) + return categories