diff --git a/src/calibre/gui2/viewer/__init__.py b/src/calibre/gui2/viewer/__init__.py index f5d62f621c..3d60292729 100644 --- a/src/calibre/gui2/viewer/__init__.py +++ b/src/calibre/gui2/viewer/__init__.py @@ -34,6 +34,23 @@ def link_prefix_for_location_links(add_open_at=True): return link_prefix +def url_for_book_in_library(): + cbd = get_current_book_data() + ans = library_id = None + if 'calibre_library_id' in cbd: + library_id = cbd['calibre_library_id'] + book_id = cbd['calibre_book_id'] + elif cbd.get('book_library_details'): + bld = cbd['book_library_details'] + book_id = bld['book_id'] + library_id = bld['library_id'] + if library_id: + library_id = '_hex_-' + library_id.encode('utf-8').hex() + ans = f'calibre://show-book/{library_id}/{book_id}' + return ans + + + class PerformanceMonitor: def __init__(self): diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index f9a6e3ac0e..845abaa0d6 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -22,7 +22,7 @@ from calibre.constants import ( from calibre.ebooks.metadata.book.base import field_metadata from calibre.ebooks.oeb.polish.utils import guess_type from calibre.gui2 import choose_images, config, error_dialog, safe_open_url -from calibre.gui2.viewer import link_prefix_for_location_links, performance_monitor +from calibre.gui2.viewer import link_prefix_for_location_links, performance_monitor, url_for_book_in_library from calibre.gui2.viewer.config import viewer_config_dir, vprefs from calibre.gui2.viewer.tts import TTS from calibre.gui2.webengine import RestartingWebEngineView @@ -631,7 +631,10 @@ class WebView(RestartingWebEngineView): def start_book_load(self, initial_position=None, highlights=None, current_book_data=None, reading_rates=None): key = (set_book_path.path,) book_url = link_prefix_for_location_links(add_open_at=False) - self.execute_when_ready('start_book_load', key, initial_position, set_book_path.pathtoebook, highlights or [], book_url, reading_rates) + book_in_library_url = url_for_book_in_library() + self.execute_when_ready( + 'start_book_load', key, initial_position, set_book_path.pathtoebook, highlights or [], book_url, + reading_rates, book_in_library_url) def execute_when_ready(self, action, *args): if self.bridge.ready: diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 0890e18a6c..a3e4bcb1a0 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -751,7 +751,7 @@ class Overlay: self.hide_current_panel() from_read_book = short_uuid() - def show_metadata_overlay(mi, pathtoebook, lname, book_id, overlay, container): + def show_metadata_overlay(mi, pathtoebook, calibre_book_in_library_url, lname, book_id, overlay, container): container_id = ensure_id(container) container.appendChild(E.div(class_=BD_CLASS_NAME, style='padding: 1ex 1em')) table = E.table(class_='metadata') @@ -808,12 +808,21 @@ class Overlay: pathtoebook) ) ) + if calibre_book_in_library_url: + container.lastChild.appendChild(E.div( + style='margin-top: 1ex; padding-top: 1ex;', + E.a( + href=calibre_book_in_library_url, + class_='blue-link', title=_('Click to see this book in the main calibre program book list'), + _('Show book in the main calibre program')) + ) + ) book = self.view.book key = book.key or v'[null, 0]' lname, book_id = key book_id = int(book_id or 0) - panel = SimpleOverlay(self, show_metadata_overlay.bind(None, book.metadata, book.manifest.pathtoebook, lname, book_id), self.view.book.metadata.title) + panel = SimpleOverlay(self, show_metadata_overlay.bind(None, book.metadata, book.manifest.pathtoebook, book.calibre_book_in_library_url, lname, book_id), self.view.book.metadata.title) panel.from_read_book = from_read_book self.panels.push(panel) self.show_current_panel() diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index a1ee403da2..28410a05b5 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -95,7 +95,7 @@ def show_error(title, msg, details): to_python.show_error(title, msg, details) -def manifest_received(key, initial_position, pathtoebook, highlights, book_url, reading_rates, end_type, xhr, ev): +def manifest_received(key, initial_position, pathtoebook, highlights, book_url, reading_rates, book_in_library_url, end_type, xhr, ev): nonlocal book end_type = workaround_qt_bug(xhr, end_type) if end_type is 'load': @@ -107,6 +107,7 @@ def manifest_received(key, initial_position, pathtoebook, highlights, book_url, book.highlights = highlights book.stored_files = {} book.calibre_book_url = book_url + book.calibre_book_in_library_url = book_in_library_url book.saved_reading_rates = reading_rates book.is_complete = True v'delete book.manifest["metadata"]' @@ -229,8 +230,8 @@ def show_home_page(): @from_python -def start_book_load(key, initial_position, pathtoebook, highlights, book_url, reading_rates): - xhr = ajax('manifest', manifest_received.bind(None, key, initial_position, pathtoebook, highlights, book_url, reading_rates), ok_code=0) +def start_book_load(key, initial_position, pathtoebook, highlights, book_url, reading_rates, book_in_library_url): + xhr = ajax('manifest', manifest_received.bind(None, key, initial_position, pathtoebook, highlights, book_url, reading_rates, book_in_library_url), ok_code=0) xhr.responseType = 'json' xhr.send()