Avoid using QApplication for downloads

This commit is contained in:
Florian Bruhin 2014-06-23 17:30:28 +02:00
parent da0bfb4861
commit 81990f792f
5 changed files with 17 additions and 3 deletions

View File

@ -424,6 +424,7 @@ class Application(QApplication):
# downloads # downloads
tabs.start_download.connect(self.downloadmanager.fetch) tabs.start_download.connect(self.downloadmanager.fetch)
tabs.download_get.connect(self.downloadmanager.get)
def get_all_widgets(self): def get_all_widgets(self):
"""Get a string list of all widgets.""" """Get a string list of all widgets."""

View File

@ -24,7 +24,7 @@ import subprocess
from functools import partial from functools import partial
from PyQt5.QtWidgets import QApplication 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.QtGui import QClipboard
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
from PyQt5.QtWebKitWidgets import QWebInspector from PyQt5.QtWebKitWidgets import QWebInspector
@ -59,8 +59,14 @@ class CommandDispatcher:
_tabs: The TabbedBrowser object. _tabs: The TabbedBrowser object.
_editor: The ExternalEditor object. _editor: The ExternalEditor object.
_userscript_runners: A list of userscript runners. _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): def __init__(self, parent):
"""Constructor. """Constructor.
@ -696,7 +702,7 @@ class CommandDispatcher:
@cmdutils.register(instance='mainwindow.tabs.cmd') @cmdutils.register(instance='mainwindow.tabs.cmd')
def download_page(self): def download_page(self):
"""Download the current page.""" """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'], @cmdutils.register(instance='mainwindow.tabs.cmd', modes=['insert'],
hide=True) hide=True)

View File

@ -332,6 +332,7 @@ class DownloadManager(QObject):
def __repr__(self): def __repr__(self):
return '<{}>'.format(self.__class__.__name__) return '<{}>'.format(self.__class__.__name__)
@pyqtSlot('QUrl')
def get(self, url): def get(self, url):
"""Start a download with a link URL. """Start a download with a link URL.

View File

@ -90,6 +90,8 @@ class HintManager(QObject):
arg 0: URL to open as QUrl. arg 0: URL to open as QUrl.
arg 1: True if it should be opened in a new tab, else False. 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. 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 = """ HINT_CSS = """
@ -123,6 +125,7 @@ class HintManager(QObject):
mouse_event = pyqtSignal('QMouseEvent') mouse_event = pyqtSignal('QMouseEvent')
openurl = pyqtSignal('QUrl', bool) openurl = pyqtSignal('QUrl', bool)
set_open_target = pyqtSignal(str) set_open_target = pyqtSignal(str)
download_get = pyqtSignal('QUrl')
def __init__(self, parent=None): def __init__(self, parent=None):
"""Constructor. """Constructor.
@ -331,7 +334,7 @@ class HintManager(QObject):
url: The URL to download, as a QUrl. url: The URL to download, as a QUrl.
""" """
qt_ensure_valid(url) qt_ensure_valid(url)
QApplication.instance().downloadmanager.get(url) self.download_get.emit(url)
def _resolve_url(self, elem, baseurl=None): def _resolve_url(self, elem, baseurl=None):
"""Resolve a URL and check if we want to keep it. """Resolve a URL and check if we want to keep it.

View File

@ -79,6 +79,7 @@ class TabbedBrowser(TabWidget):
current_tab_changed: The current tab changed to the emitted WebView. current_tab_changed: The current tab changed to the emitted WebView.
title_changed: Emitted when the application title should be changed. title_changed: Emitted when the application title should be changed.
arg: The new title as string. arg: The new title as string.
download_get: Emitted when a QUrl should be downloaded.
""" """
cur_progress = pyqtSignal(int) cur_progress = pyqtSignal(int)
@ -90,6 +91,7 @@ class TabbedBrowser(TabWidget):
cur_scroll_perc_changed = pyqtSignal(int, int) cur_scroll_perc_changed = pyqtSignal(int, int)
cur_load_status_changed = pyqtSignal(str) cur_load_status_changed = pyqtSignal(str)
start_download = pyqtSignal('QNetworkReply*') start_download = pyqtSignal('QNetworkReply*')
download_get = pyqtSignal('QUrl')
hint_strings_updated = pyqtSignal(list) hint_strings_updated = pyqtSignal(list)
shutdown_complete = pyqtSignal() shutdown_complete = pyqtSignal()
quit = pyqtSignal() quit = pyqtSignal()
@ -163,6 +165,7 @@ class TabbedBrowser(TabWidget):
self._filter.create(self.cur_load_status_changed)) self._filter.create(self.cur_load_status_changed))
# hintmanager # hintmanager
tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated) tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated)
tab.hintmanager.download_get.connect(self.download_get)
tab.hintmanager.openurl.connect(self.openurl) tab.hintmanager.openurl.connect(self.openurl)
# downloads # downloads
tab.page().unsupportedContent.connect(self.start_download) tab.page().unsupportedContent.connect(self.start_download)