mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanups
This commit is contained in:
commit
07a8847f8a
@ -15,6 +15,7 @@ from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, \
|
|||||||
from calibre.gui2 import config, NONE
|
from calibre.gui2 import config, NONE
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.library.field_metadata import TagsIcons
|
from calibre.library.field_metadata import TagsIcons
|
||||||
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
|
|
||||||
class TagsView(QTreeView): # {{{
|
class TagsView(QTreeView): # {{{
|
||||||
|
|
||||||
@ -221,6 +222,18 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
self.db = db
|
self.db = db
|
||||||
self.search_restriction = ''
|
self.search_restriction = ''
|
||||||
self.ignore_next_search = 0
|
self.ignore_next_search = 0
|
||||||
|
|
||||||
|
# Reconstruct the user categories, putting them into metadata
|
||||||
|
tb_cats = self.db.field_metadata
|
||||||
|
for k in tb_cats.keys():
|
||||||
|
if tb_cats[k]['kind'] in ['user', 'search']:
|
||||||
|
del tb_cats[k]
|
||||||
|
for user_cat in sorted(prefs['user_categories'].keys()):
|
||||||
|
cat_name = user_cat+':' # add the ':' to avoid name collision
|
||||||
|
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
||||||
|
if len(saved_searches.names()):
|
||||||
|
tb_cats.add_search_category(label='search', name=_('Searches'))
|
||||||
|
|
||||||
data = self.get_node_tree(config['sort_by_popularity'])
|
data = self.get_node_tree(config['sort_by_popularity'])
|
||||||
self.root_item = TagTreeItem()
|
self.root_item = TagTreeItem()
|
||||||
for i, r in enumerate(self.row_map):
|
for i, r in enumerate(self.row_map):
|
||||||
|
@ -231,6 +231,18 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
self.conn.executescript(script)
|
self.conn.executescript(script)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
|
# Reconstruct the user categories, putting them into field_metadata
|
||||||
|
# Assumption is that someone else will fix them if they change.
|
||||||
|
tb_cats = self.field_metadata
|
||||||
|
for k in tb_cats.keys():
|
||||||
|
if tb_cats[k]['kind'] in ['user', 'search']:
|
||||||
|
del tb_cats[k]
|
||||||
|
for user_cat in sorted(prefs['user_categories'].keys()):
|
||||||
|
cat_name = user_cat+':' # add the ':' to avoid name collision
|
||||||
|
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
||||||
|
if len(saved_searches.names()):
|
||||||
|
tb_cats.add_search_category(label='search', name=_('Searches'))
|
||||||
|
|
||||||
self.book_on_device_func = None
|
self.book_on_device_func = None
|
||||||
self.data = ResultCache(self.FIELD_MAP, self.field_metadata)
|
self.data = ResultCache(self.FIELD_MAP, self.field_metadata)
|
||||||
self.search = self.data.search
|
self.search = self.data.search
|
||||||
@ -653,17 +665,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
raise TypeError('icon_map passed to get_categories must be of type TagIcons')
|
raise TypeError('icon_map passed to get_categories must be of type TagIcons')
|
||||||
|
|
||||||
tb_cats = self.field_metadata
|
tb_cats = self.field_metadata
|
||||||
|
|
||||||
# remove all user categories from field_metadata. They can
|
|
||||||
# easily come and go. We will add all the existing ones in below.
|
|
||||||
for k in tb_cats.keys():
|
|
||||||
if tb_cats[k]['kind'] in ['user', 'search']:
|
|
||||||
del tb_cats[k]
|
|
||||||
|
|
||||||
#### First, build the standard and custom-column categories ####
|
#### First, build the standard and custom-column categories ####
|
||||||
for category in tb_cats.keys():
|
for category in tb_cats.keys():
|
||||||
cat = tb_cats[category]
|
cat = tb_cats[category]
|
||||||
if not cat['is_category']:
|
if not cat['is_category'] or not cat['kind'] == 'field':
|
||||||
continue
|
continue
|
||||||
tn = cat['table']
|
tn = cat['table']
|
||||||
categories[category] = [] #reserve the position in the ordered list
|
categories[category] = [] #reserve the position in the ordered list
|
||||||
@ -757,7 +762,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
# else: do nothing, to not include nodes w zero counts
|
# else: do nothing, to not include nodes w zero counts
|
||||||
if len(items):
|
if len(items):
|
||||||
cat_name = user_cat+':' # add the ':' to avoid name collision
|
cat_name = user_cat+':' # add the ':' to avoid name collision
|
||||||
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
|
||||||
# Not a problem if we accumulate entries in the icon map
|
# Not a problem if we accumulate entries in the icon map
|
||||||
if icon_map is not None:
|
if icon_map is not None:
|
||||||
icon_map[cat_name] = icon_map[':user']
|
icon_map[cat_name] = icon_map[':user']
|
||||||
@ -776,7 +780,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
for srch in saved_searches.names():
|
for srch in saved_searches.names():
|
||||||
items.append(Tag(srch, tooltip=saved_searches.lookup(srch), icon=icon))
|
items.append(Tag(srch, tooltip=saved_searches.lookup(srch), icon=icon))
|
||||||
if len(items):
|
if len(items):
|
||||||
tb_cats.add_search_category(label='search', name=_('Searches'))
|
|
||||||
if icon_map is not None:
|
if icon_map is not None:
|
||||||
icon_map['search'] = icon_map['search']
|
icon_map['search'] = icon_map['search']
|
||||||
categories['search'] = items
|
categories['search'] = items
|
||||||
|
@ -64,6 +64,7 @@ class FieldMetadata(dict):
|
|||||||
_field_metadata = [
|
_field_metadata = [
|
||||||
('authors', {'table':'authors',
|
('authors', {'table':'authors',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
|
'link_column':'author',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':',',
|
'is_multiple':',',
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -73,6 +74,7 @@ class FieldMetadata(dict):
|
|||||||
'is_category':True}),
|
'is_category':True}),
|
||||||
('series', {'table':'series',
|
('series', {'table':'series',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
|
'link_column':'series',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -91,6 +93,7 @@ class FieldMetadata(dict):
|
|||||||
'is_category':True}),
|
'is_category':True}),
|
||||||
('publisher', {'table':'publishers',
|
('publisher', {'table':'publishers',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
|
'link_column':'publisher',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -100,6 +103,7 @@ class FieldMetadata(dict):
|
|||||||
'is_category':True}),
|
'is_category':True}),
|
||||||
('rating', {'table':'ratings',
|
('rating', {'table':'ratings',
|
||||||
'column':'rating',
|
'column':'rating',
|
||||||
|
'link_column':'rating',
|
||||||
'datatype':'rating',
|
'datatype':'rating',
|
||||||
'is_multiple':None,
|
'is_multiple':None,
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
@ -118,6 +122,7 @@ class FieldMetadata(dict):
|
|||||||
'is_category':True}),
|
'is_category':True}),
|
||||||
('tags', {'table':'tags',
|
('tags', {'table':'tags',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
|
'link_column': 'tag',
|
||||||
'datatype':'text',
|
'datatype':'text',
|
||||||
'is_multiple':',',
|
'is_multiple':',',
|
||||||
'kind':'field',
|
'kind':'field',
|
||||||
|
@ -290,9 +290,5 @@ class SchemaUpgrade(object):
|
|||||||
self.conn.executescript(script)
|
self.conn.executescript(script)
|
||||||
|
|
||||||
for field in self.field_metadata.itervalues():
|
for field in self.field_metadata.itervalues():
|
||||||
if field['is_category'] and not field['is_custom'] and \
|
if field['is_category'] and not field['is_custom'] and 'link_column' in field:
|
||||||
field['table'] != 'news' and field['table'] is not None:
|
create_tag_browser_view(field['table'], field['link_column'], field['column'])
|
||||||
cn = field['table'][:-1]
|
|
||||||
if cn == 'serie':
|
|
||||||
cn += 's'
|
|
||||||
create_tag_browser_view(field['table'], cn, field['column'])
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user