eric6/WebBrowser/AdBlock/AdBlockManager.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the AdBlock manager.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 from PyQt5.QtCore import (
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
13 pyqtSignal, QObject, QUrl, QUrlQuery, QFile, QByteArray, QMutex
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 )
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
15 from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInfo
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
16
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
17 from E5Gui import E5MessageBox
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
19 from E5Utilities.E5MutexLocker import E5MutexLocker
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
20
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
21 from .AdBlockSubscription import AdBlockSubscription
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
22 from .AdBlockUrlInterceptor import AdBlockUrlInterceptor
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
23 from .AdBlockMatcher import AdBlockMatcher
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1960
diff changeset
24
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 from Utilities.AutoSaver import AutoSaver
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 import Utilities
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
29
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 class AdBlockManager(QObject):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Class implementing the AdBlock manager.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @signal rulesChanged() emitted after some rule has changed
5726
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
35 @signal requiredSubscriptionLoaded(subscription) emitted to indicate
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
36 loading of a required subscription is finished (AdBlockSubscription)
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
37 @signal enabledChanged(enabled) emitted to indicate a change of the
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
38 enabled state
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
40 rulesChanged = pyqtSignal()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
41 requiredSubscriptionLoaded = pyqtSignal(AdBlockSubscription)
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
42 enabledChanged = pyqtSignal(bool)
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
43
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
44 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
48 @param parent reference to the parent object
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
49 @type QObject
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
51 super(AdBlockManager, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__loaded = False
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
54 self.__subscriptionsLoaded = False
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__enabled = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__adBlockDialog = None
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
57 self.__adBlockExceptionsDialog = None
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__adBlockNetwork = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__adBlockPage = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__subscriptions = []
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
61 self.__exceptedHosts = Preferences.getWebBrowser("AdBlockExceptions")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__saveTimer = AutoSaver(self, self.save)
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
63 self.__limitedEasyList = Preferences.getWebBrowser(
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
64 "AdBlockUseLimitedEasyList")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
66 self.__defaultSubscriptionUrlString = (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
67 "abp:subscribe?location="
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
68 "https://easylist-downloads.adblockplus.org/easylist.txt&"
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
69 "title=EasyList"
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
70 )
6150
20efcd29b237 AdBlock: added the NoCoin list to the defaults and fixed an issue updating subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
71 self.__additionalDefaultSubscriptionUrlStrings = (
20efcd29b237 AdBlock: added the NoCoin list to the defaults and fixed an issue updating subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
72 "abp:subscribe?location=https://raw.githubusercontent.com/"
20efcd29b237 AdBlock: added the NoCoin list to the defaults and fixed an issue updating subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
73 "hoshsadiq/adblock-nocoin-list/master/nocoin.txt&"
20efcd29b237 AdBlock: added the NoCoin list to the defaults and fixed an issue updating subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
74 "title=NoCoin",
20efcd29b237 AdBlock: added the NoCoin list to the defaults and fixed an issue updating subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
75 )
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
76 self.__customSubscriptionUrlString = (
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
77 bytes(self.__customSubscriptionUrl().toEncoded()).decode()
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
78 )
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
79
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
80 self.__mutex = QMutex()
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
81 self.__matcher = AdBlockMatcher(self)
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
82
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
83 self.rulesChanged.connect(self.__saveTimer.changeOccurred)
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
84 self.rulesChanged.connect(self.__rulesChanged)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
85
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
86 self.__interceptor = AdBlockUrlInterceptor(self)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
87
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
88 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
89 WebBrowserWindow.networkManager().installUrlInterceptor(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
90 self.__interceptor)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
91
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
92 def __rulesChanged(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
93 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
94 Private slot handling a change of the AdBlock rules.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
95 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
96 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
97 WebBrowserWindow.mainWindow().reloadUserStyleSheet()
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
98 self.__updateMatcher()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def close(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Public method to close the open search engines manager.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
104 self.__adBlockDialog and self.__adBlockDialog.close()
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
105 (self.__adBlockExceptionsDialog and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
106 self.__adBlockExceptionsDialog.close())
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
107
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.__saveTimer.saveIfNeccessary()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 def isEnabled(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 Public method to check, if blocking ads is enabled.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
114 @return flag indicating the enabled state
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
115 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if not self.__loaded:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.load()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 return self.__enabled
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 def setEnabled(self, enabled):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 Public slot to set the enabled state.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
126 @param enabled flag indicating the enabled state
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
127 @type bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 if self.isEnabled() == enabled:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 from WebBrowser.WebBrowserWindow import WebBrowserWindow
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.__enabled = enabled
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 for mainWindow in WebBrowserWindow.mainWindows():
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1960
diff changeset
135 mainWindow.adBlockIcon().setEnabled(enabled)
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
136 if enabled:
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
137 self.__loadSubscriptions()
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
138
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
139 self.rulesChanged.emit()
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
140 self.enabledChanged.emit(enabled)
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
141
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
142 def block(self, info):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
143 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
144 Public method to check, if a request should be blocked.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
145
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
146 @param info request info object
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
147 @type QWebEngineUrlRequestInfo
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
148 @return flag indicating to block the request
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
149 @rtype bool
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
150 """
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
151 with E5MutexLocker(self.__mutex):
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
152 if not self.isEnabled():
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
153 return False
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
154
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
155 urlString = bytes(info.requestUrl().toEncoded()).decode().lower()
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
156 urlDomain = info.requestUrl().host().lower()
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
157 urlScheme = info.requestUrl().scheme().lower()
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
158
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
159 if (
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
160 not self.canRunOnScheme(urlScheme) or
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
161 not self.__canBeBlocked(info.firstPartyUrl())
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
162 ):
7774
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
163 return False
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
164
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
165 res = False
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
166 blockedRule = self.__matcher.match(info, urlDomain, urlString)
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
167
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
168 if blockedRule:
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
169 res = True
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
170 if (
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
171 info.resourceType() ==
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
172 QWebEngineUrlRequestInfo.ResourceTypeMainFrame
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
173 ):
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
174 url = QUrl("eric:adblock")
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
175 query = QUrlQuery()
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
176 query.addQueryItem("rule", blockedRule.filter())
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
177 query.addQueryItem(
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
178 "subscription", blockedRule.subscription().title())
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
179 url.setQuery(query)
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
180 info.redirect(url)
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
181 else:
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
182 info.block(True)
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
183
9eed155411f0 Changed code to our own context manager type mutex locker class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
184 return res
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
185
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
186 def canRunOnScheme(self, scheme):
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
187 """
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
188 Public method to check, if AdBlock can be performed on the scheme.
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
189
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
190 @param scheme scheme to check
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
191 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
192 @return flag indicating, that AdBlock can be performed
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
193 @rtype bool
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
194 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
195 return scheme not in ["data", "eric", "qthelp", "qrc", "file", "abp"]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 def page(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 Public method to get a reference to the page block object.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
201 @return reference to the page block object
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
202 @rtype AdBlockPage
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 if self.__adBlockPage is None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
205 from .AdBlockPage import AdBlockPage
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.__adBlockPage = AdBlockPage(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 return self.__adBlockPage
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 def __customSubscriptionLocation(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 Private method to generate the path for custom subscriptions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
213 @return URL for custom subscriptions
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
214 @rtype QUrl
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 """
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
216 dataDir = os.path.join(Utilities.getConfigDir(), "web_browser",
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
217 "subscriptions")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 if not os.path.exists(dataDir):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 os.makedirs(dataDir)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 fileName = os.path.join(dataDir, "adblock_subscription_custom")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 return QUrl.fromLocalFile(fileName)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 def __customSubscriptionUrl(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 Private method to generate the URL for custom subscriptions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
227 @return URL for custom subscriptions
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
228 @rtype QUrl
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 location = self.__customSubscriptionLocation()
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
231 encodedUrl = bytes(location.toEncoded()).decode()
414
8c91e942d2da Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 168
diff changeset
232 url = QUrl("abp:subscribe?location={0}&title={1}".format(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
233 encodedUrl, self.tr("Custom Rules")))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 return url
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 def customRules(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 Public method to get a subscription for custom rules.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
240 @return subscription object for custom rules
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
241 @rtype AdBlockSubscription
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 location = self.__customSubscriptionLocation()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 for subscription in self.__subscriptions:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 if subscription.location() == location:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 return subscription
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 url = self.__customSubscriptionUrl()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
249 customAdBlockSubscription = AdBlockSubscription(url, True, self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 self.addSubscription(customAdBlockSubscription)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 return customAdBlockSubscription
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 def subscriptions(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 Public method to get all subscriptions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
257 @return list of subscriptions
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
258 @rtype list of AdBlockSubscription
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 if not self.__loaded:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 self.load()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 return self.__subscriptions[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
265 def subscription(self, location):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
266 """
2763
e4794166ad70 Fixed a serious typo.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
267 Public method to get a subscription based on its location.
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
268
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
269 @param location location of the subscription to search for
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
270 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
271 @return subscription or None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
272 @rtype AdBlockSubscription
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
273 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
274 if location != "":
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
275 for subscription in self.__subscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
276 if subscription.location().toString() == location:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
277 return subscription
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
278
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
279 return None
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
280
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
281 def updateAllSubscriptions(self):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
282 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
283 Public method to update all subscriptions.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
284 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
285 for subscription in self.__subscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
286 subscription.updateNow()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
287
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
288 def removeSubscription(self, subscription, emitSignal=True):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 Public method to remove an AdBlock subscription.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
292 @param subscription AdBlock subscription to be removed
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
293 @type AdBlockSubscription
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
294 @param emitSignal flag indicating to send a signal
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
295 @type bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 if subscription is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
300 if subscription.url().toString().startswith(
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
301 (self.__defaultSubscriptionUrlString,
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
302 self.__customSubscriptionUrlString)):
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
303 return
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
304
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.__subscriptions.remove(subscription)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 rulesFileName = subscription.rulesFileName()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 QFile.remove(rulesFileName)
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
309 requiresSubscriptions = self.getRequiresSubscriptions(subscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
310 for requiresSubscription in requiresSubscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
311 self.removeSubscription(requiresSubscription, False)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
312 if emitSignal:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
313 self.rulesChanged.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 except ValueError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 pass
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
317 def addSubscriptionFromUrl(self, url):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
318 """
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4860
diff changeset
319 Public method to ad an AdBlock subscription given the abp URL.
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
320
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
321 @param url URL to subscribe an AdBlock subscription
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
322 @type QUrl
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
323 @return flag indicating success
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
324 @rtype bool
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
325 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
326 if url.path() != "subscribe":
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
327 return False
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
328
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
329 title = QUrl.fromPercentEncoding(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
330 QByteArray(QUrlQuery(url).queryItemValue("title").encode()))
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
331 if not title:
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
332 return False
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
333
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
334 res = E5MessageBox.yesNo(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
335 None,
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
336 self.tr("Subscribe?"),
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
337 self.tr(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
338 """<p>Subscribe to this AdBlock subscription?</p>"""
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
339 """<p>{0}</p>""").format(title))
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
340 if res:
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
341 from .AdBlockSubscription import AdBlockSubscription
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
342 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
343
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
344 dlg = WebBrowserWindow.adBlockManager().showDialog()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
345 subscription = AdBlockSubscription(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
346 url, False,
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
347 WebBrowserWindow.adBlockManager())
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
348 WebBrowserWindow.adBlockManager().addSubscription(subscription)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
349 dlg.addSubscription(subscription, False)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
350 dlg.setFocus()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
351 dlg.raise_()
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
352
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
353 return res
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
354
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 def addSubscription(self, subscription):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 Public method to add an AdBlock subscription.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
359 @param subscription AdBlock subscription to be added
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
360 @type AdBlockSubscription
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 if subscription is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
365 self.__subscriptions.insert(-1, subscription)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
367 subscription.rulesChanged.connect(self.rulesChanged)
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
368 subscription.changed.connect(self.rulesChanged)
1971
a68d78702c98 Fixed an issue remembering the enabled state of AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1970
diff changeset
369 subscription.enabledChanged.connect(self.rulesChanged)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
371 self.rulesChanged.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 def save(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 Public method to save the AdBlock subscriptions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 if not self.__loaded:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
380 Preferences.setWebBrowser("AdBlockEnabled", self.__enabled)
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
381 if self.__subscriptionsLoaded:
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
382 subscriptions = []
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
383 requiresSubscriptions = []
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
384 # intermediate store for subscription requiring others
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
385 for subscription in self.__subscriptions:
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
386 if subscription is None:
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
387 continue
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
388 urlString = bytes(subscription.url().toEncoded()).decode()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
389 if "requiresLocation" in urlString:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
390 requiresSubscriptions.append(urlString)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
391 else:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
392 subscriptions.append(urlString)
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
393 subscription.saveRules()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
394 for subscription in requiresSubscriptions:
2016
2bbc81fcce4a Fixed a few PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
395 subscriptions.insert(-1, subscription) # custom should be last
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
396 Preferences.setWebBrowser("AdBlockSubscriptions", subscriptions)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 def load(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 Public method to load the AdBlock subscriptions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 if self.__loaded:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 self.__loaded = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
407 self.__enabled = Preferences.getWebBrowser("AdBlockEnabled")
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
408 if self.__enabled:
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
409 self.__loadSubscriptions()
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
410
134
c2dd2bf92ece Fixed a few issues with the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 132
diff changeset
411 def __loadSubscriptions(self):
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
412 """
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
413 Private method to load the set of subscriptions.
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
414 """
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
415 if self.__subscriptionsLoaded:
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
416 return
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
418 subscriptions = Preferences.getWebBrowser("AdBlockSubscriptions")
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
419 if subscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
420 for subscription in subscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
421 if subscription.startswith(self.__customSubscriptionUrlString):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
422 break
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
423 else:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
424 subscriptions.append(self.__customSubscriptionUrlString)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
425 else:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
426 subscriptions = (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
427 [self.__defaultSubscriptionUrlString] +
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
428 self.__additionalDefaultSubscriptionUrlStrings +
6160
70441ce79d5a AdBlockManager: Changed a line of code slightly to make it (hopefully) compatible with Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6150
diff changeset
429 [self.__customSubscriptionUrlString]
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
430 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 for subscription in subscriptions:
4331
711e7c35a49b Changed code to make eric compatible to PyQt 5.5 (QByteArry issue).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
432 url = QUrl.fromEncoded(subscription.encode("utf-8"))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3000
diff changeset
433 adBlockSubscription = AdBlockSubscription(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3000
diff changeset
434 url,
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
435 subscription.startswith(self.__customSubscriptionUrlString),
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
436 self,
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
437 subscription.startswith(self.__defaultSubscriptionUrlString))
483
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
438 adBlockSubscription.rulesChanged.connect(self.rulesChanged)
ca7d8599a575 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 414
diff changeset
439 adBlockSubscription.changed.connect(self.rulesChanged)
1971
a68d78702c98 Fixed an issue remembering the enabled state of AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1970
diff changeset
440 adBlockSubscription.enabledChanged.connect(self.rulesChanged)
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
441 adBlockSubscription.rulesEnabledChanged.connect(
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
442 self.__updateMatcher)
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
443 adBlockSubscription.rulesEnabledChanged.connect(
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
444 self.__saveTimer.changeOccurred)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 self.__subscriptions.append(adBlockSubscription)
132
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
446
2c870b5b485a Changed AdBlockManager to load subscriptions only when it is enabled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
447 self.__subscriptionsLoaded = True
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
448
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
449 self.__updateMatcher()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
451 def loadRequiredSubscription(self, location, title):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
452 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
453 Public method to load a subscription required by another one.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
454
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
455 @param location location of the required subscription
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
456 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
457 @param title title of the required subscription
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
458 @type str
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
459 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
460 # Step 1: check, if the subscription is in the list of subscriptions
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
461 urlString = "abp:subscribe?location={0}&title={1}".format(
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
462 location, title)
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
463 for subscription in self.__subscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
464 if subscription.url().toString().startswith(urlString):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
465 # We found it!
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
466 return
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
467
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
468 # Step 2: if it is not, get it
4331
711e7c35a49b Changed code to make eric compatible to PyQt 5.5 (QByteArry issue).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
469 url = QUrl.fromEncoded(urlString.encode("utf-8"))
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
470 adBlockSubscription = AdBlockSubscription(url, False, self)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
471 self.addSubscription(adBlockSubscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
472 self.requiredSubscriptionLoaded.emit(adBlockSubscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
473
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
474 def getRequiresSubscriptions(self, subscription):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
475 """
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
476 Public method to get a list of subscriptions, that require the given
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2763
diff changeset
477 one.
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
478
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
479 @param subscription subscription to check for
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
480 @type AdBlockSubscription
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
481 @return list of subscription requiring the given one
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
482 @rtype list of AdBlockSubscription
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
483 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
484 subscriptions = []
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
485 location = subscription.location().toString()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
486 for subscription in self.__subscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
487 if subscription.requiresLocation() == location:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
488 subscriptions.append(subscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
489
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
490 return subscriptions
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
491
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 def showDialog(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 Public slot to show the AdBlock subscription management dialog.
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
495
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
496 @return reference to the dialog
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
497 @rtype AdBlockDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 if self.__adBlockDialog is None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
500 from .AdBlockDialog import AdBlockDialog
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
501 self.__adBlockDialog = AdBlockDialog(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 self.__adBlockDialog.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 return self.__adBlockDialog
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
505
4990
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
506 def elementHidingRules(self, url):
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
507 """
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
508 Public method to get the element hiding rules.
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
509
4990
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
510
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
511 @param url URL to get hiding rules for
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
512 @type QUrl
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
513 @return element hiding rules
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
514 @rtype str
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
515 """
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
516 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
517 not self.isEnabled() or
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
518 not self.canRunOnScheme(url.scheme()) or
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
519 not self.__canBeBlocked(url)
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
520 ):
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
521 return ""
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
522
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
523 return self.__matcher.elementHidingRules()
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
524
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
525 def elementHidingRulesForDomain(self, url):
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
526 """
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
527 Public method to get the element hiding rules for a domain.
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
528
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
529 @param url URL to get hiding rules for
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
530 @type QUrl
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
531 @return element hiding rules
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
532 @rtype str
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
533 """
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
534 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
535 not self.isEnabled() or
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
536 not self.canRunOnScheme(url.scheme()) or
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
537 not self.__canBeBlocked(url)
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
538 ):
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
539 return ""
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
540
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
541 return self.__matcher.elementHidingRulesForDomain(url.host())
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
542
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
543 def exceptions(self):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
544 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
545 Public method to get a list of excepted hosts.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
546
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
547 @return list of excepted hosts
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
548 @rtype list of str
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
549 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
550 return self.__exceptedHosts
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
551
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
552 def setExceptions(self, hosts):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
553 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
554 Public method to set the list of excepted hosts.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
555
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
556 @param hosts list of excepted hosts
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
557 @type list of str
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
558 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
559 self.__exceptedHosts = [host.lower() for host in hosts]
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
560 Preferences.setWebBrowser("AdBlockExceptions", self.__exceptedHosts)
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
561
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
562 def addException(self, host):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
563 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
564 Public method to add an exception.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
565
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
566 @param host to be excepted
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
567 @type str
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
568 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
569 host = host.lower()
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
570 if host and host not in self.__exceptedHosts:
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
571 self.__exceptedHosts.append(host)
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
572 Preferences.setWebBrowser(
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
573 "AdBlockExceptions", self.__exceptedHosts)
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
574
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
575 def removeException(self, host):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
576 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
577 Public method to remove an exception.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
578
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
579 @param host to be removed from the list of exceptions
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
580 @type str
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
581 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
582 host = host.lower()
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
583 if host in self.__exceptedHosts:
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
584 self.__exceptedHosts.remove(host)
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
585 Preferences.setWebBrowser(
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
586 "AdBlockExceptions", self.__exceptedHosts)
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
587
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
588 def isHostExcepted(self, host):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
589 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
590 Public slot to check, if a host is excepted.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
591
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
592 @param host host to check
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
593 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
594 @return flag indicating an exception
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
595 @rtype bool
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
596 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
597 host = host.lower()
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
598 return host in self.__exceptedHosts
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
599
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
600 def showExceptionsDialog(self):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
601 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
602 Public method to show the AdBlock Exceptions dialog.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
603
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
604 @return reference to the exceptions dialog
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
605 @rtype AdBlockExceptionsDialog
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
606 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
607 if self.__adBlockExceptionsDialog is None:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
608 from .AdBlockExceptionsDialog import AdBlockExceptionsDialog
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
609 self.__adBlockExceptionsDialog = AdBlockExceptionsDialog()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
610
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
611 self.__adBlockExceptionsDialog.load(self.__exceptedHosts)
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
612 self.__adBlockExceptionsDialog.show()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1971
diff changeset
613 return self.__adBlockExceptionsDialog
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
614
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
615 def useLimitedEasyList(self):
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
616 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
617 Public method to test, if limited EasyList rules shall be used.
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
618
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
619 @return flag indicating limited EasyList rules
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
620 @rtype bool
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
621 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
622 return self.__limitedEasyList
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
623
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
624 def setUseLimitedEasyList(self, limited):
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
625 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
626 Public method to set the limited EasyList flag.
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
627
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
628 @param limited flag indicating to use limited EasyList
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
629 @type bool
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
630 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
631 self.__limitedEasyList = limited
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
632
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
633 for subscription in self.__subscriptions:
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
634 if subscription.url().toString().startswith(
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
635 self.__defaultSubscriptionUrlString):
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
636 subscription.updateNow()
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
637
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
638 Preferences.setWebBrowser("AdBlockUseLimitedEasyList", limited)
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
639
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
640 def getDefaultSubscriptionUrl(self):
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
641 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
642 Public method to get the default subscription URL.
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
643
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
644 @return default subscription URL
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
645 @rtype str
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
646 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
647 return self.__defaultSubscriptionUrlString
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
648
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
649 def __updateMatcher(self):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
650 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
651 Private slot to update the adblock matcher.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
652 """
6326
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
653 from WebBrowser.WebBrowserWindow import WebBrowserWindow
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
654 WebBrowserWindow.networkManager().removeUrlInterceptor(
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
655 self.__interceptor)
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
656
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
657 if self.__enabled:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
658 self.__matcher.update()
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
659 else:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
660 self.__matcher.clear()
6326
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
661
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
662 WebBrowserWindow.networkManager().installUrlInterceptor(
5ef9456a0cbe WebBrowser: Some little changes to increase stability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6160
diff changeset
663 self.__interceptor)
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
664
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
665 def __canBeBlocked(self, url):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
666 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
667 Private method to check, if the given URL could be blocked (i.e. is
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
668 not whitelisted).
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
669
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
670 @param url URL to be checked
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
671 @type QUrl
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
672 @return flag indicating that the given URL can be blocked
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
673 @rtype bool
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
674 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
675 return not self.__matcher.adBlockDisabledForUrl(url)

eric ide

mercurial