51 self.currentChanged() |
51 self.currentChanged() |
52 else: |
52 else: |
53 self.setPixmap( |
53 self.setPixmap( |
54 UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) |
54 UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) |
55 |
55 |
56 def __createMenu(self, menu=None): |
56 def __createMenu(self, menu): |
57 """ |
57 """ |
58 Private slot to create the context menu. |
58 Private slot to create the context menu. |
59 |
59 |
60 @param menu parent menu (QMenu) |
60 @param menu parent menu |
61 """ |
61 @type QMenu |
62 if menu is None: |
62 """ |
63 menu = self.sender() |
|
64 if menu is None: |
|
65 return |
|
66 |
|
67 menu.clear() |
63 menu.clear() |
68 |
64 |
69 import Helpviewer.HelpWindow |
65 import Helpviewer.HelpWindow |
70 manager = Helpviewer.HelpWindow.HelpWindow.adBlockManager() |
66 manager = Helpviewer.HelpWindow.HelpWindow.adBlockManager() |
71 |
67 |
72 if manager.isEnabled(): |
68 if manager.isEnabled(): |
73 menu.addAction( |
69 act = menu.addAction( |
74 UI.PixmapCache.getIcon("adBlockPlusDisabled.png"), |
70 UI.PixmapCache.getIcon("adBlockPlusDisabled.png"), |
75 self.tr("Disable AdBlock"), |
71 self.tr("Disable AdBlock")) |
76 self.__enableAdBlock).setData(False) |
72 act.setData(False) |
77 else: |
73 act.triggered.connect(lambda: self.__enableAdBlock(act)) |
78 menu.addAction( |
74 else: |
|
75 act = menu.addAction( |
79 UI.PixmapCache.getIcon("adBlockPlus.png"), |
76 UI.PixmapCache.getIcon("adBlockPlus.png"), |
80 self.tr("Enable AdBlock"), |
77 self.tr("Enable AdBlock")) |
81 self.__enableAdBlock).setData(True) |
78 act.setData(True) |
|
79 act.triggered.connect(lambda: self.__enableAdBlock(act)) |
82 menu.addSeparator() |
80 menu.addSeparator() |
83 if manager.isEnabled() and \ |
81 if manager.isEnabled() and \ |
84 self.__mw.currentBrowser().page().url().host(): |
82 self.__mw.currentBrowser().page().url().host(): |
85 if self.__isCurrentHostExcepted(): |
83 if self.__isCurrentHostExcepted(): |
86 menu.addAction( |
84 act = menu.addAction( |
87 UI.PixmapCache.getIcon("adBlockPlus.png"), |
85 UI.PixmapCache.getIcon("adBlockPlus.png"), |
88 self.tr("Remove AdBlock Exception"), |
86 self.tr("Remove AdBlock Exception")) |
89 self.__setException).setData(False) |
87 act.setData(False) |
|
88 act.triggered.connect(lambda: self.__setException(act)) |
90 else: |
89 else: |
91 menu.addAction( |
90 act = menu.addAction( |
92 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
91 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
93 self.tr("Add AdBlock Exception"), |
92 self.tr("Add AdBlock Exception")) |
94 self.__setException).setData(True) |
93 act.setData(True) |
|
94 act.triggered.connect(lambda: self.__setException(act)) |
95 menu.addAction( |
95 menu.addAction( |
96 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
96 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
97 self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) |
97 self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) |
98 menu.addSeparator() |
98 menu.addSeparator() |
99 menu.addAction( |
99 menu.addAction( |
108 .setEnabled(False) |
108 .setEnabled(False) |
109 for entry in entries: |
109 for entry in entries: |
110 address = entry.urlString()[-55:] |
110 address = entry.urlString()[-55:] |
111 actionText = self.tr("{0} with ({1})").format( |
111 actionText = self.tr("{0} with ({1})").format( |
112 address, entry.rule.filter()).replace("&", "&&") |
112 address, entry.rule.filter()).replace("&", "&&") |
113 act = menu.addAction(actionText, manager.showRule) |
113 act = menu.addAction(actionText) |
114 act.setData(entry.rule) |
114 act.setData(entry.rule) |
|
115 act.triggered.connect(lambda: manager.showRule(act)) |
115 else: |
116 else: |
116 menu.addAction(self.tr("No content blocked")).setEnabled(False) |
117 menu.addAction(self.tr("No content blocked")).setEnabled(False) |
117 |
118 |
118 def menuAction(self): |
119 def menuAction(self): |
119 """ |
120 """ |
122 @return reference to the menu action (QAction) |
123 @return reference to the menu action (QAction) |
123 """ |
124 """ |
124 if not self.__menuAction: |
125 if not self.__menuAction: |
125 self.__menuAction = QAction(self.tr("AdBlock"), self) |
126 self.__menuAction = QAction(self.tr("AdBlock"), self) |
126 self.__menuAction.setMenu(QMenu()) |
127 self.__menuAction.setMenu(QMenu()) |
127 self.__menuAction.menu().aboutToShow.connect(self.__createMenu) |
128 self.__menuAction.menu().aboutToShow.connect( |
|
129 lambda: self.__createMenu(self.__menuAction.menu())) |
128 |
130 |
129 if self.__enabled: |
131 if self.__enabled: |
130 self.__menuAction.setIcon( |
132 self.__menuAction.setIcon( |
131 UI.PixmapCache.getIcon("adBlockPlus.png")) |
133 UI.PixmapCache.getIcon("adBlockPlus.png")) |
132 else: |
134 else: |
143 """ |
145 """ |
144 menu = QMenu() |
146 menu = QMenu() |
145 self.__createMenu(menu) |
147 self.__createMenu(menu) |
146 menu.exec_(pos) |
148 menu.exec_(pos) |
147 |
149 |
148 def __enableAdBlock(self): |
150 def __enableAdBlock(self, act): |
149 """ |
151 """ |
150 Private slot to enable or disable AdBlock. |
152 Private slot to enable or disable AdBlock. |
151 """ |
153 |
152 act = self.sender() |
154 @param act reference to the action |
153 if act is not None: |
155 @type QAction |
154 import Helpviewer.HelpWindow |
156 """ |
155 Helpviewer.HelpWindow.HelpWindow.adBlockManager().setEnabled( |
157 import Helpviewer.HelpWindow |
156 act.data()) |
158 Helpviewer.HelpWindow.HelpWindow.adBlockManager().setEnabled( |
|
159 act.data()) |
157 |
160 |
158 def __isCurrentHostExcepted(self): |
161 def __isCurrentHostExcepted(self): |
159 """ |
162 """ |
160 Private method to check, if the host of the current browser is |
163 Private method to check, if the host of the current browser is |
161 excepted. |
164 excepted. |
182 self.setPixmap( |
185 self.setPixmap( |
183 UI.PixmapCache.getPixmap("adBlockPlusGreen16.png")) |
186 UI.PixmapCache.getPixmap("adBlockPlusGreen16.png")) |
184 else: |
187 else: |
185 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) |
188 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) |
186 |
189 |
187 def __setException(self): |
190 def __setException(self, act): |
188 """ |
191 """ |
189 Private slot to add or remove the current host from the list of |
192 Private slot to add or remove the current host from the list of |
190 exceptions. |
193 exceptions. |
191 """ |
194 |
192 act = self.sender() |
195 @param act referenced to the action |
193 if act is not None: |
196 @type QAction |
194 import Helpviewer.HelpWindow |
197 """ |
195 urlHost = self.__mw.currentBrowser().page().url().host() |
198 import Helpviewer.HelpWindow |
196 if act.data(): |
199 urlHost = self.__mw.currentBrowser().page().url().host() |
197 Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ |
200 if act.data(): |
198 .addException(urlHost) |
201 Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ |
199 else: |
202 .addException(urlHost) |
200 Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ |
203 else: |
201 .removeException(urlHost) |
204 Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ |
202 self.currentChanged() |
205 .removeException(urlHost) |
|
206 self.currentChanged() |
203 |
207 |
204 def sourceChanged(self, browser, url): |
208 def sourceChanged(self, browser, url): |
205 """ |
209 """ |
206 Public slot to handle URL changes. |
210 Public slot to handle URL changes. |
207 |
211 |