10 from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QDateTime |
10 from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QDateTime |
11 from PyQt6.QtWidgets import ( |
11 from PyQt6.QtWidgets import ( |
12 QDialog, QDialogButtonBox, QAbstractButton |
12 QDialog, QDialogButtonBox, QAbstractButton |
13 ) |
13 ) |
14 |
14 |
15 from E5Gui import E5MessageBox |
15 from E5Gui import EricMessageBox |
16 from E5Gui.E5OverrideCursor import E5OverrideCursor |
16 from E5Gui.EricOverrideCursor import EricOverrideCursor |
17 |
17 |
18 from .Ui_SafeBrowsingDialog import Ui_SafeBrowsingDialog |
18 from .Ui_SafeBrowsingDialog import Ui_SafeBrowsingDialog |
19 |
19 |
20 import UI.PixmapCache |
20 import UI.PixmapCache |
21 import Preferences |
21 import Preferences |
80 """ |
80 """ |
81 Private slot to show some help text "How to create a safe |
81 Private slot to show some help text "How to create a safe |
82 browsing API key.". |
82 browsing API key.". |
83 """ |
83 """ |
84 if self.__gsbHelpDialog is None: |
84 if self.__gsbHelpDialog is None: |
85 from E5Gui.E5SimpleHelpDialog import E5SimpleHelpDialog |
85 from E5Gui.EricSimpleHelpDialog import EricSimpleHelpDialog |
86 from . import SafeBrowsingHelp |
86 from . import SafeBrowsingHelp |
87 |
87 |
88 helpStr = SafeBrowsingHelp() |
88 helpStr = SafeBrowsingHelp() |
89 self.__gsbHelpDialog = E5SimpleHelpDialog( |
89 self.__gsbHelpDialog = EricSimpleHelpDialog( |
90 title=self.tr("Google Safe Browsing API Help"), |
90 title=self.tr("Google Safe Browsing API Help"), |
91 helpStr=helpStr, parent=self) |
91 helpStr=helpStr, parent=self) |
92 |
92 |
93 self.__gsbHelpDialog.show() |
93 self.__gsbHelpDialog.show() |
94 |
94 |
168 |
168 |
169 @return flag indicating safe to close |
169 @return flag indicating safe to close |
170 @rtype bool |
170 @rtype bool |
171 """ |
171 """ |
172 if self.__isModified(): |
172 if self.__isModified(): |
173 res = E5MessageBox.okToClearData( |
173 res = EricMessageBox.okToClearData( |
174 self, |
174 self, |
175 self.tr("Safe Browsing Management"), |
175 self.tr("Safe Browsing Management"), |
176 self.tr("""The dialog contains unsaved changes."""), |
176 self.tr("""The dialog contains unsaved changes."""), |
177 self.__save) |
177 self.__save) |
178 if not res: |
178 if not res: |
193 @pyqtSlot() |
193 @pyqtSlot() |
194 def on_updateCacheButton_clicked(self): |
194 def on_updateCacheButton_clicked(self): |
195 """ |
195 """ |
196 Private slot to update the local cache database. |
196 Private slot to update the local cache database. |
197 """ |
197 """ |
198 E5MessageBox.information( |
198 EricMessageBox.information( |
199 self, |
199 self, |
200 self.tr("Update Safe Browsing Cache"), |
200 self.tr("Update Safe Browsing Cache"), |
201 self.tr("""Updating the Safe Browsing cache might be a lengthy""" |
201 self.tr("""Updating the Safe Browsing cache might be a lengthy""" |
202 """ operation. Please be patient!""")) |
202 """ operation. Please be patient!""")) |
203 |
203 |
204 with E5OverrideCursor(): |
204 with EricOverrideCursor(): |
205 ok, error = self.__manager.updateHashPrefixCache() |
205 ok, error = self.__manager.updateHashPrefixCache() |
206 self.__resetProgress() |
206 self.__resetProgress() |
207 if not ok: |
207 if not ok: |
208 if error: |
208 if error: |
209 E5MessageBox.critical( |
209 EricMessageBox.critical( |
210 self, |
210 self, |
211 self.tr("Update Safe Browsing Cache"), |
211 self.tr("Update Safe Browsing Cache"), |
212 self.tr("""<p>Updating the Safe Browsing cache failed.""" |
212 self.tr("""<p>Updating the Safe Browsing cache failed.""" |
213 """</p><p>Reason: {0}</p>""").format(error)) |
213 """</p><p>Reason: {0}</p>""").format(error)) |
214 else: |
214 else: |
215 E5MessageBox.critical( |
215 EricMessageBox.critical( |
216 self, |
216 self, |
217 self.tr("Update Safe Browsing Cache"), |
217 self.tr("Update Safe Browsing Cache"), |
218 self.tr("""<p>Updating the Safe Browsing cache failed.""" |
218 self.tr("""<p>Updating the Safe Browsing cache failed.""" |
219 """</p>""")) |
219 """</p>""")) |
220 |
220 |
221 @pyqtSlot() |
221 @pyqtSlot() |
222 def on_clearCacheButton_clicked(self): |
222 def on_clearCacheButton_clicked(self): |
223 """ |
223 """ |
224 Private slot to clear the local cache database. |
224 Private slot to clear the local cache database. |
225 """ |
225 """ |
226 res = E5MessageBox.yesNo( |
226 res = EricMessageBox.yesNo( |
227 self, |
227 self, |
228 self.tr("Clear Safe Browsing Cache"), |
228 self.tr("Clear Safe Browsing Cache"), |
229 self.tr("""Do you really want to clear the Safe Browsing cache?""" |
229 self.tr("""Do you really want to clear the Safe Browsing cache?""" |
230 """ Re-populating it might take some time.""")) |
230 """ Re-populating it might take some time.""")) |
231 if res: |
231 if res: |
232 with E5OverrideCursor(): |
232 with EricOverrideCursor(): |
233 self.__manager.fullCacheCleanup() |
233 self.__manager.fullCacheCleanup() |
234 |
234 |
235 @pyqtSlot(str, int) |
235 @pyqtSlot(str, int) |
236 def __setProgressMessage(self, message, maximum): |
236 def __setProgressMessage(self, message, maximum): |
237 """ |
237 """ |
293 urlStr = self.urlEdit.text() |
293 urlStr = self.urlEdit.text() |
294 url = QUrl.fromUserInput(urlStr) |
294 url = QUrl.fromUserInput(urlStr) |
295 threatLists, error = self.__manager.lookupUrl(url) |
295 threatLists, error = self.__manager.lookupUrl(url) |
296 |
296 |
297 if error: |
297 if error: |
298 E5MessageBox.warning( |
298 EricMessageBox.warning( |
299 self, |
299 self, |
300 self.tr("Check URL"), |
300 self.tr("Check URL"), |
301 self.tr("<p>The Google Safe Browsing Server reported an" |
301 self.tr("<p>The Google Safe Browsing Server reported an" |
302 " error.</p><p>{0}</p>").format(error) |
302 " error.</p><p>{0}</p>").format(error) |
303 ) |
303 ) |
304 elif threatLists: |
304 elif threatLists: |
305 threatMessages = self.__manager.getThreatMessages(threatLists) |
305 threatMessages = self.__manager.getThreatMessages(threatLists) |
306 E5MessageBox.warning( |
306 EricMessageBox.warning( |
307 self, |
307 self, |
308 self.tr("Check URL"), |
308 self.tr("Check URL"), |
309 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
309 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
310 " Browsing Database.</p>{1}").format( |
310 " Browsing Database.</p>{1}").format( |
311 urlStr, "".join(threatMessages)) |
311 urlStr, "".join(threatMessages)) |
312 ) |
312 ) |
313 else: |
313 else: |
314 E5MessageBox.information( |
314 EricMessageBox.information( |
315 self, |
315 self, |
316 self.tr("Check URL"), |
316 self.tr("Check URL"), |
317 self.tr("<p>The URL <b>{0}</b> was not found in the Safe" |
317 self.tr("<p>The URL <b>{0}</b> was not found in the Safe" |
318 " Browsing Database and may be considered safe." |
318 " Browsing Database and may be considered safe." |
319 "</p>") |
319 "</p>") |
341 self.tr("<p>The next automatic threat list update will be done at" |
341 self.tr("<p>The next automatic threat list update will be done at" |
342 " <b>{0}</b>.</p>").format( |
342 " <b>{0}</b>.</p>").format( |
343 nextUpdateDateTime.toString("yyyy-MM-dd, HH:mm:ss")) |
343 nextUpdateDateTime.toString("yyyy-MM-dd, HH:mm:ss")) |
344 ) |
344 ) |
345 |
345 |
346 E5MessageBox.information( |
346 EricMessageBox.information( |
347 self, |
347 self, |
348 self.tr("Update Time"), |
348 self.tr("Update Time"), |
349 message) |
349 message) |