From e16748e85486f4e7aac0d73b380e272b6712ac01 Mon Sep 17 00:00:00 2001 From: NoDRM Date: Wed, 19 Oct 2022 17:14:26 +0200 Subject: [PATCH] Untested code for the Obok plugin to allow adding duplicate books. See #148 --- CHANGELOG.md | 2 ++ Obok_plugin/action.py | 5 ++++- Obok_plugin/config.py | 26 ++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26c27fa..3d61094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,3 +83,5 @@ List of changes since the fork of Apprentice Harper's repository: - Update the README (fixes #136) to indicate that Apprentice Harper's version is no longer being updated. - Fix a bug where PDFs with empty arrays (`<>`) in a PDF object failed to decrypt, fixes #183. - Automatically strip whitespace from entered Amazon Kindle serial numbers, should fix #158. +- Obok: Add new setting option "Add new entry" for duplicate books to always add them to the Calibre database as a new book. Untested. Should fix #148. +- Obok: Fix where changing the Calibre UI language to some languages would cause the "duplicate book" setting to reset. Untested. diff --git a/Obok_plugin/action.py b/Obok_plugin/action.py index fb8f26e..e4ef377 100644 --- a/Obok_plugin/action.py +++ b/Obok_plugin/action.py @@ -237,7 +237,10 @@ class InterfacePluginAction(InterfaceAction): :param books_to_add: List of calibre bookmaps (created in get_decrypted_kobo_books) ''' - added = self.db.add_books(books_to_add, add_duplicates=False, run_hooks=False) + + cfg_add_duplicates = (cfg['finding_homes_for_formats'] == 'Add new entry') + + added = self.db.add_books(books_to_add, add_duplicates=cfg_add_duplicates, run_hooks=False) if len(added[0]): # Record the id(s) that got added for id in added[0]: diff --git a/Obok_plugin/config.py b/Obok_plugin/config.py index a9363ad..fdfb424 100644 --- a/Obok_plugin/config.py +++ b/Obok_plugin/config.py @@ -39,8 +39,13 @@ class ConfigWidget(QWidget): self.find_homes = QComboBox() self.find_homes.setToolTip(_('

Default behavior when duplicates are detected. None of the choices will cause calibre ebooks to be overwritten')) layout.addWidget(self.find_homes) - self.find_homes.addItems([_('Ask'), _('Always'), _('Never')]) + + self.find_homes.addItems([_('Ask'), _('Always'), _('Never'), _('Add new entry')]) + index = self.find_homes.findText(plugin_prefs['finding_homes_for_formats']) + if index == -1: + index = self.find_homes.findText(_(plugin_prefs['finding_homes_for_formats'])) + self.find_homes.setCurrentIndex(index) self.serials_button = QtGui.QPushButton(self) @@ -69,7 +74,24 @@ class ConfigWidget(QWidget): def save_settings(self): - plugin_prefs['finding_homes_for_formats'] = self.find_homes.currentText() + + + # Make sure the config file string is *always* english. + find_homes = None + if self.find_homes.currentText() == _('Ask'): + find_homes = 'Ask' + elif self.find_homes.currentText() == _('Always'): + find_homes = 'Always' + elif self.find_homes.currentText() == _('Never'): + find_homes = 'Never' + elif self.find_homes.currentText() == _('Add new entry'): + find_homes = 'Add new entry' + + if find_homes is None: + # Fallback + find_homes = self.find_homes.currentText() + + plugin_prefs['finding_homes_for_formats'] = find_homes plugin_prefs['kobo_serials'] = self.tmpserials plugin_prefs['kobo_directory'] = self.kobodirectory