11 import contextlib |
11 import contextlib |
12 |
12 |
13 from PyQt6.QtCore import pyqtSignal, QObject, QUrl, QUrlQuery, QByteArray, QMutex |
13 from PyQt6.QtCore import pyqtSignal, QObject, QUrl, QUrlQuery, QByteArray, QMutex |
14 from PyQt6.QtWebEngineCore import QWebEngineUrlRequestInfo |
14 from PyQt6.QtWebEngineCore import QWebEngineUrlRequestInfo |
15 |
15 |
16 from EricWidgets import EricMessageBox |
16 from eric7.EricWidgets import EricMessageBox |
17 |
17 |
18 from EricUtilities.EricMutexLocker import EricMutexLocker |
18 from eric7.EricUtilities.EricMutexLocker import EricMutexLocker |
19 |
19 |
20 from .AdBlockSubscription import AdBlockSubscription |
20 from .AdBlockSubscription import AdBlockSubscription |
21 from .AdBlockUrlInterceptor import AdBlockUrlInterceptor |
21 from .AdBlockUrlInterceptor import AdBlockUrlInterceptor |
22 from .AdBlockMatcher import AdBlockMatcher |
22 from .AdBlockMatcher import AdBlockMatcher |
23 |
23 |
24 from Utilities.AutoSaver import AutoSaver |
24 from eric7.Utilities.AutoSaver import AutoSaver |
25 import Utilities |
25 from eric7 import Preferences, Utilities |
26 import Preferences |
|
27 |
26 |
28 |
27 |
29 class AdBlockManager(QObject): |
28 class AdBlockManager(QObject): |
30 """ |
29 """ |
31 Class implementing the AdBlock manager. |
30 Class implementing the AdBlock manager. |
82 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
81 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
83 self.rulesChanged.connect(self.__rulesChanged) |
82 self.rulesChanged.connect(self.__rulesChanged) |
84 |
83 |
85 self.__interceptor = AdBlockUrlInterceptor(self) |
84 self.__interceptor = AdBlockUrlInterceptor(self) |
86 |
85 |
87 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
86 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
88 |
87 |
89 WebBrowserWindow.networkManager().installUrlInterceptor(self.__interceptor) |
88 WebBrowserWindow.networkManager().installUrlInterceptor(self.__interceptor) |
90 |
89 |
91 def __rulesChanged(self): |
90 def __rulesChanged(self): |
92 """ |
91 """ |
93 Private slot handling a change of the AdBlock rules. |
92 Private slot handling a change of the AdBlock rules. |
94 """ |
93 """ |
95 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
94 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
96 |
95 |
97 WebBrowserWindow.mainWindow().reloadUserStyleSheet() |
96 WebBrowserWindow.mainWindow().reloadUserStyleSheet() |
98 self.__updateMatcher() |
97 self.__updateMatcher() |
99 |
98 |
100 def close(self): |
99 def close(self): |
126 @type bool |
125 @type bool |
127 """ |
126 """ |
128 if self.isEnabled() == enabled: |
127 if self.isEnabled() == enabled: |
129 return |
128 return |
130 |
129 |
131 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
130 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
132 |
131 |
133 self.__enabled = enabled |
132 self.__enabled = enabled |
134 for mainWindow in WebBrowserWindow.mainWindows(): |
133 for mainWindow in WebBrowserWindow.mainWindows(): |
135 mainWindow.adBlockIcon().setEnabled(enabled) |
134 mainWindow.adBlockIcon().setEnabled(enabled) |
136 if enabled: |
135 if enabled: |
347 """<p>Subscribe to this AdBlock subscription?</p>""" """<p>{0}</p>""" |
346 """<p>Subscribe to this AdBlock subscription?</p>""" """<p>{0}</p>""" |
348 ).format(title), |
347 ).format(title), |
349 ) |
348 ) |
350 if res: |
349 if res: |
351 from .AdBlockSubscription import AdBlockSubscription |
350 from .AdBlockSubscription import AdBlockSubscription |
352 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
351 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
353 |
352 |
354 dlg = WebBrowserWindow.adBlockManager().showDialog() |
353 dlg = WebBrowserWindow.adBlockManager().showDialog() |
355 subscription = AdBlockSubscription( |
354 subscription = AdBlockSubscription( |
356 url, False, WebBrowserWindow.adBlockManager() |
355 url, False, WebBrowserWindow.adBlockManager() |
357 ) |
356 ) |
661 |
660 |
662 def __updateMatcher(self): |
661 def __updateMatcher(self): |
663 """ |
662 """ |
664 Private slot to update the adblock matcher. |
663 Private slot to update the adblock matcher. |
665 """ |
664 """ |
666 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
665 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
667 |
666 |
668 WebBrowserWindow.networkManager().removeUrlInterceptor(self.__interceptor) |
667 WebBrowserWindow.networkManager().removeUrlInterceptor(self.__interceptor) |
669 |
668 |
670 if self.__enabled: |
669 if self.__enabled: |
671 self.__matcher.update() |
670 self.__matcher.update() |