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