eric7/Preferences/ConfigurationPages/NetworkPage.py

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

eric ide

mercurial