From a78460f09fea2ea6dcff313734fee2c80c72c4af Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Jan 2025 11:31:13 +0530 Subject: [PATCH] Add from ISBN: Add a checkbox to automatically convert obsolete ISBN 10 to ISBN 13. Fixes #2092483 [Add from ISBN: Option to convert to ISBN13](https://bugs.launchpad.net/calibre/+bug/2092483) --- src/calibre/gui2/dialogs/add_from_isbn.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/dialogs/add_from_isbn.py b/src/calibre/gui2/dialogs/add_from_isbn.py index 6d914a3bbc..7bc1b99921 100644 --- a/src/calibre/gui2/dialogs/add_from_isbn.py +++ b/src/calibre/gui2/dialogs/add_from_isbn.py @@ -10,7 +10,7 @@ import os from qt.core import QApplication, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, QLabel, QLineEdit, QPlainTextEdit, QPushButton, Qt, QVBoxLayout from calibre.constants import iswindows -from calibre.ebooks.metadata import check_isbn +from calibre.ebooks.metadata import check_isbn, normalize_isbn from calibre.gui2 import error_dialog, gprefs, question_dialog @@ -69,6 +69,9 @@ class AddFromISBN(QDialog): self._check_for_existing = ce = QCheckBox(_('Check for books with the same ISBN already in library'), self) ce.setChecked(gprefs.get('add from ISBN dup check', False)) l.addWidget(ce) + self._convert_to_13 = c13 = QCheckBox(_('Convert ISBN-10 to ISBN-13 automatically'), self) + c13.setChecked(gprefs.get('convert_isbn_10_to_13', False)) + l.addWidget(c13) l.addStretch(10) @@ -85,11 +88,17 @@ class AddFromISBN(QDialog): def check_for_existing(self): return self._check_for_existing.isChecked() + @property + def convert_to_13(self): + return self._convert_to_13.isChecked() + def accept(self, *args): tags = str(self.add_tags.text()).strip().split(',') tags = list(filter(None, [x.strip() for x in tags])) - gprefs['add from ISBN tags'] = tags - gprefs['add from ISBN dup check'] = self.check_for_existing + with gprefs: + gprefs['add from ISBN tags'] = tags + gprefs['add from ISBN dup check'] = self.check_for_existing + gprefs['convert_isbn_10_to_13'] = self.convert_to_13 self.set_tags = tags bad = set() for line in str(self.isbn_box.toPlainText()).strip().splitlines(): @@ -113,6 +122,8 @@ class AddFromISBN(QDialog): if prefix == 'isbn': isbn = check_isbn(parts[0]) if isbn is not None: + if gprefs['convert_isbn_10_to_13']: + isbn = normalize_isbn(isbn) isbn = isbn.upper() if isbn not in self.isbns: self.isbns.append(isbn)