mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GUI convert: Bulk convert.
This commit is contained in:
parent
4b5392bf01
commit
516e508c50
114
src/calibre/gui2/convert/bulk.py
Normal file
114
src/calibre/gui2/convert/bulk.py
Normal file
@ -0,0 +1,114 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import sys
|
||||
|
||||
from PyQt4.Qt import QString, SIGNAL
|
||||
|
||||
from calibre.gui2.convert.single import Config, sort_formats_by_preference, \
|
||||
GroupModel
|
||||
from calibre.customize.ui import available_output_formats
|
||||
from calibre.gui2 import ResizableDialog
|
||||
from calibre.gui2.convert.look_and_feel import LookAndFeelWidget
|
||||
from calibre.gui2.convert.page_setup import PageSetupWidget
|
||||
from calibre.gui2.convert import GuiRecommendations
|
||||
from calibre.ebooks.conversion.plumber import Plumber, OUTPUT_FORMAT_PREFERENCES
|
||||
from calibre.utils.logging import Log
|
||||
|
||||
class BulkConfig(Config):
|
||||
|
||||
def __init__(self, parent, db, preferred_output_format=None):
|
||||
ResizableDialog.__init__(self, parent)
|
||||
|
||||
self.setup_output_formats(db, preferred_output_format)
|
||||
self.db = db
|
||||
|
||||
self.setup_pipeline()
|
||||
|
||||
self.input_formats.hide()
|
||||
|
||||
self.connect(self.output_formats, SIGNAL('currentIndexChanged(QString)'),
|
||||
self.setup_pipeline)
|
||||
self.connect(self.groups, SIGNAL('activated(QModelIndex)'),
|
||||
self.show_pane)
|
||||
self.connect(self.groups, SIGNAL('clicked(QModelIndex)'),
|
||||
self.show_pane)
|
||||
self.connect(self.groups, SIGNAL('entered(QModelIndex)'),
|
||||
self.show_group_help)
|
||||
self.groups.setMouseTracking(True)
|
||||
|
||||
|
||||
def setup_pipeline(self, *args):
|
||||
output_format = self.output_format
|
||||
|
||||
input_path = 'dummy.epub'
|
||||
output_path = 'dummy.'+output_format
|
||||
log = Log()
|
||||
log.outputs = []
|
||||
self.plumber = Plumber(input_path, output_path, log)
|
||||
|
||||
def widget_factory(cls):
|
||||
return cls(self.stack, self.plumber.get_option_by_name,
|
||||
self.plumber.get_option_help, self.db)
|
||||
|
||||
self.setWindowTitle(_('Convert Bulk'))
|
||||
lf = widget_factory(LookAndFeelWidget)
|
||||
ps = widget_factory(PageSetupWidget)
|
||||
|
||||
output_widget = None
|
||||
name = 'calibre.gui2.convert.%s' % self.plumber.output_plugin.name.lower().replace(' ', '_')
|
||||
try:
|
||||
__import__(name)
|
||||
output_widget = sys.modules[name]
|
||||
pw = output_widget.PluginWidget
|
||||
pw.ICON = ':/images/back.svg'
|
||||
pw.HELP = _('Options specific to the output format.')
|
||||
output_widget = widget_factory(pw)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
while True:
|
||||
c = self.stack.currentWidget()
|
||||
if not c: break
|
||||
self.stack.removeWidget(c)
|
||||
|
||||
widgets = [lf, ps]
|
||||
if output_widget is not None:
|
||||
widgets.append(output_widget)
|
||||
for w in widgets:
|
||||
self.stack.addWidget(w)
|
||||
self.connect(w, SIGNAL('set_help(PyQt_PyObject)'),
|
||||
self.help.setPlainText)
|
||||
|
||||
self._groups_model = GroupModel(widgets)
|
||||
self.groups.setModel(self._groups_model)
|
||||
|
||||
self.groups.setCurrentIndex(self._groups_model.index(0))
|
||||
|
||||
|
||||
def setup_output_formats(self, db, preferred_output_format):
|
||||
available_formats = ''
|
||||
available_formats = set([x.lower() for x in
|
||||
available_formats.split(',')])
|
||||
output_formats = sorted(available_output_formats())
|
||||
output_formats.remove('oeb')
|
||||
preferred_output_format = preferred_output_format if \
|
||||
preferred_output_format in output_formats else \
|
||||
sort_formats_by_preference(output_formats,
|
||||
OUTPUT_FORMAT_PREFERENCES)[0]
|
||||
self.output_formats.addItems(list(map(QString, [x.upper() for x in
|
||||
output_formats])))
|
||||
self.output_formats.setCurrentIndex(output_formats.index(preferred_output_format))
|
||||
|
||||
def accept(self):
|
||||
recs = GuiRecommendations()
|
||||
for w in self._groups_model.widgets:
|
||||
x = w.commit(save_defaults=False)
|
||||
recs.update(x)
|
||||
self._recommendations = recs
|
||||
ResizableDialog.accept(self)
|
||||
|
||||
|
@ -16,6 +16,7 @@ from calibre.gui2 import warning_dialog
|
||||
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.bulk import BulkConfig
|
||||
|
||||
def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format=None):
|
||||
changed = False
|
||||
@ -72,7 +73,6 @@ def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format
|
||||
return jobs, changed, bad
|
||||
|
||||
def convert_bulk_ebook(parent, db, book_ids):
|
||||
return [], False, []
|
||||
changed = False
|
||||
jobs = []
|
||||
bad = []
|
||||
@ -82,18 +82,18 @@ def convert_bulk_ebook(parent, db, book_ids):
|
||||
return None, None, None
|
||||
parent.status_bar.showMessage(_('Starting conversion of %d books') % total, 2000)
|
||||
|
||||
d = SingleConfig(parent, db)
|
||||
d = BulkConfig(parent, db)
|
||||
if d.exec_() != QDialog.Accepted:
|
||||
return jobs, changed, bad
|
||||
|
||||
out_format = d.output_format
|
||||
output_format = d.output_format
|
||||
recs = cPickle.loads(d.recommendations)
|
||||
|
||||
for i, book_id in enumerate(book_ids):
|
||||
temp_files = []
|
||||
|
||||
try:
|
||||
d = SingleConfig(parent, db, book_id, None, out_format)
|
||||
d = SingleConfig(parent, db, book_id, None, output_format)
|
||||
d.accept()
|
||||
|
||||
mi = db.get_metadata(book_id, True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user