Saved search categories

This commit is contained in:
Kovid Goyal 2013-01-25 13:52:35 +05:30
parent 6b4aad42d0
commit dc0f280cae
3 changed files with 58 additions and 46 deletions

View File

@ -15,6 +15,7 @@ from future_builtins import map
from calibre.library.field_metadata import TagsIcons
from calibre.utils.config_base import tweaks
from calibre.utils.icu import sort_key
from calibre.utils.search_query_parser import saved_searches
CATEGORY_SORTS = ('name', 'popularity', 'rating') # This has to be a tuple not a set
@ -158,6 +159,7 @@ def get_categories(dbcache, sort='name', book_ids=None, icon_map=None):
# User categories
user_categories = clean_user_categories(dbcache).copy()
if user_categories:
# We want to use same node in the user category as in the source
# category. To do that, we need to find the original Tag node. There is
# a time/space tradeoff here. By converting the tags into a map, we can
@ -206,7 +208,18 @@ def get_categories(dbcache, sort='name', book_ids=None, icon_map=None):
icon_map[cat_name] = icon_map['user:']
categories[cat_name] = sort_categories(items, sort)
# TODO: saved searches
#### Finally, the saved searches category ####
items = []
icon = None
if icon_map and 'search' in icon_map:
icon = icon_map['search']
ss = saved_searches()
for srch in ss.names():
items.append(Tag(srch, tooltip=ss.lookup(srch),
sort=srch, icon=icon, category='search',
is_editable=False))
if len(items):
categories['search'] = items
return categories

View File

@ -17,7 +17,6 @@ from calibre.utils.icu import primary_find
from calibre.utils.localization import lang_map, canonicalize_lang
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
# TODO: Thread safety of saved searches
CONTAINS_MATCH = 0
EQUALS_MATCH = 1
REGEXP_MATCH = 2

Binary file not shown.