diff --git a/src/calibre/ebooks/oeb/iterator/book.py b/src/calibre/ebooks/oeb/iterator/book.py
index 11cf19d7f9..384608e718 100644
--- a/src/calibre/ebooks/oeb/iterator/book.py
+++ b/src/calibre/ebooks/oeb/iterator/book.py
@@ -50,7 +50,8 @@ class EbookIterator(BookmarksMixin):
CHARACTERS_PER_PAGE = 1000
- def __init__(self, pathtoebook, log=None):
+ def __init__(self, pathtoebook, log=None, copy_bookmarks_to_file=True):
+ BookmarksMixin.__init__(self, copy_bookmarks_to_file=copy_bookmarks_to_file)
self.log = log or default_log
pathtoebook = pathtoebook.strip()
self.pathtoebook = os.path.abspath(pathtoebook)
@@ -101,8 +102,8 @@ class EbookIterator(BookmarksMixin):
if not only_input_plugin:
# Run the HTML preprocess/parsing from the conversion pipeline as
# well
- if (processed or plumber.input_fmt.lower() in {'pdb', 'pdf', 'rb'}
- and not hasattr(self.pathtoopf, 'manifest')):
+ if (processed or plumber.input_fmt.lower() in {'pdb', 'pdf', 'rb'} and
+ not hasattr(self.pathtoopf, 'manifest')):
if hasattr(self.pathtoopf, 'manifest'):
self.pathtoopf = write_oebbook(self.pathtoopf, self.base)
self.pathtoopf = create_oebbook(self.log, self.pathtoopf,
diff --git a/src/calibre/ebooks/oeb/iterator/bookmarks.py b/src/calibre/ebooks/oeb/iterator/bookmarks.py
index 0e2d97da55..3e52c6b4b9 100644
--- a/src/calibre/ebooks/oeb/iterator/bookmarks.py
+++ b/src/calibre/ebooks/oeb/iterator/bookmarks.py
@@ -17,6 +17,9 @@ BM_LEGACY_ESC = u'esc-text-%&*#%(){}ads19-end-esc'
class BookmarksMixin(object):
+ def __init__(self, copy_bookmarks_to_file=True):
+ self.copy_bookmarks_to_file = copy_bookmarks_to_file
+
def parse_bookmarks(self, raw):
for line in raw.splitlines():
bm = None
@@ -64,16 +67,14 @@ class BookmarksMixin(object):
def read_bookmarks(self):
self.bookmarks = []
- bmfile = os.path.join(self.base, 'META-INF', 'calibre_bookmarks.txt')
- raw = ''
- if os.path.exists(bmfile):
- with open(bmfile, 'rb') as f:
- raw = f.read()
- else:
- saved = self.config['bookmarks_'+self.pathtoebook]
- if saved:
- raw = saved
- if not isinstance(raw, unicode):
+ raw = self.config['bookmarks_'+self.pathtoebook] or ''
+ if not raw:
+ # Look for bookmarks saved inside the ebook
+ bmfile = os.path.join(self.base, 'META-INF', 'calibre_bookmarks.txt')
+ if os.path.exists(bmfile):
+ with open(bmfile, 'rb') as f:
+ raw = f.read()
+ if isinstance(raw, bytes):
raw = raw.decode('utf-8')
self.parse_bookmarks(raw)
@@ -81,8 +82,9 @@ class BookmarksMixin(object):
if bookmarks is None:
bookmarks = self.bookmarks
dat = self.serialize_bookmarks(bookmarks)
- if os.path.splitext(self.pathtoebook)[1].lower() == '.epub' and \
- os.access(self.pathtoebook, os.R_OK):
+ self.config['bookmarks_'+self.pathtoebook] = dat
+ if self.copy_bookmarks_to_file and os.path.splitext(
+ self.pathtoebook)[1].lower() == '.epub' and os.access(self.pathtoebook, os.W_OK):
try:
zf = open(self.pathtoebook, 'r+b')
except IOError:
@@ -90,8 +92,6 @@ class BookmarksMixin(object):
safe_replace(zf, 'META-INF/calibre_bookmarks.txt',
BytesIO(dat.encode('utf-8')),
add_missing=True)
- else:
- self.config['bookmarks_'+self.pathtoebook] = dat
def add_bookmark(self, bm):
self.bookmarks = [x for x in self.bookmarks if x['title'] !=
diff --git a/src/calibre/gui2/viewer/config.py b/src/calibre/gui2/viewer/config.py
index 21c986cf2c..99cceee265 100644
--- a/src/calibre/gui2/viewer/config.py
+++ b/src/calibre/gui2/viewer/config.py
@@ -49,6 +49,8 @@ def config(defaults=None):
help=_('Default language for hyphenation rules'))
c.add_opt('remember_current_page', default=True,
help=_('Save the current position in the document, when quitting'))
+ c.add_opt('copy_bookmarks_to_file', default=True,
+ help=_('Copy bookmarks to the ebook file for easy sharing, if possible'))
c.add_opt('wheel_flips_pages', default=False,
help=_('Have the mouse wheel turn pages'))
c.add_opt('tap_flips_pages', default=True,
@@ -281,6 +283,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
def load_options(self, opts):
self.opt_remember_window_size.setChecked(opts.remember_window_size)
self.opt_remember_current_page.setChecked(opts.remember_current_page)
+ self.opt_copy_bookmarks_to_file.setChecked(opts.copy_bookmarks_to_file)
self.opt_wheel_flips_pages.setChecked(opts.wheel_flips_pages)
self.opt_tap_flips_pages.setChecked(opts.tap_flips_pages)
self.opt_page_flip_duration.setValue(opts.page_flip_duration)
@@ -383,6 +386,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
c.set('max_fs_height', max_fs_height)
c.set('hyphenate', self.hyphenate.isChecked())
c.set('remember_current_page', self.opt_remember_current_page.isChecked())
+ c.set('copy_bookmarks_to_file', self.opt_copy_bookmarks_to_file.isChecked())
c.set('wheel_flips_pages', self.opt_wheel_flips_pages.isChecked())
c.set('tap_flips_pages', self.opt_tap_flips_pages.isChecked())
c.set('page_flip_duration', self.opt_page_flip_duration.value())
diff --git a/src/calibre/gui2/viewer/config.ui b/src/calibre/gui2/viewer/config.ui
index b87097eea8..7783072187 100644
--- a/src/calibre/gui2/viewer/config.ui
+++ b/src/calibre/gui2/viewer/config.ui
@@ -213,7 +213,7 @@ QToolBox::tab:hover {
-
- M&inimum font size:
+ Minimum font si&ze:
minimum_font_size
@@ -551,8 +551,8 @@ QToolBox::tab:hover {
0
0
- 799
- 378
+ 384
+ 140
@@ -629,8 +629,8 @@ QToolBox::tab:hover {
0
0
- 368
- 167
+ 799
+ 378
@@ -661,7 +661,7 @@ QToolBox::tab:hover {
- -
+
-
Clear search history
@@ -689,6 +689,16 @@ QToolBox::tab:hover {
+ -
+
+
+ Keep a copy of all bookmarks/current page information inside the ebook file, so that you can share them by simply sending the ebook file itself. Currently only works with ebooks in the EPUB format.
+
+
+ Keep a copy of bookmarks/current page inside the ebook file, for easy sharing
+
+
+
diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py
index 66392d7d5a..632e082f33 100644
--- a/src/calibre/gui2/viewer/documentview.py
+++ b/src/calibre/gui2/viewer/documentview.py
@@ -183,6 +183,8 @@ class Document(QWebPage): # {{{
self.side_margin = opts.side_margin
self.top_margin, self.bottom_margin = opts.top_margin, opts.bottom_margin
self.show_controls = opts.show_controls
+ self.remember_current_page = opts.remember_current_page
+ self.copy_bookmarks_to_file = opts.copy_bookmarks_to_file
def fit_images(self):
if self.do_fit_images and not self.in_paged_mode:
diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py
index 8c4192c3c7..7c0dbc3da5 100644
--- a/src/calibre/gui2/viewer/main.py
+++ b/src/calibre/gui2/viewer/main.py
@@ -304,11 +304,6 @@ class EbookViewer(MainWindow):
url = default_lookup_website(canonicalize_lang(self.view.current_language) or 'en').format(word=word)
open_url(url)
- def get_remember_current_page_opt(self):
- from calibre.gui2.viewer.documentview import config
- c = config().parse()
- return c.remember_current_page
-
def print_book(self):
p = Printing(self.iterator, self)
p.start_print()
@@ -764,6 +759,8 @@ class EbookViewer(MainWindow):
def do_config(self):
self.view.config(self)
self.load_theme_menu()
+ if self.iterator is not None:
+ self.iterator.copy_bookmarks_to_file = self.view.document.copy_bookmarks_to_file
from calibre.gui2 import config
if not config['viewer_search_history']:
self.search.clear_history()
@@ -802,7 +799,7 @@ class EbookViewer(MainWindow):
self.existing_bookmarks = []
for bm in bookmarks:
if bm['title'] == 'calibre_current_page_bookmark':
- if self.get_remember_current_page_opt():
+ if self.view.document.remember_current_page:
current_page = bm
else:
self.existing_bookmarks.append(bm['title'])
@@ -821,7 +818,7 @@ class EbookViewer(MainWindow):
return bm
def save_current_position(self):
- if not self.get_remember_current_page_opt():
+ if not self.view.document.remember_current_page:
return
if hasattr(self, 'current_index'):
try:
@@ -833,7 +830,7 @@ class EbookViewer(MainWindow):
if self.iterator is not None:
self.save_current_position()
self.iterator.__exit__()
- self.iterator = EbookIterator(pathtoebook)
+ self.iterator = EbookIterator(pathtoebook, copy_bookmarks_to_file=self.view.document.copy_bookmarks_to_file)
self.history.clear()
self.open_progress_indicator(_('Loading ebook...'))
worker = Worker(target=partial(self.iterator.__enter__, view_kepub=True))