Nicer duplicate list when automerging books on add

When automerging books during during an add, include the author as well
as the title in the report of merged books.
This commit is contained in:
Kovid Goyal 2013-10-24 12:37:36 +05:30
parent 54508172a4
commit 795ae4e84f
2 changed files with 14 additions and 6 deletions

View File

@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en'
import os import os
from functools import partial from functools import partial
from collections import defaultdict
from PyQt4.Qt import QPixmap, QTimer from PyQt4.Qt import QPixmap, QTimer
@ -19,7 +20,8 @@ from calibre.gui2.dialogs.progress import ProgressDialog
from calibre.gui2.widgets import IMAGE_EXTENSIONS from calibre.gui2.widgets import IMAGE_EXTENSIONS
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
from calibre.constants import preferred_encoding, filesystem_encoding from calibre.utils.icu import sort_key
from calibre.constants import filesystem_encoding
from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import InterfaceAction
from calibre.gui2 import question_dialog from calibre.gui2 import question_dialog
from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata import MetaInformation
@ -358,15 +360,21 @@ class AddAction(InterfaceAction):
self.gui.tags_view.recount() self.gui.tags_view.recount()
if getattr(self._adder, 'merged_books', False): if getattr(self._adder, 'merged_books', False):
books = u'\n'.join([x if isinstance(x, unicode) else merged = defaultdict(list)
x.decode(preferred_encoding, 'replace') for x in for title, author in self._adder.merged_books:
self._adder.merged_books]) merged[author].append(title)
lines = []
for author in sorted(merged, key=sort_key):
lines.append(author)
for title in sorted(merged[author], key=sort_key):
lines.append('\t' + title)
lines.append('')
info_dialog(self.gui, _('Merged some books'), info_dialog(self.gui, _('Merged some books'),
_('The following %d duplicate books were found and incoming ' _('The following %d duplicate books were found and incoming '
'book formats were processed and merged into your ' 'book formats were processed and merged into your '
'Calibre database according to your automerge ' 'Calibre database according to your automerge '
'settings:')%len(self._adder.merged_books), 'settings:')%len(self._adder.merged_books),
det_msg=books, show=True) det_msg='\n'.join(lines), show=True)
if getattr(self._adder, 'number_of_books_added', 0) > 0 or \ if getattr(self._adder, 'number_of_books_added', 0) > 0 or \
getattr(self._adder, 'merged_books', False): getattr(self._adder, 'merged_books', False):

View File

@ -189,7 +189,7 @@ class DBAdder(QObject): # {{{
if prefs['add_formats_to_existing']: # automerge is on if prefs['add_formats_to_existing']: # automerge is on
identical_book_list = self.db.find_identical_books(mi) identical_book_list = self.db.find_identical_books(mi)
if identical_book_list: # books with same author and nearly same title exist in db if identical_book_list: # books with same author and nearly same title exist in db
self.merged_books.add(mi.title) self.merged_books.add((mi.title, ' & '.join(mi.authors)))
seen_fmts = set([]) seen_fmts = set([])
for identical_book in identical_book_list: for identical_book in identical_book_list: