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)

This commit is contained in:
Kovid Goyal 2025-01-07 11:31:13 +05:30
parent 7e1796eafd
commit a78460f09f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -10,7 +10,7 @@ import os
from qt.core import QApplication, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, QLabel, QLineEdit, QPlainTextEdit, QPushButton, Qt, QVBoxLayout from qt.core import QApplication, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, QLabel, QLineEdit, QPlainTextEdit, QPushButton, Qt, QVBoxLayout
from calibre.constants import iswindows 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 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) 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)) ce.setChecked(gprefs.get('add from ISBN dup check', False))
l.addWidget(ce) 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) l.addStretch(10)
@ -85,11 +88,17 @@ class AddFromISBN(QDialog):
def check_for_existing(self): def check_for_existing(self):
return self._check_for_existing.isChecked() return self._check_for_existing.isChecked()
@property
def convert_to_13(self):
return self._convert_to_13.isChecked()
def accept(self, *args): def accept(self, *args):
tags = str(self.add_tags.text()).strip().split(',') tags = str(self.add_tags.text()).strip().split(',')
tags = list(filter(None, [x.strip() for x in tags])) tags = list(filter(None, [x.strip() for x in tags]))
with gprefs:
gprefs['add from ISBN tags'] = tags gprefs['add from ISBN tags'] = tags
gprefs['add from ISBN dup check'] = self.check_for_existing gprefs['add from ISBN dup check'] = self.check_for_existing
gprefs['convert_isbn_10_to_13'] = self.convert_to_13
self.set_tags = tags self.set_tags = tags
bad = set() bad = set()
for line in str(self.isbn_box.toPlainText()).strip().splitlines(): for line in str(self.isbn_box.toPlainText()).strip().splitlines():
@ -113,6 +122,8 @@ class AddFromISBN(QDialog):
if prefix == 'isbn': if prefix == 'isbn':
isbn = check_isbn(parts[0]) isbn = check_isbn(parts[0])
if isbn is not None: if isbn is not None:
if gprefs['convert_isbn_10_to_13']:
isbn = normalize_isbn(isbn)
isbn = isbn.upper() isbn = isbn.upper()
if isbn not in self.isbns: if isbn not in self.isbns:
self.isbns.append(isbn) self.isbns.append(isbn)