WebBrowser/Network/NetworkManager.py

branch
maintenance
changeset 5391
5e79ebb03b10
parent 5369
69705ef2a0af
parent 5389
9b1c800daff3
child 5730
6422afc7adc4
equal deleted inserted replaced
5370:78bf5989530b 5391:5e79ebb03b10
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2016 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a network manager class. 7 Module implementing a network manager class.
8 """ 8 """
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import json 12 import json
13 13
14 from PyQt5.QtCore import pyqtSignal, QByteArray 14 from PyQt5.QtCore import pyqtSignal, QByteArray
15 from PyQt5.QtWidgets import QDialog 15 from PyQt5.QtWidgets import qApp, QStyle, QDialog
16 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \ 16 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \
17 QNetworkRequest 17 QNetworkRequest
18 from PyQt5.QtWebEngineWidgets import QWebEnginePage
18 19
19 from E5Gui import E5MessageBox 20 from E5Gui import E5MessageBox
20 21
21 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired 22 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired
22 try: 23 try:
25 except ImportError: 26 except ImportError:
26 SSL_AVAILABLE = False 27 SSL_AVAILABLE = False
27 28
28 from WebBrowser.WebBrowserWindow import WebBrowserWindow 29 from WebBrowser.WebBrowserWindow import WebBrowserWindow
29 from .NetworkUrlInterceptor import NetworkUrlInterceptor 30 from .NetworkUrlInterceptor import NetworkUrlInterceptor
31 from ..Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl
30 32
31 from Utilities.AutoSaver import AutoSaver 33 from Utilities.AutoSaver import AutoSaver
32 import Preferences 34 import Preferences
33 35
34 36
242 auth.setUser(username) 244 auth.setUser(username)
243 auth.setPassword(password) 245 auth.setPassword(password)
244 if Preferences.getUser("SavePasswords") and dlg.shallSave(): 246 if Preferences.getUser("SavePasswords") and dlg.shallSave():
245 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\ 247 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
246 .setLogin(url, realm, username, password) 248 .setLogin(url, realm, username, password)
249 else:
250 page = self.sender()
251 if isinstance(page, QWebEnginePage):
252 self.__showAuthenticationErrorPage(page, url)
253
254 def __showAuthenticationErrorPage(self, page, url):
255 """
256 Private method to show an authentication error page.
257
258 @param page reference to the page
259 @type QWebEnginePage
260 @param url reference to the URL requesting authentication
261 @type QUrl
262 """
263 html = readAllFileContents(":/html/authenticationErrorPage.html")
264 html = html.replace("@IMAGE@", pixmapToDataUrl(
265 qApp.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap(
266 48, 48)).toString())
267 html = html.replace("@FAVICON@", pixmapToDataUrl(
268 qApp.style() .standardIcon(QStyle.SP_MessageBoxCritical).pixmap(
269 16, 16)).toString())
270 html = html.replace("@TITLE@", self.tr("Authentication required"))
271 html = html.replace("@H1@", self.tr("Authentication required"))
272 html = html.replace(
273 "@LI-1@",
274 self.tr("Authentication is required to access:"))
275 html = html.replace(
276 "@LI-2@",
277 '<a href="{0}">{0}</a>'.format(url.toString()))
278 page.setHtml(html, url)
247 279
248 def proxyAuthentication(self, requestUrl, auth, proxyHost): 280 def proxyAuthentication(self, requestUrl, auth, proxyHost):
249 """ 281 """
250 Public slot to handle a proxy authentication request. 282 Public slot to handle a proxy authentication request.
251 283

eric ide

mercurial