diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 1a371e5610..081112444a 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -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_wont_display is a list of custom fields not to be displayed. # 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: # content_server_will_display = ['*'] -# content_server_wont_display = [''] +# content_server_wont_display = [] # Examples: # To display only the custom fields #mytags and #genre: # content_server_will_display = ['#mytags', '#genre'] -# content_server_wont_display = [''] +# content_server_wont_display = [] # To display all fields except #mycomments: # content_server_will_display = ['*'] # content_server_wont_display['#mycomments'] 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 diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 5214f1a1d5..8a9d40d73b 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -20,6 +20,7 @@ from calibre.constants import preferred_encoding from calibre.library.comments import comments_to_html from calibre.gui2 import config, open_local_file from calibre.utils.icu import sort_key +from calibre.utils.config import tweaks # render_rows(data) {{{ WEIGHTS = collections.defaultdict(lambda : 100) @@ -29,8 +30,25 @@ WEIGHTS[_('Collections')] = 2 WEIGHTS[_('Series')] = 3 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): - keys = data.keys() + keys = keys_to_display(data) # First sort by name. The WEIGHTS sort will preserve this sub-order keys.sort(key=sort_key) keys.sort(key=lambda x: WEIGHTS[x]) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index e82e1dddd4..2bf521283f 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -337,6 +337,11 @@ class BooksModel(QAbstractTableModel): # {{{ name, val = mi.format_field(key) if 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 def set_cache(self, idx):