Implement --continue

This commit is contained in:
Kovid Goyal 2019-08-15 12:28:51 +05:30
parent 4476d63b27
commit cd71b471e1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 6 deletions

View File

@ -2,8 +2,6 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
# TODO: --open-at and --continue command line options
from __future__ import absolute_import, division, print_function, unicode_literals from __future__ import absolute_import, division, print_function, unicode_literals
import os import os
@ -112,7 +110,8 @@ View an e-book.
'The position at which to open the specified book. The position is ' 'The position at which to open the specified book. The position is '
'a location as displayed in the top left corner of the viewer. ' 'a location as displayed in the top left corner of the viewer. '
'Alternately, you can use the form toc:something and it will open ' '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', a('--continue', default=False, action='store_true', dest='continue_reading',
help=_('Continue reading at the previously opened book')) help=_('Continue reading at the previously opened book'))
@ -154,7 +153,7 @@ def main(args=sys.argv):
app.file_event_hook = acc app.file_event_hook = acc
app.load_builtin_fonts() app.load_builtin_fonts()
app.setWindowIcon(QIcon(I('viewer.png'))) app.setWindowIcon(QIcon(I('viewer.png')))
main = EbookViewer() main = EbookViewer(open_at=open_at, continue_reading=opts.continue_reading)
main.set_exception_handler() main.set_exception_handler()
if len(args) > 1: if len(args) > 1:
acc.events.append(args[-1]) acc.events.append(args[-1])

View File

@ -47,7 +47,7 @@ class EbookViewer(MainWindow):
book_prepared = pyqtSignal(object, object) book_prepared = pyqtSignal(object, object)
MAIN_WINDOW_STATE_VERSION = 1 MAIN_WINDOW_STATE_VERSION = 1
def __init__(self): def __init__(self, open_at=None, continue_reading=None):
MainWindow.__init__(self, None) MainWindow.__init__(self, None)
self.base_window_title = _('E-book viewer') self.base_window_title = _('E-book viewer')
self.setWindowTitle(self.base_window_title) 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.web_view.ask_for_open.connect(self.ask_for_open, type=Qt.QueuedConnection)
self.setCentralWidget(self.web_view) self.setCentralWidget(self.web_view)
self.restore_state() self.restore_state()
if continue_reading:
self.continue_reading()
def toggle_inspector(self): def toggle_inspector(self):
visible = self.inspector_dock.toggleViewAction().isChecked() visible = self.inspector_dock.toggleViewAction().isChecked()
@ -181,9 +183,15 @@ class EbookViewer(MainWindow):
path = files[0] path = files[0]
self.load_ebook(path) 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): def load_ebook(self, pathtoebook, open_at=None, reload_book=False):
# TODO: Implement open_at # 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.web_view.show_preparing_message()
self.save_annotations() self.save_annotations()
self.current_book_data = {} self.current_book_data = {}