53 self.currentChanged() |
53 self.currentChanged() |
54 else: |
54 else: |
55 self.setPixmap( |
55 self.setPixmap( |
56 UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) |
56 UI.PixmapCache.getPixmap("adBlockPlusDisabled16.png")) |
57 |
57 |
58 def __createMenu(self, menu=None): |
58 def __createMenu(self, menu): |
59 """ |
59 """ |
60 Private slot to create the context menu. |
60 Private slot to create the context menu. |
61 |
61 |
62 @param menu parent menu |
62 @param menu parent menu |
63 @type QMenu |
63 @type QMenu |
64 """ |
64 """ |
65 if menu is None: |
|
66 menu = self.sender() |
|
67 if menu is None: |
|
68 return |
|
69 |
|
70 menu.clear() |
65 menu.clear() |
71 |
66 |
72 manager = self.__mw.adBlockManager() |
67 manager = self.__mw.adBlockManager() |
73 |
68 |
74 if manager.isEnabled(): |
69 if manager.isEnabled(): |
75 menu.addAction( |
70 act = menu.addAction( |
76 UI.PixmapCache.getIcon("adBlockPlusDisabled.png"), |
71 UI.PixmapCache.getIcon("adBlockPlusDisabled.png"), |
77 self.tr("Disable AdBlock"), |
72 self.tr("Disable AdBlock")) |
78 self.__enableAdBlock).setData(False) |
73 act.setData(False) |
|
74 act.triggered.connect(lambda: self.__enableAdBlock(act)) |
79 else: |
75 else: |
80 menu.addAction( |
76 act = menu.addAction( |
81 UI.PixmapCache.getIcon("adBlockPlus.png"), |
77 UI.PixmapCache.getIcon("adBlockPlus.png"), |
82 self.tr("Enable AdBlock"), |
78 self.tr("Enable AdBlock")) |
83 self.__enableAdBlock).setData(True) |
79 act.setData(True) |
|
80 act.triggered.connect(lambda: self.__enableAdBlock(act)) |
84 menu.addSeparator() |
81 menu.addSeparator() |
85 if manager.isEnabled() and self.__mw.currentBrowser().url().host(): |
82 if manager.isEnabled() and self.__mw.currentBrowser().url().host(): |
86 if self.__isCurrentHostExcepted(): |
83 if self.__isCurrentHostExcepted(): |
87 menu.addAction( |
84 act = menu.addAction( |
88 UI.PixmapCache.getIcon("adBlockPlus.png"), |
85 UI.PixmapCache.getIcon("adBlockPlus.png"), |
89 self.tr("Remove AdBlock Exception"), |
86 self.tr("Remove AdBlock Exception")) |
90 self.__setException).setData(False) |
87 act.setData(False) |
|
88 act.triggered.connect(lambda: self.__setException(act)) |
91 else: |
89 else: |
92 menu.addAction( |
90 act = menu.addAction( |
93 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
91 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
94 self.tr("Add AdBlock Exception"), |
92 self.tr("Add AdBlock Exception")) |
95 self.__setException).setData(True) |
93 act.setData(True) |
|
94 act.triggered.connect(lambda: self.__setException(act)) |
96 menu.addAction( |
95 menu.addAction( |
97 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
96 UI.PixmapCache.getIcon("adBlockPlusGreen.png"), |
98 self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) |
97 self.tr("AdBlock Exceptions..."), manager.showExceptionsDialog) |
99 menu.addSeparator() |
98 menu.addSeparator() |
100 menu.addAction( |
99 menu.addAction( |
109 @rtype QAction |
108 @rtype QAction |
110 """ |
109 """ |
111 if not self.__menuAction: |
110 if not self.__menuAction: |
112 self.__menuAction = QAction(self.tr("AdBlock"), self) |
111 self.__menuAction = QAction(self.tr("AdBlock"), self) |
113 self.__menuAction.setMenu(QMenu()) |
112 self.__menuAction.setMenu(QMenu()) |
114 self.__menuAction.menu().aboutToShow.connect(self.__createMenu) |
113 self.__menuAction.menu().aboutToShow.connect( |
|
114 lambda: self.__createMenu(self.__menuAction.menu())) |
115 |
115 |
116 if self.__enabled: |
116 if self.__enabled: |
117 self.__menuAction.setIcon( |
117 self.__menuAction.setIcon( |
118 UI.PixmapCache.getIcon("adBlockPlus.png")) |
118 UI.PixmapCache.getIcon("adBlockPlus.png")) |
119 else: |
119 else: |
131 """ |
131 """ |
132 menu = QMenu() |
132 menu = QMenu() |
133 self.__createMenu(menu) |
133 self.__createMenu(menu) |
134 menu.exec_(pos) |
134 menu.exec_(pos) |
135 |
135 |
136 def __enableAdBlock(self): |
136 def __enableAdBlock(self, act): |
137 """ |
137 """ |
138 Private slot to enable or disable AdBlock. |
138 Private slot to enable or disable AdBlock. |
|
139 |
|
140 @param act reference to the action |
|
141 @type QAction |
139 """ |
142 """ |
140 act = self.sender() |
143 self.__mw.adBlockManager().setEnabled(act.data()) |
141 if act is not None: |
|
142 self.__mw.adBlockManager().setEnabled(act.data()) |
|
143 |
144 |
144 def __isCurrentHostExcepted(self): |
145 def __isCurrentHostExcepted(self): |
145 """ |
146 """ |
146 Private method to check, if the host of the current browser is |
147 Private method to check, if the host of the current browser is |
147 excepted. |
148 excepted. |
167 self.setPixmap( |
168 self.setPixmap( |
168 UI.PixmapCache.getPixmap("adBlockPlusGreen16.png")) |
169 UI.PixmapCache.getPixmap("adBlockPlusGreen16.png")) |
169 else: |
170 else: |
170 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) |
171 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16.png")) |
171 |
172 |
172 def __setException(self): |
173 def __setException(self, act): |
173 """ |
174 """ |
174 Private slot to add or remove the current host from the list of |
175 Private slot to add or remove the current host from the list of |
175 exceptions. |
176 exceptions. |
|
177 |
|
178 @param act referenced to the action |
|
179 @type QAction |
176 """ |
180 """ |
177 act = self.sender() |
181 urlHost = self.__mw.currentBrowser().url().host() |
178 if act is not None: |
182 if act.data(): |
179 urlHost = self.__mw.currentBrowser().url().host() |
183 self.__mw.adBlockManager().addException(urlHost) |
180 if act.data(): |
184 else: |
181 self.__mw.adBlockManager().addException(urlHost) |
185 self.__mw.adBlockManager().removeException(urlHost) |
182 else: |
186 self.currentChanged() |
183 self.__mw.adBlockManager().removeException(urlHost) |
|
184 self.currentChanged() |
|
185 |
187 |
186 def sourceChanged(self, browser, url): |
188 def sourceChanged(self, browser, url): |
187 """ |
189 """ |
188 Public slot to handle URL changes. |
190 Public slot to handle URL changes. |
189 |
191 |