diff --git a/src/calibre/ebooks/oeb/polish/main.py b/src/calibre/ebooks/oeb/polish/main.py index 51b7db77ac..509a9c761a 100644 --- a/src/calibre/ebooks/oeb/polish/main.py +++ b/src/calibre/ebooks/oeb/polish/main.py @@ -44,6 +44,7 @@ CUSTOMIZATION = { 'remove_unused_classes': False, 'merge_identical_selectors': False, 'merge_rules_with_identical_properties': False, + 'remove_ncx': True, } SUPPORTED = {'EPUB', 'AZW3'} @@ -250,7 +251,7 @@ def polish_one(ebook, opts, report, customization=None): if opts.upgrade_book: rt(_('Upgrading book, if possible')) - if upgrade_book(ebook, report): + if upgrade_book(ebook, report, remove_ncx=customization['remove_ncx']): changed = True report('') diff --git a/src/calibre/ebooks/oeb/polish/upgrade.py b/src/calibre/ebooks/oeb/polish/upgrade.py index e98a8d8471..44a01429bc 100644 --- a/src/calibre/ebooks/oeb/polish/upgrade.py +++ b/src/calibre/ebooks/oeb/polish/upgrade.py @@ -114,12 +114,12 @@ def create_nav(container, toc, landmarks, previous_nav=None): commit_nav_toc(container, toc, lang=lang, landmarks=landmarks, previous_nav=previous_nav) -def epub_2_to_3(container, report, previous_nav=None): +def epub_2_to_3(container, report, previous_nav=None, remove_ncx=True): upgrade_metadata(container.opf) collect_properties(container) toc = get_toc(container) toc_name = find_existing_ncx_toc(container) - if toc_name: + if toc_name and remove_ncx: container.remove_item(toc_name) container.opf_xpath('./opf:spine')[0].attrib.pop('toc', None) landmarks = get_landmarks(container) @@ -132,11 +132,11 @@ def epub_2_to_3(container, report, previous_nav=None): container.dirty(container.opf_name) -def upgrade_book(container, report): +def upgrade_book(container, report, remove_ncx=True): if container.book_type != 'epub' or container.opf_version_parsed.major >= 3: report(_('No upgrade needed')) return False - epub_2_to_3(container, report) + epub_2_to_3(container, report, remove_ncx=remove_ncx) report(_('Updated EPUB from version 2 to 3')) return True diff --git a/src/calibre/gui2/tweak_book/polish.py b/src/calibre/gui2/tweak_book/polish.py index c9d41b9621..fd148c698f 100644 --- a/src/calibre/gui2/tweak_book/polish.py +++ b/src/calibre/gui2/tweak_book/polish.py @@ -17,7 +17,7 @@ from PyQt5.Qt import ( from calibre import human_readable, fit_image, force_unicode from calibre.ebooks.oeb.polish.main import CUSTOMIZATION -from calibre.gui2 import empty_index +from calibre.gui2 import empty_index, question_dialog from calibre.gui2.tweak_book import tprefs, current_container, set_current_container from calibre.gui2.tweak_book.widgets import Dialog from calibre.utils.icu import numeric_sort_key @@ -78,6 +78,17 @@ def get_customization(action, name, parent): try: if action == 'remove_unused_css': customize_remove_unused_css(name, parent, ans) + elif action == 'upgrade_book': + ans['remove_ncx'] = question_dialog( + parent, _('Remove NCX ToC file'), + _('Remove the legacy Table of Contents in NCX form?'), + _('This form of Table of Contents is superseded by the new HTML based Table of Contents.' + ' Leaving it behind is useful only if you expect this book to be read on very' + ' old devices that lack proper support for EPUB 3'), + skip_dialog_name='edit-book-remove-ncx', + skip_dialog_msg=_('Ask this question again in the future'), + yes_text=_('Remove NCX'), no_text=_('Keep NCX') + ) except Abort: return None return ans