Wed, 12 Aug 2015 20:13:45 +0200
Continued adding code for a Flash cookie manager.
--- a/Helpviewer/FlashCookieManager/FlashCookieManagerDialog.py Tue Aug 11 19:49:05 2015 +0200 +++ b/Helpviewer/FlashCookieManager/FlashCookieManagerDialog.py Wed Aug 12 20:13:45 2015 +0200 @@ -8,7 +8,9 @@ """ from PyQt5.QtCore import pyqtSlot, Qt, QPoint, QTimer -from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QApplication +from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QApplication, QMenu + +from E5Gui import E5MessageBox from .Ui_FlashCookieManagerDialog import Ui_FlashCookieManagerDialog @@ -42,18 +44,18 @@ @pyqtSlot() def on_whiteList_itemSelectionChanged(self): """ - Slot documentation goes here. + Private slot handling the selection of items in the whitelist. """ - # TODO: not implemented yet - raise NotImplementedError + enable = len(self.whiteList.selectedItems()) > 0 + self.removeWhiteButton.setEnabled(enable) @pyqtSlot() def on_blackList_itemSelectionChanged(self): """ - Slot documentation goes here. + Private slot handling the selection of items in the blacklist. """ - # TODO: not implemented yet - raise NotImplementedError + enable = len(self.blackList.selectedItems()) > 0 + self.removeBlackButton.setEnabled(enable) @pyqtSlot() def on_removeWhiteButton_clicked(self): @@ -92,56 +94,139 @@ """ Slot documentation goes here. """ + return # TODO: not implemented yet raise NotImplementedError @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) def on_cookiesList_currentItemChanged(self, current, previous): """ - Slot documentation goes here. + Private slot handling a change of the current cookie item. + + @param current reference to the current item + @type QTreeWidgetItem + @param previous reference to the previous item + @type QTreeWidgetItem """ - # TODO: not implemented yet - raise NotImplementedError - - @pyqtSlot() - def on_cookiesList_itemSelectionChanged(self): - """ - Slot documentation goes here. - """ - # TODO: not implemented yet - raise NotImplementedError + if current is None: + self.removeButton.setEnabled(False) + return + + cookie = current.data(0, Qt.UserRole) + if cookie is None: + self.nameLabel.setText(self.tr("<no flash cookie selected>")) + self.sizeLabel.setText(self.tr("<no flash cookie selected>")) + self.originLabel.setText(self.tr("<no flash cookie selected>")) + self.modifiedLabel.setText(self.tr("<no flash cookie selected>")) + self.contentsEdit.clear() + self.pathEdit.clear() + self.removeButton.setText(self.tr("Remove Cookie Group")) + else: + suffix = "" + if cookie.path.startswith( + self.__manager.flashPlayerDataPath() + + "/macromedia.com/support/flashplayer/sys"): + suffix = self.tr(" (settings)") + self.nameLabel.setText( + self.tr("{0}{1}", "name and suffix") + .format(cookie.name, suffix)) + self.sizeLabel.setText(self.tr("{0} Byte").format(cookie.size)) + self.originLabel.setText(cookie.origin) + self.modifiedLabel.setText( + cookie.lastModified.toString("yyyy-MM-dd hh:mm:ss")) + self.contentsEdit.setPlainText(cookie.contents) + self.pathEdit.setText(cookie.path) + self.removeButton.setText(self.tr("Remove Cookie")) + self.removeButton.setEnabled(True) @pyqtSlot(QPoint) - def __cookiesListContextMenuRequested(self, point): + def __cookiesListContextMenuRequested(self, pos): + """ + Private slot handling the cookies list context menu. + + @param pos position to show the menu at + @type QPoint """ - Slot documentation goes here. - """ - # TODO: not implemented yet - raise NotImplementedError + itm = self.cookiesList.itemAt(pos) + if itm is None: + return + + menu = QMenu() + addBlacklistAct = menu.addAction(self.tr("Add to blacklist")) + addWhitelistAct = menu.addAction(self.tr("Add to whitelist")) + + self.cookiesList.setCurrentItem(itm) + + activatedAction = menu.exec_( + self.cookiesList.viewport().mapToGlobal(pos)) + if itm.childCount() == 0: + origin = itm.data(0, Qt.UserRole).origin + else: + origin = itm.text(0) + + if activatedAction == addBlacklistAct: + self.__addBlacklist(origin) + elif activatedAction == addWhitelistAct: + self.__addWhitelist(origin) @pyqtSlot() def on_reloadButton_clicked(self): """ - Slot documentation goes here. + Private slot handling a press of the reload button. """ - # TODO: not implemented yet - raise NotImplementedError + self.refreshView(True) @pyqtSlot() def on_removeAllButton_clicked(self): """ - Slot documentation goes here. + Private slot to remove all cookies. """ - # TODO: not implemented yet - raise NotImplementedError + ok = E5MessageBox.yesNo( + self, + self.tr("Remove All"), + self.tr("""Do you really want to delete all flash cookies on""" + """ your computer?""")) + if ok: + cookies = self.__manager.flashCookies() + for cookie in cookies: + self.__manager.removeCookie(cookie) + + self.cookiesList.clear() + self.__manager.clearNewOrigins() + self.__manager.clearCache() @pyqtSlot() def on_removeButton_clicked(self): """ - Slot documentation goes here. + Private slot to remove one cookie or a cookie group. """ - # TODO: not implemented yet - raise NotImplementedError + itm = self.cookiesList.currentItem() + if itm is None: + return + + cookie = itm.data(0, Qt.UserRole) + if cookie is None: + # remove a whole cookie group + origin = itm.text(0) + cookieList = self.__manager.flashCookies() + for fcookie in cookieList: + if fcookie.origin == origin: + self.__manager.removeCookie(fcookie) + + index = self.cookiesList.indexOfTopLevelItem(itm) + self.cookiesList.takeTopLevelItem(index) + else: + self.__manager.removeCookie(cookie) + parent = itm.parent() + index = parent.indexOfChild(itm) + parent.takeChild(index) + + if parent.childCount() == 0: + # remove origin item as well + index = self.cookiesList.indexOfTopLevelItem(parent) + self.cookiesList.takeTopLevelItem(index) + del parent + del itm def refreshView(self, forceReload=False): """ @@ -193,7 +278,7 @@ else: newParent = QTreeWidgetItem(self.cookiesList) newParent.setText(0, cookieOrigin) - newParent.setIcon(UI.PixmapCache.getIcon("dirOpen.png")) + newParent.setIcon(0, UI.PixmapCache.getIcon("dirOpen.png")) self.cookiesList.addTopLevelItem(newParent) originDict[cookieOrigin] = newParent @@ -213,7 +298,8 @@ itm.setFont(font) itm.parent().setExpanded(True) - itm.setText(0, cookie.name + suffix) + itm.setText(0, self.tr("{0}{1}", "name and suffix").format( + cookie.name, suffix)) itm.setData(0, Qt.UserRole, cookie) counter += 1 @@ -221,6 +307,10 @@ QApplication.processEvents() counter = 0 + self.removeAllButton.setEnabled( + self.cookiesList.topLevelItemCount() > 0) + self.removeButton.setEnabled(False) + QApplication.restoreOverrideCursor() @pyqtSlot() @@ -233,3 +323,28 @@ self.whiteList.addItems(Preferences.getHelp("FlashCookiesWhitelist")) self.blackList.addItems(Preferences.getHelp("FlashCookiesBlacklist")) + + self.on_whiteList_itemSelectionChanged() + self.on_blackList_itemSelectionChanged() + + def closeEvent(self, evt): + """ + Protected method to handle the close event. + + @param evt reference to the close event + @type QCloseEvent + """ + self.__manager.clearNewOrigins() + + whiteList = [] + for row in range(self.whiteList.count()): + whiteList.append(self.whiteList.item(row).text()) + + blackList = [] + for row in range(self.blackList.count()): + blackList.append(self.blackList.item(row).text()) + + Preferences.setHelp("FlashCookiesWhitelist", whiteList) + Preferences.setHelp("FlashCookiesBlacklist", blackList) + + evt.accept()
--- a/Helpviewer/FlashCookieManager/FlashCookieManagerDialog.ui Tue Aug 11 19:49:05 2015 +0200 +++ b/Helpviewer/FlashCookieManager/FlashCookieManagerDialog.ui Wed Aug 12 20:13:45 2015 +0200 @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>550</width> - <height>450</height> + <height>500</height> </rect> </property> <property name="windowTitle"> @@ -222,7 +222,7 @@ <string>Press to remove selected flash cookies</string> </property> <property name="text"> - <string>Remove Cookies</string> + <string>Remove Cookie</string> </property> </widget> </item>
--- a/Helpviewer/HelpWindow.py Tue Aug 11 19:49:05 2015 +0200 +++ b/Helpviewer/HelpWindow.py Wed Aug 12 20:13:45 2015 +0200 @@ -1133,6 +1133,21 @@ self.__showCookiesConfiguration) self.__actions.append(self.cookiesAct) + self.flashCookiesAct = E5Action( + self.tr('Flash Cookies'), + UI.PixmapCache.getIcon("flashCookie.png"), + self.tr('&Flash Cookies...'), 0, 0, self, 'help_flash_cookies') + self.flashCookiesAct.setStatusTip(self.tr( + 'Manage flash cookies')) + self.flashCookiesAct.setWhatsThis(self.tr( + """<b>Flash Cookies</b>""" + """<p>Show a dialog to manage the flash cookies.</p>""" + )) + if not self.initShortcutsOnly: + self.flashCookiesAct.triggered.connect( + self.__showFlashCookiesManagement) + self.__actions.append(self.flashCookiesAct) + self.offlineStorageAct = E5Action( self.tr('Offline Storage'), UI.PixmapCache.getIcon("preferences-html5.png"), @@ -1654,6 +1669,7 @@ menu.addAction(self.prefAct) menu.addAction(self.acceptedLanguagesAct) menu.addAction(self.cookiesAct) + menu.addAction(self.flashCookiesAct) menu.addAction(self.offlineStorageAct) menu.addAction(self.personalDataAct) menu.addAction(self.greaseMonkeyAct) @@ -1784,6 +1800,7 @@ settingstb.addAction(self.prefAct) settingstb.addAction(self.acceptedLanguagesAct) settingstb.addAction(self.cookiesAct) + settingstb.addAction(self.flashCookiesAct) settingstb.addAction(self.offlineStorageAct) settingstb.addAction(self.personalDataAct) settingstb.addAction(self.greaseMonkeyAct) @@ -2541,6 +2558,12 @@ dlg = CookiesConfigurationDialog(self) dlg.exec_() + def __showFlashCookiesManagement(self): + """ + Private slot to show the flash cookies management dialog. + """ + self.flashCookieManager().showFlashCookieManagerDialog() + def __showOfflineStorageConfiguration(self): """ Private slot to configure the offline storage.