mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Cover Browser: Allow any metadata field to be used as the sub-title, not just the rating
This commit is contained in:
parent
33b9f5e520
commit
ad30806ba9
@ -445,6 +445,7 @@ class DB(object):
|
||||
defs['update_all_last_mod_dates_on_start'] = False
|
||||
defs['field_under_covers_in_grid'] = 'title'
|
||||
defs['cover_browser_title_template'] = '{title}'
|
||||
defs['cover_browser_subtitle_field'] = 'rating'
|
||||
|
||||
# Migrate the bool tristate tweak
|
||||
defs['bools_are_tristate'] = \
|
||||
|
@ -140,7 +140,6 @@ defs['show_vl_tabs'] = False
|
||||
defs['show_highlight_toggle_button'] = False
|
||||
defs['add_comments_to_email'] = False
|
||||
defs['cb_preserve_aspect_ratio'] = False
|
||||
defs['show_rating_in_cover_browser'] = True
|
||||
defs['gpm_template_editor_font_size'] = 10
|
||||
defs['show_emblems'] = False
|
||||
defs['emblem_size'] = 32
|
||||
|
@ -87,6 +87,7 @@ if pictureflow is not None:
|
||||
self.model.modelReset.connect(self.reset, type=Qt.QueuedConnection)
|
||||
self.ignore_image_requests = True
|
||||
self.template_inited = False
|
||||
self.subtitle_error_reported = False
|
||||
|
||||
def init_template(self, db):
|
||||
self.template_cache = {}
|
||||
@ -97,6 +98,11 @@ if pictureflow is not None:
|
||||
def count(self):
|
||||
return self.model.count()
|
||||
|
||||
def render_template(self, template, index, db):
|
||||
book_id = self.model.id(index)
|
||||
mi = db.get_proxy_metadata(book_id)
|
||||
return mi.formatter.safe_format(template, mi, _('TEMPLATE ERROR'), mi, template_cache=self.template_cache)
|
||||
|
||||
def caption(self, index):
|
||||
if self.ignore_image_requests:
|
||||
return ''
|
||||
@ -108,10 +114,8 @@ if pictureflow is not None:
|
||||
if self.template_is_title:
|
||||
ans = self.model.title(index)
|
||||
else:
|
||||
book_id = self.model.id(index)
|
||||
mi = db.get_proxy_metadata(book_id)
|
||||
try:
|
||||
ans = mi.formatter.safe_format(self.template, mi, _('TEMPLATE ERROR'), mi, template_cache=self.template_cache)
|
||||
ans = self.render_template(self.template, index, db)
|
||||
except Exception:
|
||||
if not self.template_error_reported:
|
||||
self.template_error_reported = True
|
||||
@ -124,11 +128,23 @@ if pictureflow is not None:
|
||||
return ans
|
||||
|
||||
def subtitle(self, index):
|
||||
if gprefs['show_rating_in_cover_browser']:
|
||||
try:
|
||||
return rating_to_stars(self.model.rating(index) * 2)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
db = self.model.db.new_api
|
||||
field = db.pref('cover_browser_subtitle_field', 'rating')
|
||||
if field and field != 'none':
|
||||
book_id = self.model.id(index)
|
||||
fm = db.field_metadata[field]
|
||||
if fm['datatype'] == 'rating':
|
||||
val = db.field_for(field, book_id, default_value=0)
|
||||
if val:
|
||||
return rating_to_stars(val, allow_half_stars=db.field_metadata[field]['display'].get('allow_half_stars'))
|
||||
else:
|
||||
return self.render_template('{%s}' % field, index, db).replace('&', '&&')
|
||||
except Exception:
|
||||
if not self.subtitle_error_reported:
|
||||
self.subtitle_error_reported = True
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return ''
|
||||
|
||||
def reset(self):
|
||||
@ -163,10 +179,15 @@ if pictureflow is not None:
|
||||
self.context_menu = None
|
||||
self.setContextMenuPolicy(Qt.DefaultContextMenu)
|
||||
self.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio'])
|
||||
self.setSubtitleFont(QFont(rating_font()))
|
||||
if not gprefs['cover_browser_reflections']:
|
||||
self.setShowReflections(False)
|
||||
|
||||
def set_subtitle_font(self, for_ratings=True):
|
||||
if for_ratings:
|
||||
self.setSubtitleFont(QFont(rating_font()))
|
||||
else:
|
||||
self.setSubtitleFont(self.font())
|
||||
|
||||
def set_context_menu(self, cm):
|
||||
self.context_menu = cm
|
||||
|
||||
@ -283,6 +304,7 @@ class CoverFlowMixin(object):
|
||||
self.db_images = DatabaseImages(self.library_view.model(), self.is_cover_browser_visible)
|
||||
self.cover_flow.setImages(self.db_images)
|
||||
self.cover_flow.itemActivated.connect(self.iactions['View'].view_specific_book)
|
||||
self.update_cover_flow_subtitle_font()
|
||||
else:
|
||||
self.cover_flow = QLabel('<p>'+_('Cover browser could not be loaded') +
|
||||
'<br>'+pictureflowerror)
|
||||
@ -302,6 +324,16 @@ class CoverFlowMixin(object):
|
||||
self.cover_flow.stop.connect(self.cb_splitter.hide_side_pane)
|
||||
self.cb_splitter.button.toggled.connect(self.cover_browser_toggled, type=Qt.QueuedConnection)
|
||||
|
||||
def update_cover_flow_subtitle_font(self):
|
||||
db = self.current_db.new_api
|
||||
field = db.pref('cover_browser_subtitle_field', 'rating')
|
||||
try:
|
||||
is_rating = db.field_metadata[field]['datatype'] == 'rating'
|
||||
except Exception:
|
||||
is_rating = False
|
||||
if hasattr(self.cover_flow, 'set_subtitle_font'):
|
||||
self.cover_flow.set_subtitle_font(is_rating)
|
||||
|
||||
def toggle_cover_browser(self, *args):
|
||||
cbd = getattr(self, 'cb_dialog', None)
|
||||
if cbd is not None:
|
||||
|
@ -291,8 +291,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
|
||||
r('cover_flow_queue_length', config, restart_required=True)
|
||||
r('cover_browser_reflections', gprefs)
|
||||
r('show_rating_in_cover_browser', gprefs)
|
||||
r('cover_browser_title_template', db.prefs)
|
||||
fm = db.field_metadata
|
||||
r('cover_browser_subtitle_field', db.prefs, choices=[(_('No subtitle'), 'none')] + sorted(
|
||||
(fm[k].get('name'), k) for k in fm.all_field_keys() if fm[k].get('name')
|
||||
))
|
||||
r('emblem_size', gprefs)
|
||||
r('emblem_position', gprefs, choices=[
|
||||
(_('Left'), 'left'), (_('Top'), 'top'), (_('Right'), 'right'), (_('Bottom'), 'bottom')])
|
||||
@ -636,6 +639,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
gui.library_view.refresh_book_details()
|
||||
gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections'])
|
||||
gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio'])
|
||||
gui.update_cover_flow_subtitle_font()
|
||||
gui.cover_flow.template_inited = False
|
||||
gui.library_view.refresh_row_sizing()
|
||||
gui.grid_view.refresh_settings()
|
||||
|
@ -977,7 +977,7 @@ if you never want subcategories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<item row="9" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -990,13 +990,6 @@ if you never want subcategories</string>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="opt_show_rating_in_cover_browser">
|
||||
<property name="text">
|
||||
<string>Show book &rating in cover browser</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_23">
|
||||
<property name="text">
|
||||
@ -1017,7 +1010,7 @@ if you never want subcategories</string>
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QSpinBox" name="opt_cover_flow_queue_length"/>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="3">
|
||||
<item row="7" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="opt_cb_fullscreen">
|
||||
<property name="text">
|
||||
<string>When showing cover browser in separate window, show it &fullscreen</string>
|
||||
@ -1049,7 +1042,7 @@ them to all have the same width and height</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="3">
|
||||
<item row="8" column="0" colspan="3">
|
||||
<widget class="QLabel" name="fs_help_msg">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">margin-left: 1.5em</string>
|
||||
@ -1062,6 +1055,19 @@ them to all have the same width and height</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="text">
|
||||
<string>Fie&ld for sub-title:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_cover_browser_subtitle_field</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="opt_cover_browser_subtitle_field"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
Loading…
x
Reference in New Issue
Block a user