diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/WebBrowser/CookieJar/CookiesDialog.py --- a/src/eric7/WebBrowser/CookieJar/CookiesDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/CookieJar/CookiesDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -19,48 +19,49 @@ """ Class implementing a dialog to show all cookies. """ + DomainRole = Qt.ItemDataRole.UserRole + 1 CookieRole = Qt.ItemDataRole.UserRole + 2 - + def __init__(self, cookieJar, parent=None): """ Constructor - + @param cookieJar reference to the cookie jar (CookieJar) @param parent reference to the parent widget (QWidget) """ super().__init__(parent) self.setupUi(self) - + self.addButton.setEnabled(False) - + self.__cookieJar = cookieJar - + self.__domainDict = {} - - self.cookiesTree.headerItem().setText( - self.cookiesTree.columnCount(), "") - + + self.cookiesTree.headerItem().setText(self.cookiesTree.columnCount(), "") + for cookie in self.__cookieJar.cookies(): self.__addCookie(cookie) self.__resizeColumns() - + self.cookiesTree.itemExpanded.connect(self.__resizeColumns) self.cookiesTree.itemCollapsed.connect(self.__resizeColumns) - + @pyqtSlot() def __resizeColumns(self): """ Private slot to resize the columns. """ self.cookiesTree.header().resizeSections( - QHeaderView.ResizeMode.ResizeToContents) + QHeaderView.ResizeMode.ResizeToContents + ) self.cookiesTree.header().setStretchLastSection(True) - + def __cookieDomain(self, cookie): """ Private method to extract the cookie domain. - + @param cookie cookie to get the domain from @type QNetworkCookie @return domain of the cookie @@ -70,11 +71,11 @@ if domain.startswith("."): domain = domain[1:] return domain - + def __addCookie(self, cookie): """ Private method to add a cookie to the tree. - + @param cookie reference to the cookie @type QNetworkCookie """ @@ -86,13 +87,13 @@ newParent.setText(0, domain) newParent.setData(0, self.DomainRole, cookie.domain()) self.__domainDict[domain] = newParent - + itm = QTreeWidgetItem(newParent) - + itm.setText(0, cookie.domain()) itm.setText(1, bytes(cookie.name()).decode()) itm.setData(0, self.CookieRole, cookie) - + @pyqtSlot() def on_addButton_clicked(self): """ @@ -101,14 +102,14 @@ current = self.cookiesTree.currentItem() if current is None: return - + from .CookiesExceptionsDialog import CookiesExceptionsDialog - + domain = current.text(0) dlg = CookiesExceptionsDialog(self.__cookieJar, self) dlg.setDomainName(domain) dlg.exec() - + @pyqtSlot() def on_removeButton_clicked(self): """ @@ -117,7 +118,7 @@ current = self.cookiesTree.currentItem() if current is None: return - + if current.childCount() == 0: # single cookie cookie = current.data(0, self.CookieRole) @@ -135,7 +136,7 @@ index = self.cookiesTree.indexOfTopLevelItem(current) self.cookiesTree.takeTopLevelItem(index) del current - + @pyqtSlot() def on_removeAllButton_clicked(self): """ @@ -144,17 +145,18 @@ res = EricMessageBox.yesNo( self, self.tr("Remove All Cookies"), - self.tr("""Do you really want to remove all stored cookies?""")) + self.tr("""Do you really want to remove all stored cookies?"""), + ) if res: self.__cookieJar.clear() self.__domainDict = {} self.cookiesTree.clear() - + @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) def on_cookiesTree_currentItemChanged(self, current, previous): """ Private slot to handle a change of the current item. - + @param current reference to the current item @type QTreeWidgetItem @param previous reference to the previous current item @@ -162,10 +164,10 @@ """ self.addButton.setEnabled(current is not None) self.removeButton.setEnabled(current is not None) - + if current is None: return - + if not current.text(1): # it is a cookie domain entry self.domain.setText(self.tr("<no cookie selected>")) @@ -174,12 +176,12 @@ self.secure.setText(self.tr("<no cookie selected>")) self.expiration.setText(self.tr("<no cookie selected>")) self.value.setText(self.tr("<no cookie selected>")) - + self.removeButton.setText(self.tr("Remove Cookies")) else: # it is a cookie entry cookie = current.data(0, self.CookieRole) - + self.domain.setText(cookie.domain()) self.name.setText(bytes(cookie.name()).decode()) self.path.setText(cookie.path()) @@ -191,17 +193,19 @@ self.expiration.setText(self.tr("Session Cookie")) else: self.expiration.setText( - cookie.expirationDate().toString("yyyy-MM-dd HH:mm:ss")) + cookie.expirationDate().toString("yyyy-MM-dd HH:mm:ss") + ) self.value.setText( - bytes(QByteArray.fromPercentEncoding(cookie.value())).decode()) - + bytes(QByteArray.fromPercentEncoding(cookie.value())).decode() + ) + self.removeButton.setText(self.tr("Remove Cookie")) - + @pyqtSlot(str) def on_searchEdit_textChanged(self, txt): """ Private slot to search and filter the cookie tree. - + @param txt text to search for @type str """