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