18 |
18 |
19 def __init__(self, cookieJar, parent=None): |
19 def __init__(self, cookieJar, parent=None): |
20 """ |
20 """ |
21 Constructor |
21 Constructor |
22 |
22 |
23 @param cookieJar reference to the cookie jar (CookieJar) |
23 @param cookieJar reference to the cookie jar |
24 @param parent reference to the parent object (QObject) |
24 @type CookieJar |
|
25 @param parent reference to the parent object |
|
26 @type QObject |
25 """ |
27 """ |
26 super().__init__(parent) |
28 super().__init__(parent) |
27 |
29 |
28 self.__cookieJar = cookieJar |
30 self.__cookieJar = cookieJar |
29 self.__allowedCookies = self.__cookieJar.allowedCookies() |
31 self.__allowedCookies = self.__cookieJar.allowedCookies() |
37 |
39 |
38 def headerData(self, section, orientation, role): |
40 def headerData(self, section, orientation, role): |
39 """ |
41 """ |
40 Public method to get header data from the model. |
42 Public method to get header data from the model. |
41 |
43 |
42 @param section section number (integer) |
44 @param section section number |
43 @param orientation orientation (Qt.Orientation) |
45 @type int |
44 @param role role of the data to retrieve (Qt.ItemDataRole) |
46 @param orientation orientation |
|
47 @type Qt.Orientation |
|
48 @param role role of the data to retrieve |
|
49 @type Qt.ItemDataRole |
45 @return requested data |
50 @return requested data |
|
51 @rtype Any |
46 """ |
52 """ |
47 if role == Qt.ItemDataRole.SizeHintRole: |
53 if role == Qt.ItemDataRole.SizeHintRole: |
48 fm = QFontMetrics(QFont()) |
54 fm = QFontMetrics(QFont()) |
49 height = fm.height() + fm.height() // 3 |
55 height = fm.height() + fm.height() // 3 |
50 width = fm.horizontalAdvance( |
56 width = fm.horizontalAdvance( |
65 |
71 |
66 def data(self, index, role): |
72 def data(self, index, role): |
67 """ |
73 """ |
68 Public method to get data from the model. |
74 Public method to get data from the model. |
69 |
75 |
70 @param index index to get data for (QModelIndex) |
76 @param index index to get data for |
71 @param role role of the data to retrieve (integer) |
77 @type QModelIndex |
|
78 @param role role of the data to retrieve |
|
79 @type int |
72 @return requested data |
80 @return requested data |
|
81 @rtype Any |
73 """ |
82 """ |
74 if index.row() < 0 or index.row() >= self.rowCount(): |
83 if index.row() < 0 or index.row() >= self.rowCount(): |
75 return None |
84 return None |
76 |
85 |
77 if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole): |
86 if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole): |
108 |
117 |
109 def columnCount(self, parent=None): |
118 def columnCount(self, parent=None): |
110 """ |
119 """ |
111 Public method to get the number of columns of the model. |
120 Public method to get the number of columns of the model. |
112 |
121 |
113 @param parent parent index (QModelIndex) |
122 @param parent parent index |
114 @return number of columns (integer) |
123 @type QModelIndex |
|
124 @return number of columns |
|
125 @rtype int |
115 """ |
126 """ |
116 if parent is None: |
127 if parent is None: |
117 parent = QModelIndex() |
128 parent = QModelIndex() |
118 |
129 |
119 if parent.isValid(): |
130 if parent.isValid(): |
123 |
134 |
124 def rowCount(self, parent=None): |
135 def rowCount(self, parent=None): |
125 """ |
136 """ |
126 Public method to get the number of rows of the model. |
137 Public method to get the number of rows of the model. |
127 |
138 |
128 @param parent parent index (QModelIndex) |
139 @param parent parent index |
129 @return number of rows (integer) |
140 @type QModelIndex |
|
141 @return number of rows |
|
142 @rtype int |
130 """ |
143 """ |
131 if parent is None: |
144 if parent is None: |
132 parent = QModelIndex() |
145 parent = QModelIndex() |
133 |
146 |
134 if parent.isValid() or self.__cookieJar is None: |
147 if parent.isValid() or self.__cookieJar is None: |
142 |
155 |
143 def removeRows(self, row, count, parent=None): |
156 def removeRows(self, row, count, parent=None): |
144 """ |
157 """ |
145 Public method to remove entries from the model. |
158 Public method to remove entries from the model. |
146 |
159 |
147 @param row start row (integer) |
160 @param row start row |
148 @param count number of rows to remove (integer) |
161 @type int |
149 @param parent parent index (QModelIndex) |
162 @param count number of rows to remove |
150 @return flag indicating success (boolean) |
163 @type int |
|
164 @param parent parent index |
|
165 @type QModelIndex |
|
166 @return flag indicating success |
|
167 @rtype bool |
151 """ |
168 """ |
152 if parent is None: |
169 if parent is None: |
153 parent = QModelIndex() |
170 parent = QModelIndex() |
154 |
171 |
155 if parent.isValid() or self.__cookieJar is None: |
172 if parent.isValid() or self.__cookieJar is None: |
183 |
200 |
184 def addRule(self, host, rule): |
201 def addRule(self, host, rule): |
185 """ |
202 """ |
186 Public method to add an exception rule. |
203 Public method to add an exception rule. |
187 |
204 |
188 @param host name of the host to add a rule for (string) |
205 @param host name of the host to add a rule for |
|
206 @type str |
189 @param rule type of rule to add (CookieJar.Allow, CookieJar.Block or |
207 @param rule type of rule to add (CookieJar.Allow, CookieJar.Block or |
190 CookieJar.AllowForSession) |
208 CookieJar.AllowForSession) |
|
209 @type int |
191 """ |
210 """ |
192 from .CookieJar import CookieJar |
211 from .CookieJar import CookieJar |
193 |
212 |
194 if not host: |
213 if not host: |
195 return |
214 return |
221 |
240 |
222 def __addHost(self, host, addList, removeList1, removeList2): |
241 def __addHost(self, host, addList, removeList1, removeList2): |
223 """ |
242 """ |
224 Private method to add a host to an exception list. |
243 Private method to add a host to an exception list. |
225 |
244 |
226 @param host name of the host to add (string) |
245 @param host name of the host to add |
227 @param addList reference to the list to add it to (list of strings) |
246 @type str |
|
247 @param addList reference to the list to add it to |
|
248 @type list of str |
228 @param removeList1 reference to first list to remove it from |
249 @param removeList1 reference to first list to remove it from |
229 (list of strings) |
250 @type list of str |
230 @param removeList2 reference to second list to remove it from |
251 @param removeList2 reference to second list to remove it from |
231 (list of strings) |
252 @type list of str |
232 """ |
253 """ |
233 if host not in addList: |
254 if host not in addList: |
234 addList.append(host) |
255 addList.append(host) |
235 if host in removeList1: |
256 if host in removeList1: |
236 removeList1.remove(host) |
257 removeList1.remove(host) |