mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
When merging book records, show more information about the target book record. Fixes #1490343 [Merge: also specify date along with name of "first selected" book](https://bugs.launchpad.net/calibre/+bug/1490343)
This commit is contained in:
parent
7a9951020a
commit
ab0394779b
@ -408,6 +408,7 @@ class EditMetadataAction(InterfaceAction):
|
||||
'''
|
||||
Merge selected books in library.
|
||||
'''
|
||||
from calibre.gui2.dialogs.confirm_merge import confirm_merge
|
||||
if self.gui.stack.currentIndex() != 0:
|
||||
return
|
||||
rows = self.gui.library_view.selectionModel().selectedRows()
|
||||
@ -425,20 +426,21 @@ class EditMetadataAction(InterfaceAction):
|
||||
return
|
||||
|
||||
dest_id, src_ids = self.books_to_merge(rows)
|
||||
title = self.gui.library_view.model().db.title(dest_id, index_is_id=True)
|
||||
mi = self.gui.current_db.new_api.get_proxy_metadata(dest_id)
|
||||
title = mi.title
|
||||
if safe_merge:
|
||||
if not confirm('<p>'+_(
|
||||
if not confirm_merge('<p>'+_(
|
||||
'Book formats and metadata from the selected books '
|
||||
'will be added to the <b>first selected book</b> (%s).<br> '
|
||||
'The second and subsequently selected books will not '
|
||||
'be deleted or changed.<br><br>'
|
||||
'Please confirm you want to proceed.')%title +
|
||||
'</p>', 'merge_books_safe', self.gui):
|
||||
'</p>', 'merge_books_safe', self.gui, mi):
|
||||
return
|
||||
self.add_formats(dest_id, self.formats_for_books(rows))
|
||||
self.merge_metadata(dest_id, src_ids)
|
||||
elif merge_only_formats:
|
||||
if not confirm('<p>'+_(
|
||||
if not confirm_merge('<p>'+_(
|
||||
'Book formats from the selected books will be merged '
|
||||
'into the <b>first selected book</b> (%s). '
|
||||
'Metadata in the first selected book will not be changed. '
|
||||
@ -449,12 +451,12 @@ class EditMetadataAction(InterfaceAction):
|
||||
'and any duplicate formats in the second and subsequently selected books '
|
||||
'will be permanently <b>deleted</b> from your calibre library.<br><br> '
|
||||
'Are you <b>sure</b> you want to proceed?')%title +
|
||||
'</p>', 'merge_only_formats', self.gui):
|
||||
'</p>', 'merge_only_formats', self.gui, mi):
|
||||
return
|
||||
self.add_formats(dest_id, self.formats_for_books(rows))
|
||||
self.delete_books_after_merge(src_ids)
|
||||
else:
|
||||
if not confirm('<p>'+_(
|
||||
if not confirm_merge('<p>'+_(
|
||||
'Book formats and metadata from the selected books will be merged '
|
||||
'into the <b>first selected book</b> (%s).<br><br>'
|
||||
'After merger the second and '
|
||||
@ -463,7 +465,7 @@ class EditMetadataAction(InterfaceAction):
|
||||
'and any duplicate formats in the second and subsequently selected books '
|
||||
'will be permanently <b>deleted</b> from your calibre library.<br><br> '
|
||||
'Are you <b>sure</b> you want to proceed?')%title +
|
||||
'</p>', 'merge_books', self.gui):
|
||||
'</p>', 'merge_books', self.gui, mi):
|
||||
return
|
||||
self.add_formats(dest_id, self.formats_for_books(rows))
|
||||
self.merge_metadata(dest_id, src_ids)
|
||||
|
85
src/calibre/gui2/dialogs/confirm_merge.py
Normal file
85
src/calibre/gui2/dialogs/confirm_merge.py
Normal file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=utf-8
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QVBoxLayout, QSplitter, QWidget, QLabel, QCheckBox, QTextBrowser
|
||||
)
|
||||
|
||||
from calibre.ebooks.metadata import authors_to_string
|
||||
from calibre.ebooks.metadata.book.base import field_metadata
|
||||
from calibre.gui2 import dynamic
|
||||
from calibre.gui2.widgets2 import Dialog
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm_config_name
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.utils.date import format_date
|
||||
|
||||
class ConfirmMerge(Dialog):
|
||||
|
||||
def __init__(self, msg, name, parent, mi):
|
||||
self.msg, self.mi, self.conf_name = msg, mi, name
|
||||
Dialog.__init__(self, _('Are you sure?'), 'confirm-merge-dialog', parent)
|
||||
|
||||
def setup_ui(self):
|
||||
self.l = l = QVBoxLayout(self)
|
||||
self.splitter = s = QSplitter(self)
|
||||
s.setChildrenCollapsible(False)
|
||||
l.addWidget(s), l.addWidget(self.bb)
|
||||
self.bb.setStandardButtons(self.bb.Yes | self.bb.No)
|
||||
|
||||
self.left = w = QWidget(self)
|
||||
s.addWidget(w)
|
||||
w.l = l = QVBoxLayout(w)
|
||||
l.setContentsMargins(0, 0, 0, 0)
|
||||
self.la = la = QLabel(self.msg)
|
||||
la.setWordWrap(True)
|
||||
l.addWidget(la)
|
||||
self.confirm = c = QCheckBox(_('Show this confirmation again'), self)
|
||||
c.setChecked(True)
|
||||
c.stateChanged.connect(self.toggle)
|
||||
l.addWidget(c)
|
||||
|
||||
self.right = r = QTextBrowser(self)
|
||||
series = ''
|
||||
mi, fm = self.mi, field_metadata
|
||||
if mi.series:
|
||||
series = _('{num} of {series}').format(num=mi.format_series_index(), series='<i>%s</i>' % mi.series)
|
||||
r.setHtml('''
|
||||
<h3 style="text-align:center">{mb}</h3>
|
||||
<p><b>{title}</b> - <i>{authors}</i><br></p>
|
||||
<table>
|
||||
<tr><td>{fm[timestamp][name]}:</td><td>{date}</td></tr>
|
||||
<tr><td>{fm[pubdate][name]}:</td><td>{published}</td></tr>
|
||||
<tr><td>{fm[formats][name]}:</td><td>{formats}</td></tr>
|
||||
<tr><td>{fm[series][name]}:</td><td>{series}</td></tr>
|
||||
</table>
|
||||
'''.format(
|
||||
mb=_('Target book'),
|
||||
title=mi.title,
|
||||
authors=authors_to_string(mi.authors),
|
||||
date=format_date(mi.timestamp, tweaks['gui_timestamp_display_format']), fm=fm,
|
||||
published=(format_date(mi.pubdate, tweaks['gui_pubdate_display_format']) if mi.pubdate else ''),
|
||||
formats=', '.join(mi.formats or ()),
|
||||
series=series
|
||||
))
|
||||
s.addWidget(r)
|
||||
|
||||
def toggle(self):
|
||||
dynamic[confirm_config_name(self.conf_name)] = self.confirm.isChecked()
|
||||
|
||||
def sizeHint(self):
|
||||
ans = Dialog.sizeHint(self)
|
||||
ans.setWidth(max(700, ans.width()))
|
||||
return ans
|
||||
|
||||
|
||||
def confirm_merge(msg, name, parent, mi):
|
||||
config_set = dynamic
|
||||
if not config_set.get(confirm_config_name(name), True):
|
||||
return True
|
||||
d = ConfirmMerge(msg, name, parent, mi)
|
||||
return d.exec_() == d.Accepted
|
Loading…
x
Reference in New Issue
Block a user