Helpviewer/FlashCookieManager/FlashCookieManagerDialog.py

changeset 4362
1a171c85b275
parent 4361
9eec3a532d59
child 4363
c00061f670c7
equal deleted inserted replaced
4361:9eec3a532d59 4362:1a171c85b275
6 """ 6 """
7 Module implementing a dialog to manage the flash cookies. 7 Module implementing a dialog to manage the flash cookies.
8 """ 8 """
9 9
10 from PyQt5.QtCore import pyqtSlot, Qt, QPoint, QTimer 10 from PyQt5.QtCore import pyqtSlot, Qt, QPoint, QTimer
11 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QApplication 11 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QApplication, QMenu
12
13 from E5Gui import E5MessageBox
12 14
13 from .Ui_FlashCookieManagerDialog import Ui_FlashCookieManagerDialog 15 from .Ui_FlashCookieManagerDialog import Ui_FlashCookieManagerDialog
14 16
15 import Preferences 17 import Preferences
16 import UI.PixmapCache 18 import UI.PixmapCache
40 self.__manager = manager 42 self.__manager = manager
41 43
42 @pyqtSlot() 44 @pyqtSlot()
43 def on_whiteList_itemSelectionChanged(self): 45 def on_whiteList_itemSelectionChanged(self):
44 """ 46 """
45 Slot documentation goes here. 47 Private slot handling the selection of items in the whitelist.
46 """ 48 """
47 # TODO: not implemented yet 49 enable = len(self.whiteList.selectedItems()) > 0
48 raise NotImplementedError 50 self.removeWhiteButton.setEnabled(enable)
49 51
50 @pyqtSlot() 52 @pyqtSlot()
51 def on_blackList_itemSelectionChanged(self): 53 def on_blackList_itemSelectionChanged(self):
52 """ 54 """
53 Slot documentation goes here. 55 Private slot handling the selection of items in the blacklist.
54 """ 56 """
55 # TODO: not implemented yet 57 enable = len(self.blackList.selectedItems()) > 0
56 raise NotImplementedError 58 self.removeBlackButton.setEnabled(enable)
57 59
58 @pyqtSlot() 60 @pyqtSlot()
59 def on_removeWhiteButton_clicked(self): 61 def on_removeWhiteButton_clicked(self):
60 """ 62 """
61 Slot documentation goes here. 63 Slot documentation goes here.
90 @pyqtSlot(str) 92 @pyqtSlot(str)
91 def on_filterEdit_textChanged(self, p0): 93 def on_filterEdit_textChanged(self, p0):
92 """ 94 """
93 Slot documentation goes here. 95 Slot documentation goes here.
94 """ 96 """
97 return
95 # TODO: not implemented yet 98 # TODO: not implemented yet
96 raise NotImplementedError 99 raise NotImplementedError
97 100
98 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) 101 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
99 def on_cookiesList_currentItemChanged(self, current, previous): 102 def on_cookiesList_currentItemChanged(self, current, previous):
100 """ 103 """
101 Slot documentation goes here. 104 Private slot handling a change of the current cookie item.
102 """ 105
103 # TODO: not implemented yet 106 @param current reference to the current item
104 raise NotImplementedError 107 @type QTreeWidgetItem
105 108 @param previous reference to the previous item
106 @pyqtSlot() 109 @type QTreeWidgetItem
107 def on_cookiesList_itemSelectionChanged(self): 110 """
108 """ 111 if current is None:
109 Slot documentation goes here. 112 self.removeButton.setEnabled(False)
110 """ 113 return
111 # TODO: not implemented yet 114
112 raise NotImplementedError 115 cookie = current.data(0, Qt.UserRole)
116 if cookie is None:
117 self.nameLabel.setText(self.tr("<no flash cookie selected>"))
118 self.sizeLabel.setText(self.tr("<no flash cookie selected>"))
119 self.originLabel.setText(self.tr("<no flash cookie selected>"))
120 self.modifiedLabel.setText(self.tr("<no flash cookie selected>"))
121 self.contentsEdit.clear()
122 self.pathEdit.clear()
123 self.removeButton.setText(self.tr("Remove Cookie Group"))
124 else:
125 suffix = ""
126 if cookie.path.startswith(
127 self.__manager.flashPlayerDataPath() +
128 "/macromedia.com/support/flashplayer/sys"):
129 suffix = self.tr(" (settings)")
130 self.nameLabel.setText(
131 self.tr("{0}{1}", "name and suffix")
132 .format(cookie.name, suffix))
133 self.sizeLabel.setText(self.tr("{0} Byte").format(cookie.size))
134 self.originLabel.setText(cookie.origin)
135 self.modifiedLabel.setText(
136 cookie.lastModified.toString("yyyy-MM-dd hh:mm:ss"))
137 self.contentsEdit.setPlainText(cookie.contents)
138 self.pathEdit.setText(cookie.path)
139 self.removeButton.setText(self.tr("Remove Cookie"))
140 self.removeButton.setEnabled(True)
113 141
114 @pyqtSlot(QPoint) 142 @pyqtSlot(QPoint)
115 def __cookiesListContextMenuRequested(self, point): 143 def __cookiesListContextMenuRequested(self, pos):
116 """ 144 """
117 Slot documentation goes here. 145 Private slot handling the cookies list context menu.
118 """ 146
119 # TODO: not implemented yet 147 @param pos position to show the menu at
120 raise NotImplementedError 148 @type QPoint
149 """
150 itm = self.cookiesList.itemAt(pos)
151 if itm is None:
152 return
153
154 menu = QMenu()
155 addBlacklistAct = menu.addAction(self.tr("Add to blacklist"))
156 addWhitelistAct = menu.addAction(self.tr("Add to whitelist"))
157
158 self.cookiesList.setCurrentItem(itm)
159
160 activatedAction = menu.exec_(
161 self.cookiesList.viewport().mapToGlobal(pos))
162 if itm.childCount() == 0:
163 origin = itm.data(0, Qt.UserRole).origin
164 else:
165 origin = itm.text(0)
166
167 if activatedAction == addBlacklistAct:
168 self.__addBlacklist(origin)
169 elif activatedAction == addWhitelistAct:
170 self.__addWhitelist(origin)
121 171
122 @pyqtSlot() 172 @pyqtSlot()
123 def on_reloadButton_clicked(self): 173 def on_reloadButton_clicked(self):
124 """ 174 """
125 Slot documentation goes here. 175 Private slot handling a press of the reload button.
126 """ 176 """
127 # TODO: not implemented yet 177 self.refreshView(True)
128 raise NotImplementedError
129 178
130 @pyqtSlot() 179 @pyqtSlot()
131 def on_removeAllButton_clicked(self): 180 def on_removeAllButton_clicked(self):
132 """ 181 """
133 Slot documentation goes here. 182 Private slot to remove all cookies.
134 """ 183 """
135 # TODO: not implemented yet 184 ok = E5MessageBox.yesNo(
136 raise NotImplementedError 185 self,
186 self.tr("Remove All"),
187 self.tr("""Do you really want to delete all flash cookies on"""
188 """ your computer?"""))
189 if ok:
190 cookies = self.__manager.flashCookies()
191 for cookie in cookies:
192 self.__manager.removeCookie(cookie)
193
194 self.cookiesList.clear()
195 self.__manager.clearNewOrigins()
196 self.__manager.clearCache()
137 197
138 @pyqtSlot() 198 @pyqtSlot()
139 def on_removeButton_clicked(self): 199 def on_removeButton_clicked(self):
140 """ 200 """
141 Slot documentation goes here. 201 Private slot to remove one cookie or a cookie group.
142 """ 202 """
143 # TODO: not implemented yet 203 itm = self.cookiesList.currentItem()
144 raise NotImplementedError 204 if itm is None:
205 return
206
207 cookie = itm.data(0, Qt.UserRole)
208 if cookie is None:
209 # remove a whole cookie group
210 origin = itm.text(0)
211 cookieList = self.__manager.flashCookies()
212 for fcookie in cookieList:
213 if fcookie.origin == origin:
214 self.__manager.removeCookie(fcookie)
215
216 index = self.cookiesList.indexOfTopLevelItem(itm)
217 self.cookiesList.takeTopLevelItem(index)
218 else:
219 self.__manager.removeCookie(cookie)
220 parent = itm.parent()
221 index = parent.indexOfChild(itm)
222 parent.takeChild(index)
223
224 if parent.childCount() == 0:
225 # remove origin item as well
226 index = self.cookiesList.indexOfTopLevelItem(parent)
227 self.cookiesList.takeTopLevelItem(index)
228 del parent
229 del itm
145 230
146 def refreshView(self, forceReload=False): 231 def refreshView(self, forceReload=False):
147 """ 232 """
148 Public method to refresh the dialog view. 233 Public method to refresh the dialog view.
149 234
191 if cookieOrigin in originDict: 276 if cookieOrigin in originDict:
192 itm = QTreeWidgetItem(originDict[cookieOrigin]) 277 itm = QTreeWidgetItem(originDict[cookieOrigin])
193 else: 278 else:
194 newParent = QTreeWidgetItem(self.cookiesList) 279 newParent = QTreeWidgetItem(self.cookiesList)
195 newParent.setText(0, cookieOrigin) 280 newParent.setText(0, cookieOrigin)
196 newParent.setIcon(UI.PixmapCache.getIcon("dirOpen.png")) 281 newParent.setIcon(0, UI.PixmapCache.getIcon("dirOpen.png"))
197 self.cookiesList.addTopLevelItem(newParent) 282 self.cookiesList.addTopLevelItem(newParent)
198 originDict[cookieOrigin] = newParent 283 originDict[cookieOrigin] = newParent
199 284
200 itm = QTreeWidgetItem(newParent) 285 itm = QTreeWidgetItem(newParent)
201 286
211 font = itm.font(0) 296 font = itm.font(0)
212 font.setBold(True) 297 font.setBold(True)
213 itm.setFont(font) 298 itm.setFont(font)
214 itm.parent().setExpanded(True) 299 itm.parent().setExpanded(True)
215 300
216 itm.setText(0, cookie.name + suffix) 301 itm.setText(0, self.tr("{0}{1}", "name and suffix").format(
302 cookie.name, suffix))
217 itm.setData(0, Qt.UserRole, cookie) 303 itm.setData(0, Qt.UserRole, cookie)
218 304
219 counter += 1 305 counter += 1
220 if counter > 100: 306 if counter > 100:
221 QApplication.processEvents() 307 QApplication.processEvents()
222 counter = 0 308 counter = 0
223 309
310 self.removeAllButton.setEnabled(
311 self.cookiesList.topLevelItemCount() > 0)
312 self.removeButton.setEnabled(False)
313
224 QApplication.restoreOverrideCursor() 314 QApplication.restoreOverrideCursor()
225 315
226 @pyqtSlot() 316 @pyqtSlot()
227 def __refreshFilterLists(self): 317 def __refreshFilterLists(self):
228 """ 318 """
231 self.whiteList.clear() 321 self.whiteList.clear()
232 self.blackList.clear() 322 self.blackList.clear()
233 323
234 self.whiteList.addItems(Preferences.getHelp("FlashCookiesWhitelist")) 324 self.whiteList.addItems(Preferences.getHelp("FlashCookiesWhitelist"))
235 self.blackList.addItems(Preferences.getHelp("FlashCookiesBlacklist")) 325 self.blackList.addItems(Preferences.getHelp("FlashCookiesBlacklist"))
326
327 self.on_whiteList_itemSelectionChanged()
328 self.on_blackList_itemSelectionChanged()
329
330 def closeEvent(self, evt):
331 """
332 Protected method to handle the close event.
333
334 @param evt reference to the close event
335 @type QCloseEvent
336 """
337 self.__manager.clearNewOrigins()
338
339 whiteList = []
340 for row in range(self.whiteList.count()):
341 whiteList.append(self.whiteList.item(row).text())
342
343 blackList = []
344 for row in range(self.blackList.count()):
345 blackList.append(self.blackList.item(row).text())
346
347 Preferences.setHelp("FlashCookiesWhitelist", whiteList)
348 Preferences.setHelp("FlashCookiesBlacklist", blackList)
349
350 evt.accept()

eric ide

mercurial