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)

This commit is contained in:
Kovid Goyal 2016-09-05 14:53:34 +05:30
parent ad30806ba9
commit a60aeaa1ba
3 changed files with 14 additions and 3 deletions

View File

@ -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 = ()

View File

@ -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():

View File

@ -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