Avoid using QApplication for downloads
This commit is contained in:
parent
da0bfb4861
commit
81990f792f
@ -424,6 +424,7 @@ class Application(QApplication):
|
||||
|
||||
# downloads
|
||||
tabs.start_download.connect(self.downloadmanager.fetch)
|
||||
tabs.download_get.connect(self.downloadmanager.get)
|
||||
|
||||
def get_all_widgets(self):
|
||||
"""Get a string list of all widgets."""
|
||||
|
@ -24,7 +24,7 @@ import subprocess
|
||||
from functools import partial
|
||||
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtCore import Qt, QUrl
|
||||
from PyQt5.QtCore import pyqtSignal, Qt, QUrl
|
||||
from PyQt5.QtGui import QClipboard
|
||||
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
|
||||
from PyQt5.QtWebKitWidgets import QWebInspector
|
||||
@ -59,8 +59,14 @@ class CommandDispatcher:
|
||||
_tabs: The TabbedBrowser object.
|
||||
_editor: The ExternalEditor object.
|
||||
_userscript_runners: A list of userscript runners.
|
||||
|
||||
Signals:
|
||||
start_download: When a download should be started.
|
||||
arg: What to download, as QUrl.
|
||||
"""
|
||||
|
||||
start_download = pyqtSignal('QUrl')
|
||||
|
||||
def __init__(self, parent):
|
||||
"""Constructor.
|
||||
|
||||
@ -696,7 +702,7 @@ class CommandDispatcher:
|
||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
||||
def download_page(self):
|
||||
"""Download the current page."""
|
||||
QApplication.instance().downloadmanager.get(self._current_url())
|
||||
self.start_download.emit(self._current_url())
|
||||
|
||||
@cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'],
|
||||
hide=True)
|
||||
|
@ -332,6 +332,7 @@ class DownloadManager(QObject):
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
|
||||
@pyqtSlot('QUrl')
|
||||
def get(self, url):
|
||||
"""Start a download with a link URL.
|
||||
|
||||
|
@ -90,6 +90,8 @@ class HintManager(QObject):
|
||||
arg 0: URL to open as QUrl.
|
||||
arg 1: True if it should be opened in a new tab, else False.
|
||||
set_open_target: Set a new target to open the links in.
|
||||
download_get: Download an URL.
|
||||
arg: The URL to download, as QUrl.
|
||||
"""
|
||||
|
||||
HINT_CSS = """
|
||||
@ -123,6 +125,7 @@ class HintManager(QObject):
|
||||
mouse_event = pyqtSignal('QMouseEvent')
|
||||
openurl = pyqtSignal('QUrl', bool)
|
||||
set_open_target = pyqtSignal(str)
|
||||
download_get = pyqtSignal('QUrl')
|
||||
|
||||
def __init__(self, parent=None):
|
||||
"""Constructor.
|
||||
@ -331,7 +334,7 @@ class HintManager(QObject):
|
||||
url: The URL to download, as a QUrl.
|
||||
"""
|
||||
qt_ensure_valid(url)
|
||||
QApplication.instance().downloadmanager.get(url)
|
||||
self.download_get.emit(url)
|
||||
|
||||
def _resolve_url(self, elem, baseurl=None):
|
||||
"""Resolve a URL and check if we want to keep it.
|
||||
|
@ -79,6 +79,7 @@ class TabbedBrowser(TabWidget):
|
||||
current_tab_changed: The current tab changed to the emitted WebView.
|
||||
title_changed: Emitted when the application title should be changed.
|
||||
arg: The new title as string.
|
||||
download_get: Emitted when a QUrl should be downloaded.
|
||||
"""
|
||||
|
||||
cur_progress = pyqtSignal(int)
|
||||
@ -90,6 +91,7 @@ class TabbedBrowser(TabWidget):
|
||||
cur_scroll_perc_changed = pyqtSignal(int, int)
|
||||
cur_load_status_changed = pyqtSignal(str)
|
||||
start_download = pyqtSignal('QNetworkReply*')
|
||||
download_get = pyqtSignal('QUrl')
|
||||
hint_strings_updated = pyqtSignal(list)
|
||||
shutdown_complete = pyqtSignal()
|
||||
quit = pyqtSignal()
|
||||
@ -163,6 +165,7 @@ class TabbedBrowser(TabWidget):
|
||||
self._filter.create(self.cur_load_status_changed))
|
||||
# hintmanager
|
||||
tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated)
|
||||
tab.hintmanager.download_get.connect(self.download_get)
|
||||
tab.hintmanager.openurl.connect(self.openurl)
|
||||
# downloads
|
||||
tab.page().unsupportedContent.connect(self.start_download)
|
||||
|
Loading…
Reference in New Issue
Block a user