mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Pull from driver-dev
This commit is contained in:
commit
e933db70aa
@ -211,6 +211,7 @@ def main(args=sys.argv):
|
|||||||
OptionRecommendation.HIGH) \
|
OptionRecommendation.HIGH) \
|
||||||
for n in parser.options_iter()
|
for n in parser.options_iter()
|
||||||
if n.dest]
|
if n.dest]
|
||||||
|
print recommendations
|
||||||
plumber.merge_ui_recommendations(recommendations)
|
plumber.merge_ui_recommendations(recommendations)
|
||||||
|
|
||||||
plumber.run()
|
plumber.run()
|
||||||
|
17
src/calibre/gui2/convert/gui_conversion.py
Normal file
17
src/calibre/gui2/convert/gui_conversion.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from calibre.ebooks.conversion.plumber import Plumber
|
||||||
|
from calibre.utils.logging import Log
|
||||||
|
|
||||||
|
def gui_convert(input, output, recommendations, notification):
|
||||||
|
plumber = Plumber(input, output, Log(), notification)
|
||||||
|
plumber.merge_ui_recommendations(recommendations)
|
||||||
|
|
||||||
|
plumber.run()
|
||||||
|
|
@ -136,9 +136,10 @@ class Config(ResizableDialog, Ui_Dialog):
|
|||||||
ps = widget_factory(PageSetupWidget)
|
ps = widget_factory(PageSetupWidget)
|
||||||
|
|
||||||
output_widget = None
|
output_widget = None
|
||||||
name = self.plumber.output_plugin.name.lower().replace(' ', '_')
|
name = 'calibre.gui2.convert.%s' % self.plumber.output_plugin.name.lower().replace(' ', '_')
|
||||||
try:
|
try:
|
||||||
output_widget = __import__(name)
|
__import__(name)
|
||||||
|
output_widget = sys.modules[name]
|
||||||
pw = output_widget.PluginWidget
|
pw = output_widget.PluginWidget
|
||||||
pw.ICON = ':/images/back.svg'
|
pw.ICON = ':/images/back.svg'
|
||||||
pw.HELP = _('Options specific to the output format.')
|
pw.HELP = _('Options specific to the output format.')
|
||||||
|
@ -678,16 +678,20 @@ class DeviceGUI(object):
|
|||||||
bad.append(self.library_view.model().title(row))
|
bad.append(self.library_view.model().title(row))
|
||||||
|
|
||||||
if auto != []:
|
if auto != []:
|
||||||
autos = [self.library_view.model().title(row) for row in auto]
|
format = None
|
||||||
autos = '\n'.join('<li>%s</li>'%(i,) for i in autos)
|
|
||||||
d = info_dialog(self, _('No suitable formats'),
|
|
||||||
_('Auto converting the following books before uploading to the device:<br><ul>%s</ul>')%(autos,))
|
|
||||||
for fmt in self.device_manager.device_class.settings().format_map:
|
for fmt in self.device_manager.device_class.settings().format_map:
|
||||||
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
|
if fmt in list(set(self.device_manager.device_class.settings().format_map).intersection(set(available_output_formats()))):
|
||||||
format = fmt
|
format = fmt
|
||||||
break
|
break
|
||||||
d.exec_()
|
if format is None:
|
||||||
self.auto_convert(_auto_ids, on_card, format)
|
bad += auto
|
||||||
|
else:
|
||||||
|
autos = [self.library_view.model().title(row) for row in auto]
|
||||||
|
autos = '\n'.join('<li>%s</li>'%(i,) for i in autos)
|
||||||
|
d = info_dialog(self, _('No suitable formats'),
|
||||||
|
_('Auto converting the following books before uploading to the device:<br><ul>%s</ul>')%(autos,))
|
||||||
|
d.exec_()
|
||||||
|
self.auto_convert(_auto_ids, on_card, format)
|
||||||
|
|
||||||
if bad:
|
if bad:
|
||||||
bad = '\n'.join('<li>%s</li>'%(i,) for i in bad)
|
bad = '\n'.join('<li>%s</li>'%(i,) for i in bad)
|
||||||
|
@ -973,12 +973,13 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
def auto_convert(self, row_ids, on_card, format):
|
def auto_convert(self, row_ids, on_card, format):
|
||||||
previous = self.library_view.currentIndex()
|
previous = self.library_view.currentIndex()
|
||||||
|
|
||||||
jobs, changed = convert_single_ebook(self, self.library_view.model().db, row_ids, True)
|
jobs, changed, bad = convert_single_ebook(self, self.library_view.model().db, row_ids, True, format)
|
||||||
if jobs == []: return
|
if jobs == []: return
|
||||||
for func, args, desc, fmt, id, temp_files in jobs:
|
for func, args, desc, fmt, id, temp_files in jobs:
|
||||||
job = self.job_manager.run_job(Dispatcher(self.book_auto_converted),
|
if id not in bad:
|
||||||
|
job = self.job_manager.run_job(Dispatcher(self.book_auto_converted),
|
||||||
func, args=args, description=desc)
|
func, args=args, description=desc)
|
||||||
self.conversion_jobs[job] = (temp_files, fmt, id, on_card)
|
self.conversion_jobs[job] = (temp_files, fmt, id, on_card)
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
self.library_view.model().refresh_rows(rows)
|
self.library_view.model().refresh_rows(rows)
|
||||||
@ -1021,12 +1022,13 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
previous = self.library_view.currentIndex()
|
previous = self.library_view.currentIndex()
|
||||||
rows = [x.row() for x in \
|
rows = [x.row() for x in \
|
||||||
self.library_view.selectionModel().selectedRows()]
|
self.library_view.selectionModel().selectedRows()]
|
||||||
jobs, changed = convert_single_ebook(self,
|
jobs, changed, bad = convert_single_ebook(self,
|
||||||
self.library_view.model().db, row_ids)
|
self.library_view.model().db, row_ids)
|
||||||
for func, args, desc, fmt, id, temp_files in jobs:
|
for func, args, desc, fmt, id, temp_files in jobs:
|
||||||
job = self.job_manager.run_job(Dispatcher(self.book_converted),
|
if id not in bad:
|
||||||
|
job = self.job_manager.run_job(Dispatcher(self.book_converted),
|
||||||
func, args=args, description=desc)
|
func, args=args, description=desc)
|
||||||
self.conversion_jobs[job] = (temp_files, fmt, id)
|
self.conversion_jobs[job] = (temp_files, fmt, id)
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
self.library_view.model().refresh_rows(rows)
|
self.library_view.model().refresh_rows(rows)
|
||||||
|
@ -6,7 +6,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''
|
'''
|
||||||
Logic for setting up conversion jobs
|
Logic for setting up conversion jobs
|
||||||
'''
|
'''
|
||||||
import os
|
|
||||||
|
import cPickle, os
|
||||||
|
|
||||||
from PyQt4.Qt import QDialog
|
from PyQt4.Qt import QDialog
|
||||||
|
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
@ -14,30 +16,30 @@ from calibre.gui2.convert import load_specifics
|
|||||||
from calibre.gui2.convert.single import NoSupportedInputFormats
|
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, book_ids, auto_conversion=False, out_format=None):
|
||||||
changed = False
|
changed = False
|
||||||
jobs = []
|
jobs = []
|
||||||
bad = []
|
bad = []
|
||||||
|
|
||||||
total = len(row_ids)
|
total = len(book_ids)
|
||||||
if total == 0:
|
if total == 0:
|
||||||
return None, None, None
|
return None, None, None
|
||||||
parent.status_bar.showMessage(_('Starting conversion of %d books') % total, 2000)
|
parent.status_bar.showMessage(_('Starting conversion of %d books') % total, 2000)
|
||||||
|
|
||||||
for i, row_id in enumerate(row_ids):
|
for i, book_id in enumerate(book_ids):
|
||||||
temp_files = []
|
temp_files = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
d = SingleConfig(parent, db, row_id)
|
d = SingleConfig(parent, db, book_id, None, out_format)
|
||||||
|
|
||||||
if auto_conversion:
|
if auto_conversion:
|
||||||
result = QDialog.Accepted
|
result = QDialog.Accepted
|
||||||
else:
|
else:
|
||||||
retult = d.exec_()
|
result = d.exec_()
|
||||||
|
|
||||||
if result == QDialog.Accepted:
|
if result == QDialog.Accepted:
|
||||||
mi = db.get_metadata(row_id, True)
|
mi = db.get_metadata(book_id, True)
|
||||||
in_file = db.format_abspath(row_id, d.input_format, True)
|
in_file = db.format_abspath(book_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)
|
||||||
@ -45,18 +47,14 @@ def convert_single_ebook(parent, db, row_ids, auto_conversion=False):
|
|||||||
|
|
||||||
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)
|
recs = cPickle.loads(d.recommendations)
|
||||||
opts_string = ''
|
args = [in_file, out_file.name, recs]
|
||||||
for opt in opts.keys():
|
|
||||||
opts_string += ' --%s %s ' % (opt, opts[opt])
|
|
||||||
|
|
||||||
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(('gui_convert', args, desc, d.output_format.upper(), book_id, temp_files))
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
except NoSupportedInputFormats:
|
except NoSupportedInputFormats:
|
||||||
bad.append(row_id)
|
bad.append(book_id)
|
||||||
|
|
||||||
if bad != []:
|
if bad != []:
|
||||||
res = []
|
res = []
|
||||||
@ -67,8 +65,7 @@ def convert_single_ebook(parent, db, row_ids, auto_conversion=False):
|
|||||||
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))
|
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_()
|
warning_dialog(parent, _('Could not convert some books'), msg).exec_()
|
||||||
|
|
||||||
return jobs, changed
|
return jobs, changed, bad
|
||||||
|
|
||||||
|
|
||||||
def convert_bulk_ebooks(*args):
|
def convert_bulk_ebooks(*args):
|
||||||
pass
|
pass
|
||||||
|
@ -38,50 +38,20 @@ DEBUG = False
|
|||||||
|
|
||||||
#: A mapping from job names to functions that perform the jobs
|
#: A mapping from job names to functions that perform the jobs
|
||||||
PARALLEL_FUNCS = {
|
PARALLEL_FUNCS = {
|
||||||
'any2lrf' :
|
|
||||||
('calibre.ebooks.lrf.any.convert_from', 'main', dict(gui_mode=True), None),
|
|
||||||
|
|
||||||
'lrfviewer' :
|
'lrfviewer' :
|
||||||
('calibre.gui2.lrf_renderer.main', 'main', {}, None),
|
('calibre.gui2.lrf_renderer.main', 'main', {}, None),
|
||||||
|
|
||||||
'ebook-viewer' :
|
'ebook-viewer' :
|
||||||
('calibre.gui2.viewer.main', 'main', {}, None),
|
('calibre.gui2.viewer.main', 'main', {}, None),
|
||||||
|
|
||||||
'feeds2lrf' :
|
|
||||||
('calibre.ebooks.lrf.feeds.convert_from', 'main', {}, 'notification'),
|
|
||||||
|
|
||||||
'render_table' :
|
|
||||||
('calibre.ebooks.lrf.html.table_as_image', 'do_render', {}, None),
|
|
||||||
|
|
||||||
'render_pages' :
|
'render_pages' :
|
||||||
('calibre.ebooks.comic.input', 'render_pages', {}, 'notification'),
|
('calibre.ebooks.comic.input', 'render_pages', {}, 'notification'),
|
||||||
|
|
||||||
'comic2lrf' :
|
|
||||||
('calibre.ebooks.lrf.comic.convert_from', 'do_convert', {}, 'notification'),
|
|
||||||
|
|
||||||
'any2epub' :
|
|
||||||
('calibre.ebooks.epub.from_any', 'any2epub', {}, None),
|
|
||||||
|
|
||||||
'feeds2epub' :
|
|
||||||
('calibre.ebooks.epub.from_feeds', 'main', {}, 'notification'),
|
|
||||||
|
|
||||||
'comic2epub' :
|
|
||||||
('calibre.ebooks.epub.from_comic', 'convert', {}, 'notification'),
|
|
||||||
|
|
||||||
'any2mobi' :
|
|
||||||
('calibre.ebooks.mobi.from_any', 'any2mobi', {}, None),
|
|
||||||
|
|
||||||
'any2pdf' :
|
|
||||||
('calibre.ebooks.pdf.from_any', 'any2pdf', {}, None),
|
|
||||||
|
|
||||||
'feeds2mobi' :
|
|
||||||
('calibre.ebooks.mobi.from_feeds', 'main', {}, 'notification'),
|
|
||||||
|
|
||||||
'comic2mobi' :
|
|
||||||
('calibre.ebooks.mobi.from_comic', 'convert', {}, 'notification'),
|
|
||||||
|
|
||||||
'ebook-convert' :
|
'ebook-convert' :
|
||||||
('calibre.ebooks.conversion.cli', 'main', {}, None),
|
('calibre.ebooks.conversion.cli', 'main', {}, None),
|
||||||
|
|
||||||
|
'gui_convert' :
|
||||||
|
('calibre.gui2.convert.gui_conversion', 'gui_convert', {}, 'notification'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user