mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: Show URL for current book in the Goto location panel
This commit is contained in:
parent
cb1476c8ff
commit
b87cd867b1
@ -128,7 +128,7 @@ class ViewAction(InterfaceAction):
|
|||||||
merge_annotations(other_annotations_map, annotations_map, merge_last_read=False)
|
merge_annotations(other_annotations_map, annotations_map, merge_last_read=False)
|
||||||
return {
|
return {
|
||||||
'book_id': book_id, 'uuid': db.field_for('uuid', book_id), 'fmt': fmt.upper(),
|
'book_id': book_id, 'uuid': db.field_for('uuid', book_id), 'fmt': fmt.upper(),
|
||||||
'annotations_map': annotations_map,
|
'annotations_map': annotations_map, 'library_id': getattr(self.gui.current_db.new_api, 'server_library_id', None)
|
||||||
}
|
}
|
||||||
|
|
||||||
def view_format_by_id(self, id_, format, open_at=None):
|
def view_format_by_id(self, id_, format, open_at=None):
|
||||||
|
@ -635,8 +635,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
def decode_library_id(x):
|
def decode_library_id(x):
|
||||||
if x == '_':
|
if x == '_':
|
||||||
return getattr(self.current_db.new_api, 'server_library_id', None) or '_'
|
return getattr(self.current_db.new_api, 'server_library_id', None) or '_'
|
||||||
if x.startswith('hex-'):
|
if x.startswith('_hex_-'):
|
||||||
return bytes.fromhex(x[4:]).decode('utf-8')
|
return bytes.fromhex(x[6:]).decode('utf-8')
|
||||||
return x
|
return x
|
||||||
|
|
||||||
if action == 'switch-library':
|
if action == 'switch-library':
|
||||||
|
@ -537,7 +537,7 @@ class EbookViewer(MainWindow):
|
|||||||
initial_position = {'type': 'bookpos', 'data': float(open_at)}
|
initial_position = {'type': 'bookpos', 'data': float(open_at)}
|
||||||
highlights = self.current_book_data['annotations_map']['highlight']
|
highlights = self.current_book_data['annotations_map']['highlight']
|
||||||
self.highlights_widget.load(highlights)
|
self.highlights_widget.load(highlights)
|
||||||
self.web_view.start_book_load(initial_position=initial_position, highlights=highlights)
|
self.web_view.start_book_load(initial_position=initial_position, highlights=highlights, current_book_data=self.current_book_data)
|
||||||
|
|
||||||
def load_book_data(self, calibre_book_data=None):
|
def load_book_data(self, calibre_book_data=None):
|
||||||
self.current_book_data['book_library_details'] = get_book_library_details(self.current_book_data['pathtoebook'])
|
self.current_book_data['book_library_details'] = get_book_library_details(self.current_book_data['pathtoebook'])
|
||||||
@ -545,6 +545,7 @@ class EbookViewer(MainWindow):
|
|||||||
self.current_book_data['calibre_book_id'] = calibre_book_data['book_id']
|
self.current_book_data['calibre_book_id'] = calibre_book_data['book_id']
|
||||||
self.current_book_data['calibre_book_uuid'] = calibre_book_data['uuid']
|
self.current_book_data['calibre_book_uuid'] = calibre_book_data['uuid']
|
||||||
self.current_book_data['calibre_book_fmt'] = calibre_book_data['fmt']
|
self.current_book_data['calibre_book_fmt'] = calibre_book_data['fmt']
|
||||||
|
self.current_book_data['calibre_library_id'] = calibre_book_data['library_id']
|
||||||
self.load_book_annotations(calibre_book_data)
|
self.load_book_annotations(calibre_book_data)
|
||||||
path = os.path.join(self.current_book_data['base'], 'calibre-book-manifest.json')
|
path = os.path.join(self.current_book_data['base'], 'calibre-book-manifest.json')
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
|
@ -598,9 +598,14 @@ class WebView(RestartingWebEngineView):
|
|||||||
def on_content_file_changed(self, data):
|
def on_content_file_changed(self, data):
|
||||||
self.current_content_file = data
|
self.current_content_file = data
|
||||||
|
|
||||||
def start_book_load(self, initial_position=None, highlights=None):
|
def start_book_load(self, initial_position=None, highlights=None, current_book_data=None):
|
||||||
key = (set_book_path.path,)
|
key = (set_book_path.path,)
|
||||||
self.execute_when_ready('start_book_load', key, initial_position, set_book_path.pathtoebook, highlights or [])
|
cbd = current_book_data or {}
|
||||||
|
book_url = None
|
||||||
|
if 'calibre_library_id' in cbd:
|
||||||
|
lid = cbd['calibre_library_id'].encode('utf-8').hex()
|
||||||
|
book_url = f'calibre://view-book/_hex_-{lid}/{cbd["calibre_book_id"]}/{cbd["calibre_book_fmt"]}'
|
||||||
|
self.execute_when_ready('start_book_load', key, initial_position, set_book_path.pathtoebook, highlights or [], book_url)
|
||||||
|
|
||||||
def execute_when_ready(self, action, *args):
|
def execute_when_ready(self, action, *args):
|
||||||
if self.bridge.ready:
|
if self.bridge.ready:
|
||||||
|
@ -5,6 +5,7 @@ from __python__ import bound_methods, hash_literals
|
|||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
from ajax import encode_query_component
|
||||||
from book_list.item_list import build_list, create_item
|
from book_list.item_list import build_list, create_item
|
||||||
from dom import ensure_id, set_css
|
from dom import ensure_id, set_css
|
||||||
from modals import error_dialog
|
from modals import error_dialog
|
||||||
@ -58,22 +59,18 @@ def create_goto_panel(current_position_data, book, container, onclick):
|
|||||||
container.appendChild(panel)
|
container.appendChild(panel)
|
||||||
|
|
||||||
|
|
||||||
def create_location_overlay(current_position_data, overlay, container):
|
def create_location_overlay(current_position_data, book, overlay, container):
|
||||||
container_id = ensure_id(container)
|
container_id = ensure_id(container)
|
||||||
container.appendChild(E.div(style='margin: 0 1rem'))
|
container.appendChild(E.div(style='margin: 0 1rem'))
|
||||||
container = container.lastChild
|
container = container.lastChild
|
||||||
current_cfi = current_position_data.cfi
|
current_cfi = current_position_data.cfi
|
||||||
if current_cfi:
|
calibre_book_url = book?.calibre_book_url
|
||||||
container.appendChild(E.div(
|
|
||||||
style='margin: 1rem; margin-bottom: calc(1rem - 1ex); display: flex; align-items: baseline; flex-wrap: wrap',
|
def copy_button(text_to_copy):
|
||||||
E.div(
|
return create_button(_('Copy'), action=def():
|
||||||
_('Current location: {}').format(current_cfi),
|
|
||||||
style='flex-grow: 10; text-overflow: ellipsis; margin-bottom: 1ex'
|
|
||||||
),
|
|
||||||
create_button(_('Copy'), action=def():
|
|
||||||
src = document.querySelector(f'#{container_id} input')
|
src = document.querySelector(f'#{container_id} input')
|
||||||
orig = src.value
|
orig = src.value
|
||||||
src.value = current_cfi
|
src.value = text_to_copy
|
||||||
src.focus()
|
src.focus()
|
||||||
src.select()
|
src.select()
|
||||||
try:
|
try:
|
||||||
@ -81,8 +78,18 @@ def create_location_overlay(current_position_data, overlay, container):
|
|||||||
finally:
|
finally:
|
||||||
src.value = orig
|
src.value = orig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def display_and_copy(label, text):
|
||||||
|
container.appendChild(E.div(
|
||||||
|
style='margin: 1rem; margin-bottom: calc(1rem - 1ex); display: flex; align-items: baseline; flex-wrap: wrap',
|
||||||
|
E.div(style='flex-grow: 10; text-overflow: ellipsis; margin-bottom: 1ex',
|
||||||
|
label, ' ', E.span(text, style='font-size: smaller; font-family: monospace')),
|
||||||
|
copy_button(text)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
if current_cfi:
|
||||||
|
display_and_copy(_('Current location:'), current_cfi)
|
||||||
|
|
||||||
def goto_cfi(cfi):
|
def goto_cfi(cfi):
|
||||||
if ui_operations.goto_cfi(cfi):
|
if ui_operations.goto_cfi(cfi):
|
||||||
overlay.hide()
|
overlay.hide()
|
||||||
@ -134,4 +141,11 @@ def create_location_overlay(current_position_data, overlay, container):
|
|||||||
create_button(_('Go'), action=goto_pos)
|
create_button(_('Go'), action=goto_pos)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
if calibre_book_url:
|
||||||
|
if current_cfi:
|
||||||
|
calibre_book_url += '?open_at=' + encode_query_component(current_cfi)
|
||||||
|
display_and_copy(_('URL for this position:'), calibre_book_url)
|
||||||
|
elif not runtime.is_standalone_viewer:
|
||||||
|
display_and_copy(_('URL for this position:'), window.top.location.toString())
|
||||||
container.querySelector('[name=newpos]').focus()
|
container.querySelector('[name=newpos]').focus()
|
||||||
|
@ -761,7 +761,7 @@ class Overlay:
|
|||||||
def show_ask_for_location(self):
|
def show_ask_for_location(self):
|
||||||
self.hide_current_panel()
|
self.hide_current_panel()
|
||||||
self.panels.push(SimpleOverlay(
|
self.panels.push(SimpleOverlay(
|
||||||
self, create_location_overlay.bind(None, self.view.current_position_data), _('Go to location, position or reference…')))
|
self, create_location_overlay.bind(None, self.view.current_position_data, self.view.book), _('Go to location, position or reference…')))
|
||||||
self.show_current_panel()
|
self.show_current_panel()
|
||||||
|
|
||||||
def show_search(self):
|
def show_search(self):
|
||||||
|
@ -91,7 +91,7 @@ def show_error(title, msg, details):
|
|||||||
to_python.show_error(title, msg, details)
|
to_python.show_error(title, msg, details)
|
||||||
|
|
||||||
|
|
||||||
def manifest_received(key, initial_position, pathtoebook, highlights, end_type, xhr, ev):
|
def manifest_received(key, initial_position, pathtoebook, highlights, book_url, end_type, xhr, ev):
|
||||||
nonlocal book
|
nonlocal book
|
||||||
end_type = workaround_qt_bug(xhr, end_type)
|
end_type = workaround_qt_bug(xhr, end_type)
|
||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
@ -102,6 +102,7 @@ def manifest_received(key, initial_position, pathtoebook, highlights, end_type,
|
|||||||
book.manifest.pathtoebook = pathtoebook
|
book.manifest.pathtoebook = pathtoebook
|
||||||
book.highlights = highlights
|
book.highlights = highlights
|
||||||
book.stored_files = {}
|
book.stored_files = {}
|
||||||
|
book.calibre_book_url = book_url
|
||||||
book.is_complete = True
|
book.is_complete = True
|
||||||
v'delete book.manifest["metadata"]'
|
v'delete book.manifest["metadata"]'
|
||||||
v'delete book.manifest["last_read_positions"]'
|
v'delete book.manifest["last_read_positions"]'
|
||||||
@ -210,8 +211,8 @@ def show_home_page():
|
|||||||
|
|
||||||
|
|
||||||
@from_python
|
@from_python
|
||||||
def start_book_load(key, initial_position, pathtoebook, highlights):
|
def start_book_load(key, initial_position, pathtoebook, highlights, book_url):
|
||||||
xhr = ajax('manifest', manifest_received.bind(None, key, initial_position, pathtoebook, highlights), ok_code=0)
|
xhr = ajax('manifest', manifest_received.bind(None, key, initial_position, pathtoebook, highlights, book_url), ok_code=0)
|
||||||
xhr.responseType = 'json'
|
xhr.responseType = 'json'
|
||||||
xhr.send()
|
xhr.send()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user