Track the current content file

This commit is contained in:
Kovid Goyal 2020-01-18 10:40:45 +05:30
parent 5c8093e554
commit 90eb2c43f0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 2 deletions

View File

@ -33,6 +33,7 @@ from calibre.gui2.webengine import (
from calibre.srv.code import get_translations_data
from calibre.utils.config import JSONConfig
from calibre.utils.serialize import json_loads
from calibre.utils.shared_file import share_open
from polyglot.builtins import as_bytes, iteritems
try:
@ -75,7 +76,7 @@ def get_data(name):
if path is None:
return None, None
try:
with lopen(path, 'rb') as f:
with share_open(path, 'rb') as f:
return f.read(), guess_type(name)
except EnvironmentError as err:
prints('Failed to read from book file: {} with error: {}'.format(name, as_unicode(err)))
@ -235,6 +236,7 @@ def create_profile():
class ViewerBridge(Bridge):
view_created = from_js(object)
content_file_changed = from_js(object)
set_session_data = from_js(object, object)
set_local_storage = from_js(object, object)
reload_book = from_js()
@ -437,7 +439,7 @@ class WebView(RestartingWebEngineView):
self._host_widget = None
self.callback_id_counter = count()
self.callback_map = {}
self.current_cfi = None
self.current_cfi = self.current_content_file = None
RestartingWebEngineView.__init__(self, parent)
self.dead_renderer_error_shown = False
self.render_process_failed.connect(self.render_process_died)
@ -448,6 +450,7 @@ class WebView(RestartingWebEngineView):
self._page = WebPage(self)
self.bridge.bridge_ready.connect(self.on_bridge_ready)
self.bridge.view_created.connect(self.on_view_created)
self.bridge.content_file_changed.connect(self.on_content_file_created)
self.bridge.set_session_data.connect(self.set_session_data)
self.bridge.set_local_storage.connect(self.set_local_storage)
self.bridge.reload_book.connect(self.reload_book)
@ -556,6 +559,9 @@ class WebView(RestartingWebEngineView):
def on_view_created(self, data):
self.view_created.emit(data)
def on_content_file_created(self, data):
self.current_content_file = data
def start_book_load(self, initial_position=None):
key = (set_book_path.path,)
self.execute_when_ready('start_book_load', key, initial_position, set_book_path.pathtoebook)

View File

@ -1035,6 +1035,8 @@ class View:
self.book_load_started = False
if ui_operations.clear_history:
ui_operations.clear_history()
if ui_operations.content_file_changed:
ui_operations.content_file_changed(self.currently_showing.name)
def set_progress_frac(self, progress_frac, file_progress_frac):
self.current_progress_frac = progress_frac or 0

View File

@ -337,6 +337,8 @@ if window is window.top:
to_python.toggle_bookmarks()
ui_operations.toggle_inspector = def():
to_python.toggle_inspector()
ui_operations.content_file_changed = def(name):
to_python.content_file_changed(name)
ui_operations.reset_interface = def():
sd = get_session_data()
defaults = session_defaults()