mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
GUI: Convert auto.
This commit is contained in:
parent
035d85392a
commit
c956f5fa30
@ -686,7 +686,8 @@ class DeviceGUI(object):
|
||||
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
|
||||
format = fmt
|
||||
break
|
||||
d.exec_()
|
||||
d.exec_()
|
||||
_auto_rows = [self.library_view.model().db.id(r) for r in _auto_rows]
|
||||
self.auto_convert(_auto_rows, on_card, format)
|
||||
|
||||
if bad:
|
||||
|
@ -979,17 +979,15 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
|
||||
############################### Convert ####################################
|
||||
|
||||
def auto_convert(self, rows, on_card, format):
|
||||
def auto_convert(self, row_ids, on_card, format):
|
||||
previous = self.library_view.currentIndex()
|
||||
|
||||
jobs, changed, bad_rows = auto_convert_ebook(format, self, self.library_view.model().db, rows)
|
||||
if jobs is None:
|
||||
return
|
||||
jobs, changed = convert_single_ebook(self, self.library_view.model().db, row_ids, True)
|
||||
if jobs == []: return
|
||||
for func, args, desc, fmt, id, temp_files in jobs:
|
||||
if id not in bad_rows:
|
||||
job = self.job_manager.run_job(Dispatcher(self.book_auto_converted),
|
||||
func, args=args, description=desc)
|
||||
self.conversion_jobs[job] = (temp_files, fmt, id, on_card)
|
||||
job = self.job_manager.run_job(Dispatcher(self.book_auto_converted),
|
||||
func, args=args, description=desc)
|
||||
self.conversion_jobs[job] = (temp_files, fmt, id, on_card)
|
||||
|
||||
if changed:
|
||||
self.library_view.model().refresh_rows(rows)
|
||||
|
@ -9,85 +9,11 @@ Logic for setting up conversion jobs
|
||||
import os
|
||||
from PyQt4.Qt import QDialog
|
||||
|
||||
from calibre.customize.ui import available_input_formats
|
||||
from calibre.utils.config import prefs
|
||||
from calibre.gui2 import warning_dialog
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
|
||||
from calibre.gui2.convert import load_specifics
|
||||
from calibre.gui2.convert.single import Config as SingleConfig
|
||||
|
||||
# Ordered list of source formats. Items closer to the beginning are
|
||||
# preferred for conversion over those toward the end.
|
||||
PREFERRED_SOURCE_FORMATS = ['epub', 'lit', 'mobi', 'prc', 'azw', 'fb2', 'odt', 'rtf',
|
||||
'txt', 'pdf', 'oebzip', 'htm', 'html']
|
||||
|
||||
def get_dialog(fmt):
|
||||
return {
|
||||
'epub':EPUBConvert,
|
||||
'mobi':MOBIConvert,
|
||||
}[fmt]
|
||||
|
||||
def get_config(fmt):
|
||||
return {
|
||||
'epub':epubconfig,
|
||||
'mobi':mobiconfig,
|
||||
}[fmt]
|
||||
|
||||
def auto_convert(fmt, parent, db, rows):
|
||||
changed = False
|
||||
jobs = []
|
||||
|
||||
total = len(rows)
|
||||
if total == 0:
|
||||
return None, None, None
|
||||
parent.status_bar.showMessage(_('Starting auto conversion of %d books')%total, 2000)
|
||||
|
||||
bad_rows = []
|
||||
|
||||
for i, row in enumerate(rows):
|
||||
row_id = db.id(row)
|
||||
|
||||
temp_files = []
|
||||
|
||||
data = None
|
||||
in_formats = [f.lower() for f in db.formats(row).split(',')]
|
||||
in_formats = list(set(in_formats).intersection(available_input_formats()))
|
||||
for _fmt in PREFERRED_SOURCE_FORMATS:
|
||||
if _fmt in in_formats:
|
||||
data = _fmt
|
||||
break
|
||||
if data is None:
|
||||
if in_formats != []:
|
||||
data = list(in_formats)[0]
|
||||
else:
|
||||
bad_rows.append(row)
|
||||
continue
|
||||
|
||||
mi = db.get_metadata(row)
|
||||
in_file = db.format_abspath(row, data)
|
||||
out_file = PersistentTemporaryFile('.'+fmt.lower())
|
||||
out_file.write(data)
|
||||
out_file.close()
|
||||
desc = _('Auto convert book %d of %d (%s)')%(i+1, total, repr(mi.title))
|
||||
args = [['', in_file, out_file.name]]
|
||||
temp_files = [out_file]
|
||||
jobs.append(('ebook-convert', args, desc, fmt.upper(), row_id, temp_files))
|
||||
|
||||
changed = True
|
||||
|
||||
if bad_rows:
|
||||
res = []
|
||||
for row in bad_rows:
|
||||
title = db.title(row)
|
||||
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, bad_rows
|
||||
|
||||
def convert_single_ebook(parent, db, row_ids):
|
||||
def convert_single_ebook(parent, db, row_ids, auto_conversion=False):
|
||||
changed = False
|
||||
jobs = []
|
||||
|
||||
@ -100,7 +26,13 @@ def convert_single_ebook(parent, db, row_ids):
|
||||
temp_files = []
|
||||
|
||||
d = SingleConfig(parent, db, row_id)
|
||||
if d.exec_() == QDialog.Accepted:
|
||||
|
||||
if auto_conversion:
|
||||
result = QDialog.Accepted
|
||||
else:
|
||||
retult = d.exec_()
|
||||
|
||||
if result == QDialog.Accepted:
|
||||
mi = db.get_metadata(row_id, True)
|
||||
in_file = db.format_abspath(row_id, d.input_format, True)
|
||||
|
||||
@ -363,9 +295,6 @@ def fetch_scheduled_recipe(recipe, script):
|
||||
args.append(script)
|
||||
return 'feeds2'+fmt, [args], _('Fetch news from ')+recipe.title, fmt.upper(), [pt]
|
||||
|
||||
def auto_convert_ebook(*args):
|
||||
return auto_convert(*args)
|
||||
|
||||
def convert_bulk_ebooks(*args):
|
||||
fmt = prefs['output_format'].lower()
|
||||
if fmt == 'lrf':
|
||||
|
Loading…
x
Reference in New Issue
Block a user