mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Upgrade book: Ask whether to keep the NCX based Table of Contents. Fixes #1287 (Add an option to remove NCX TOC file when upgrading book internals)
This commit is contained in:
parent
687dc10cfa
commit
8e44992888
@ -44,6 +44,7 @@ CUSTOMIZATION = {
|
|||||||
'remove_unused_classes': False,
|
'remove_unused_classes': False,
|
||||||
'merge_identical_selectors': False,
|
'merge_identical_selectors': False,
|
||||||
'merge_rules_with_identical_properties': False,
|
'merge_rules_with_identical_properties': False,
|
||||||
|
'remove_ncx': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
SUPPORTED = {'EPUB', 'AZW3'}
|
SUPPORTED = {'EPUB', 'AZW3'}
|
||||||
@ -250,7 +251,7 @@ def polish_one(ebook, opts, report, customization=None):
|
|||||||
|
|
||||||
if opts.upgrade_book:
|
if opts.upgrade_book:
|
||||||
rt(_('Upgrading book, if possible'))
|
rt(_('Upgrading book, if possible'))
|
||||||
if upgrade_book(ebook, report):
|
if upgrade_book(ebook, report, remove_ncx=customization['remove_ncx']):
|
||||||
changed = True
|
changed = True
|
||||||
report('')
|
report('')
|
||||||
|
|
||||||
|
@ -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)
|
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)
|
upgrade_metadata(container.opf)
|
||||||
collect_properties(container)
|
collect_properties(container)
|
||||||
toc = get_toc(container)
|
toc = get_toc(container)
|
||||||
toc_name = find_existing_ncx_toc(container)
|
toc_name = find_existing_ncx_toc(container)
|
||||||
if toc_name:
|
if toc_name and remove_ncx:
|
||||||
container.remove_item(toc_name)
|
container.remove_item(toc_name)
|
||||||
container.opf_xpath('./opf:spine')[0].attrib.pop('toc', None)
|
container.opf_xpath('./opf:spine')[0].attrib.pop('toc', None)
|
||||||
landmarks = get_landmarks(container)
|
landmarks = get_landmarks(container)
|
||||||
@ -132,11 +132,11 @@ def epub_2_to_3(container, report, previous_nav=None):
|
|||||||
container.dirty(container.opf_name)
|
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:
|
if container.book_type != 'epub' or container.opf_version_parsed.major >= 3:
|
||||||
report(_('No upgrade needed'))
|
report(_('No upgrade needed'))
|
||||||
return False
|
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'))
|
report(_('Updated EPUB from version 2 to 3'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from PyQt5.Qt import (
|
|||||||
|
|
||||||
from calibre import human_readable, fit_image, force_unicode
|
from calibre import human_readable, fit_image, force_unicode
|
||||||
from calibre.ebooks.oeb.polish.main import CUSTOMIZATION
|
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 import tprefs, current_container, set_current_container
|
||||||
from calibre.gui2.tweak_book.widgets import Dialog
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
@ -78,6 +78,17 @@ def get_customization(action, name, parent):
|
|||||||
try:
|
try:
|
||||||
if action == 'remove_unused_css':
|
if action == 'remove_unused_css':
|
||||||
customize_remove_unused_css(name, parent, ans)
|
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:
|
except Abort:
|
||||||
return None
|
return None
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user