Improvements in display of grouped search terms in the tag browser. Consolodate tags and use the category name. Use the catalog icon for grouped search terms. Searching from the tag browser uses the GST name instead of the underlying category.

This commit is contained in:
Charles Haley 2011-07-08 13:56:42 +01:00
parent 231c0a4bbf
commit cf02b7c2b5
3 changed files with 27 additions and 6 deletions

View File

@ -21,6 +21,7 @@ from calibre.utils.icu import sort_key, lower, strcmp
from calibre.library.field_metadata import TagsIcons, category_icon_map from calibre.library.field_metadata import TagsIcons, category_icon_map
from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.dialogs.confirm_delete import confirm
from calibre.utils.formatter import EvalFormatter from calibre.utils.formatter import EvalFormatter
from calibre.utils.ordered_dict import OrderedDict
from calibre.utils.search_query_parser import saved_searches from calibre.utils.search_query_parser import saved_searches
TAG_SEARCH_STATES = {'clear': 0, 'mark_plus': 1, 'mark_plusplus': 2, TAG_SEARCH_STATES = {'clear': 0, 'mark_plus': 1, 'mark_plusplus': 2,
@ -315,9 +316,11 @@ class TagsModel(QAbstractItemModel): # {{{
for i,p in enumerate(path_parts): for i,p in enumerate(path_parts):
path += p path += p
if path not in category_node_map: if path not in category_node_map:
icon = self.category_icon_map['gst'] if is_gst else \
self.category_icon_map[key]
node = self.create_node(parent=last_category_node, node = self.create_node(parent=last_category_node,
data=p[1:] if i == 0 else p, data=p[1:] if i == 0 else p,
category_icon=self.category_icon_map[key], category_icon=icon,
tooltip=tt if path == key else path, tooltip=tt if path == key else path,
category_key=path, category_key=path,
icon_map=self.icon_state_map) icon_map=self.icon_state_map)
@ -375,6 +378,7 @@ class TagsModel(QAbstractItemModel): # {{{
collapse_letter = None collapse_letter = None
category_node = category category_node = category
key = category_node.category_key key = category_node.category_key
is_gst = category_node.is_gst
if key not in data: if key not in data:
return return
cat_len = len(data[key]) cat_len = len(data[key])
@ -455,6 +459,7 @@ class TagsModel(QAbstractItemModel): # {{{
tooltip = None, temporary=True, tooltip = None, temporary=True,
category_key=category_node.category_key, category_key=category_node.category_key,
icon_map=self.icon_state_map) icon_map=self.icon_state_map)
sub_cat.is_gst = is_gst
node_parent = sub_cat node_parent = sub_cat
else: else:
node_parent = category node_parent = category
@ -1161,7 +1166,10 @@ class TagsModel(QAbstractItemModel): # {{{
prefix = ' not ' prefix = ' not '
else: else:
prefix = '' prefix = ''
category = tag.category if key != 'news' else 'tag' if node.is_gst:
category = key
else:
category = tag.category if key != 'news' else 'tag'
add_colon = False add_colon = False
if self.db.field_metadata[tag.category]['is_csp']: if self.db.field_metadata[tag.category]['is_csp']:
add_colon = True add_colon = True

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
The database used to store ebook metadata The database used to store ebook metadata
''' '''
import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \ import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \
json, uuid, tempfile, hashlib json, uuid, tempfile, hashlib, copy
from collections import defaultdict from collections import defaultdict
import threading, random import threading, random
from itertools import repeat from itertools import repeat
@ -1794,10 +1794,22 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
for user_cat in sorted(user_categories.keys(), key=sort_key): for user_cat in sorted(user_categories.keys(), key=sort_key):
items = [] items = []
names_seen = {}
for (name,label,ign) in user_categories[user_cat]: for (name,label,ign) in user_categories[user_cat]:
n = icu_lower(name) n = icu_lower(name)
if label in taglist and n in taglist[label]: if label in taglist and n in taglist[label]:
items.append(taglist[label][n]) if user_cat in gst:
# for gst items, make copy and consolidate the tags by name.
if n in names_seen:
names_seen[n].id_set |= taglist[label][n].id_set
names_seen[n].count += taglist[label][n].count
else:
t = copy.copy(taglist[label][n])
t.icon = icon_map['gst']
names_seen[t.name] = t
items.append(t)
else:
items.append(taglist[label][n])
# else: do nothing, to not include nodes w zero counts # else: do nothing, to not include nodes w zero counts
cat_name = '@' + user_cat # add the '@' to avoid name collision cat_name = '@' + user_cat # add the '@' to avoid name collision
# Not a problem if we accumulate entries in the icon map # Not a problem if we accumulate entries in the icon map

View File

@ -17,7 +17,7 @@ class TagsIcons(dict):
category_icons = ['authors', 'series', 'formats', 'publisher', 'rating', category_icons = ['authors', 'series', 'formats', 'publisher', 'rating',
'news', 'tags', 'custom:', 'user:', 'search', 'news', 'tags', 'custom:', 'user:', 'search',
'identifiers'] 'identifiers', 'gst']
def __init__(self, icon_dict): def __init__(self, icon_dict):
for a in self.category_icons: for a in self.category_icons:
if a not in icon_dict: if a not in icon_dict:
@ -35,7 +35,8 @@ category_icon_map = {
'custom:' : 'column.png', 'custom:' : 'column.png',
'user:' : 'tb_folder.png', 'user:' : 'tb_folder.png',
'search' : 'search.png', 'search' : 'search.png',
'identifiers': 'identifiers.png' 'identifiers': 'identifiers.png',
'gst' : 'catalog.png',
} }