9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import * |
12 from PyQt4.QtCore import * |
13 from PyQt4.QtGui import QDialog, QMessageBox |
13 from PyQt4.QtGui import QDialog, QMessageBox |
14 from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, \ |
14 from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest |
15 QNetworkProxy |
|
16 try: |
15 try: |
17 from PyQt4.QtNetwork import QSsl, QSslCertificate, QSslConfiguration, QSslSocket |
16 from PyQt4.QtNetwork import QSsl, QSslCertificate, QSslConfiguration, QSslSocket |
18 SSL_AVAILABLE = True |
17 SSL_AVAILABLE = True |
19 except ImportError: |
18 except ImportError: |
20 SSL_AVAILABLE = False |
19 SSL_AVAILABLE = False |
21 |
20 |
|
21 from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory |
|
22 |
22 from UI.AuthenticationDialog import AuthenticationDialog |
23 from UI.AuthenticationDialog import AuthenticationDialog |
23 |
24 |
24 from Helpviewer.HelpLanguagesDialog import HelpLanguagesDialog |
25 from Helpviewer.HelpLanguagesDialog import HelpLanguagesDialog |
25 import Helpviewer.HelpWindow |
26 import Helpviewer.HelpWindow |
26 |
27 |
54 |
55 |
55 self.__adblockNetwork = None |
56 self.__adblockNetwork = None |
56 |
57 |
57 self.__schemeHandlers = {} # dictionary of scheme handlers |
58 self.__schemeHandlers = {} # dictionary of scheme handlers |
58 |
59 |
59 self.__setAccessManagerProxy() |
60 self.__proxyFactory = E5NetworkProxyFactory() |
|
61 self.setProxyFactory(self.__proxyFactory) |
|
62 |
60 self.__setDiskCache() |
63 self.__setDiskCache() |
61 self.languagesChanged() |
64 self.languagesChanged() |
62 |
65 |
63 if SSL_AVAILABLE: |
66 if SSL_AVAILABLE: |
64 sslCfg = QSslConfiguration.defaultConfiguration() |
67 sslCfg = QSslConfiguration.defaultConfiguration() |
73 self.connect(self, |
76 self.connect(self, |
74 SIGNAL('sslErrors(QNetworkReply *, const QList<QSslError> &)'), |
77 SIGNAL('sslErrors(QNetworkReply *, const QList<QSslError> &)'), |
75 self.__sslErrors) |
78 self.__sslErrors) |
76 |
79 |
77 self.connect(self, |
80 self.connect(self, |
78 SIGNAL('proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)'), |
81 SIGNAL('proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)'), |
79 self.__proxyAuthenticationRequired) |
82 self.__proxyAuthenticationRequired) |
80 self.connect(self, |
83 self.connect(self, |
81 SIGNAL('authenticationRequired(QNetworkReply *, QAuthenticator *)'), |
84 SIGNAL('authenticationRequired(QNetworkReply *, QAuthenticator *)'), |
82 self.__authenticationRequired) |
85 self.__authenticationRequired) |
83 |
86 |
140 reply = QNetworkAccessManager.createRequest(self, op, req, outgoingData) |
143 reply = QNetworkAccessManager.createRequest(self, op, req, outgoingData) |
141 self.emit(SIGNAL("requestCreated(QNetworkAccessManager::Operation, const QNetworkRequest&, QNetworkReply*)"), |
144 self.emit(SIGNAL("requestCreated(QNetworkAccessManager::Operation, const QNetworkRequest&, QNetworkReply*)"), |
142 op, req, reply) |
145 op, req, reply) |
143 |
146 |
144 return reply |
147 return reply |
145 |
|
146 def __setAccessManagerProxy(self): |
|
147 """ |
|
148 Private method to set the proxy used by the network access manager. |
|
149 """ |
|
150 if Preferences.getUI("UseProxy"): |
|
151 host = Preferences.getUI("ProxyHost") |
|
152 if not host: |
|
153 QMessageBox.critical(None, |
|
154 self.trUtf8("Web Browser"), |
|
155 self.trUtf8("""Proxy usage was activated""" |
|
156 """ but no proxy host configured.""")) |
|
157 return |
|
158 else: |
|
159 pProxyType = Preferences.getUI("ProxyType") |
|
160 if pProxyType == 0: |
|
161 proxyType = QNetworkProxy.HttpProxy |
|
162 elif pProxyType == 1: |
|
163 proxyType = QNetworkProxy.HttpCachingProxy |
|
164 elif pProxyType == 2: |
|
165 proxyType = QNetworkProxy.Socks5Proxy |
|
166 self.__proxy = QNetworkProxy(proxyType, host, |
|
167 Preferences.getUI("ProxyPort"), |
|
168 Preferences.getUI("ProxyUser"), |
|
169 Preferences.getUI("ProxyPassword")) |
|
170 self.__proxy.setCapabilities(QNetworkProxy.Capabilities( |
|
171 QNetworkProxy.CachingCapability | \ |
|
172 QNetworkProxy.HostNameLookupCapability)) |
|
173 else: |
|
174 self.__proxy = QNetworkProxy(QNetworkProxy.NoProxy) |
|
175 self.setProxy(self.__proxy) |
|
176 |
148 |
177 def __authenticationRequired(self, reply, auth): |
149 def __authenticationRequired(self, reply, auth): |
178 """ |
150 """ |
179 Private slot to handle an authentication request. |
151 Private slot to handle an authentication request. |
180 |
152 |
325 |
297 |
326 def preferencesChanged(self): |
298 def preferencesChanged(self): |
327 """ |
299 """ |
328 Public slot to signal a change of preferences. |
300 Public slot to signal a change of preferences. |
329 """ |
301 """ |
330 self.__setAccessManagerProxy() |
|
331 self.__setDiskCache() |
302 self.__setDiskCache() |
332 |
303 |
333 def languagesChanged(self): |
304 def languagesChanged(self): |
334 """ |
305 """ |
335 Public slot to (re-)load the list of accepted languages. |
306 Public slot to (re-)load the list of accepted languages. |