diff --git a/src/calibre/gui2/dialogs/show_category_note.py b/src/calibre/gui2/dialogs/show_category_note.py index ea9def27a2..7eb6d52b93 100644 --- a/src/calibre/gui2/dialogs/show_category_note.py +++ b/src/calibre/gui2/dialogs/show_category_note.py @@ -3,12 +3,13 @@ import os from qt.core import ( - QByteArray, QDialogButtonBox, QIcon, QSize, Qt, QTextDocument, QVBoxLayout, + QByteArray, QDialogButtonBox, QIcon, QLabel, QSize, Qt, QTextDocument, QVBoxLayout, ) +from calibre import prepare_string_for_xml from calibre.db.constants import RESOURCE_URL_SCHEME from calibre.ebooks.metadata.book.render import render_author_link -from calibre.gui2 import Application, default_author_link +from calibre.gui2 import Application, default_author_link, safe_open_url from calibre.gui2.book_details import resolved_css from calibre.gui2.widgets2 import Dialog, HTMLDisplay @@ -38,11 +39,11 @@ class ShowNoteDialog(Dialog): self.item_val = self.db.get_item_name(field, item_id) self.has_links = self.db.has_link_map(field) self.item_link = (self.db.link_for(field, item_id) or '') if self.has_links else '' - self.author_search_link = self.author_search_tooltip = '' + self.extra_link = self.extra_link_tooltip = '' if field == 'authors': lk = default_author_link() if lk != 'calibre': - self.author_search_link, self.author_search_tooltip = render_author_link(lk, self.item_val) + self.extra_link, self.extra_link_tooltip = render_author_link(lk, self.item_val) self.field, self.item_id = field, item_id super().__init__(self.item_val, 'show-notes-for-category', parent=parent) self.setWindowIcon(QIcon.ic('tag.png')) @@ -51,6 +52,19 @@ class ShowNoteDialog(Dialog): def setup_ui(self): self.l = l = QVBoxLayout(self) + x = prepare_string_for_xml + src = x(self.item_val) + if self.item_link: + src = f'{src}' + if self.extra_link: + link_markup = '' + src += f' {link_markup}' + self.title = t = QLabel(f'

{src}

') + t.setResourceProvider(lambda qurl: QIcon.icon_as_png(qurl.path().lstrip('/'), as_bytearray=True)) + t.setOpenExternalLinks(False) + t.linkActivated.connect(self.open_item_link) + l.addWidget(t) + self.display = d = Display(self) l.addWidget(d) @@ -61,6 +75,9 @@ class ShowNoteDialog(Dialog): def sizeHint(self): return QSize(800, 620) + def open_item_link(self, url): + safe_open_url(url) + def develop_show_note(): from calibre.library import db as dbc