When adding books via ISBN, show the user the list of invalid ISBNs that will be ignored, if any, before starting the add operation. Fixes #905690 (report ISBN import failures)

This commit is contained in:
Kovid Goyal 2011-12-17 20:56:40 +05:30
parent 999a4df7cc
commit a85c0e5ffb

View File

@ -12,7 +12,7 @@ from PyQt4.Qt import QDialog, QApplication
from calibre.gui2.dialogs.add_from_isbn_ui import Ui_Dialog from calibre.gui2.dialogs.add_from_isbn_ui import Ui_Dialog
from calibre.ebooks.metadata import check_isbn from calibre.ebooks.metadata import check_isbn
from calibre.constants import iswindows from calibre.constants import iswindows
from calibre.gui2 import gprefs from calibre.gui2 import gprefs, question_dialog, error_dialog
class AddFromISBN(QDialog, Ui_Dialog): class AddFromISBN(QDialog, Ui_Dialog):
@ -44,6 +44,7 @@ class AddFromISBN(QDialog, Ui_Dialog):
tags = list(filter(None, [x.strip() for x in tags])) tags = list(filter(None, [x.strip() for x in tags]))
gprefs['add from ISBN tags'] = tags gprefs['add from ISBN tags'] = tags
self.set_tags = tags self.set_tags = tags
bad = set()
for line in unicode(self.isbn_box.toPlainText()).strip().splitlines(): for line in unicode(self.isbn_box.toPlainText()).strip().splitlines():
line = line.strip() line = line.strip()
if not line: if not line:
@ -64,5 +65,19 @@ class AddFromISBN(QDialog, Ui_Dialog):
os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]): os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]):
book['path'] = parts[1] book['path'] = parts[1]
self.books.append(book) self.books.append(book)
else:
bad.add(parts[0])
if bad:
if self.books:
if not question_dialog(self, _('Some invalid ISBNs'),
_('Some of the ISBNs you entered were invalid. They will'
' be ignored. Click Show Details to see which ones.'
' Do you want to proceed?'), det_msg='\n'.join(bad),
show_copy_button=True):
return
else:
return error_dialog(self, _('All invalid ISBNs'),
_('All the ISBNs you entered were invalid. No books'
' can be added.'), show=True)
QDialog.accept(self, *args) QDialog.accept(self, *args)