48 self.__exceptedHosts = Preferences.getHelp("AdBlockExceptions") |
48 self.__exceptedHosts = Preferences.getHelp("AdBlockExceptions") |
49 self.__saveTimer = AutoSaver(self, self.save) |
49 self.__saveTimer = AutoSaver(self, self.save) |
50 |
50 |
51 self.__defaultSubscriptionUrlString = \ |
51 self.__defaultSubscriptionUrlString = \ |
52 "abp:subscribe?location=" \ |
52 "abp:subscribe?location=" \ |
53 "https://easylist-downloads.adblockplus.org/easylist.txt&title=EasyList" |
53 "https://easylist-downloads.adblockplus.org/easylist.txt&"\ |
|
54 "title=EasyList" |
54 self.__customSubscriptionUrlString = \ |
55 self.__customSubscriptionUrlString = \ |
55 bytes(self.__customSubscriptionUrl().toEncoded()).decode() |
56 bytes(self.__customSubscriptionUrl().toEncoded()).decode() |
56 |
57 |
57 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
58 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
58 |
59 |
59 def close(self): |
60 def close(self): |
60 """ |
61 """ |
61 Public method to close the open search engines manager. |
62 Public method to close the open search engines manager. |
62 """ |
63 """ |
63 self.__adBlockDialog and self.__adBlockDialog.close() |
64 self.__adBlockDialog and self.__adBlockDialog.close() |
64 self.__adBlockExceptionsDialog and self.__adBlockExceptionsDialog.close() |
65 self.__adBlockExceptionsDialog and \ |
|
66 self.__adBlockExceptionsDialog.close() |
65 |
67 |
66 self.__saveTimer.saveIfNeccessary() |
68 self.__saveTimer.saveIfNeccessary() |
67 |
69 |
68 def isEnabled(self): |
70 def isEnabled(self): |
69 """ |
71 """ |
119 """ |
121 """ |
120 Private method to generate the path for custom subscriptions. |
122 Private method to generate the path for custom subscriptions. |
121 |
123 |
122 @return URL for custom subscriptions (QUrl) |
124 @return URL for custom subscriptions (QUrl) |
123 """ |
125 """ |
124 dataDir = os.path.join(Utilities.getConfigDir(), "browser", "subscriptions") |
126 dataDir = os.path.join(Utilities.getConfigDir(), "browser", |
|
127 "subscriptions") |
125 if not os.path.exists(dataDir): |
128 if not os.path.exists(dataDir): |
126 os.makedirs(dataDir) |
129 os.makedirs(dataDir) |
127 fileName = os.path.join(dataDir, "adblock_subscription_custom") |
130 fileName = os.path.join(dataDir, "adblock_subscription_custom") |
128 return QUrl.fromLocalFile(fileName) |
131 return QUrl.fromLocalFile(fileName) |
129 |
132 |
189 |
192 |
190 def removeSubscription(self, subscription, emitSignal=True): |
193 def removeSubscription(self, subscription, emitSignal=True): |
191 """ |
194 """ |
192 Public method to remove an AdBlock subscription. |
195 Public method to remove an AdBlock subscription. |
193 |
196 |
194 @param subscription AdBlock subscription to be removed (AdBlockSubscription) |
197 @param subscription AdBlock subscription to be removed |
|
198 (AdBlockSubscription) |
195 @param emitSignal flag indicating to send a signal (boolean) |
199 @param emitSignal flag indicating to send a signal (boolean) |
196 """ |
200 """ |
197 if subscription is None: |
201 if subscription is None: |
198 return |
202 return |
199 |
203 |
200 if subscription.url().toString().startswith( |
204 if subscription.url().toString().startswith( |
201 (self.__defaultSubscriptionUrlString, self.__customSubscriptionUrlString)): |
205 (self.__defaultSubscriptionUrlString, |
|
206 self.__customSubscriptionUrlString)): |
202 return |
207 return |
203 |
208 |
204 try: |
209 try: |
205 self.__subscriptions.remove(subscription) |
210 self.__subscriptions.remove(subscription) |
206 rulesFileName = subscription.rulesFileName() |
211 rulesFileName = subscription.rulesFileName() |
215 |
220 |
216 def addSubscription(self, subscription): |
221 def addSubscription(self, subscription): |
217 """ |
222 """ |
218 Public method to add an AdBlock subscription. |
223 Public method to add an AdBlock subscription. |
219 |
224 |
220 @param subscription AdBlock subscription to be added (AdBlockSubscription) |
225 @param subscription AdBlock subscription to be added |
|
226 (AdBlockSubscription) |
221 """ |
227 """ |
222 if subscription is None: |
228 if subscription is None: |
223 return |
229 return |
224 |
230 |
225 self.__subscriptions.insert(-1, subscription) |
231 self.__subscriptions.insert(-1, subscription) |
276 return |
282 return |
277 |
283 |
278 subscriptions = Preferences.getHelp("AdBlockSubscriptions") |
284 subscriptions = Preferences.getHelp("AdBlockSubscriptions") |
279 if subscriptions: |
285 if subscriptions: |
280 for subscription in subscriptions: |
286 for subscription in subscriptions: |
281 if subscription.startswith(self.__defaultSubscriptionUrlString): |
287 if subscription.startswith( |
|
288 self.__defaultSubscriptionUrlString): |
282 break |
289 break |
283 else: |
290 else: |
284 subscriptions.insert(0, self.__defaultSubscriptionUrlString) |
291 subscriptions.insert(0, self.__defaultSubscriptionUrlString) |
285 for subscription in subscriptions: |
292 for subscription in subscriptions: |
286 if subscription.startswith(self.__customSubscriptionUrlString): |
293 if subscription.startswith(self.__customSubscriptionUrlString): |
309 |
316 |
310 @param location location of the required subscription (string) |
317 @param location location of the required subscription (string) |
311 @param title title of the required subscription (string) |
318 @param title title of the required subscription (string) |
312 """ |
319 """ |
313 # Step 1: check, if the subscription is in the list of subscriptions |
320 # Step 1: check, if the subscription is in the list of subscriptions |
314 urlString = "abp:subscribe?location={0}&title={1}".format(location, title) |
321 urlString = "abp:subscribe?location={0}&title={1}".format( |
|
322 location, title) |
315 for subscription in self.__subscriptions: |
323 for subscription in self.__subscriptions: |
316 if subscription.url().toString().startswith(urlString): |
324 if subscription.url().toString().startswith(urlString): |
317 # We found it! |
325 # We found it! |
318 return |
326 return |
319 |
327 |
323 self.addSubscription(adBlockSubscription) |
331 self.addSubscription(adBlockSubscription) |
324 self.requiredSubscriptionLoaded.emit(adBlockSubscription) |
332 self.requiredSubscriptionLoaded.emit(adBlockSubscription) |
325 |
333 |
326 def getRequiresSubscriptions(self, subscription): |
334 def getRequiresSubscriptions(self, subscription): |
327 """ |
335 """ |
328 Public method to get a list of subscriptions, that require the given one. |
336 Public method to get a list of subscriptions, that require the given |
|
337 one. |
329 |
338 |
330 @param subscription subscription to check for (AdBlockSubscription) |
339 @param subscription subscription to check for (AdBlockSubscription) |
331 @return list of subscription requiring the given one (list of AdBlockSubscription) |
340 @return list of subscription requiring the given one (list of |
|
341 AdBlockSubscription) |
332 """ |
342 """ |
333 subscriptions = [] |
343 subscriptions = [] |
334 location = subscription.location().toString() |
344 location = subscription.location().toString() |
335 for subscription in self.__subscriptions: |
345 for subscription in self.__subscriptions: |
336 if subscription.requiresLocation() == location: |
346 if subscription.requiresLocation() == location: |