mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GUI: Convert, check for NoSupportedInputFormats.
This commit is contained in:
parent
3c045737da
commit
eda53229a4
@ -11,11 +11,13 @@ from PyQt4.Qt import QDialog
|
|||||||
|
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.gui2.convert import load_specifics
|
from calibre.gui2.convert import load_specifics
|
||||||
|
from calibre.gui2.convert.single import NoSupportedInputFormats
|
||||||
from calibre.gui2.convert.single import Config as SingleConfig
|
from calibre.gui2.convert.single import Config as SingleConfig
|
||||||
|
|
||||||
def convert_single_ebook(parent, db, row_ids, auto_conversion=False):
|
def convert_single_ebook(parent, db, row_ids, auto_conversion=False):
|
||||||
changed = False
|
changed = False
|
||||||
jobs = []
|
jobs = []
|
||||||
|
bad = []
|
||||||
|
|
||||||
total = len(row_ids)
|
total = len(row_ids)
|
||||||
if total == 0:
|
if total == 0:
|
||||||
@ -25,33 +27,45 @@ def convert_single_ebook(parent, db, row_ids, auto_conversion=False):
|
|||||||
for i, row_id in enumerate(row_ids):
|
for i, row_id in enumerate(row_ids):
|
||||||
temp_files = []
|
temp_files = []
|
||||||
|
|
||||||
d = SingleConfig(parent, db, row_id)
|
try:
|
||||||
|
d = SingleConfig(parent, db, row_id)
|
||||||
|
|
||||||
if auto_conversion:
|
if auto_conversion:
|
||||||
result = QDialog.Accepted
|
result = QDialog.Accepted
|
||||||
else:
|
else:
|
||||||
retult = d.exec_()
|
retult = d.exec_()
|
||||||
|
|
||||||
if result == QDialog.Accepted:
|
if result == QDialog.Accepted:
|
||||||
mi = db.get_metadata(row_id, True)
|
mi = db.get_metadata(row_id, True)
|
||||||
in_file = db.format_abspath(row_id, d.input_format, True)
|
in_file = db.format_abspath(row_id, d.input_format, True)
|
||||||
|
|
||||||
out_file = PersistentTemporaryFile('.' + d.output_format)
|
out_file = PersistentTemporaryFile('.' + d.output_format)
|
||||||
out_file.write(d.output_format)
|
out_file.write(d.output_format)
|
||||||
out_file.close()
|
out_file.close()
|
||||||
|
|
||||||
desc = _('Convert book %d of %d (%s)') % (i + 1, total, repr(mi.title))
|
desc = _('Convert book %d of %d (%s)') % (i + 1, total, repr(mi.title))
|
||||||
|
|
||||||
opts = load_specifics(db, row_id)
|
opts = load_specifics(db, row_id)
|
||||||
opts_string = ''
|
opts_string = ''
|
||||||
for opt in opts.keys():
|
for opt in opts.keys():
|
||||||
opts_string += ' --%s %s ' % (opt, opts[opt])
|
opts_string += ' --%s %s ' % (opt, opts[opt])
|
||||||
|
|
||||||
args = [['', in_file, out_file.name, opts_string]]
|
args = [['', in_file, out_file.name, opts_string]]
|
||||||
temp_files = [out_file]
|
temp_files = [out_file]
|
||||||
jobs.append(('ebook-convert', args, desc, d.output_format.upper(), row_id, temp_files))
|
jobs.append(('ebook-convert', args, desc, d.output_format.upper(), row_id, temp_files))
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
|
except NoSupportedInputFormats:
|
||||||
|
bad.append(row_id)
|
||||||
|
|
||||||
|
if bad != []:
|
||||||
|
res = []
|
||||||
|
for id in bad:
|
||||||
|
title = db.title(id, True)
|
||||||
|
res.append('<li>%s</li>'%title)
|
||||||
|
|
||||||
|
msg = _('<p>Could not convert %d of %d books, because no suitable source format was found.<ul>%s</ul>')%(len(res), total, '\n'.join(res))
|
||||||
|
warning_dialog(parent, _('Could not convert some books'), msg).exec_()
|
||||||
|
|
||||||
return jobs, changed
|
return jobs, changed
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user