mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Add tweak to control which custom fields are displayed in books info
This commit is contained in:
parent
b49f04c413
commit
c63ffe6ae8
@ -181,19 +181,25 @@ max_content_server_tags_shown=5
|
|||||||
# content_server_will_display is a list of custom fields to be displayed.
|
# content_server_will_display is a list of custom fields to be displayed.
|
||||||
# content_server_wont_display is a list of custom fields not to be displayed.
|
# content_server_wont_display is a list of custom fields not to be displayed.
|
||||||
# wont_display has priority over will_display.
|
# wont_display has priority over will_display.
|
||||||
# The special value '*' means all custom fields.
|
# The special value '*' means all custom fields. The value [] means no entries.
|
||||||
# Defaults:
|
# Defaults:
|
||||||
# content_server_will_display = ['*']
|
# content_server_will_display = ['*']
|
||||||
# content_server_wont_display = ['']
|
# content_server_wont_display = []
|
||||||
# Examples:
|
# Examples:
|
||||||
# To display only the custom fields #mytags and #genre:
|
# To display only the custom fields #mytags and #genre:
|
||||||
# content_server_will_display = ['#mytags', '#genre']
|
# content_server_will_display = ['#mytags', '#genre']
|
||||||
# content_server_wont_display = ['']
|
# content_server_wont_display = []
|
||||||
# To display all fields except #mycomments:
|
# To display all fields except #mycomments:
|
||||||
# content_server_will_display = ['*']
|
# content_server_will_display = ['*']
|
||||||
# content_server_wont_display['#mycomments']
|
# content_server_wont_display['#mycomments']
|
||||||
content_server_will_display = ['*']
|
content_server_will_display = ['*']
|
||||||
content_server_wont_display = ['']
|
content_server_wont_display = []
|
||||||
|
|
||||||
|
# Same as above (content server) but for the book details pane. Same syntax.
|
||||||
|
# As above, this tweak affects only display of custom fields. The standard
|
||||||
|
# fields are not affected
|
||||||
|
book_details_will_display = ['*']
|
||||||
|
book_details_wont_display = []
|
||||||
|
|
||||||
|
|
||||||
# Set the maximum number of sort 'levels' that calibre will use to resort the
|
# Set the maximum number of sort 'levels' that calibre will use to resort the
|
||||||
|
@ -20,6 +20,7 @@ from calibre.constants import preferred_encoding
|
|||||||
from calibre.library.comments import comments_to_html
|
from calibre.library.comments import comments_to_html
|
||||||
from calibre.gui2 import config, open_local_file
|
from calibre.gui2 import config, open_local_file
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
from calibre.utils.config import tweaks
|
||||||
|
|
||||||
# render_rows(data) {{{
|
# render_rows(data) {{{
|
||||||
WEIGHTS = collections.defaultdict(lambda : 100)
|
WEIGHTS = collections.defaultdict(lambda : 100)
|
||||||
@ -29,8 +30,25 @@ WEIGHTS[_('Collections')] = 2
|
|||||||
WEIGHTS[_('Series')] = 3
|
WEIGHTS[_('Series')] = 3
|
||||||
WEIGHTS[_('Tags')] = 4
|
WEIGHTS[_('Tags')] = 4
|
||||||
|
|
||||||
|
def keys_to_display(data):
|
||||||
|
kt = data.get('__cf_kt__', None)
|
||||||
|
if kt is None:
|
||||||
|
return data.keys()
|
||||||
|
cfkeys = frozenset([k for k in kt.values()])
|
||||||
|
yes_fields = set(tweaks['book_details_will_display'])
|
||||||
|
no_fields = set(tweaks['book_details_wont_display'])
|
||||||
|
if '*' in yes_fields:
|
||||||
|
yes_fields = cfkeys
|
||||||
|
if '*' in no_fields:
|
||||||
|
no_fields = cfkeys
|
||||||
|
todisplay = frozenset(yes_fields - no_fields)
|
||||||
|
res = [k for k in data.keys()
|
||||||
|
if k not in kt or (kt[k] not in cfkeys or kt[k] in todisplay)]
|
||||||
|
res.remove('__cf_kt__')
|
||||||
|
return res
|
||||||
|
|
||||||
def render_rows(data):
|
def render_rows(data):
|
||||||
keys = data.keys()
|
keys = keys_to_display(data)
|
||||||
# First sort by name. The WEIGHTS sort will preserve this sub-order
|
# First sort by name. The WEIGHTS sort will preserve this sub-order
|
||||||
keys.sort(key=sort_key)
|
keys.sort(key=sort_key)
|
||||||
keys.sort(key=lambda x: WEIGHTS[x])
|
keys.sort(key=lambda x: WEIGHTS[x])
|
||||||
|
@ -337,6 +337,11 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
name, val = mi.format_field(key)
|
name, val = mi.format_field(key)
|
||||||
if val:
|
if val:
|
||||||
data[name] = val
|
data[name] = val
|
||||||
|
cf_kt = {}
|
||||||
|
for key,mi in self.db.all_metadata().items():
|
||||||
|
if mi['is_custom']:
|
||||||
|
cf_kt[mi['name']] = key
|
||||||
|
data['__cf_kt__'] = cf_kt
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def set_cache(self, idx):
|
def set_cache(self, idx):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user