67 |
67 |
68 if manager.isEnabled(): |
68 if manager.isEnabled(): |
69 act = menu.addAction( |
69 act = menu.addAction( |
70 UI.PixmapCache.getIcon("adBlockPlusDisabled"), |
70 UI.PixmapCache.getIcon("adBlockPlusDisabled"), |
71 self.tr("Disable AdBlock")) |
71 self.tr("Disable AdBlock")) |
72 act.setData(False) |
72 act.triggered.connect(lambda: self.__enableAdBlock(False)) |
73 act.triggered.connect(lambda: self.__enableAdBlock(act)) |
|
74 else: |
73 else: |
75 act = menu.addAction( |
74 act = menu.addAction( |
76 UI.PixmapCache.getIcon("adBlockPlus"), |
75 UI.PixmapCache.getIcon("adBlockPlus"), |
77 self.tr("Enable AdBlock")) |
76 self.tr("Enable AdBlock")) |
78 act.setData(True) |
77 act.triggered.connect(lambda: self.__enableAdBlock(True)) |
79 act.triggered.connect(lambda: self.__enableAdBlock(act)) |
|
80 menu.addSeparator() |
78 menu.addSeparator() |
81 if manager.isEnabled() and self.__mw.currentBrowser().url().host(): |
79 if manager.isEnabled() and self.__mw.currentBrowser().url().host(): |
82 if self.__isCurrentHostExcepted(): |
80 if self.__isCurrentHostExcepted(): |
83 act = menu.addAction( |
81 act = menu.addAction( |
84 UI.PixmapCache.getIcon("adBlockPlus"), |
82 UI.PixmapCache.getIcon("adBlockPlus"), |
85 self.tr("Remove AdBlock Exception")) |
83 self.tr("Remove AdBlock Exception")) |
86 act.setData(False) |
84 act.triggered.connect(lambda: self.__setException(False)) |
87 act.triggered.connect(lambda: self.__setException(act)) |
|
88 else: |
85 else: |
89 act = menu.addAction( |
86 act = menu.addAction( |
90 UI.PixmapCache.getIcon("adBlockPlusGreen"), |
87 UI.PixmapCache.getIcon("adBlockPlusGreen"), |
91 self.tr("Add AdBlock Exception")) |
88 self.tr("Add AdBlock Exception")) |
92 act.setData(True) |
89 act.triggered.connect(lambda: self.__setException(True)) |
93 act.triggered.connect(lambda: self.__setException(act)) |
|
94 menu.addAction( |
90 menu.addAction( |
95 UI.PixmapCache.getIcon("adBlockPlusGreen"), |
91 UI.PixmapCache.getIcon("adBlockPlusGreen"), |
96 self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) |
92 self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) |
97 menu.addSeparator() |
93 menu.addSeparator() |
98 menu.addAction( |
94 menu.addAction( |
130 """ |
126 """ |
131 menu = QMenu() |
127 menu = QMenu() |
132 self.__createMenu(menu) |
128 self.__createMenu(menu) |
133 menu.exec(pos) |
129 menu.exec(pos) |
134 |
130 |
135 def __enableAdBlock(self, act): |
131 def __enableAdBlock(self, enable): |
136 """ |
132 """ |
137 Private slot to enable or disable AdBlock. |
133 Private slot to enable or disable AdBlock. |
138 |
134 |
139 @param act reference to the action |
135 @param enable flag indicating the desired enable state |
140 @type QAction |
136 @type bool |
141 """ |
137 """ |
142 self.__mw.adBlockManager().setEnabled(act.data()) |
138 self.__mw.adBlockManager().setEnabled(enable) |
143 |
139 |
144 def __isCurrentHostExcepted(self): |
140 def __isCurrentHostExcepted(self): |
145 """ |
141 """ |
146 Private method to check, if the host of the current browser is |
142 Private method to check, if the host of the current browser is |
147 excepted. |
143 excepted. |
169 self.setPixmap( |
165 self.setPixmap( |
170 UI.PixmapCache.getPixmap("adBlockPlusGreen16")) |
166 UI.PixmapCache.getPixmap("adBlockPlusGreen16")) |
171 else: |
167 else: |
172 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16")) |
168 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16")) |
173 |
169 |
174 def __setException(self, act): |
170 def __setException(self, enable): |
175 """ |
171 """ |
176 Private slot to add or remove the current host from the list of |
172 Private slot to add or remove the current host from the list of |
177 exceptions. |
173 exceptions. |
178 |
174 |
179 @param act referenced to the action |
175 @param enable flag indicating to set or remove an exception |
180 @type QAction |
176 @type bool |
181 """ |
177 """ |
182 urlHost = self.__mw.currentBrowser().url().host() |
178 urlHost = self.__mw.currentBrowser().url().host() |
183 if act.data(): |
179 if enable: |
184 self.__mw.adBlockManager().addException(urlHost) |
180 self.__mw.adBlockManager().addException(urlHost) |
185 else: |
181 else: |
186 self.__mw.adBlockManager().removeException(urlHost) |
182 self.__mw.adBlockManager().removeException(urlHost) |
187 self.currentChanged() |
183 self.currentChanged() |
188 |
184 |