downloads: Add a generic NetworkManager.

This commit is contained in:
Florian Bruhin 2014-11-14 08:30:59 +01:00
parent c8a1c979e8
commit 6301c740d1

View File

@ -35,6 +35,7 @@ from qutebrowser.config import config
from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.commands import cmdexc, cmdutils
from qutebrowser.utils import (message, http, usertypes, log, utils, urlutils, from qutebrowser.utils import (message, http, usertypes, log, utils, urlutils,
objreg, standarddir, qtutils) objreg, standarddir, qtutils)
from qutebrowser.network import networkmanager
ModelRole = usertypes.enum('ModelRole', ['item'], start=Qt.UserRole, ModelRole = usertypes.enum('ModelRole', ['item'], start=Qt.UserRole,
@ -370,6 +371,7 @@ class DownloadManager(QAbstractListModel):
Attributes: Attributes:
downloads: A list of active DownloadItems. downloads: A list of active DownloadItems.
questions: A list of Question objects to not GC them. questions: A list of Question objects to not GC them.
_networkmanager: A NetworkManager for generic downloads.
_win_id: The window ID the DownloadManager runs in. _win_id: The window ID the DownloadManager runs in.
""" """
@ -378,12 +380,13 @@ class DownloadManager(QAbstractListModel):
self._win_id = win_id self._win_id = win_id
self.downloads = [] self.downloads = []
self.questions = [] self.questions = []
self._networkmanager = networkmanager.NetworkManager(win_id, self)
def __repr__(self): def __repr__(self):
return utils.get_repr(self, downloads=len(self.downloads)) return utils.get_repr(self, downloads=len(self.downloads))
@pyqtSlot('QUrl', 'QWebPage') @pyqtSlot('QUrl', 'QWebPage')
def get(self, url, page, fileobj=None): def get(self, url, page=None, fileobj=None):
"""Start a download with a link URL. """Start a download with a link URL.
Args: Args:
@ -395,7 +398,11 @@ class DownloadManager(QAbstractListModel):
urlutils.invalid_url_error(self._win_id, url, "start download") urlutils.invalid_url_error(self._win_id, url, "start download")
return return
req = QNetworkRequest(url) req = QNetworkRequest(url)
reply = page.networkAccessManager().get(req) if page is None:
nam = self._networkmanager
else:
nam = page.networkAccessManager()
reply = nam.get(req)
self.fetch(reply, fileobj) self.fetch(reply, fileobj)
@cmdutils.register(instance='download-manager', scope='window') @cmdutils.register(instance='download-manager', scope='window')