--- a/WebBrowser/SafeBrowsing/SafeBrowsingDialog.py Sun Jul 30 19:56:04 2017 +0200 +++ b/WebBrowser/SafeBrowsing/SafeBrowsingDialog.py Fri Aug 04 18:38:45 2017 +0200 @@ -9,7 +9,7 @@ from __future__ import unicode_literals -from PyQt5.QtCore import pyqtSlot, Qt +from PyQt5.QtCore import pyqtSlot, Qt, QUrl from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ QApplication @@ -42,9 +42,6 @@ self.__manager.progressMessage.connect(self.__setProgressMessage) self.__manager.progress.connect(self.__setProgress) - self.__saveButton = self.buttonBox.addButton( - self.tr("Save"), QDialogButtonBox.ActionRole) - self.iconLabel.setPixmap( UI.PixmapCache.getPixmap("safeBrowsing48.png")) @@ -52,6 +49,8 @@ self.__enabled = Preferences.getWebBrowser("SafeBrowsingEnabled") self.__apiKey = Preferences.getWebBrowser("SafeBrowsingApiKey") + self.__filterPlatform = Preferences.getWebBrowser( + "SafeBrowsingFilterPlatform") self.buttonBox.setFocus() @@ -64,6 +63,7 @@ """ self.gsbGroupBox.setChecked(self.__enabled) self.gsbApiKeyEdit.setText(self.__apiKey) + self.gsbFilterPlatformCheckBox.setChecked(self.__filterPlatform) self.__updateCacheButtons() @@ -95,8 +95,6 @@ """ if button == self.buttonBox.button(QDialogButtonBox.Close): self.close() - elif button == self.__saveButton: - self.__save() @pyqtSlot() def __save(self): @@ -108,9 +106,12 @@ """ self.__enabled = self.gsbGroupBox.isChecked() self.__apiKey = self.gsbApiKeyEdit.text() + self.__filterPlatform = self.gsbFilterPlatformCheckBox.isChecked() Preferences.setWebBrowser("SafeBrowsingEnabled", self.__enabled) Preferences.setWebBrowser("SafeBrowsingApiKey", self.__apiKey) + Preferences.setWebBrowser("SafeBrowsingFilterPlatform", + self.__filterPlatform) self.__manager.configurationChanged() @@ -139,7 +140,8 @@ """ return ( self.__enabled != self.gsbGroupBox.isChecked() or - self.__apiKey != self.gsbApiKeyEdit.text() + self.__apiKey != self.gsbApiKeyEdit.text() or + self.__filterPlatform != self.gsbFilterPlatformCheckBox.isChecked() ) def __okToClose(self): @@ -149,6 +151,7 @@ @return flag indicating safe to close @rtype bool """ + QApplication.restoreOverrideCursor() if self.__isModified(): res = E5MessageBox.okToClearData( self, @@ -173,6 +176,12 @@ """ Private slot to update the local cache database. """ + E5MessageBox.information( + self, + self.tr("Update Safe Browsing Cache"), + self.tr("""Updating the Safe Browsing cache might be a lengthy""" + """ operation. Please be patient!""")) + QApplication.setOverrideCursor(Qt.WaitCursor) ok, error = self.__manager.updateHashPrefixCache() self.__resetProgress() @@ -196,7 +205,15 @@ """ Private slot to clear the local cache database. """ - self.__manager.fullCacheCleanup() + res = E5MessageBox.yesNo( + self, + self.tr("Clear Safe Browsing Cache"), + self.tr("""Do you really want to clear the Safe Browsing cache?""" + """ Re-populating it might take some time.""")) + if res: + QApplication.setOverrideCursor(Qt.WaitCursor) + self.__manager.fullCacheCleanup() + QApplication.restoreOverrideCursor() @pyqtSlot(str, int) def __setProgressMessage(self, message, maximum): @@ -229,3 +246,57 @@ self.progressLabel.clear() self.progressBar.setMaximum(100) self.progressBar.setValue(0) + + @pyqtSlot(str) + def on_urlEdit_textChanged(self, text): + """ + Private slot to handle changes of the entered URL text. + + @param text entered URL text + @type str + """ + url = QUrl.fromUserInput(text) + enable = ( + url.isValid() and + bool(url.scheme()) and + url.scheme() not in self.__manager.getIgnoreSchemes() + ) + self.urlCheckButton.setEnabled(enable) + + @pyqtSlot() + def on_urlCheckButton_clicked(self): + """ + Private slot to check the entered URL. + """ + # Malicious URL for testing: + # http://malware.testing.google.test/testing/malware/* + # http://ianfette.org + # + urlStr = self.urlEdit.text() + url = QUrl.fromUserInput(urlStr) + threatLists = self.__manager.lookupUrl(url) + + if threatLists: + threatMessages = self.__manager.getThreatMessages(threatLists) + E5MessageBox.warning( + self, + self.tr("Check URL"), + self.tr("<p>The URL <b>{0}</b> was found in the Safe Browsing" + " Database.</p>{1}").format(urlStr, + "".join(threatMessages)) + ) + else: + E5MessageBox.information( + self, + self.tr("Check URL"), + self.tr("<p>The URL <b>{0}</b> was not found in the Safe" + " Browsing Database and may be considered safe.</p>") + .format(urlStr) + ) + + @pyqtSlot() + def on_saveButton_clicked(self): + """ + Private slot to save the configuration data. + """ + self.__save()