15 |
15 |
16 from eric7 import Preferences, Utilities |
16 from eric7 import Preferences, Utilities |
17 from eric7.EricUtilities.EricMutexLocker import EricMutexLocker |
17 from eric7.EricUtilities.EricMutexLocker import EricMutexLocker |
18 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets import EricMessageBox |
19 from eric7.Utilities.AutoSaver import AutoSaver |
19 from eric7.Utilities.AutoSaver import AutoSaver |
|
20 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
20 |
21 |
21 from .AdBlockMatcher import AdBlockMatcher |
22 from .AdBlockMatcher import AdBlockMatcher |
22 from .AdBlockSubscription import AdBlockSubscription |
23 from .AdBlockSubscription import AdBlockSubscription |
23 from .AdBlockUrlInterceptor import AdBlockUrlInterceptor |
24 from .AdBlockUrlInterceptor import AdBlockUrlInterceptor |
24 |
25 |
79 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
80 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
80 self.rulesChanged.connect(self.__rulesChanged) |
81 self.rulesChanged.connect(self.__rulesChanged) |
81 |
82 |
82 self.__interceptor = AdBlockUrlInterceptor(self) |
83 self.__interceptor = AdBlockUrlInterceptor(self) |
83 |
84 |
84 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
85 |
|
86 WebBrowserWindow.networkManager().installUrlInterceptor(self.__interceptor) |
85 WebBrowserWindow.networkManager().installUrlInterceptor(self.__interceptor) |
87 |
86 |
88 def __rulesChanged(self): |
87 def __rulesChanged(self): |
89 """ |
88 """ |
90 Private slot handling a change of the AdBlock rules. |
89 Private slot handling a change of the AdBlock rules. |
91 """ |
90 """ |
92 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
93 |
|
94 WebBrowserWindow.mainWindow().reloadUserStyleSheet() |
91 WebBrowserWindow.mainWindow().reloadUserStyleSheet() |
95 self.__updateMatcher() |
92 self.__updateMatcher() |
96 |
93 |
97 def close(self): |
94 def close(self): |
98 """ |
95 """ |
122 @param enabled flag indicating the enabled state |
119 @param enabled flag indicating the enabled state |
123 @type bool |
120 @type bool |
124 """ |
121 """ |
125 if self.isEnabled() == enabled: |
122 if self.isEnabled() == enabled: |
126 return |
123 return |
127 |
|
128 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
129 |
124 |
130 self.__enabled = enabled |
125 self.__enabled = enabled |
131 for mainWindow in WebBrowserWindow.mainWindows(): |
126 for mainWindow in WebBrowserWindow.mainWindows(): |
132 mainWindow.adBlockIcon().setEnabled(enabled) |
127 mainWindow.adBlockIcon().setEnabled(enabled) |
133 if enabled: |
128 if enabled: |
196 Public method to get a reference to the page block object. |
191 Public method to get a reference to the page block object. |
197 |
192 |
198 @return reference to the page block object |
193 @return reference to the page block object |
199 @rtype AdBlockPage |
194 @rtype AdBlockPage |
200 """ |
195 """ |
|
196 from .AdBlockPage import AdBlockPage |
|
197 |
201 if self.__adBlockPage is None: |
198 if self.__adBlockPage is None: |
202 from .AdBlockPage import AdBlockPage |
|
203 |
|
204 self.__adBlockPage = AdBlockPage(self) |
199 self.__adBlockPage = AdBlockPage(self) |
205 return self.__adBlockPage |
200 return self.__adBlockPage |
206 |
201 |
207 def __customSubscriptionLocation(self): |
202 def __customSubscriptionLocation(self): |
208 """ |
203 """ |
326 @param url URL to subscribe an AdBlock subscription |
321 @param url URL to subscribe an AdBlock subscription |
327 @type QUrl |
322 @type QUrl |
328 @return flag indicating success |
323 @return flag indicating success |
329 @rtype bool |
324 @rtype bool |
330 """ |
325 """ |
|
326 from .AdBlockSubscription import AdBlockSubscription |
|
327 |
331 if url.path() != "subscribe": |
328 if url.path() != "subscribe": |
332 return False |
329 return False |
333 |
330 |
334 title = QUrl.fromPercentEncoding( |
331 title = QUrl.fromPercentEncoding( |
335 QByteArray(QUrlQuery(url).queryItemValue("title").encode()) |
332 QByteArray(QUrlQuery(url).queryItemValue("title").encode()) |
343 self.tr( |
340 self.tr( |
344 """<p>Subscribe to this AdBlock subscription?</p>""" """<p>{0}</p>""" |
341 """<p>Subscribe to this AdBlock subscription?</p>""" """<p>{0}</p>""" |
345 ).format(title), |
342 ).format(title), |
346 ) |
343 ) |
347 if res: |
344 if res: |
348 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
349 |
|
350 from .AdBlockSubscription import AdBlockSubscription |
|
351 |
|
352 dlg = WebBrowserWindow.adBlockManager().showDialog() |
345 dlg = WebBrowserWindow.adBlockManager().showDialog() |
353 subscription = AdBlockSubscription( |
346 subscription = AdBlockSubscription( |
354 url, False, WebBrowserWindow.adBlockManager() |
347 url, False, WebBrowserWindow.adBlockManager() |
355 ) |
348 ) |
356 WebBrowserWindow.adBlockManager().addSubscription(subscription) |
349 WebBrowserWindow.adBlockManager().addSubscription(subscription) |
495 if subscription.requiresLocation() == location: |
488 if subscription.requiresLocation() == location: |
496 subscriptions.append(subscription) |
489 subscriptions.append(subscription) |
497 |
490 |
498 return subscriptions |
491 return subscriptions |
499 |
492 |
500 def showDialog(self): |
493 def showDialog(self, parent=None): |
501 """ |
494 """ |
502 Public slot to show the AdBlock subscription management dialog. |
495 Public slot to show the AdBlock subscription management dialog. |
503 |
496 |
|
497 @param parent reference to the parent widget |
|
498 @type QWidget |
504 @return reference to the dialog |
499 @return reference to the dialog |
505 @rtype AdBlockDialog |
500 @rtype AdBlockDialog |
506 """ |
501 """ |
|
502 from .AdBlockDialog import AdBlockDialog |
|
503 |
507 if self.__adBlockDialog is None: |
504 if self.__adBlockDialog is None: |
508 from .AdBlockDialog import AdBlockDialog |
505 self.__adBlockDialog = AdBlockDialog(self, parent=parent) |
509 |
|
510 self.__adBlockDialog = AdBlockDialog(self) |
|
511 |
506 |
512 self.__adBlockDialog.show() |
507 self.__adBlockDialog.show() |
513 return self.__adBlockDialog |
508 return self.__adBlockDialog |
514 |
509 |
515 def elementHidingRules(self, url): |
510 def elementHidingRules(self, url): |
609 Public method to show the AdBlock Exceptions dialog. |
604 Public method to show the AdBlock Exceptions dialog. |
610 |
605 |
611 @return reference to the exceptions dialog |
606 @return reference to the exceptions dialog |
612 @rtype AdBlockExceptionsDialog |
607 @rtype AdBlockExceptionsDialog |
613 """ |
608 """ |
|
609 from .AdBlockExceptionsDialog import AdBlockExceptionsDialog |
|
610 |
614 if self.__adBlockExceptionsDialog is None: |
611 if self.__adBlockExceptionsDialog is None: |
615 from .AdBlockExceptionsDialog import AdBlockExceptionsDialog |
|
616 |
|
617 self.__adBlockExceptionsDialog = AdBlockExceptionsDialog() |
612 self.__adBlockExceptionsDialog = AdBlockExceptionsDialog() |
618 |
613 |
619 self.__adBlockExceptionsDialog.load(self.__exceptedHosts) |
614 self.__adBlockExceptionsDialog.load(self.__exceptedHosts) |
620 self.__adBlockExceptionsDialog.show() |
615 self.__adBlockExceptionsDialog.show() |
621 return self.__adBlockExceptionsDialog |
616 return self.__adBlockExceptionsDialog |