WebBrowser/SafeBrowsing/SafeBrowsingManager.py

changeset 5842
c3f41b959a65
parent 5839
fe4d62e23908
child 5853
e45a570528a4
diff -r f227183ae1df -r c3f41b959a65 WebBrowser/SafeBrowsing/SafeBrowsingManager.py
--- a/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Thu Aug 10 11:57:04 2017 +0200
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Thu Aug 10 13:58:50 2017 +0200
@@ -25,6 +25,8 @@
 import Preferences
 import Utilities
 
+import UI.PixmapCache
+
 from .SafeBrowsingAPIClient import SafeBrowsingAPIClient
 from .SafeBrowsingCache import SafeBrowsingCache, ThreatList, HashPrefixList
 from .SafeBrowsingUrl import SafeBrowsingUrl
@@ -133,15 +135,33 @@
         """
         return self.__enabled and self.__apiClient.fairUseDelayExpired()
     
-    def __showStatusBarMessage(self, message):
+    def __showNotificationMessage(self, message, timeout=5):
         """
-        Private method to show some message in the main window status bar.
+        Private method to show some message in a notification widget.
+        
+        If desktop notifications have been disabled, the message will
+        be shown in the status bar of the main window (either the main
+        web browser window or the eric main window)
         
         @param message message to be shown
         @type str
+        @param timeout amount of time in seconds the message should be shown
+            (0 = indefinitely)
+        @type int
         """
         from WebBrowser.WebBrowserWindow import WebBrowserWindow
-        WebBrowserWindow.mainWindow().statusBar().showMessage(message, 5000)
+        
+        if WebBrowserWindow.notificationsEnabled():
+            WebBrowserWindow.showNotification(
+                UI.PixmapCache.getPixmap("safeBrowsing48.png"),
+                self.tr("Google Safe Browsing"),
+                message,
+                timeout=timeout,
+            )
+        else:
+            statusBar = WebBrowserWindow.globalStatusBar()
+            if statusBar is not None:
+                statusBar.showMessage(message, timeout * 1000)
     
     def __setAutoUpdateThreatLists(self):
         """
@@ -174,13 +194,14 @@
         """
         ok = False
         if self.__enabled:
-            self.__showStatusBarMessage(self.tr("Updating threat lists..."))
+            self.__showNotificationMessage(
+                self.tr("Updating threat lists..."), 0)
             ok = self.updateHashPrefixCache()[0]
             if ok:
-                self.__showStatusBarMessage(
+                self.__showNotificationMessage(
                     self.tr("Updating threat lists done"))
             else:
-                self.__showStatusBarMessage(
+                self.__showNotificationMessage(
                     self.tr("Updating threat lists failed"))
         
         if ok:

eric ide

mercurial