diff --git a/resources/images/id_card.png b/resources/images/id_card.png new file mode 100644 index 0000000000..80ac5fda11 Binary files /dev/null and b/resources/images/id_card.png differ diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 92ed3bca67..0a65b8da67 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -1588,6 +1588,9 @@ class TagsModel(QAbstractItemModel): # {{{ else: prefix = '' category = tag.category if key != 'news' else 'tag' + if self.db.field_metadata[tag.category]['is_csp']: + add_colon = True + if tag.name and tag.name[0] == u'\u2605': # char is a star. Assume rating ans.append('%s%s:%s'%(prefix, category, len(tag.name))) else: @@ -1604,8 +1607,9 @@ class TagsModel(QAbstractItemModel): # {{{ n = name.replace(r'"', r'\"') if name.startswith('.'): n = '.' + n - ans.append('%s%s:"=%s%s"'%(prefix, category, - '.' if use_prefix else '', n)) + ans.append('%s%s:"=%s%s%s"'%(prefix, category, + '.' if use_prefix else '', n, + ':' if add_colon else '')) return ans def find_item_node(self, key, txt, start_path, equals_match=False): diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 556131b2c9..e72400a0bd 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1493,6 +1493,34 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): # No need for ICU here. categories['formats'].sort(key = lambda x:x.name) + # Now do identifiers. This works like formats + categories['identifiers'] = [] + icon = None + if icon_map and 'identifiers' in icon_map: + icon = icon_map['identifiers'] + for ident in self.conn.get('SELECT DISTINCT type FROM identifiers'): + ident = ident[0] + if ids is not None: + count = self.conn.get('''SELECT COUNT(book) + FROM identifiers + WHERE type="%s" AND + books_list_filter(book)'''%ident, + all=False) + else: + count = self.conn.get('''SELECT COUNT(id) + FROM identifiers + WHERE type="%s"'''%ident, + all=False) + if count > 0: + categories['identifiers'].append(Tag(ident, count=count, icon=icon, + category='identifiers')) + + if sort == 'popularity': + categories['identifiers'].sort(key=lambda x: x.count, reverse=True) + else: # no ratings exist to sort on + # No need for ICU here. + categories['identifiers'].sort(key = lambda x:x.name) + #### Now do the user-defined categories. #### user_categories = dict.copy(self.clean_user_categories()) diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index d89322954f..ff38af6890 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -16,7 +16,8 @@ class TagsIcons(dict): ''' category_icons = ['authors', 'series', 'formats', 'publisher', 'rating', - 'news', 'tags', 'custom:', 'user:', 'search',] + 'news', 'tags', 'custom:', 'user:', 'search', + 'identifiers'] def __init__(self, icon_dict): for a in self.category_icons: if a not in icon_dict: @@ -24,16 +25,17 @@ class TagsIcons(dict): self[a] = icon_dict[a] category_icon_map = { - 'authors' : 'user_profile.png', - 'series' : 'series.png', - 'formats' : 'book.png', - 'publisher' : 'publisher.png', - 'rating' : 'rating.png', - 'news' : 'news.png', - 'tags' : 'tags.png', - 'custom:' : 'column.png', - 'user:' : 'tb_folder.png', - 'search' : 'search.png' + 'authors' : 'user_profile.png', + 'series' : 'series.png', + 'formats' : 'book.png', + 'publisher' : 'publisher.png', + 'rating' : 'rating.png', + 'news' : 'news.png', + 'tags' : 'tags.png', + 'custom:' : 'column.png', + 'user:' : 'tb_folder.png', + 'search' : 'search.png', + 'identifiers': 'id_card.png' } diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index 0e132c7d11..585c1255a4 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -346,7 +346,7 @@ class BrowseServer(object): for category in sorted(categories, key=lambda x: sort_key(getter(x))): if len(categories[category]) == 0: continue - if category == 'formats': + if category in ('formats', 'identifiers'): continue meta = category_meta.get(category, None) if meta is None: diff --git a/src/calibre/library/server/opds.py b/src/calibre/library/server/opds.py index 72a802eaa9..e7fdffbbbb 100644 --- a/src/calibre/library/server/opds.py +++ b/src/calibre/library/server/opds.py @@ -580,7 +580,7 @@ class OPDSServer(object): for category in sorted(categories, key=lambda x: sort_key(getter(x))): if len(categories[category]) == 0: continue - if category == 'formats': + if category in ('formats', 'identifiers'): continue meta = category_meta.get(category, None) if meta is None: