44 """ |
44 """ |
45 Public slot to set the enabled state. |
45 Public slot to set the enabled state. |
46 |
46 |
47 @param enabled enabled state (boolean) |
47 @param enabled enabled state (boolean) |
48 """ |
48 """ |
|
49 self.__enabled = enabled |
49 if enabled: |
50 if enabled: |
50 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) |
51 self.currentChanged() |
51 else: |
52 else: |
52 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) |
53 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) |
53 self.__enabled = enabled |
|
54 |
54 |
55 def __createMenu(self, menu=None): |
55 def __createMenu(self, menu=None): |
56 """ |
56 """ |
57 Private slot to create the context menu. |
57 Private slot to create the context menu. |
58 |
58 |
72 self.trUtf8("Disable AdBlock"), self.__enableAdBlock).setData(False) |
72 self.trUtf8("Disable AdBlock"), self.__enableAdBlock).setData(False) |
73 else: |
73 else: |
74 menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"), |
74 menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"), |
75 self.trUtf8("Enable AdBlock"), self.__enableAdBlock).setData(True) |
75 self.trUtf8("Enable AdBlock"), self.__enableAdBlock).setData(True) |
76 menu.addSeparator() |
76 menu.addSeparator() |
|
77 if manager.isEnabled() and \ |
|
78 self.__mw.currentBrowser().page().url().host(): |
|
79 if self.__isCurrentHostExcepted(): |
|
80 menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"), |
|
81 self.trUtf8("Remove AdBlock Exception"), |
|
82 self.__setException).setData(False) |
|
83 else: |
|
84 menu.addAction(UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
|
85 self.trUtf8("Add AdBlock Exception"), |
|
86 self.__setException).setData(True) |
|
87 menu.addAction(UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
|
88 self.trUtf8("AdBlock Exceptions..."), manager.showExceptionsDialog) |
|
89 menu.addSeparator() |
77 menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"), |
90 menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"), |
78 self.trUtf8("AdBlock Configuration"), manager.showDialog) |
91 self.trUtf8("AdBlock Configuration..."), manager.showDialog) |
79 menu.addSeparator() |
92 menu.addSeparator() |
80 |
93 |
81 entries = self.__mw.currentBrowser().page().getAdBlockedPageEntries() |
94 entries = self.__mw.currentBrowser().page().getAdBlockedPageEntries() |
82 if entries: |
95 if entries: |
83 menu.addAction( |
96 menu.addAction( |
125 Private slot to enable or disable AdBlock. |
138 Private slot to enable or disable AdBlock. |
126 """ |
139 """ |
127 act = self.sender() |
140 act = self.sender() |
128 if act is not None: |
141 if act is not None: |
129 Helpviewer.HelpWindow.HelpWindow.adBlockManager().setEnabled(act.data()) |
142 Helpviewer.HelpWindow.HelpWindow.adBlockManager().setEnabled(act.data()) |
|
143 |
|
144 def __isCurrentHostExcepted(self): |
|
145 """ |
|
146 Private method to check, if the host of the current browser is excepted. |
|
147 |
|
148 @return flag indicating an exception (boolean) |
|
149 """ |
|
150 browser = self.__mw.currentBrowser() |
|
151 urlHost = browser.page().url().host() |
|
152 |
|
153 return urlHost and \ |
|
154 Helpviewer.HelpWindow.HelpWindow.adBlockManager().isHostExcepted(urlHost) |
|
155 |
|
156 def currentChanged(self): |
|
157 """ |
|
158 Public slot to handle a change of the current browser tab. |
|
159 """ |
|
160 if self.__enabled: |
|
161 if self.__isCurrentHostExcepted(): |
|
162 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlusGreen16.png")) |
|
163 else: |
|
164 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) |
|
165 |
|
166 def __setException(self): |
|
167 """ |
|
168 Private slot to add or remove the current host from the list of exceptions. |
|
169 """ |
|
170 act = self.sender() |
|
171 if act is not None: |
|
172 urlHost = self.__mw.currentBrowser().page().url().host() |
|
173 if act.data(): |
|
174 Helpviewer.HelpWindow.HelpWindow.adBlockManager().addException(urlHost) |
|
175 else: |
|
176 Helpviewer.HelpWindow.HelpWindow.adBlockManager().removeException(urlHost) |
|
177 self.currentChanged() |
|
178 |
|
179 def sourceChanged(self, browser, url): |
|
180 """ |
|
181 Public slot to handle URL changes. |
|
182 |
|
183 @param browser reference to the browser (HelpBrowser) |
|
184 @param url new URL (QUrl) |
|
185 """ |
|
186 if browser == self.__mw.currentBrowser(): |
|
187 self.currentChanged() |