81 itm = QTreeWidgetItem(newParent) |
76 itm = QTreeWidgetItem(newParent) |
82 |
77 |
83 itm.setText(0, cookie.domain()) |
78 itm.setText(0, cookie.domain()) |
84 itm.setText(1, bytes(cookie.name()).decode()) |
79 itm.setText(1, bytes(cookie.name()).decode()) |
85 itm.setData(0, self.CookieRole, cookie) |
80 itm.setData(0, self.CookieRole, cookie) |
86 |
|
87 ## self.__itemDict[itm] = cookie |
|
88 |
|
89 ## self.removeButton.clicked.connect(self.cookiesTable.removeSelected) |
|
90 ## self.removeAllButton.clicked.connect(self.cookiesTable.removeAll) |
|
91 ## |
|
92 ## self.cookiesTable.verticalHeader().hide() |
|
93 ## model = CookieModel(cookieJar, self) |
|
94 ## self.__proxyModel = QSortFilterProxyModel(self) |
|
95 ## self.__proxyModel.setSourceModel(model) |
|
96 ## self.searchEdit.textChanged.connect( |
|
97 ## self.__proxyModel.setFilterFixedString) |
|
98 ## self.cookiesTable.setModel(self.__proxyModel) |
|
99 ## self.cookiesTable.doubleClicked.connect(self.__showCookieDetails) |
|
100 ## self.cookiesTable.selectionModel().selectionChanged.connect( |
|
101 ## self.__tableSelectionChanged) |
|
102 ## self.cookiesTable.model().modelReset.connect(self.__tableModelReset) |
|
103 ## |
|
104 ## fm = QFontMetrics(QFont()) |
|
105 ## height = fm.height() + fm.height() // 3 |
|
106 ## self.cookiesTable.verticalHeader().setDefaultSectionSize(height) |
|
107 ## self.cookiesTable.verticalHeader().setMinimumSectionSize(-1) |
|
108 ## for section in range(model.columnCount()): |
|
109 ## header = self.cookiesTable.horizontalHeader()\ |
|
110 ## .sectionSizeHint(section) |
|
111 ## if section == 0: |
|
112 ## header = fm.width("averagebiglonghost.averagedomain.info") |
|
113 ## elif section == 1: |
|
114 ## header = fm.width("_session_id") |
|
115 ## elif section == 4: |
|
116 ## header = fm.width( |
|
117 ## QDateTime.currentDateTime().toString(Qt.LocalDate)) |
|
118 ## buffer = fm.width("mm") |
|
119 ## header += buffer |
|
120 ## self.cookiesTable.horizontalHeader().resizeSection(section, header) |
|
121 ## self.cookiesTable.horizontalHeader().setStretchLastSection(True) |
|
122 ## self.cookiesTable.model().sort( |
|
123 ## self.cookiesTable.horizontalHeader().sortIndicatorSection(), |
|
124 ## Qt.AscendingOrder) |
|
125 ## |
|
126 ## self.__detailsDialog = None |
|
127 ## |
|
128 ## def __showCookieDetails(self, index): |
|
129 ## """ |
|
130 ## Private slot to show a dialog with the cookie details. |
|
131 ## |
|
132 ## @param index index of the entry to show (QModelIndex) |
|
133 ## """ |
|
134 ## if not index.isValid(): |
|
135 ## return |
|
136 ## |
|
137 ## cookiesTable = self.sender() |
|
138 ## if cookiesTable is None: |
|
139 ## return |
|
140 ## |
|
141 ## model = cookiesTable.model() |
|
142 ## row = index.row() |
|
143 ## |
|
144 ## domain = model.data(model.index(row, 0)) |
|
145 ## name = model.data(model.index(row, 1)) |
|
146 ## path = model.data(model.index(row, 2)) |
|
147 ## secure = model.data(model.index(row, 3)) |
|
148 ## expires = model.data(model.index(row, 4)).toString("yyyy-MM-dd hh:mm") |
|
149 ## data = model.data(model.index(row, 5)) |
|
150 ## if data is None: |
|
151 ## value = "" |
|
152 ## else: |
|
153 ## value = bytes(QByteArray.fromPercentEncoding(data)).decode() |
|
154 ## |
|
155 ## if self.__detailsDialog is None: |
|
156 ## from .CookieDetailsDialog import CookieDetailsDialog |
|
157 ## self.__detailsDialog = CookieDetailsDialog(self) |
|
158 ## self.__detailsDialog.setData(domain, name, path, secure, expires, |
|
159 ## value) |
|
160 ## self.__detailsDialog.show() |
|
161 |
81 |
162 @pyqtSlot() |
82 @pyqtSlot() |
163 def on_addButton_clicked(self): |
83 def on_addButton_clicked(self): |
164 """ |
84 """ |
165 Private slot to add a new exception. |
85 Private slot to add a new exception. |
166 """ |
86 """ |
167 # TODO: change this |
87 current = self.cookiesTree.currentItem() |
168 ## selection = self.cookiesTable.selectionModel().selectedRows() |
88 if current is None: |
169 ## if len(selection) == 0: |
89 return |
170 ## return |
90 |
171 ## |
91 from .CookiesExceptionsDialog import CookiesExceptionsDialog |
172 ## from .CookiesExceptionsDialog import CookiesExceptionsDialog |
92 |
173 ## |
93 domain = current.text(0) |
174 ## firstSelected = selection[0] |
94 dlg = CookiesExceptionsDialog(self.__cookieJar, self) |
175 ## domainSelection = firstSelected.sibling(firstSelected.row(), 0) |
95 dlg.setDomainName(domain) |
176 ## domain = self.__proxyModel.data(domainSelection, Qt.DisplayRole) |
96 dlg.exec_() |
177 ## dlg = CookiesExceptionsDialog(self.__cookieJar, self) |
|
178 ## dlg.setDomainName(domain) |
|
179 ## dlg.exec_() |
|
180 ## |
|
181 ## def __tableSelectionChanged(self, selected, deselected): |
|
182 ## """ |
|
183 ## Private slot to handle a change of selected items. |
|
184 ## |
|
185 ## @param selected selected indexes (QItemSelection) |
|
186 ## @param deselected deselected indexes (QItemSelection) |
|
187 ## """ |
|
188 ## self.addButton.setEnabled(len(selected.indexes()) > 0) |
|
189 ## |
|
190 ## def __tableModelReset(self): |
|
191 ## """ |
|
192 ## Private slot to handle a reset of the cookies table. |
|
193 ## """ |
|
194 ## self.addButton.setEnabled(False) |
|
195 |
97 |
196 @pyqtSlot() |
98 @pyqtSlot() |
197 def on_removeButton_clicked(self): |
99 def on_removeButton_clicked(self): |
198 """ |
100 """ |
199 Slot documentation goes here. |
101 Private slot to remove the selected cookie(s). |
200 """ |
102 """ |
201 # TODO: not implemented yet |
103 current = self.cookiesTree.currentItem() |
202 raise NotImplementedError |
104 if current is None: |
|
105 return |
|
106 |
|
107 if current.childCount() == 0: |
|
108 # single cookie |
|
109 cookie = current.data(0, self.CookieRole) |
|
110 self.__cookieJar.removeCookie(cookie) |
|
111 current.parent().removeChild(current) |
|
112 del current |
|
113 else: |
|
114 cookies = [] |
|
115 for row in range(current.childCount() - 1, -1, -1): |
|
116 child = current.child(row) |
|
117 cookies.append(child.data(0, self.CookieRole)) |
|
118 current.removeChild(child) |
|
119 del child |
|
120 self.__cookieJar.removeCookies(cookies) |
|
121 index = self.cookiesTree.indexOfTopLevelItem(current) |
|
122 self.cookiesTree.takeTopLevelItem(index) |
|
123 del current |
203 |
124 |
204 @pyqtSlot() |
125 @pyqtSlot() |
205 def on_removeAllButton_clicked(self): |
126 def on_removeAllButton_clicked(self): |
206 """ |
127 """ |
207 Slot documentation goes here. |
128 Private slot to remove all cookies. |
208 """ |
129 """ |
209 # TODO: not implemented yet |
130 res = E5MessageBox.yesNo( |
210 raise NotImplementedError |
131 self, |
|
132 self.tr("Remove All Cookies"), |
|
133 self.tr("""Do you really want to remove all stored cookies?""")) |
|
134 if res: |
|
135 self.__cookieJar.clear() |
|
136 self.__domainDict = {} |
|
137 self.cookiesTree.clear() |
211 |
138 |
212 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
139 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
213 def on_cookiesTree_currentItemChanged(self, current, previous): |
140 def on_cookiesTree_currentItemChanged(self, current, previous): |
214 """ |
141 """ |
215 Private slot to handle a change of the current item. |
142 Private slot to handle a change of the current item. |