mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Add a clickable link to show the currently viewed book in the calibre library (Click Go to->Metadata in the viewer controls to access it). Fixes #2034905 [ebook-viewer enhancement: Show book in library](https://bugs.launchpad.net/calibre/+bug/2034905)
This commit is contained in:
parent
ec7a9cdc47
commit
ad2f746c2c
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user