24 """ |
24 """ |
25 Class implementing the AdBlock manager. |
25 Class implementing the AdBlock manager. |
26 |
26 |
27 @signal rulesChanged() emitted after some rule has changed |
27 @signal rulesChanged() emitted after some rule has changed |
28 """ |
28 """ |
|
29 rulesChanged = pyqtSignal() |
|
30 |
29 def __init__(self, parent = None): |
31 def __init__(self, parent = None): |
30 """ |
32 """ |
31 Constructor |
33 Constructor |
32 |
34 |
33 @param parent reference to the parent object (QObject) |
35 @param parent reference to the parent object (QObject) |
41 self.__adBlockNetwork = None |
43 self.__adBlockNetwork = None |
42 self.__adBlockPage = None |
44 self.__adBlockPage = None |
43 self.__subscriptions = [] |
45 self.__subscriptions = [] |
44 self.__saveTimer = AutoSaver(self, self.save) |
46 self.__saveTimer = AutoSaver(self, self.save) |
45 |
47 |
46 self.connect(self, SIGNAL("rulesChanged()"), self.__saveTimer.changeOccurred) |
48 self.rulesChanged.connect(self.__saveTimer.changeOccurred) |
47 |
49 |
48 def close(self): |
50 def close(self): |
49 """ |
51 """ |
50 Public method to close the open search engines manager. |
52 Public method to close the open search engines manager. |
51 """ |
53 """ |
158 |
160 |
159 try: |
161 try: |
160 self.__subscriptions.remove(subscription) |
162 self.__subscriptions.remove(subscription) |
161 rulesFileName = subscription.rulesFileName() |
163 rulesFileName = subscription.rulesFileName() |
162 QFile.remove(rulesFileName) |
164 QFile.remove(rulesFileName) |
163 self.emit(SIGNAL("rulesChanged()")) |
165 self.rulesChanged.emit() |
164 except ValueError: |
166 except ValueError: |
165 pass |
167 pass |
166 |
168 |
167 def addSubscription(self, subscription): |
169 def addSubscription(self, subscription): |
168 """ |
170 """ |
173 if subscription is None: |
175 if subscription is None: |
174 return |
176 return |
175 |
177 |
176 self.__subscriptions.append(subscription) |
178 self.__subscriptions.append(subscription) |
177 |
179 |
178 self.connect(subscription, SIGNAL("rulesChanged()"), |
180 subscription.rulesChanged.connect(self.rulesChanged) |
179 self, SIGNAL("rulesChanged()")) |
181 subscription.changed.connect(self.rulesChanged) |
180 self.connect(subscription, SIGNAL("changed()"), |
182 |
181 self, SIGNAL("rulesChanged()")) |
183 self.rulesChanged.emit() |
182 |
|
183 self.emit(SIGNAL("rulesChanged()")) |
|
184 |
184 |
185 def save(self): |
185 def save(self): |
186 """ |
186 """ |
187 Public method to save the AdBlock subscriptions. |
187 Public method to save the AdBlock subscriptions. |
188 """ |
188 """ |
229 if len(subscriptions) == 0: |
229 if len(subscriptions) == 0: |
230 subscriptions = defaultSubscriptions |
230 subscriptions = defaultSubscriptions |
231 for subscription in subscriptions: |
231 for subscription in subscriptions: |
232 url = QUrl.fromEncoded(subscription.encode()) |
232 url = QUrl.fromEncoded(subscription.encode()) |
233 adBlockSubscription = AdBlockSubscription(url, self) |
233 adBlockSubscription = AdBlockSubscription(url, self) |
234 self.connect(adBlockSubscription, SIGNAL("rulesChanged()"), |
234 adBlockSubscription.rulesChanged.connect(self.rulesChanged) |
235 self, SIGNAL("rulesChanged()")) |
235 adBlockSubscription.changed.connect(self.rulesChanged) |
236 self.connect(adBlockSubscription, SIGNAL("changed()"), |
|
237 self, SIGNAL("rulesChanged()")) |
|
238 self.__subscriptions.append(adBlockSubscription) |
236 self.__subscriptions.append(adBlockSubscription) |
239 |
237 |
240 self.__subscriptionsLoaded = True |
238 self.__subscriptionsLoaded = True |
241 |
239 |
242 def showDialog(self): |
240 def showDialog(self): |