diff --git a/src/calibre/gui2/viewer/ui.py b/src/calibre/gui2/viewer/ui.py index 0a59c11bf4..a0a850ba0f 100644 --- a/src/calibre/gui2/viewer/ui.py +++ b/src/calibre/gui2/viewer/ui.py @@ -48,6 +48,8 @@ class EbookViewer(MainWindow): def __init__(self): MainWindow.__init__(self, None) + self.base_window_title = _('E-book viewer') + self.setWindowTitle(self.base_window_title) self.in_full_screen_mode = None try: os.makedirs(annotations_dir) @@ -161,6 +163,7 @@ class EbookViewer(MainWindow): def load_ebook(self, pathtoebook, open_at=None, reload_book=False): # TODO: Implement open_at + self.setWindowTitle(_('Loading book … — {}').format(self.base_window_title)) self.web_view.show_preparing_message() self.save_annotations() self.current_book_data = {} @@ -185,6 +188,7 @@ class EbookViewer(MainWindow): def load_finished(self, ok, data): if not ok: + self.setWindowTitle(self.base_window_title) error_dialog(self, _('Loading book failed'), _( 'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']), det_msg=data['tb'], show=True) @@ -194,6 +198,7 @@ class EbookViewer(MainWindow): self.current_book_data['annotations_map'] = defaultdict(list) self.current_book_data['annotations_path_key'] = path_key(data['pathtoebook']) + '.json' self.load_book_data() + self.update_window_title() self.web_view.start_book_load(initial_cfi=self.initial_cfi_for_current_book()) def load_book_data(self): @@ -206,6 +211,8 @@ class EbookViewer(MainWindow): self.toc_model = TOC(toc) self.toc.setModel(self.toc_model) self.bookmarks_widget.set_bookmarks(self.current_book_data['annotations_map']['bookmark']) + self.current_book_data['metadata'] = set_book_path.parsed_metadata + self.current_book_data['manifest'] = set_book_path.parsed_manifest def load_book_annotations(self): amap = self.current_book_data['annotations_map'] @@ -219,6 +226,12 @@ class EbookViewer(MainWindow): with open(path, 'rb') as f: raw = f.read() merge_annotations(parse_annotations(raw), amap) + + def update_window_title(self): + title = self.current_book_data['metadata']['title'] + book_format = self.current_book_data['manifest']['book_format'] + title = '{} [{}] — {}'.format(title, book_format, self.base_window_title) + self.setWindowTitle(title) # }}} # CFI management {{{ diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 63984cf453..565221162f 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -29,6 +29,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 polyglot.builtins import iteritems try: @@ -44,9 +45,14 @@ vprefs.defaults['main_window_geometry'] = None # Override network access to load data from the book {{{ - def set_book_path(path=None): - set_book_path.path = os.path.abspath(path) + if path is not None: + set_book_path.path = os.path.abspath(path) + set_book_path.metadata = get_data('calibre-book-metadata.json')[0] + set_book_path.manifest, set_book_path.manifest_mime = get_data('calibre-book-manifest.json') + set_book_path.metadata = get_data('calibre-book-metadata.json')[0] + set_book_path.parsed_metadata = json_loads(set_book_path.metadata) + set_book_path.parsed_manifest = json_loads(set_book_path.manifest) def get_data(name): @@ -116,10 +122,8 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler): traceback.print_exc() rq.fail(rq.RequestFailed) elif name == 'manifest': - manifest, mime_type = get_data('calibre-book-manifest.json') - metadata = get_data('calibre-book-metadata.json')[0] - data = b'[' + manifest + b',' + metadata + b']' - send_reply(rq, mime_type, data) + data = b'[' + set_book_path.manifest + b',' + set_book_path.metadata + b']' + send_reply(rq, set_book_path.manifest_mime, data) elif name.startswith('mathjax/'): from calibre.gui2.viewer.mathjax import monkeypatch_mathjax if name == 'mathjax/manifest.json': diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index aa7be19568..12f23bba9c 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -201,6 +201,7 @@ class Container(ContainerBase): self.book_render_data = data = { 'version': RENDER_VERSION, 'toc':toc, + 'book_format': book_fmt, 'spine':spine, 'link_uid': uuid4(), 'book_hash': book_hash,