Fri, 22 Dec 2023 17:24:07 +0100
Converted some source code documentation to the new style.
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
9653
e67609152c5e
Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
3 | # Copyright (c) 2009 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a dialog to show all cookies. |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
10 | from PyQt6.QtCore import QByteArray, Qt, pyqtSlot |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
11 | from PyQt6.QtWidgets import QDialog, QHeaderView, QTreeWidgetItem |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
13 | from eric7.EricWidgets import EricMessageBox |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
14 | |
12
1d8dd9706f46
First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7
diff
changeset
|
15 | from .Ui_CookiesDialog import Ui_CookiesDialog |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
17 | |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | class CookiesDialog(QDialog, Ui_CookiesDialog): |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | """ |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | Class implementing a dialog to show all cookies. |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
22 | |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
23 | DomainRole = Qt.ItemDataRole.UserRole + 1 |
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
24 | CookieRole = Qt.ItemDataRole.UserRole + 2 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
25 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
26 | def __init__(self, cookieJar, parent=None): |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | """ |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
29 | |
10436
f6881d10e995
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
30 | @param cookieJar reference to the cookie jar |
f6881d10e995
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
31 | @type CookieJar |
f6881d10e995
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
32 | @param parent reference to the parent widget |
f6881d10e995
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
33 | @type QWidget |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
35 | super().__init__(parent) |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | self.setupUi(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
37 | |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | self.addButton.setEnabled(False) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
39 | |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | self.__cookieJar = cookieJar |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
42 | self.__domainDict = {} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
43 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
44 | self.cookiesTree.headerItem().setText(self.cookiesTree.columnCount(), "") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
46 | for cookie in self.__cookieJar.cookies(): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
47 | self.__addCookie(cookie) |
5037
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
48 | self.__resizeColumns() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | |
5037
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
50 | self.cookiesTree.itemExpanded.connect(self.__resizeColumns) |
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
51 | self.cookiesTree.itemCollapsed.connect(self.__resizeColumns) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
5037
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
53 | @pyqtSlot() |
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
54 | def __resizeColumns(self): |
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
55 | """ |
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
56 | Private slot to resize the columns. |
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
57 | """ |
8143
2c730d5fd177
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
58 | self.cookiesTree.header().resizeSections( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
59 | QHeaderView.ResizeMode.ResizeToContents |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
60 | ) |
5037
b2b37d7c0791
Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5030
diff
changeset
|
61 | self.cookiesTree.header().setStretchLastSection(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
62 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
63 | def __cookieDomain(self, cookie): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
64 | """ |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
65 | Private method to extract the cookie domain. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
66 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
67 | @param cookie cookie to get the domain from |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
68 | @type QNetworkCookie |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
69 | @return domain of the cookie |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
70 | @rtype str |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
71 | """ |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
72 | domain = cookie.domain() |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
73 | if domain.startswith("."): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
74 | domain = domain[1:] |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
75 | return domain |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
77 | def __addCookie(self, cookie): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
78 | """ |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
79 | Private method to add a cookie to the tree. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
81 | @param cookie reference to the cookie |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
82 | @type QNetworkCookie |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
83 | """ |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
84 | domain = self.__cookieDomain(cookie) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
85 | if domain in self.__domainDict: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
86 | itm = QTreeWidgetItem(self.__domainDict[domain]) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
87 | else: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
88 | newParent = QTreeWidgetItem(self.cookiesTree) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
89 | newParent.setText(0, domain) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
90 | newParent.setData(0, self.DomainRole, cookie.domain()) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
91 | self.__domainDict[domain] = newParent |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
93 | itm = QTreeWidgetItem(newParent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
95 | itm.setText(0, cookie.domain()) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
96 | itm.setText(1, bytes(cookie.name()).decode()) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
97 | itm.setData(0, self.CookieRole, cookie) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | @pyqtSlot() |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | def on_addButton_clicked(self): |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | """ |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | Private slot to add a new exception. |
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | """ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
104 | from .CookiesExceptionsDialog import CookiesExceptionsDialog |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
105 | |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
106 | current = self.cookiesTree.currentItem() |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
107 | if current is None: |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
108 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
109 | |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
110 | domain = current.text(0) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
111 | dlg = CookiesExceptionsDialog(self.__cookieJar, self) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
112 | dlg.setDomainName(domain) |
7759
51aa6c6b66f7
Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
113 | dlg.exec() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
114 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
115 | @pyqtSlot() |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
116 | def on_removeButton_clicked(self): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
117 | """ |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
118 | Private slot to remove the selected cookie(s). |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
119 | """ |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
120 | current = self.cookiesTree.currentItem() |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
121 | if current is None: |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
122 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
124 | if current.childCount() == 0: |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
125 | # single cookie |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
126 | cookie = current.data(0, self.CookieRole) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
127 | self.__cookieJar.removeCookie(cookie) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
128 | current.parent().removeChild(current) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
129 | del current |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
130 | else: |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
131 | cookies = [] |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
132 | for row in range(current.childCount() - 1, -1, -1): |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
133 | child = current.child(row) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
134 | cookies.append(child.data(0, self.CookieRole)) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
135 | current.removeChild(child) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
136 | del child |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
137 | self.__cookieJar.removeCookies(cookies) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
138 | index = self.cookiesTree.indexOfTopLevelItem(current) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
139 | self.cookiesTree.takeTopLevelItem(index) |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
140 | del current |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
141 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
142 | @pyqtSlot() |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
143 | def on_removeAllButton_clicked(self): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
144 | """ |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
145 | Private slot to remove all cookies. |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
146 | """ |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
147 | res = EricMessageBox.yesNo( |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
148 | self, |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
149 | self.tr("Remove All Cookies"), |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
150 | self.tr("""Do you really want to remove all stored cookies?"""), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
151 | ) |
5030
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
152 | if res: |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
153 | self.__cookieJar.clear() |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
154 | self.__domainDict = {} |
b728bb00886e
Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5029
diff
changeset
|
155 | self.cookiesTree.clear() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
156 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
157 | @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
158 | def on_cookiesTree_currentItemChanged(self, current, previous): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
159 | """ |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
160 | Private slot to handle a change of the current item. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
161 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
162 | @param current reference to the current item |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
163 | @type QTreeWidgetItem |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
164 | @param previous reference to the previous current item |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
165 | @type QTreeWidgetItem |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
166 | """ |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
167 | self.addButton.setEnabled(current is not None) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
168 | self.removeButton.setEnabled(current is not None) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
169 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
170 | if current is None: |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
172 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
173 | if not current.text(1): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
174 | # it is a cookie domain entry |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
175 | self.domain.setText(self.tr("<no cookie selected>")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
176 | self.name.setText(self.tr("<no cookie selected>")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
177 | self.path.setText(self.tr("<no cookie selected>")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
178 | self.secure.setText(self.tr("<no cookie selected>")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
179 | self.expiration.setText(self.tr("<no cookie selected>")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
180 | self.value.setText(self.tr("<no cookie selected>")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
181 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
182 | self.removeButton.setText(self.tr("Remove Cookies")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
183 | else: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
184 | # it is a cookie entry |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
185 | cookie = current.data(0, self.CookieRole) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
186 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
187 | self.domain.setText(cookie.domain()) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
188 | self.name.setText(bytes(cookie.name()).decode()) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
189 | self.path.setText(cookie.path()) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
190 | if cookie.isSecure(): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
191 | self.secure.setText(self.tr("Secure connections only")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
192 | else: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
193 | self.secure.setText(self.tr("All connections")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
194 | if cookie.isSessionCookie(): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
195 | self.expiration.setText(self.tr("Session Cookie")) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
196 | else: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
197 | self.expiration.setText( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
198 | cookie.expirationDate().toString("yyyy-MM-dd HH:mm:ss") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
199 | ) |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
200 | self.value.setText( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
201 | bytes(QByteArray.fromPercentEncoding(cookie.value())).decode() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
202 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
203 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
204 | self.removeButton.setText(self.tr("Remove Cookie")) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
205 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
206 | @pyqtSlot(str) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
207 | def on_searchEdit_textChanged(self, txt): |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | """ |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
209 | Private slot to search and filter the cookie tree. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
210 | |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
211 | @param txt text to search for |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
212 | @type str |
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | """ |
5029
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
214 | if not txt: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
215 | for row in range(self.cookiesTree.topLevelItemCount()): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
216 | self.cookiesTree.topLevelItem(row).setHidden(False) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
217 | else: |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
218 | for row in range(self.cookiesTree.topLevelItemCount()): |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
219 | text = self.cookiesTree.topLevelItem(row).text(0) |
1ce5e98ebc43
Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5028
diff
changeset
|
220 | self.cookiesTree.topLevelItem(row).setHidden(txt not in text) |