|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Network configuration page. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 |
|
14 from E5Gui.E5PathPicker import E5PathPickerModes |
|
15 |
|
16 from E5Network.E5Ftp import E5FtpProxyType |
|
17 |
|
18 from .ConfigurationPageBase import ConfigurationPageBase |
|
19 from .Ui_NetworkPage import Ui_NetworkPage |
|
20 |
|
21 import Preferences |
|
22 |
|
23 |
|
24 class NetworkPage(ConfigurationPageBase, Ui_NetworkPage): |
|
25 """ |
|
26 Class implementing the Network configuration page. |
|
27 """ |
|
28 def __init__(self, configDialog): |
|
29 """ |
|
30 Constructor |
|
31 |
|
32 @param configDialog reference to the configuration dialog |
|
33 (ConfigurationDialog) |
|
34 """ |
|
35 super(NetworkPage, self).__init__() |
|
36 self.setupUi(self) |
|
37 self.setObjectName("NetworkPage") |
|
38 |
|
39 self.__configDlg = configDialog |
|
40 self.__displayMode = None |
|
41 self.__webEngine = False |
|
42 self.__webKit = False |
|
43 |
|
44 self.downloadDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
45 |
|
46 self.ftpProxyTypeCombo.addItem( |
|
47 self.tr("No FTP Proxy"), E5FtpProxyType.NoProxy) |
|
48 self.ftpProxyTypeCombo.addItem( |
|
49 self.tr("No Proxy Authentication required"), |
|
50 E5FtpProxyType.NonAuthorizing) |
|
51 self.ftpProxyTypeCombo.addItem( |
|
52 self.tr("User@Server"), E5FtpProxyType.UserAtServer) |
|
53 self.ftpProxyTypeCombo.addItem( |
|
54 self.tr("SITE"), E5FtpProxyType.Site) |
|
55 self.ftpProxyTypeCombo.addItem( |
|
56 self.tr("OPEN"), E5FtpProxyType.Open) |
|
57 self.ftpProxyTypeCombo.addItem( |
|
58 self.tr("User@Proxyuser@Server"), |
|
59 E5FtpProxyType.UserAtProxyuserAtServer) |
|
60 self.ftpProxyTypeCombo.addItem( |
|
61 self.tr("Proxyuser@Server"), E5FtpProxyType.ProxyuserAtServer) |
|
62 self.ftpProxyTypeCombo.addItem( |
|
63 self.tr("AUTH and RESP"), E5FtpProxyType.AuthResp) |
|
64 self.ftpProxyTypeCombo.addItem( |
|
65 self.tr("Bluecoat Proxy"), E5FtpProxyType.Bluecoat) |
|
66 |
|
67 # set initial values |
|
68 self.dynamicOnlineCheckBox.setChecked( |
|
69 Preferences.getUI("DynamicOnlineCheck")) |
|
70 self.downloadDirPicker.setText(Preferences.getUI("DownloadPath")) |
|
71 self.requestFilenameCheckBox.setChecked( |
|
72 Preferences.getUI("RequestDownloadFilename")) |
|
73 |
|
74 # HTTP proxy |
|
75 self.httpProxyHostEdit.setText( |
|
76 Preferences.getUI("ProxyHost/Http")) |
|
77 self.httpProxyPortSpin.setValue( |
|
78 Preferences.getUI("ProxyPort/Http")) |
|
79 |
|
80 # HTTPS proxy |
|
81 self.httpsProxyHostEdit.setText( |
|
82 Preferences.getUI("ProxyHost/Https")) |
|
83 self.httpsProxyPortSpin.setValue( |
|
84 Preferences.getUI("ProxyPort/Https")) |
|
85 |
|
86 # FTP proxy |
|
87 self.ftpProxyHostEdit.setText( |
|
88 Preferences.getUI("ProxyHost/Ftp")) |
|
89 self.ftpProxyPortSpin.setValue( |
|
90 Preferences.getUI("ProxyPort/Ftp")) |
|
91 self.ftpProxyTypeCombo.setCurrentIndex( |
|
92 self.ftpProxyTypeCombo.findData( |
|
93 Preferences.getUI("ProxyType/Ftp"))) |
|
94 self.ftpProxyUserEdit.setText( |
|
95 Preferences.getUI("ProxyUser/Ftp")) |
|
96 self.ftpProxyPasswordEdit.setText( |
|
97 Preferences.getUI("ProxyPassword/Ftp")) |
|
98 self.ftpProxyAccountEdit.setText( |
|
99 Preferences.getUI("ProxyAccount/Ftp")) |
|
100 |
|
101 self.httpProxyForAllCheckBox.setChecked( |
|
102 Preferences.getUI("UseHttpProxyForAll")) |
|
103 if not Preferences.getUI("UseProxy"): |
|
104 self.noProxyButton.setChecked(True) |
|
105 elif Preferences.getUI("UseSystemProxy"): |
|
106 self.systemProxyButton.setChecked(True) |
|
107 else: |
|
108 self.manualProxyButton.setChecked(True) |
|
109 |
|
110 self.exceptionsEdit.setText( |
|
111 ", ".join(Preferences.getUI("ProxyExceptions").split(","))) |
|
112 |
|
113 def setMode(self, displayMode): |
|
114 """ |
|
115 Public method to perform mode dependent setups. |
|
116 |
|
117 @param displayMode mode of the configuration dialog |
|
118 (ConfigurationWidget.DefaultMode, |
|
119 ConfigurationWidget.HelpBrowserMode, |
|
120 ConfigurationWidget.WebBrowserMode) |
|
121 """ |
|
122 from ..ConfigurationDialog import ConfigurationWidget |
|
123 assert displayMode in ( |
|
124 ConfigurationWidget.DefaultMode, |
|
125 ConfigurationWidget.HelpBrowserMode, |
|
126 ConfigurationWidget.WebBrowserMode |
|
127 ) |
|
128 |
|
129 self.__displayMode = displayMode |
|
130 if self.__displayMode == ConfigurationWidget.HelpBrowserMode or \ |
|
131 not self.__configDlg.isUsingWebEngine(): |
|
132 try: |
|
133 policy = Preferences.getHelp("DownloadManagerRemovePolicy") |
|
134 from Helpviewer.Download.DownloadManager import DownloadManager |
|
135 if policy == DownloadManager.RemoveNever: |
|
136 self.cleanupNeverButton.setChecked(True) |
|
137 elif policy == DownloadManager.RemoveExit: |
|
138 self.cleanupExitButton.setChecked(True) |
|
139 else: |
|
140 self.cleanupSuccessfulButton.setChecked(True) |
|
141 self.__webKit = True |
|
142 except ImportError: |
|
143 self.cleanupGroup.hide() |
|
144 self.displayGroup.hide() |
|
145 else: |
|
146 policy = Preferences.getWebBrowser("DownloadManagerRemovePolicy") |
|
147 from WebBrowser.Download.DownloadManager import DownloadManager |
|
148 if policy == DownloadManager.RemoveNever: |
|
149 self.cleanupNeverButton.setChecked(True) |
|
150 elif policy == DownloadManager.RemoveExit: |
|
151 self.cleanupExitButton.setChecked(True) |
|
152 else: |
|
153 self.cleanupSuccessfulButton.setChecked(True) |
|
154 self.openOnStartCheckBox.setChecked( |
|
155 Preferences.getWebBrowser("DownloadManagerAutoOpen")) |
|
156 self.closeOnFinishedCheckBox.setChecked( |
|
157 Preferences.getWebBrowser("DownloadManagerAutoClose")) |
|
158 self.__webEngine = True |
|
159 |
|
160 def save(self): |
|
161 """ |
|
162 Public slot to save the Networj configuration. |
|
163 """ |
|
164 Preferences.setUI( |
|
165 "DynamicOnlineCheck", |
|
166 self.dynamicOnlineCheckBox.isChecked()) |
|
167 Preferences.setUI( |
|
168 "DownloadPath", |
|
169 self.downloadDirPicker.text()) |
|
170 Preferences.setUI( |
|
171 "RequestDownloadFilename", |
|
172 self.requestFilenameCheckBox.isChecked()) |
|
173 if self.__webKit: |
|
174 from Helpviewer.Download.DownloadManager import DownloadManager |
|
175 if self.cleanupNeverButton.isChecked(): |
|
176 policy = DownloadManager.RemoveNever |
|
177 elif self.cleanupExitButton.isChecked(): |
|
178 policy = DownloadManager.RemoveExit |
|
179 else: |
|
180 policy = DownloadManager.RemoveSuccessFullDownload |
|
181 Preferences.setHelp("DownloadManagerRemovePolicy", policy) |
|
182 elif self.__webEngine: |
|
183 from WebBrowser.Download.DownloadManager import DownloadManager |
|
184 if self.cleanupNeverButton.isChecked(): |
|
185 policy = DownloadManager.RemoveNever |
|
186 elif self.cleanupExitButton.isChecked(): |
|
187 policy = DownloadManager.RemoveExit |
|
188 else: |
|
189 policy = DownloadManager.RemoveSuccessFullDownload |
|
190 Preferences.setWebBrowser("DownloadManagerRemovePolicy", policy) |
|
191 Preferences.setWebBrowser( |
|
192 "DownloadManagerAutoOpen", |
|
193 self.openOnStartCheckBox.isChecked()) |
|
194 Preferences.setWebBrowser( |
|
195 "DownloadManagerAutoClose", |
|
196 self.closeOnFinishedCheckBox.isChecked()) |
|
197 |
|
198 Preferences.setUI( |
|
199 "UseProxy", |
|
200 not self.noProxyButton.isChecked()) |
|
201 Preferences.setUI( |
|
202 "UseSystemProxy", |
|
203 self.systemProxyButton.isChecked()) |
|
204 Preferences.setUI( |
|
205 "UseHttpProxyForAll", |
|
206 self.httpProxyForAllCheckBox.isChecked()) |
|
207 |
|
208 Preferences.setUI( |
|
209 "ProxyExceptions", |
|
210 ",".join( |
|
211 [h.strip() for h in self.exceptionsEdit.text().split(",")])) |
|
212 |
|
213 # HTTP proxy |
|
214 Preferences.setUI( |
|
215 "ProxyHost/Http", |
|
216 self.httpProxyHostEdit.text()) |
|
217 Preferences.setUI( |
|
218 "ProxyPort/Http", |
|
219 self.httpProxyPortSpin.value()) |
|
220 |
|
221 # HTTPS proxy |
|
222 Preferences.setUI( |
|
223 "ProxyHost/Https", |
|
224 self.httpsProxyHostEdit.text()) |
|
225 Preferences.setUI( |
|
226 "ProxyPort/Https", |
|
227 self.httpsProxyPortSpin.value()) |
|
228 |
|
229 # FTP proxy |
|
230 Preferences.setUI( |
|
231 "ProxyHost/Ftp", |
|
232 self.ftpProxyHostEdit.text()) |
|
233 Preferences.setUI( |
|
234 "ProxyPort/Ftp", |
|
235 self.ftpProxyPortSpin.value()) |
|
236 Preferences.setUI( |
|
237 "ProxyType/Ftp", |
|
238 self.ftpProxyTypeCombo.itemData( |
|
239 self.ftpProxyTypeCombo.currentIndex())) |
|
240 Preferences.setUI( |
|
241 "ProxyUser/Ftp", |
|
242 self.ftpProxyUserEdit.text()) |
|
243 Preferences.setUI( |
|
244 "ProxyPassword/Ftp", |
|
245 self.ftpProxyPasswordEdit.text()) |
|
246 Preferences.setUI( |
|
247 "ProxyAccount/Ftp", |
|
248 self.ftpProxyAccountEdit.text()) |
|
249 |
|
250 @pyqtSlot() |
|
251 def on_clearProxyPasswordsButton_clicked(self): |
|
252 """ |
|
253 Private slot to clear the saved HTTP(S) proxy passwords. |
|
254 """ |
|
255 Preferences.setUI("ProxyPassword/Http", "") |
|
256 Preferences.setUI("ProxyPassword/Https", "") |
|
257 |
|
258 @pyqtSlot(int) |
|
259 def on_ftpProxyTypeCombo_currentIndexChanged(self, index): |
|
260 """ |
|
261 Private slot handling the selection of a proxy type. |
|
262 |
|
263 @param index index of the selected item (integer) |
|
264 """ |
|
265 proxyType = self.ftpProxyTypeCombo.itemData(index) |
|
266 self.ftpProxyHostEdit.setEnabled(proxyType != E5FtpProxyType.NoProxy) |
|
267 self.ftpProxyPortSpin.setEnabled(proxyType != E5FtpProxyType.NoProxy) |
|
268 self.ftpProxyUserEdit.setEnabled( |
|
269 proxyType not in [E5FtpProxyType.NoProxy, |
|
270 E5FtpProxyType.NonAuthorizing]) |
|
271 self.ftpProxyPasswordEdit.setEnabled( |
|
272 proxyType not in [E5FtpProxyType.NoProxy, |
|
273 E5FtpProxyType.NonAuthorizing]) |
|
274 self.ftpProxyAccountEdit.setEnabled( |
|
275 proxyType not in [E5FtpProxyType.NoProxy, |
|
276 E5FtpProxyType.NonAuthorizing]) |
|
277 |
|
278 |
|
279 def create(dlg): |
|
280 """ |
|
281 Module function to create the configuration page. |
|
282 |
|
283 @param dlg reference to the configuration dialog |
|
284 @return reference to the instantiated page (ConfigurationPageBase) |
|
285 """ |
|
286 page = NetworkPage(dlg) |
|
287 return page |