7 Module implementing a dialog to configure safe browsing support. |
7 Module implementing a dialog to configure safe browsing support. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, Qt, QUrl |
12 from PyQt5.QtCore import pyqtSlot, Qt, QUrl, QDateTime |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ |
14 QApplication |
14 QApplication |
15 |
15 |
16 from E5Gui import E5MessageBox |
16 from E5Gui import E5MessageBox |
17 |
17 |
49 |
49 |
50 self.__enabled = Preferences.getWebBrowser("SafeBrowsingEnabled") |
50 self.__enabled = Preferences.getWebBrowser("SafeBrowsingEnabled") |
51 self.__apiKey = Preferences.getWebBrowser("SafeBrowsingApiKey") |
51 self.__apiKey = Preferences.getWebBrowser("SafeBrowsingApiKey") |
52 self.__filterPlatform = Preferences.getWebBrowser( |
52 self.__filterPlatform = Preferences.getWebBrowser( |
53 "SafeBrowsingFilterPlatform") |
53 "SafeBrowsingFilterPlatform") |
|
54 self.__automaticUpdate = Preferences.getWebBrowser( |
|
55 "SafeBrowsingAutoUpdate") |
54 |
56 |
55 self.buttonBox.setFocus() |
57 self.buttonBox.setFocus() |
56 |
58 |
57 msh = self.minimumSizeHint() |
59 msh = self.minimumSizeHint() |
58 self.resize(max(self.width(), msh.width()), msh.height()) |
60 self.resize(max(self.width(), msh.width()), msh.height()) |
62 Public slot to show the dialog. |
64 Public slot to show the dialog. |
63 """ |
65 """ |
64 self.gsbGroupBox.setChecked(self.__enabled) |
66 self.gsbGroupBox.setChecked(self.__enabled) |
65 self.gsbApiKeyEdit.setText(self.__apiKey) |
67 self.gsbApiKeyEdit.setText(self.__apiKey) |
66 self.gsbFilterPlatformCheckBox.setChecked(self.__filterPlatform) |
68 self.gsbFilterPlatformCheckBox.setChecked(self.__filterPlatform) |
|
69 self.gsbAutoUpdateCheckBox.setChecked(self.__automaticUpdate) |
67 |
70 |
68 self.__updateCacheButtons() |
71 self.__updateCacheButtons() |
69 |
72 |
70 super(SafeBrowsingDialog, self).show() |
73 super(SafeBrowsingDialog, self).show() |
71 |
74 |
105 @rtype bool |
108 @rtype bool |
106 """ |
109 """ |
107 self.__enabled = self.gsbGroupBox.isChecked() |
110 self.__enabled = self.gsbGroupBox.isChecked() |
108 self.__apiKey = self.gsbApiKeyEdit.text() |
111 self.__apiKey = self.gsbApiKeyEdit.text() |
109 self.__filterPlatform = self.gsbFilterPlatformCheckBox.isChecked() |
112 self.__filterPlatform = self.gsbFilterPlatformCheckBox.isChecked() |
|
113 self.__automaticUpdate = self.gsbAutoUpdateCheckBox.isChecked() |
110 |
114 |
111 Preferences.setWebBrowser("SafeBrowsingEnabled", self.__enabled) |
115 Preferences.setWebBrowser("SafeBrowsingEnabled", self.__enabled) |
112 Preferences.setWebBrowser("SafeBrowsingApiKey", self.__apiKey) |
116 Preferences.setWebBrowser("SafeBrowsingApiKey", self.__apiKey) |
113 Preferences.setWebBrowser("SafeBrowsingFilterPlatform", |
117 Preferences.setWebBrowser("SafeBrowsingFilterPlatform", |
114 self.__filterPlatform) |
118 self.__filterPlatform) |
|
119 Preferences.setWebBrowser("SafeBrowsingAutoUpdate", |
|
120 self.__automaticUpdate) |
115 |
121 |
116 self.__manager.configurationChanged() |
122 self.__manager.configurationChanged() |
117 |
123 |
118 self.__updateCacheButtons() |
124 self.__updateCacheButtons() |
119 |
125 |
137 |
143 |
138 @return flag indicating the presence of modified data |
144 @return flag indicating the presence of modified data |
139 @rtype bool |
145 @rtype bool |
140 """ |
146 """ |
141 return ( |
147 return ( |
142 self.__enabled != self.gsbGroupBox.isChecked() or |
148 (self.__enabled != self.gsbGroupBox.isChecked()) or |
143 self.__apiKey != self.gsbApiKeyEdit.text() or |
149 (self.__apiKey != self.gsbApiKeyEdit.text()) or |
144 self.__filterPlatform != self.gsbFilterPlatformCheckBox.isChecked() |
150 (self.__filterPlatform != |
|
151 self.gsbFilterPlatformCheckBox.isChecked()) or |
|
152 (self.__automaticUpdate != self.gsbAutoUpdateCheckBox.isChecked()) |
145 ) |
153 ) |
146 |
154 |
147 def __okToClose(self): |
155 def __okToClose(self): |
148 """ |
156 """ |
149 Private method to check, if it is safe to close the dialog. |
157 Private method to check, if it is safe to close the dialog. |
168 """ |
176 """ |
169 enable = self.__enabled and bool(self.__apiKey) |
177 enable = self.__enabled and bool(self.__apiKey) |
170 |
178 |
171 self.updateCacheButton.setEnabled(enable) |
179 self.updateCacheButton.setEnabled(enable) |
172 self.clearCacheButton.setEnabled(enable) |
180 self.clearCacheButton.setEnabled(enable) |
|
181 |
|
182 self.showUpdateTimeButton.setEnabled(enable and self.__automaticUpdate) |
173 |
183 |
174 @pyqtSlot() |
184 @pyqtSlot() |
175 def on_updateCacheButton_clicked(self): |
185 def on_updateCacheButton_clicked(self): |
176 """ |
186 """ |
177 Private slot to update the local cache database. |
187 Private slot to update the local cache database. |
235 Private slot to set the progress value. |
245 Private slot to set the progress value. |
236 |
246 |
237 @param value progress value to be set |
247 @param value progress value to be set |
238 @type int |
248 @type int |
239 """ |
249 """ |
240 self.progressBar.setValue(value) |
250 if bool(self.progressLabel.text()): |
|
251 self.progressBar.setValue(value) |
241 |
252 |
242 def __resetProgress(self): |
253 def __resetProgress(self): |
243 """ |
254 """ |
244 Private method to reset the progress info. |
255 Private method to reset the progress info. |
245 """ |
256 """ |
298 def on_saveButton_clicked(self): |
309 def on_saveButton_clicked(self): |
299 """ |
310 """ |
300 Private slot to save the configuration data. |
311 Private slot to save the configuration data. |
301 """ |
312 """ |
302 self.__save() |
313 self.__save() |
|
314 |
|
315 @pyqtSlot() |
|
316 def on_showUpdateTimeButton_clicked(self): |
|
317 """ |
|
318 Private slot to show the time of the next automatic threat list update. |
|
319 """ |
|
320 nextUpdateDateTime = Preferences.getWebBrowser( |
|
321 "SafeBrowsingUpdateDateTime") |
|
322 if not nextUpdateDateTime.isValid() or \ |
|
323 nextUpdateDateTime <= QDateTime.currentDateTime(): |
|
324 message = self.tr("The next automatic threat list update will be" |
|
325 " done now.") |
|
326 else: |
|
327 message = self.tr("<p>The next automatic threat list update will" |
|
328 " be done at <b>{0}</b>.</p>").format( |
|
329 nextUpdateDateTime.toString("yyyy-MM-dd, HH:mm:ss")) |
|
330 |
|
331 E5MessageBox.information( |
|
332 self, |
|
333 self.tr("Update Time"), |
|
334 message) |