Auto-remove PDF.js downloads

This commit is contained in:
Florian Bruhin 2018-09-24 19:45:31 +02:00
parent 9ab3188b43
commit 3efb7e6957
2 changed files with 5 additions and 3 deletions

View File

@ -212,16 +212,17 @@ class DownloadManager(downloads.AbstractDownloadManager):
def handle_download(self, qt_item):
"""Start a download coming from a QWebEngineProfile."""
suggested_filename = _get_suggested_filename(qt_item.path())
use_pdfjs = pdfjs.should_use_pdfjs(qt_item.mimeType(), qt_item.url())
download = DownloadItem(qt_item)
self._init_item(download, auto_remove=False,
self._init_item(download, auto_remove=use_pdfjs,
suggested_filename=suggested_filename)
if self._mhtml_target is not None:
download.set_target(self._mhtml_target)
self._mhtml_target = None
return
if pdfjs.should_use_pdfjs(qt_item.mimeType(), qt_item.url()):
if use_pdfjs:
download.set_target(downloads.PDFJSDownloadTarget())
return

View File

@ -270,7 +270,8 @@ class BrowserPage(QWebPage):
self.display_content, reply, 'image/jpeg'))
elif pdfjs.should_use_pdfjs(mimetype, reply.url()):
download_manager.fetch(reply,
target=downloads.PDFJSDownloadTarget())
target=downloads.PDFJSDownloadTarget(),
auto_remove=True)
else:
# Unknown mimetype, so download anyways.
download_manager.fetch(reply,