WebBrowser/CookieJar/CookiesDialog.py

Sun, 31 Dec 2017 16:52:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 31 Dec 2017 16:52:09 +0100
changeset 6048
82ad8ec9548c
parent 5389
9b1c800daff3
child 6645
ad476851d7e0
permissions
-rw-r--r--

Updated copyright for 2018.

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
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
3 # Copyright (c) 2009 - 2018 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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3057
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
12 from PyQt5.QtCore import pyqtSlot, Qt, QByteArray
5038
df7103c3f2a6 Added capabilities to open links in a new background tab, and several other link open actions to various context menus of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5037
diff changeset
13 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QHeaderView
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
15 from E5Gui import E5MessageBox
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
16
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
17 from .Ui_CookiesDialog import Ui_CookiesDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class CookiesDialog(QDialog, Ui_CookiesDialog):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing a dialog to show all cookies.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
24 DomainRole = Qt.UserRole + 1
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
25 CookieRole = Qt.UserRole + 2
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
26
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
27 def __init__(self, cookieJar, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param cookieJar reference to the cookie jar (CookieJar)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param parent reference to the parent widget (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
34 super(CookiesDialog, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.setupUi(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.addButton.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__cookieJar = cookieJar
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
41 self.__domainDict = {}
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
42
5037
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
43 self.cookiesTree.headerItem().setText(
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
44 self.cookiesTree.columnCount(), "")
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
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()
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
49
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)
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
52
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 """
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
58 self.cookiesTree.header().resizeSections(QHeaderView.ResizeToContents)
b2b37d7c0791 Refinement of the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
59 self.cookiesTree.header().setStretchLastSection(True)
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
60
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
61 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
62 """
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
63 Private method to extract the cookie domain.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
65 @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
66 @type QNetworkCookie
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
67 @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
68 @rtype str
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
69 """
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
70 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
71 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
72 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
73 return domain
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
74
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
75 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
76 """
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
77 Private method to add a cookie to the tree.
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 @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
80 @type QNetworkCookie
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
81 """
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
82 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
83 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
84 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
85 else:
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
86 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
87 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
88 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
89 self.__domainDict[domain] = newParent
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
90
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
91 itm = QTreeWidgetItem(newParent)
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
92
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
93 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
94 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
95 itm.setData(0, self.CookieRole, cookie)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 def on_addButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 Private slot to add a new exception.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
102 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
103 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
104 return
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
105
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
106 from .CookiesExceptionsDialog import CookiesExceptionsDialog
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
107
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
108 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
109 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
110 dlg.setDomainName(domain)
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
111 dlg.exec_()
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
112
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
113 @pyqtSlot()
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
114 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
115 """
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
116 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
117 """
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
118 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
119 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
120 return
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
121
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
122 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
123 # single cookie
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
124 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
125 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
126 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
127 del current
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
128 else:
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
129 cookies = []
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
130 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
131 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
132 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
133 current.removeChild(child)
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
134 del child
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
135 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
136 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
137 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
138 del current
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
139
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
140 @pyqtSlot()
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
141 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
142 """
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
143 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
144 """
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
145 res = E5MessageBox.yesNo(
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
146 self,
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
147 self.tr("Remove All Cookies"),
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
148 self.tr("""Do you really want to remove all stored cookies?"""))
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
149 if res:
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
150 self.__cookieJar.clear()
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
151 self.__domainDict = {}
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5029
diff changeset
152 self.cookiesTree.clear()
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
153
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
154 @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
155 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
156 """
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
157 Private slot to handle a change of 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
158
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
159 @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
160 @type QTreeWidgetItem
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
161 @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
162 @type QTreeWidgetItem
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
163 """
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
164 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
165 self.removeButton.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
166
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
167 if current is None:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 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
171 # 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
172 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
173 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
174 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
175 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
176 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
177 self.value.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
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
179 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
180 else:
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
181 # 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
182 cookie = current.data(0, self.CookieRole)
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
183
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
184 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
185 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
186 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
187 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
188 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
189 else:
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
190 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
191 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
192 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
193 else:
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
194 self.expiration.setText(
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
195 cookie.expirationDate().toString("yyyy-MM-dd HH:mm:ss"))
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
196 self.value.setText(
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
197 bytes(QByteArray.fromPercentEncoding(cookie.value())).decode())
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
198
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
199 self.removeButton.setText(self.tr("Remove Cookie"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
5029
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
201 @pyqtSlot(str)
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
202 def on_searchEdit_textChanged(self, txt):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 Private slot to search and filter the cookie tree.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 @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
207 @type str
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 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
210 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
211 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
212 else:
1ce5e98ebc43 Started to rework the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
213 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
214 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
215 self.cookiesTree.topLevelItem(row).setHidden(txt not in text)

eric ide

mercurial