mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 16:33:43 +02:00
When adding empty books to the library also allow creating duplicates of the current book, with all metadata copied. To use right click the Add Books button and select 'Add Empty Books'. Fixes #1488398 [Enhancement: Create duplicate book record of existing one](https://bugs.launchpad.net/calibre/+bug/1488398)
This commit is contained in:
parent
20a4140c56
commit
ccc52ba308
2 changed files with 26 additions and 7 deletions
|
|
@ -238,7 +238,7 @@ def add_empty(self, *args):
|
|||
Add an empty book item to the library. This does not import any formats
|
||||
from a book file.
|
||||
'''
|
||||
author = series = None
|
||||
author = series = title = None
|
||||
index = self.gui.library_view.currentIndex()
|
||||
if index.isValid():
|
||||
raw = index.model().db.authors(index.row())
|
||||
|
|
@ -247,8 +247,9 @@ def add_empty(self, *args):
|
|||
if authors:
|
||||
author = authors[0]
|
||||
series = index.model().db.series(index.row())
|
||||
title = index.model().db.title(index.row())
|
||||
dlg = AddEmptyBookDialog(self.gui, self.gui.library_view.model().db,
|
||||
author, series)
|
||||
author, series, dup_title=title)
|
||||
if dlg.exec_() == dlg.Accepted:
|
||||
temp_files = []
|
||||
num = dlg.qty_to_add
|
||||
|
|
@ -256,11 +257,16 @@ def add_empty(self, *args):
|
|||
title = dlg.selected_title or _('Unknown')
|
||||
db = self.gui.library_view.model().db
|
||||
ids = []
|
||||
if dlg.duplicate_current_book:
|
||||
origmi = db.get_metadata(index.row(), get_cover=True, cover_as_data=True)
|
||||
for x in xrange(num):
|
||||
mi = MetaInformation(title, dlg.selected_authors)
|
||||
if series:
|
||||
mi.series = series
|
||||
mi.series_index = db.get_next_series_num_for(series)
|
||||
if dlg.duplicate_current_book:
|
||||
mi = origmi
|
||||
else:
|
||||
mi = MetaInformation(title, dlg.selected_authors)
|
||||
if series:
|
||||
mi.series = series
|
||||
mi.series_index = db.get_next_series_num_for(series)
|
||||
fmts = []
|
||||
empty_format = gprefs.get('create_empty_format_file', '')
|
||||
if empty_format:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
class AddEmptyBookDialog(QDialog):
|
||||
|
||||
def __init__(self, parent, db, author, series=None, title=None):
|
||||
def __init__(self, parent, db, author, series=None, title=None, dup_title=None):
|
||||
QDialog.__init__(self, parent)
|
||||
self.db = db
|
||||
|
||||
|
|
@ -99,7 +99,20 @@ def __init__(self, parent, db, author, series=None, title=None):
|
|||
button_box.accepted.connect(self.accept)
|
||||
button_box.rejected.connect(self.reject)
|
||||
self._layout.addWidget(button_box, 10, 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)
|
||||
b.setIcon(QIcon(I('edit-copy.png')))
|
||||
b.setToolTip(_(
|
||||
'Make the new empty book records exact duplicates\n'
|
||||
'of the current book "%s", with all metadata identical'
|
||||
) % dup_title)
|
||||
self.resize(self.sizeHint())
|
||||
self.duplicate_current_book = False
|
||||
|
||||
def do_duplicate_book(self):
|
||||
self.duplicate_current_book = True
|
||||
self.accept()
|
||||
|
||||
def accept(self):
|
||||
gprefs['create_empty_format_file'] = self.format_value.currentText().lower()
|
||||
|
|
|
|||
Loading…
Reference in a new issue