From a60aeaa1ba6dfa3ff50d6d001f0ac91a844a15ec Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Sep 2016 14:53:34 +0530 Subject: [PATCH] Add a tweak in Preferences->Tweaks to exclude some images types from being treated a covers when dropped onto the Book Details panel. Fixes #1620198 [{Enhancement] Tweak to control image DnD to Book Details](https://bugs.launchpad.net/calibre/+bug/1620198) --- resources/default_tweaks.py | 8 ++++++++ src/calibre/gui2/actions/add.py | 4 +++- src/calibre/gui2/book_details.py | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index aa53133213..cc73dcbd7f 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -565,3 +565,11 @@ restrict_output_formats = None # numbers. # The value can be between 50 and 99 content_server_thumbnail_compression_quality = 75 + +#: Image file types to treat as ebooks when dropping onto the Book Details panel +# Normally, if you drop any image file in a format known to calibre onto the +# Book Details panel, it will be used to set the cover. If you want to store +# some image types as ebooks instead, you can set this tweak. +# Examples: +# cover_drop_exclude = {'tiff', 'webp'} +cover_drop_exclude = () diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index dcf5ad7bb5..b800ab5b41 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -18,6 +18,7 @@ from calibre.gui2.dialogs.add_empty_book import AddEmptyBookDialog from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.dialogs.progress import ProgressDialog from calibre.ebooks import BOOK_EXTENSIONS +from calibre.utils.config_base import tweaks from calibre.utils.filenames import ascii_filename from calibre.utils.icu import sort_key from calibre.gui2.actions import InterfaceAction @@ -359,11 +360,12 @@ class AddAction(InterfaceAction): cid = db.id(current_idx.row()) if cid is None else cid formats = [] from calibre.gui2.dnd import image_extensions + image_exts = set(image_extensions()) - set(tweaks['cover_drop_exclude']) for path in paths: ext = os.path.splitext(path)[1].lower() if ext: ext = ext[1:] - if ext in image_extensions(): + if ext in image_exts: pmap = QPixmap() pmap.load(path) if not pmap.isNull(): diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index e1a25a8aa3..dc4a41db64 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -653,7 +653,8 @@ class BookDetails(QWidget): # {{{ event.setDropAction(Qt.CopyAction) md = event.mimeData() - x, y = dnd_get_image(md) + image_exts = set(image_extensions()) - set(tweaks['cover_drop_exclude']) + x, y = dnd_get_image(md, image_exts) if x is not None: # We have an image, set cover event.accept() @@ -668,7 +669,7 @@ class BookDetails(QWidget): # {{{ return # Now look for ebook files - urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True, filter_exts=image_extensions()) + urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True, filter_exts=image_exts) if not urls: # Nothing found return