diff --git a/src/calibre/ebooks/oeb/transforms/htmltoc.py b/src/calibre/ebooks/oeb/transforms/htmltoc.py index 1aef7e56cc..b570420756 100644 --- a/src/calibre/ebooks/oeb/transforms/htmltoc.py +++ b/src/calibre/ebooks/oeb/transforms/htmltoc.py @@ -62,7 +62,16 @@ class HTMLTOCAdder(object): def __call__(self, oeb, context): if 'toc' in oeb.guide: - return + # Ensure toc pointed to in is in spine + from calibre.ebooks.oeb.base import urlnormalize + href = urlnormalize(oeb.guide['toc'].href) + if href in oeb.manifest.hrefs: + item = oeb.manifest.hrefs[href] + if oeb.spine.index(item) < 0: + oeb.spine.add(item, linear=False) + return + else: + oeb.guide.remove('toc') if not getattr(getattr(oeb, 'toc', False), 'nodes', False): return oeb.logger.info('Generating in-line TOC...') diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index 3988c9663d..ff2bcd47c8 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -66,7 +66,8 @@ class Worker(Thread): for identical_book in identical_book_list: self.add_formats(identical_book, paths, newdb, replace=False) if not added: - newdb.import_book(mi, paths, notify=False, import_hooks=False) + newdb.import_book(mi, paths, notify=False, import_hooks=False, + apply_import_tags=False) co = self.db.conversion_options(x, 'PIPE') if co is not None: newdb.set_conversion_options(x, 'PIPE', co) diff --git a/src/calibre/gui2/dialogs/config/__init__.py b/src/calibre/gui2/dialogs/config/__init__.py index 1dca3e28ff..091b98dc86 100644 --- a/src/calibre/gui2/dialogs/config/__init__.py +++ b/src/calibre/gui2/dialogs/config/__init__.py @@ -457,7 +457,7 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): self.priority.setCurrentIndex(p) self.priority.setVisible(iswindows) self.priority_label.setVisible(iswindows) - self.new_book_tags.setText(prefs['new_book_tags']) + self.new_book_tags.setText(', '.join(prefs['new_book_tags'])) self._plugin_model = PluginModel() self.plugin_view.setModel(self._plugin_model) self.plugin_view.setStyleSheet( @@ -907,7 +907,9 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): config['disable_tray_notification'] = not self.systray_notifications.isChecked() p = {0:'normal', 1:'high', 2:'low'}[self.priority.currentIndex()] prefs['worker_process_priority'] = p - prefs['new_book_tags'] = unicode(self.new_book_tags.text()).strip() + nbt = [x.strip() for x in + unicode(self.new_book_tags.text()).strip().split(',')] + prefs['new_book_tags'] = [x for x in nbt if x] prefs['output_format'] = unicode(self.output_format.currentText()).upper() config['cover_flow_queue_length'] = self.cover_browse.value() prefs['language'] = str(self.language.itemData(self.language.currentIndex()).toString()) diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui index 09d83f29de..c6c07a1220 100644 --- a/src/calibre/gui2/preferences/behavior.ui +++ b/src/calibre/gui2/preferences/behavior.ui @@ -164,6 +164,20 @@ + + + + A comma-separated list of tags that will be applied to books added to the library + + + + + + + Tags to apply when adding a book: + + + diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 76801a9893..192a45cccb 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1726,13 +1726,14 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return run_plugins_on_import(path, format) def _add_newbook_tag(self, mi): - tags = prefs['new_book_tags'].strip() + tags = prefs['new_book_tags'] if tags: - for tag in [t.strip() for t in tags.split(',')]: - if mi.tags is None: - mi.tags = [tag] - else: - mi.tags.append(tag) + for tag in [t.strip() for t in tags]: + if tag: + if mi.tags is None: + mi.tags = [tag] + else: + mi.tags.append(tag) def create_book_entry(self, mi, cover=None, add_duplicates=True): self._add_newbook_tag(mi) @@ -1813,9 +1814,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return (paths, formats, metadata), len(ids) return None, len(ids) - def import_book(self, mi, formats, notify=True, import_hooks=True): + def import_book(self, mi, formats, notify=True, import_hooks=True, + apply_import_tags=True): series_index = 1.0 if mi.series_index is None else mi.series_index - self._add_newbook_tag(mi) + if apply_import_tags: + self._add_newbook_tag(mi) if not mi.title: mi.title = _('Unknown') if not mi.authors: diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index 5682cab5e1..695ece3c48 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -717,7 +717,7 @@ def _prefs(): c.add_opt('add_formats_to_existing', default=False, help=_('Add new formats to existing book records')) c.add_opt('installation_uuid', default=None, help='Installation UUID') - c.add_opt('new_book_tags', default='', help=_('Tags to apply to books added to the library')) + c.add_opt('new_book_tags', default=[], help=_('Tags to apply to books added to the library')) # these are here instead of the gui preferences because calibredb and # calibre server can execute searches