diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index bd8e2de93a..9ed6274db0 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -256,9 +256,13 @@ class AddAction(InterfaceAction): series = dlg.selected_series title = dlg.selected_title or _('Unknown') db = self.gui.library_view.model().db - ids = [] + ids, orig_fmts = [], [] if dlg.duplicate_current_book: origmi = db.get_metadata(index.row(), get_cover=True, cover_as_data=True) + if dlg.copy_formats.isChecked(): + book_id = db.id(index.row()) + orig_fmts = tuple(db.new_api.format(book_id, fmt, as_path=True) for fmt in db.new_api.formats(book_id)) + for x in xrange(num): if dlg.duplicate_current_book: mi = origmi @@ -269,7 +273,9 @@ class AddAction(InterfaceAction): mi.series_index = db.get_next_series_num_for(series) fmts = [] empty_format = gprefs.get('create_empty_format_file', '') - if empty_format: + if dlg.duplicate_current_book and dlg.copy_formats.isChecked(): + fmts = orig_fmts + elif empty_format: from calibre.ebooks.oeb.polish.create import create_book pt = PersistentTemporaryFile(suffix='.' + empty_format) pt.close() @@ -277,6 +283,7 @@ class AddAction(InterfaceAction): create_book(mi, pt.name, fmt=empty_format) fmts = [pt.name] ids.append(db.import_book(mi, fmts)) + tuple(map(os.remove, orig_fmts)) self.gui.library_view.model().books_added(num) self.gui.refresh_cover_browser() self.gui.tags_view.recount() diff --git a/src/calibre/gui2/dialogs/add_empty_book.py b/src/calibre/gui2/dialogs/add_empty_book.py index 0352d029bf..c920d9dd7d 100644 --- a/src/calibre/gui2/dialogs/add_empty_book.py +++ b/src/calibre/gui2/dialogs/add_empty_book.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' from PyQt5.Qt import ( QDialog, QGridLayout, QLabel, QDialogButtonBox, QApplication, QSpinBox, - QToolButton, QIcon, QLineEdit, QComboBox) + QToolButton, QIcon, QLineEdit, QComboBox, QCheckBox) from calibre.ebooks.metadata import string_to_authors from calibre.gui2.complete2 import EditWithComplete from calibre.utils.config import tweaks @@ -95,10 +95,17 @@ class AddEmptyBookDialog(QDialog): pass self._layout.addWidget(c, 9, 0, 1, 1) + self.copy_formats = cf = QCheckBox(_('Also copy book &formats when duplicating a book'), self) + cf.setToolTip(_( + 'Also copy all ebook files into the newly created duplicate' + ' books.')) + cf.setChecked(gprefs.get('create_empty_copy_dup_formats', False)) + self._layout.addWidget(cf, 10, 0, 1, -1) + button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) - self._layout.addWidget(button_box, 10, 0, 1, -1) + self._layout.addWidget(button_box, 11, 0, 1, -1) if dup_title: self.dup_button = b = button_box.addButton(_('&Duplicate current book'), button_box.ActionRole) b.clicked.connect(self.do_duplicate_book) @@ -115,9 +122,17 @@ class AddEmptyBookDialog(QDialog): self.accept() def accept(self): - gprefs['create_empty_format_file'] = self.format_value.currentText().lower() + self.save_settings() return QDialog.accept(self) + def save_settings(self): + gprefs['create_empty_format_file'] = self.format_value.currentText().lower() + gprefs['create_empty_copy_dup_formats'] = self.copy_formats.isChecked() + + def reject(self): + self.save_settings() + return QDialog.reject(self) + def reset_author(self, *args): self.authors_combo.setEditText(_('Unknown'))