Use an icon for notes in book details.

The icon comes from https://www.iconfinder.com/icons/8726310/notes_icon. Feel free to replace it. :)
This commit is contained in:
Charles Haley 2023-09-22 14:35:09 +01:00 committed by Kovid Goyal
parent d74fa0e4da
commit 071145e70c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 28 additions and 13 deletions

1
imgsrc/notes.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" ?><svg data-name="Layer 1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M16,14H8a1,1,0,0,0,0,2h8a1,1,0,0,0,0-2Zm0-4H10a1,1,0,0,0,0,2h6a1,1,0,0,0,0-2Zm4-6H17V3a1,1,0,0,0-2,0V4H13V3a1,1,0,0,0-2,0V4H9V3A1,1,0,0,0,7,3V4H4A1,1,0,0,0,3,5V19a3,3,0,0,0,3,3H18a3,3,0,0,0,3-3V5A1,1,0,0,0,20,4ZM19,19a1,1,0,0,1-1,1H6a1,1,0,0,1-1-1V6H7V7A1,1,0,0,0,9,7V6h2V7a1,1,0,0,0,2,0V6h2V7a1,1,0,0,0,2,0V6h2Z" fill="#6563ff"/></svg>

After

Width:  |  Height:  |  Size: 447 B

BIN
resources/images/notes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -105,24 +105,33 @@ def mi_to_html(
mi, mi,
field_list=None, default_author_link=None, use_roman_numbers=True, field_list=None, default_author_link=None, use_roman_numbers=True,
rating_font='Liberation Serif', rtl=False, comments_heading_pos='hide', rating_font='Liberation Serif', rtl=False, comments_heading_pos='hide',
for_qt=False, vertical_fields=(), show_links=True, for_qt=False, vertical_fields=(), show_links=True, all_notes=None
): ):
link_markup = '↗️' link_markup = '↗️'
if for_qt: if for_qt:
link_markup = '<img valign="bottom" src="calibre-icon:///external-link.png" width=16 height=16>' link_markup = '<img valign="bottom" src="calibre-icon:///external-link.png" width=16 height=16>'
note_markup = '<img valign="bottom" src="calibre-icon:///notes.png" width=16 height=16>'
def get_link_map(column): def get_link_map(column):
try: try:
return mi.link_maps[column] return mi.link_maps[column]
except Exception: except Exception:
return {} return {}
def add_other_link(field, field_value): def add_other_links(field, field_value):
if show_links: if show_links:
link = get_link_map(field).get(field_value) link = get_link_map(field).get(field_value)
if link: if link:
link = prepare_string_for_xml(link, True) link = prepare_string_for_xml(link, True)
return ' <a title="{0}: {1}" href="{1}">{2}</a>'.format(_('Click to open'), link, link_markup) link = ' <a title="{0}: {1}" href="{1}">{2}</a>'.format(_('Click to open'), link, link_markup)
else:
link = ''
if field_value in all_notes.get(field, set()):
note = ' <a title="{0}" href="{1}">{2}</a>'.format(_('Click to open note'),
action('note', field=field, value=field_value), note_markup)
else:
note = ''
return link + note
return '' return ''
if field_list is None: if field_list is None:
@ -294,7 +303,7 @@ def mi_to_html(
url=link, name=aut, title=lt), aut) url=link, name=aut, title=lt), aut)
else: else:
val = aut val = aut
val += add_other_link('authors', aut) val += add_other_links('authors', aut)
authors.append(val) authors.append(val)
ans.append((field, row % (name, value_list(' & ', authors)))) ans.append((field, row % (name, value_list(' & ', authors))))
elif field == 'languages': elif field == 'languages':
@ -313,7 +322,7 @@ def mi_to_html(
search_action_with_data('publisher', mi.publisher, book_id), search_action_with_data('publisher', mi.publisher, book_id),
_('Click to see books with {0}: {1}').format(metadata['name'], a(mi.publisher)), _('Click to see books with {0}: {1}').format(metadata['name'], a(mi.publisher)),
p(mi.publisher)) p(mi.publisher))
val += add_other_link('publisher', mi.publisher) val += add_other_links('publisher', mi.publisher)
else: else:
val = p(mi.publisher) val = p(mi.publisher)
ans.append((field, row % (name, val))) ans.append((field, row % (name, val)))
@ -345,7 +354,7 @@ def mi_to_html(
sidx=fmt_sidx(sidx, use_roman=use_roman_numbers), cls="series_name", sidx=fmt_sidx(sidx, use_roman=use_roman_numbers), cls="series_name",
series=p(series), href=search_action_with_data(st, series, book_id, field), series=p(series), href=search_action_with_data(st, series, book_id, field),
tt=p(_('Click to see books in this series'))) tt=p(_('Click to see books in this series')))
val += add_other_link(field, series) val += add_other_links(field, series)
elif metadata['datatype'] == 'datetime': elif metadata['datatype'] == 'datetime':
aval = getattr(mi, field) aval = getattr(mi, field)
if is_date_undefined(aval): if is_date_undefined(aval):
@ -374,7 +383,7 @@ def mi_to_html(
v = '<a href="{}" title="{}">{}</a>'.format( v = '<a href="{}" title="{}">{}</a>'.format(
search_action_with_data(st, x, book_id, field), _('Click to see books with {0}: {1}').format( search_action_with_data(st, x, book_id, field), _('Click to see books with {0}: {1}').format(
metadata['name'] or field, a(x)), p(x)) metadata['name'] or field, a(x)), p(x))
v += add_other_link(field, x) v += add_other_links(field, x)
links.append(v) links.append(v)
val = value_list(metadata['is_multiple']['list_to_ui'], links) val = value_list(metadata['is_multiple']['list_to_ui'], links)
elif metadata['datatype'] == 'text' or metadata['datatype'] == 'enumeration': elif metadata['datatype'] == 'text' or metadata['datatype'] == 'enumeration':
@ -386,7 +395,7 @@ def mi_to_html(
v = '<a href="{}" title="{}">{}</a>'.format( v = '<a href="{}" title="{}">{}</a>'.format(
search_action_with_data(st, unescaped_val, book_id, field), a( search_action_with_data(st, unescaped_val, book_id, field), a(
_('Click to see books with {0}: {1}').format(metadata['name'] or field, val)), val) _('Click to see books with {0}: {1}').format(metadata['name'] or field, val)), val)
val = v + add_other_link(field, val) val = v + add_other_links(field, val)
elif metadata['datatype'] == 'bool': elif metadata['datatype'] == 'bool':
val = '<a href="{}" title="{}">{}</a>'.format( val = '<a href="{}" title="{}">{}</a>'.format(
search_action_with_data(field, val, book_id, None), a( search_action_with_data(field, val, book_id, None), a(

View File

@ -319,11 +319,15 @@ def render_data(mi, use_roman_numbers=True, all_fields=False, pref_name='book_di
field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata), field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata),
pref_name=pref_name, mi=mi) pref_name=pref_name, mi=mi)
field_list = [(x, all_fields or display) for x, display in field_list] field_list = [(x, all_fields or display) for x, display in field_list]
db, _ = db_for_mi(mi)
db = db.new_api
all_notes = db.get_all_items_that_have_notes()
all_notes = {fld: {db.get_item_name(fld, id_) for id_ in all_notes[fld]} for fld in all_notes.keys()}
return mi_to_html( return mi_to_html(
mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(), mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(),
rating_font=rating_font(), default_author_link=default_author_link(), rating_font=rating_font(), default_author_link=default_author_link(),
comments_heading_pos=gprefs['book_details_comments_heading_pos'], for_qt=True, comments_heading_pos=gprefs['book_details_comments_heading_pos'], for_qt=True,
vertical_fields=vertical_fields, show_links=show_links vertical_fields=vertical_fields, show_links=show_links, all_notes=all_notes
) )
# }}} # }}}
@ -1291,16 +1295,17 @@ class BookDetails(DetailsLayout): # {{{
dt = data['type'] dt = data['type']
if dt == 'search': if dt == 'search':
field = data.get('field') field = data.get('field')
search_term(data['term'], data['value'])
elif dt == 'note':
field = data.get('field')
# It shouldn't be possible for the field to be invalid or the
# note not to exist, but ...
if field and db.field_supports_notes(field): if field and db.field_supports_notes(field):
item_id = db.get_item_id(field, data['value']) item_id = db.get_item_id(field, data['value'])
if item_id is not None and db.notes_for(field, item_id): if item_id is not None and db.notes_for(field, item_id):
return self.show_notes(field, item_id) return self.show_notes(field, item_id)
search_term(data['term'], data['value'])
elif dt == 'author': elif dt == 'author':
url = data['url'] url = data['url']
item_id = db.get_item_id('authors', data['name'])
if item_id is not None and db.notes_for('authors', item_id):
return self.show_notes('authors', item_id)
if url == 'calibre': if url == 'calibre':
search_term('authors', data['name']) search_term('authors', data['name'])
else: else: