mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
ad30806ba9
commit
a60aeaa1ba
@ -565,3 +565,11 @@ restrict_output_formats = None
|
|||||||
# numbers.
|
# numbers.
|
||||||
# The value can be between 50 and 99
|
# The value can be between 50 and 99
|
||||||
content_server_thumbnail_compression_quality = 75
|
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 = ()
|
||||||
|
@ -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.confirm_delete import confirm
|
||||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
|
from calibre.utils.config_base import tweaks
|
||||||
from calibre.utils.filenames import ascii_filename
|
from calibre.utils.filenames import ascii_filename
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.gui2.actions import InterfaceAction
|
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
|
cid = db.id(current_idx.row()) if cid is None else cid
|
||||||
formats = []
|
formats = []
|
||||||
from calibre.gui2.dnd import image_extensions
|
from calibre.gui2.dnd import image_extensions
|
||||||
|
image_exts = set(image_extensions()) - set(tweaks['cover_drop_exclude'])
|
||||||
for path in paths:
|
for path in paths:
|
||||||
ext = os.path.splitext(path)[1].lower()
|
ext = os.path.splitext(path)[1].lower()
|
||||||
if ext:
|
if ext:
|
||||||
ext = ext[1:]
|
ext = ext[1:]
|
||||||
if ext in image_extensions():
|
if ext in image_exts:
|
||||||
pmap = QPixmap()
|
pmap = QPixmap()
|
||||||
pmap.load(path)
|
pmap.load(path)
|
||||||
if not pmap.isNull():
|
if not pmap.isNull():
|
||||||
|
@ -653,7 +653,8 @@ class BookDetails(QWidget): # {{{
|
|||||||
event.setDropAction(Qt.CopyAction)
|
event.setDropAction(Qt.CopyAction)
|
||||||
md = event.mimeData()
|
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:
|
if x is not None:
|
||||||
# We have an image, set cover
|
# We have an image, set cover
|
||||||
event.accept()
|
event.accept()
|
||||||
@ -668,7 +669,7 @@ class BookDetails(QWidget): # {{{
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Now look for ebook files
|
# 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:
|
if not urls:
|
||||||
# Nothing found
|
# Nothing found
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user