Abort questions in NetworkManager on destroyed.

Hopefully fixes #333.
This commit is contained in:
Florian Bruhin 2014-12-16 17:22:01 +01:00
parent 676313e7ae
commit cafb487ac9

View File

@ -105,13 +105,15 @@ class NetworkManager(QNetworkAccessManager):
self.setCache(cache)
cache.setParent(app)
def _ask(self, win_id, text, mode):
def _ask(self, win_id, text, mode, owners=()):
"""Ask a blocking question in the statusbar.
Args:
win_id: The ID of the window which is calling this function.
text: The text to display to the user.
mode: A PromptMode.
owners: An iterable of objects which will abort the question if
destroyed.
Return:
The answer the user gave or None if the prompt was cancelled.
@ -120,6 +122,8 @@ class NetworkManager(QNetworkAccessManager):
q.text = text
q.mode = mode
self.shutting_down.connect(q.abort)
for owner in owners:
owner.destroyed.connect(q.abort)
bridge = objreg.get('message-bridge', scope='window', window=win_id)
bridge.ask(q, blocking=True)
q.deleteLater()
@ -158,7 +162,8 @@ class NetworkManager(QNetworkAccessManager):
err_string = '\n'.join('- ' + err.errorString() for err in errors)
answer = self._ask(self._win_id,
'SSL errors - continue?\n{}'.format(err_string),
mode=usertypes.PromptMode.yesno)
mode=usertypes.PromptMode.yesno,
owners=(reply,))
if answer:
reply.ignoreSslErrors()
elif ssl_strict:
@ -172,18 +177,20 @@ class NetworkManager(QNetworkAccessManager):
reply.ignoreSslErrors()
@pyqtSlot('QNetworkReply', 'QAuthenticator')
def on_authentication_required(self, _reply, authenticator):
def on_authentication_required(self, reply, authenticator):
"""Called when a website needs authentication."""
answer = self._ask(self._win_id,
"Username ({}):".format(authenticator.realm()),
mode=usertypes.PromptMode.user_pwd)
mode=usertypes.PromptMode.user_pwd,
owners=(reply, authenticator))
self._fill_authenticator(authenticator, answer)
@pyqtSlot('QNetworkProxy', 'QAuthenticator')
def on_proxy_authentication_required(self, _proxy, authenticator):
def on_proxy_authentication_required(self, proxy, authenticator):
"""Called when a proxy needs authentication."""
answer = self._ask(self._win_id, "Proxy username ({}):".format(
authenticator.realm()), mode=usertypes.PromptMode.user_pwd)
authenticator.realm()), mode=usertypes.PromptMode.user_pwd,
owners=(proxy, authenticator))
self._fill_authenticator(authenticator, answer)
@config.change_filter('general', 'private-browsing')