9 |
9 |
10 |
10 |
11 from PyQt4.QtCore import pyqtSlot, QUrl, Qt, QByteArray, QTimer |
11 from PyQt4.QtCore import pyqtSlot, QUrl, Qt, QByteArray, QTimer |
12 from PyQt4.QtGui import QWidget, QMenu, QCursor, QDialog, QLabel, QFormLayout |
12 from PyQt4.QtGui import QWidget, QMenu, QCursor, QDialog, QLabel, QFormLayout |
13 from PyQt4.QtNetwork import QNetworkRequest |
13 from PyQt4.QtNetwork import QNetworkRequest |
14 from PyQt4.QtWebKit import QWebHitTestResult, QWebElement, QWebView, QWebElementCollection |
14 from PyQt4.QtWebKit import QWebHitTestResult, QWebElement, QWebView, \ |
|
15 QWebElementCollection |
15 |
16 |
16 from .Ui_ClickToFlash import Ui_ClickToFlash |
17 from .Ui_ClickToFlash import Ui_ClickToFlash |
17 |
18 |
18 import UI.PixmapCache |
19 import UI.PixmapCache |
19 |
20 |
24 """ |
25 """ |
25 _acceptedUrl = QUrl() |
26 _acceptedUrl = QUrl() |
26 _acceptedArgNames = [] |
27 _acceptedArgNames = [] |
27 _acceptedArgValues = [] |
28 _acceptedArgValues = [] |
28 |
29 |
29 def __init__(self, plugin, mimeType, url, argumentNames, argumentValues, parent=None): |
30 def __init__(self, plugin, mimeType, url, argumentNames, argumentValues, |
|
31 parent=None): |
30 """ |
32 """ |
31 Constructor |
33 Constructor |
32 |
34 |
33 @param plugin reference to the plug-in (ClickToFlashPlugin) |
35 @param plugin reference to the plug-in (ClickToFlashPlugin) |
34 @param mimeType MIME type for the plug-in (string) |
36 @param mimeType MIME type for the plug-in (string) |
87 menu = QMenu() |
89 menu = QMenu() |
88 act = menu.addAction(self.trUtf8("Object blocked by ClickToFlash")) |
90 act = menu.addAction(self.trUtf8("Object blocked by ClickToFlash")) |
89 font = act.font() |
91 font = act.font() |
90 font.setBold(True) |
92 font.setBold(True) |
91 act.setFont(font) |
93 act.setFont(font) |
92 menu.addAction(self.trUtf8("Show information about object"), self.__showInfo) |
94 menu.addAction( |
|
95 self.trUtf8("Show information about object"), self.__showInfo) |
93 menu.addSeparator() |
96 menu.addSeparator() |
94 menu.addAction(self.trUtf8("Load"), self.__load) |
97 menu.addAction(self.trUtf8("Load"), self.__load) |
95 menu.addAction(self.trUtf8("Delete object"), self.__hideAdBlocked) |
98 menu.addAction(self.trUtf8("Delete object"), self.__hideAdBlocked) |
96 menu.addSeparator() |
99 menu.addSeparator() |
97 host = self.__url.host() |
100 host = self.__url.host() |
98 add = menu.addAction(self.trUtf8("Add '{0}' to Whitelist".format(host)), |
101 add = menu.addAction( |
99 self.__addToWhitelist) |
102 self.trUtf8("Add '{0}' to Whitelist").format(host), |
100 remove = menu.addAction(self.trUtf8("Remove '{0}' from Whitelist".format(host)), |
103 self.__addToWhitelist) |
101 self.__removeFromWhitelist) |
104 remove = menu.addAction( |
|
105 self.trUtf8("Remove '{0}' from Whitelist").format(host), |
|
106 self.__removeFromWhitelist) |
102 onWhitelist = self.__plugin.onWhitelist(host) |
107 onWhitelist = self.__plugin.onWhitelist(host) |
103 add.setEnabled(not onWhitelist) |
108 add.setEnabled(not onWhitelist) |
104 remove.setEnabled(onWhitelist) |
109 remove.setEnabled(onWhitelist) |
105 menu.addSeparator() |
110 menu.addSeparator() |
106 menu.addAction(self.trUtf8("Configure Whitelist"), self.__configure) |
111 menu.addAction(self.trUtf8("Configure Whitelist"), self.__configure) |
150 ClickToFlash._acceptedArgNames = self.__argumentNames |
155 ClickToFlash._acceptedArgNames = self.__argumentNames |
151 ClickToFlash._acceptedArgValues = self.__argumentValues |
156 ClickToFlash._acceptedArgValues = self.__argumentValues |
152 |
157 |
153 def __findElement(self): |
158 def __findElement(self): |
154 """ |
159 """ |
155 Private method to find the element belonging to this ClickToFlash instance. |
160 Private method to find the element belonging to this ClickToFlash |
|
161 instance. |
156 """ |
162 """ |
157 parent = self.parentWidget() |
163 parent = self.parentWidget() |
158 view = None |
164 view = None |
159 while parent is not None: |
165 while parent is not None: |
160 if isinstance(parent, QWebView): |
166 if isinstance(parent, QWebView): |
214 if checkString == "": |
220 if checkString == "": |
215 checkString = element.attribute("value") |
221 checkString = element.attribute("value") |
216 |
222 |
217 checkString = view.url().resolved(QUrl(checkString)).toString( |
223 checkString = view.url().resolved(QUrl(checkString)).toString( |
218 QUrl.RemoveQuery) |
224 QUrl.RemoveQuery) |
219 return self.__url.toEncoded().contains(QByteArray(checkString.encode("utf-8"))) |
225 return self.__url.toEncoded().contains( |
|
226 QByteArray(checkString.encode("utf-8"))) |
220 |
227 |
221 def __checkElement(self, element): |
228 def __checkElement(self, element): |
222 """ |
229 """ |
223 Private slot to check an element against the saved arguments. |
230 Private slot to check an element against the saved arguments. |
224 |
231 |
295 return txt |
302 return txt |
296 |
303 |
297 @classmethod |
304 @classmethod |
298 def isAlreadyAccepted(cls, url, argumentNames, argumentValues): |
305 def isAlreadyAccepted(cls, url, argumentNames, argumentValues): |
299 """ |
306 """ |
300 Class method to check, if the given parameter combination is being accepted. |
307 Class method to check, if the given parameter combination is being |
|
308 accepted. |
301 |
309 |
302 @param url URL to be checked for (QUrl) |
310 @param url URL to be checked for (QUrl) |
303 @param argumentNames argument names to be checked for (list of strings) |
311 @param argumentNames argument names to be checked for (list of strings) |
304 @param argumentValues argument values to be checked for (list of strings) |
312 @param argumentValues argument values to be checked for (list of |
|
313 strings) |
305 @return flag indicating that this was already accepted (boolean) |
314 @return flag indicating that this was already accepted (boolean) |
306 """ |
315 """ |
307 return url == cls._acceptedUrl and \ |
316 return url == cls._acceptedUrl and \ |
308 argumentNames == cls._acceptedArgNames and \ |
317 argumentNames == cls._acceptedArgNames and \ |
309 argumentValues == cls._acceptedArgValues |
318 argumentValues == cls._acceptedArgValues |