diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index 8c7ea97104..ecbb5e6e2b 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -370,7 +370,7 @@ class AddAction(InterfaceAction): accept = True db.set_cover(cid, pmap) cover_changed = True - elif ext in BOOK_EXTENSIONS: + else: formats.append((ext, path)) accept = True if accept and event is not None: diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 86b754eab7..1b53973435 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -619,7 +619,7 @@ class BookDetails(QWidget): # {{{ def dragEnterEvent(self, event): md = event.mimeData() - if dnd_has_extension(md, self.DROPABBLE_EXTENSIONS) or \ + if dnd_has_extension(md, self.DROPABBLE_EXTENSIONS, allow_all_extensions=True) or \ dnd_has_image(md): event.acceptProposedAction() @@ -642,7 +642,7 @@ class BookDetails(QWidget): # {{{ return # Now look for ebook files - urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS) + urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True) if not urls: # Nothing found return diff --git a/src/calibre/gui2/dnd.py b/src/calibre/gui2/dnd.py index 245e87129f..01f4a356e9 100644 --- a/src/calibre/gui2/dnd.py +++ b/src/calibre/gui2/dnd.py @@ -158,7 +158,7 @@ def remote_urls_from_qurl(qurls, allowed_exts): qurl.path())[1][1:].lower() in allowed_exts: yield bytes(qurl.toEncoded()), posixpath.basename(qurl.path()) -def dnd_has_extension(md, extensions): +def dnd_has_extension(md, extensions, allow_all_extensions=False): if DEBUG: prints('\nDebugging DND event') for f in md.formats(): @@ -177,6 +177,8 @@ def dnd_has_extension(md, extensions): prints('Paths:', paths) prints('Extensions:', exts) + if allow_all_extensions: + return bool(exts) return bool(exts.intersection(frozenset(extensions))) def dnd_get_image(md, image_exts=IMAGE_EXTENSIONS): @@ -236,7 +238,7 @@ def dnd_get_image(md, image_exts=IMAGE_EXTENSIONS): return None, None -def dnd_get_files(md, exts): +def dnd_get_files(md, exts, allow_all_extensions=False): ''' Get the file in the QMimeData object md with an extension that is one of the extensions in exts. @@ -249,9 +251,12 @@ def dnd_get_files(md, exts): urls = urls_from_md(md) # First look for a local file local_files = [path_from_qurl(x) for x in urls] - local_files = [p for p in local_files if - posixpath.splitext(urllib.unquote(p))[1][1:].lower() in - exts] + def is_ok(path): + ext = posixpath.splitext(path)[1][1:].lower() + if allow_all_extensions and ext: + return True + return ext in exts + local_files = [p for p in local_files if is_ok(urllib.unquote(p))] local_files = [x for x in local_files if os.path.exists(x)] if local_files: return local_files, None diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 85b649109b..7ff14d2f56 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -177,14 +177,14 @@ class FormatList(QListWidget): # {{{ def dragEnterEvent(self, event): md = event.mimeData() - if dnd_has_extension(md, self.DROPABBLE_EXTENSIONS): + if dnd_has_extension(md, self.DROPABBLE_EXTENSIONS, allow_all_extensions=True): event.acceptProposedAction() def dropEvent(self, event): event.setDropAction(Qt.CopyAction) md = event.mimeData() # Now look for ebook files - urls, filenames = dnd_get_files(md, self.DROPABBLE_EXTENSIONS) + urls, filenames = dnd_get_files(md, self.DROPABBLE_EXTENSIONS, allow_all_extensions=True) if not urls: # Nothing found return