WebBrowser/SafeBrowsing/SafeBrowsingManager.py

changeset 5842
c3f41b959a65
parent 5839
fe4d62e23908
child 5853
e45a570528a4
equal deleted inserted replaced
5841:f227183ae1df 5842:c3f41b959a65
22 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QCoreApplication, \ 22 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QCoreApplication, \
23 QUrl, QDateTime, QTimer 23 QUrl, QDateTime, QTimer
24 24
25 import Preferences 25 import Preferences
26 import Utilities 26 import Utilities
27
28 import UI.PixmapCache
27 29
28 from .SafeBrowsingAPIClient import SafeBrowsingAPIClient 30 from .SafeBrowsingAPIClient import SafeBrowsingAPIClient
29 from .SafeBrowsingCache import SafeBrowsingCache, ThreatList, HashPrefixList 31 from .SafeBrowsingCache import SafeBrowsingCache, ThreatList, HashPrefixList
30 from .SafeBrowsingUrl import SafeBrowsingUrl 32 from .SafeBrowsingUrl import SafeBrowsingUrl
31 from .SafeBrowsingUtilities import toHex 33 from .SafeBrowsingUtilities import toHex
131 @return flag indicating expiration 133 @return flag indicating expiration
132 @rtype bool 134 @rtype bool
133 """ 135 """
134 return self.__enabled and self.__apiClient.fairUseDelayExpired() 136 return self.__enabled and self.__apiClient.fairUseDelayExpired()
135 137
136 def __showStatusBarMessage(self, message): 138 def __showNotificationMessage(self, message, timeout=5):
137 """ 139 """
138 Private method to show some message in the main window status bar. 140 Private method to show some message in a notification widget.
141
142 If desktop notifications have been disabled, the message will
143 be shown in the status bar of the main window (either the main
144 web browser window or the eric main window)
139 145
140 @param message message to be shown 146 @param message message to be shown
141 @type str 147 @type str
148 @param timeout amount of time in seconds the message should be shown
149 (0 = indefinitely)
150 @type int
142 """ 151 """
143 from WebBrowser.WebBrowserWindow import WebBrowserWindow 152 from WebBrowser.WebBrowserWindow import WebBrowserWindow
144 WebBrowserWindow.mainWindow().statusBar().showMessage(message, 5000) 153
154 if WebBrowserWindow.notificationsEnabled():
155 WebBrowserWindow.showNotification(
156 UI.PixmapCache.getPixmap("safeBrowsing48.png"),
157 self.tr("Google Safe Browsing"),
158 message,
159 timeout=timeout,
160 )
161 else:
162 statusBar = WebBrowserWindow.globalStatusBar()
163 if statusBar is not None:
164 statusBar.showMessage(message, timeout * 1000)
145 165
146 def __setAutoUpdateThreatLists(self): 166 def __setAutoUpdateThreatLists(self):
147 """ 167 """
148 Private method to set auto update for the threat lists. 168 Private method to set auto update for the threat lists.
149 """ 169 """
172 """ 192 """
173 Private slot to perform the auto update of the threat lists. 193 Private slot to perform the auto update of the threat lists.
174 """ 194 """
175 ok = False 195 ok = False
176 if self.__enabled: 196 if self.__enabled:
177 self.__showStatusBarMessage(self.tr("Updating threat lists...")) 197 self.__showNotificationMessage(
198 self.tr("Updating threat lists..."), 0)
178 ok = self.updateHashPrefixCache()[0] 199 ok = self.updateHashPrefixCache()[0]
179 if ok: 200 if ok:
180 self.__showStatusBarMessage( 201 self.__showNotificationMessage(
181 self.tr("Updating threat lists done")) 202 self.tr("Updating threat lists done"))
182 else: 203 else:
183 self.__showStatusBarMessage( 204 self.__showNotificationMessage(
184 self.tr("Updating threat lists failed")) 205 self.tr("Updating threat lists failed"))
185 206
186 if ok: 207 if ok:
187 nextUpdateDateTime = \ 208 nextUpdateDateTime = \
188 self.__apiClient.getFairUseDelayExpirationDateTime() 209 self.__apiClient.getFairUseDelayExpirationDateTime()

eric ide

mercurial