25 Class implementing the AdBlock configuration dialog. |
25 Class implementing the AdBlock configuration dialog. |
26 """ |
26 """ |
27 def __init__(self, parent=None): |
27 def __init__(self, parent=None): |
28 """ |
28 """ |
29 Constructor |
29 Constructor |
|
30 |
|
31 @param parent reference to the parent object (QWidget) |
30 """ |
32 """ |
31 super(AdBlockDialog, self).__init__(parent) |
33 super(AdBlockDialog, self).__init__(parent) |
32 self.setupUi(self) |
34 self.setupUi(self) |
33 |
35 |
34 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus48.png")) |
36 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus48.png")) |
76 tree = AdBlockTreeWidget(subscription, self.subscriptionsTabWidget) |
78 tree = AdBlockTreeWidget(subscription, self.subscriptionsTabWidget) |
77 if subscription.isEnabled(): |
79 if subscription.isEnabled(): |
78 icon = UI.PixmapCache.getIcon("adBlockPlus.png") |
80 icon = UI.PixmapCache.getIcon("adBlockPlus.png") |
79 else: |
81 else: |
80 icon = UI.PixmapCache.getIcon("adBlockPlusDisabled.png") |
82 icon = UI.PixmapCache.getIcon("adBlockPlusDisabled.png") |
81 self.subscriptionsTabWidget.addTab(tree, icon, subscription.title()) |
83 self.subscriptionsTabWidget.addTab( |
|
84 tree, icon, subscription.title()) |
82 |
85 |
83 self.__loaded = True |
86 self.__loaded = True |
84 QCoreApplication.processEvents() |
87 QCoreApplication.processEvents() |
85 |
88 |
86 QTimer.singleShot(50, self.__loadSubscriptions) |
89 QTimer.singleShot(50, self.__loadSubscriptions) |
94 @param refresh flag indicating to refresh the tree (boolean) |
97 @param refresh flag indicating to refresh the tree (boolean) |
95 """ |
98 """ |
96 from .AdBlockTreeWidget import AdBlockTreeWidget |
99 from .AdBlockTreeWidget import AdBlockTreeWidget |
97 tree = AdBlockTreeWidget(subscription, self.subscriptionsTabWidget) |
100 tree = AdBlockTreeWidget(subscription, self.subscriptionsTabWidget) |
98 index = self.subscriptionsTabWidget.insertTab( |
101 index = self.subscriptionsTabWidget.insertTab( |
99 self.subscriptionsTabWidget.count() - 1, tree, subscription.title()) |
102 self.subscriptionsTabWidget.count() - 1, tree, |
|
103 subscription.title()) |
100 self.subscriptionsTabWidget.setCurrentIndex(index) |
104 self.subscriptionsTabWidget.setCurrentIndex(index) |
101 QCoreApplication.processEvents() |
105 QCoreApplication.processEvents() |
102 if refresh: |
106 if refresh: |
103 tree.refresh() |
107 tree.refresh() |
104 self.__setSubscriptionEnabled(subscription, True) |
108 self.__setSubscriptionEnabled(subscription, True) |
120 menu.addAction(self.trUtf8("Add Rule"), self.__addCustomRule)\ |
124 menu.addAction(self.trUtf8("Add Rule"), self.__addCustomRule)\ |
121 .setEnabled(subscriptionEditable) |
125 .setEnabled(subscriptionEditable) |
122 menu.addAction(self.trUtf8("Remove Rule"), self.__removeCustomRule)\ |
126 menu.addAction(self.trUtf8("Remove Rule"), self.__removeCustomRule)\ |
123 .setEnabled(subscriptionEditable) |
127 .setEnabled(subscriptionEditable) |
124 menu.addSeparator() |
128 menu.addSeparator() |
125 menu.addAction(self.trUtf8("Browse Subscriptions..."), self.__browseSubscriptions) |
129 menu.addAction( |
126 menu.addAction(self.trUtf8("Remove Subscription"), self.__removeSubscription)\ |
130 self.trUtf8("Browse Subscriptions..."), self.__browseSubscriptions) |
|
131 menu.addAction( |
|
132 self.trUtf8("Remove Subscription"), self.__removeSubscription)\ |
127 .setEnabled(subscriptionRemovable) |
133 .setEnabled(subscriptionRemovable) |
128 if self.__currentSubscription: |
134 if self.__currentSubscription: |
129 menu.addSeparator() |
135 menu.addSeparator() |
130 if subscriptionEnabled: |
136 if subscriptionEnabled: |
131 txt = self.trUtf8("Disable Subscription") |
137 txt = self.trUtf8("Disable Subscription") |
132 else: |
138 else: |
133 txt = self.trUtf8("Enable Subscription") |
139 txt = self.trUtf8("Enable Subscription") |
134 menu.addAction(txt, self.__switchSubscriptionEnabled) |
140 menu.addAction(txt, self.__switchSubscriptionEnabled) |
135 menu.addSeparator() |
141 menu.addSeparator() |
136 menu.addAction(self.trUtf8("Update Subscription"), self.__updateSubscription)\ |
142 menu.addAction( |
|
143 self.trUtf8("Update Subscription"), self.__updateSubscription)\ |
137 .setEnabled(not subscriptionEditable) |
144 .setEnabled(not subscriptionEditable) |
138 menu.addAction(self.trUtf8("Update All Subscriptions"), |
145 menu.addAction(self.trUtf8("Update All Subscriptions"), |
139 self.__updateAllSubscriptions) |
146 self.__updateAllSubscriptions) |
140 menu.addSeparator() |
147 menu.addSeparator() |
141 menu.addAction(self.trUtf8("Learn more about writing rules..."), |
148 menu.addAction(self.trUtf8("Learn more about writing rules..."), |
201 requiresSubscriptions = \ |
208 requiresSubscriptions = \ |
202 self.__manager.getRequiresSubscriptions(self.__currentSubscription) |
209 self.__manager.getRequiresSubscriptions(self.__currentSubscription) |
203 for subscription in requiresSubscriptions: |
210 for subscription in requiresSubscriptions: |
204 requiresTitles.append(subscription.title()) |
211 requiresTitles.append(subscription.title()) |
205 if requiresTitles: |
212 if requiresTitles: |
206 message = self.trUtf8("<p>Do you really want to remove subscription" |
213 message = self.trUtf8( |
|
214 "<p>Do you really want to remove subscription" |
207 " <b>{0}</b> and all subscriptions requiring it?</p>" |
215 " <b>{0}</b> and all subscriptions requiring it?</p>" |
208 "<ul><li>{1}</li></ul>").format( |
216 "<ul><li>{1}</li></ul>").format( |
209 self.__currentSubscription.title(), |
217 self.__currentSubscription.title(), |
210 "</li><li>".join(requiresTitles)) |
218 "</li><li>".join(requiresTitles)) |
211 else: |
219 else: |
212 message = self.trUtf8("<p>Do you really want to remove subscription" |
220 message = self.trUtf8( |
|
221 "<p>Do you really want to remove subscription" |
213 " <b>{0}</b>?</p>").format(self.__currentSubscription.title()) |
222 " <b>{0}</b>?</p>").format(self.__currentSubscription.title()) |
214 res = E5MessageBox.yesNo(self, |
223 res = E5MessageBox.yesNo(self, |
215 self.trUtf8("Remove Subscription"), |
224 self.trUtf8("Remove Subscription"), |
216 message) |
225 message) |
217 |
226 |
227 self.subscriptionsTabWidget.indexOf(tree)) |
236 self.subscriptionsTabWidget.indexOf(tree)) |
228 self.__manager.removeSubscription(removeSubscription) |
237 self.__manager.removeSubscription(removeSubscription) |
229 |
238 |
230 def __switchSubscriptionEnabled(self): |
239 def __switchSubscriptionEnabled(self): |
231 """ |
240 """ |
232 Private slot to switch the enabled state of the selected subscription |
241 Private slot to switch the enabled state of the selected subscription. |
233 """ |
242 """ |
234 newState = not self.__currentSubscription.isEnabled() |
243 newState = not self.__currentSubscription.isEnabled() |
235 self.__setSubscriptionEnabled(self.__currentSubscription, newState) |
244 self.__setSubscriptionEnabled(self.__currentSubscription, newState) |
236 |
245 |
237 def __setSubscriptionEnabled(self, subscription, enable): |
246 def __setSubscriptionEnabled(self, subscription, enable): |
238 """ |
247 """ |
239 Private slot to set the enabled state of a subscription. |
248 Private slot to set the enabled state of a subscription. |
240 |
249 |
241 @param subscription subscription to set the state for (AdBlockSubscription) |
250 @param subscription subscription to set the state for |
|
251 (AdBlockSubscription) |
242 @param enable state to set to (boolean) |
252 @param enable state to set to (boolean) |
243 """ |
253 """ |
244 if enable: |
254 if enable: |
245 # enable required one as well |
255 # enable required one as well |
246 sub = self.__manager.subscription(subscription.requiresLocation()) |
256 sub = self.__manager.subscription(subscription.requiresLocation()) |
282 Private slot handling the selection of another tab. |
292 Private slot handling the selection of another tab. |
283 |
293 |
284 @param index index of the new current tab (integer) |
294 @param index index of the new current tab (integer) |
285 """ |
295 """ |
286 if index != -1: |
296 if index != -1: |
287 self.__currentTreeWidget = self.subscriptionsTabWidget.widget(index) |
297 self.__currentTreeWidget = \ |
288 self.__currentSubscription = self.__currentTreeWidget.subscription() |
298 self.subscriptionsTabWidget.widget(index) |
|
299 self.__currentSubscription = \ |
|
300 self.__currentTreeWidget.subscription() |
289 |
301 |
290 @pyqtSlot(str) |
302 @pyqtSlot(str) |
291 def on_searchEdit_textChanged(self, filter): |
303 def on_searchEdit_textChanged(self, filter): |
292 """ |
304 """ |
293 Private slot to set a new filter on the current widget. |
305 Private slot to set a new filter on the current widget. |