mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When running Edit book on a book with no formats ask if an empty book should be created. Fixes #1864234 [[Enhancement] Add option to open Edit book even if the selected book is not an EPUB or AZW3](https://bugs.launchpad.net/calibre/+bug/1864234)
This commit is contained in:
parent
7af7fcf561
commit
56c0102d20
@ -232,21 +232,25 @@ class AddAction(InterfaceAction):
|
||||
return
|
||||
|
||||
for id_ in ids:
|
||||
from calibre.ebooks.oeb.polish.create import create_book
|
||||
pt = PersistentTemporaryFile(suffix='.' + format_)
|
||||
pt.close()
|
||||
try:
|
||||
mi = db.new_api.get_metadata(id_, get_cover=False,
|
||||
get_user_categories=False, cover_as_data=False)
|
||||
create_book(mi, pt.name, fmt=format_)
|
||||
db.add_format_with_hooks(id_, format_, pt.name, index_is_id=True, notify=True)
|
||||
finally:
|
||||
os.remove(pt.name)
|
||||
self.add_empty_format_to_book(id_, format_)
|
||||
|
||||
current_idx = self.gui.library_view.currentIndex()
|
||||
if current_idx.isValid():
|
||||
view.model().current_changed(current_idx, current_idx)
|
||||
|
||||
def add_empty_format_to_book(self, book_id, fmt):
|
||||
from calibre.ebooks.oeb.polish.create import create_book
|
||||
db = self.gui.current_db
|
||||
pt = PersistentTemporaryFile(suffix='.' + fmt.lower())
|
||||
pt.close()
|
||||
try:
|
||||
mi = db.new_api.get_metadata(book_id, get_cover=False,
|
||||
get_user_categories=False, cover_as_data=False)
|
||||
create_book(mi, pt.name, fmt=fmt.lower())
|
||||
db.add_format_with_hooks(book_id, fmt, pt.name, index_is_id=True, notify=True)
|
||||
finally:
|
||||
os.remove(pt.name)
|
||||
|
||||
def add_archive(self, single):
|
||||
paths = choose_files(
|
||||
self.gui, 'recursive-archive-add', _('Choose archive file'),
|
||||
|
@ -10,7 +10,7 @@ import time
|
||||
|
||||
from PyQt5.Qt import QTimer, QDialog, QDialogButtonBox, QCheckBox, QVBoxLayout, QLabel, Qt
|
||||
|
||||
from calibre.gui2 import error_dialog
|
||||
from calibre.gui2 import error_dialog, question_dialog
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
|
||||
|
||||
@ -105,13 +105,23 @@ class TweakEpubAction(InterfaceAction):
|
||||
from calibre.ebooks.oeb.polish.main import SUPPORTED
|
||||
db = self.gui.library_view.model().db
|
||||
fmts = db.formats(book_id, index_is_id=True) or ''
|
||||
fmts = [x.upper().strip() for x in fmts.split(',')]
|
||||
fmts = [x.upper().strip() for x in fmts.split(',') if x]
|
||||
tweakable_fmts = set(fmts).intersection(SUPPORTED)
|
||||
if not tweakable_fmts:
|
||||
return error_dialog(self.gui, _('Cannot edit book'),
|
||||
_('The book must be in the %s formats to edit.'
|
||||
'\n\nFirst convert the book to one of these formats.') % (_(' or ').join(SUPPORTED)),
|
||||
show=True)
|
||||
if not fmts:
|
||||
if not question_dialog(self.gui, _('No editable formats'),
|
||||
_('Do you want to create an empty EPUB file to edit?')):
|
||||
return
|
||||
tweakable_fmts = {'EPUB'}
|
||||
self.gui.iactions['Add Books'].add_empty_format_to_book(book_id, 'EPUB')
|
||||
current_idx = self.gui.library_view.currentIndex()
|
||||
if current_idx.isValid():
|
||||
self.gui.library_view.model().current_changed(current_idx, current_idx)
|
||||
else:
|
||||
return error_dialog(self.gui, _('Cannot edit book'), _(
|
||||
'The book must be in the %s formats to edit.'
|
||||
'\n\nFirst convert the book to one of these formats.'
|
||||
) % (_(' or ').join(SUPPORTED)), show=True)
|
||||
from calibre.gui2.tweak_book import tprefs
|
||||
tprefs.refresh() # In case they were changed in a Tweak Book process
|
||||
if len(tweakable_fmts) > 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user