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