diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 4c4d9db47e..ff902abfe6 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -2,8 +2,6 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal -# TODO: --open-at and --continue command line options - from __future__ import absolute_import, division, print_function, unicode_literals import os @@ -112,7 +110,8 @@ View an e-book. 'The position at which to open the specified book. The position is ' 'a location as displayed in the top left corner of the viewer. ' 'Alternately, you can use the form toc:something and it will open ' - 'at the location of the first Table of Contents entry that contains the string "something".')) + 'at the location of the first Table of Contents entry that contains ' + 'the string "something".')) a('--continue', default=False, action='store_true', dest='continue_reading', help=_('Continue reading at the previously opened book')) @@ -154,7 +153,7 @@ def main(args=sys.argv): app.file_event_hook = acc app.load_builtin_fonts() app.setWindowIcon(QIcon(I('viewer.png'))) - main = EbookViewer() + main = EbookViewer(open_at=open_at, continue_reading=opts.continue_reading) main.set_exception_handler() if len(args) > 1: acc.events.append(args[-1]) diff --git a/src/calibre/gui2/viewer/ui.py b/src/calibre/gui2/viewer/ui.py index e585f47dde..5d24df7b52 100644 --- a/src/calibre/gui2/viewer/ui.py +++ b/src/calibre/gui2/viewer/ui.py @@ -47,7 +47,7 @@ class EbookViewer(MainWindow): book_prepared = pyqtSignal(object, object) MAIN_WINDOW_STATE_VERSION = 1 - def __init__(self): + def __init__(self, open_at=None, continue_reading=None): MainWindow.__init__(self, None) self.base_window_title = _('E-book viewer') self.setWindowTitle(self.base_window_title) @@ -99,6 +99,8 @@ class EbookViewer(MainWindow): self.web_view.ask_for_open.connect(self.ask_for_open, type=Qt.QueuedConnection) self.setCentralWidget(self.web_view) self.restore_state() + if continue_reading: + self.continue_reading() def toggle_inspector(self): visible = self.inspector_dock.toggleViewAction().isChecked() @@ -181,9 +183,15 @@ class EbookViewer(MainWindow): path = files[0] self.load_ebook(path) + def continue_reading(self): + rl = vprefs['session_data'].get('standalone_recently_opened') + if rl: + entry = rl[0] + self.load_ebook(entry['pathtoebook']) + 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.setWindowTitle(_('Loading book… — {}').format(self.base_window_title)) self.web_view.show_preparing_message() self.save_annotations() self.current_book_data = {}