Add easy access to downloaded news via the tag browsing mode

This commit is contained in:
Kovid Goyal 2008-11-30 21:57:01 -08:00
parent 0a1f3b4525
commit 02c9864c6a
2 changed files with 15 additions and 4 deletions

View File

@ -39,8 +39,8 @@ class TagsView(QTreeView):
class TagsModel(QAbstractItemModel): class TagsModel(QAbstractItemModel):
categories = [_('Authors'), _('Series'), _('Formats'), _('Publishers'), _('Tags')] categories = [_('Authors'), _('Series'), _('Formats'), _('Publishers'), _('News'), _('Tags')]
row_map = {0: 'author', 1:'series', 2:'format', 3:'publisher', 4:'tag'} row_map = {0: 'author', 1:'series', 2:'format', 3:'publisher', 4:'news', 5:'tag'}
def __init__(self, db): def __init__(self, db):
QAbstractItemModel.__init__(self) QAbstractItemModel.__init__(self)
@ -53,7 +53,7 @@ class TagsModel(QAbstractItemModel):
self.bold_font = QVariant(self.bold_font) 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 = [QColor(200,200,200, 0), QIcon(':/images/plus.svg'), QIcon(':/images/minus.svg')]
self.status_map = list(map(QVariant, self.status_map)) 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.cmap = list(map(QVariant, self.cmap))
self.db.add_listener(self.database_changed) self.db.add_listener(self.database_changed)
@ -95,9 +95,10 @@ class TagsModel(QAbstractItemModel):
ans = [] ans = []
for key in self.row_map.values(): for key in self.row_map.values():
for tag in self._data[key]: for tag in self._data[key]:
category = key if key != 'news' else 'tag'
if tag.state > 0: if tag.state > 0:
prefix = ' not ' if tag.state == 2 else '' 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 return ans
def index(self, row, col, parent=QModelIndex()): def index(self, row, col, parent=QModelIndex()):

View File

@ -746,6 +746,16 @@ class LibraryDatabase2(LibraryDatabase):
('series', 'series')): ('series', 'series')):
get(*x) get(*x)
get('data', 'format', 'format') 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 return categories