src/eric7/WebBrowser/FeaturePermissions/FeaturePermissionsDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
6 """ 6 """
7 Module implementing the feature permission dialog. 7 Module implementing the feature permission dialog.
8 """ 8 """
9 9
10 from PyQt6.QtCore import pyqtSlot, Qt 10 from PyQt6.QtCore import pyqtSlot, Qt
11 from PyQt6.QtWidgets import ( 11 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem, QTreeWidget, QAbstractItemView
12 QDialog, QTreeWidgetItem, QTreeWidget, QAbstractItemView
13 )
14 from PyQt6.QtWebEngineCore import QWebEnginePage 12 from PyQt6.QtWebEngineCore import QWebEnginePage
15 13
16 import UI.PixmapCache 14 import UI.PixmapCache
17 15
18 from .Ui_FeaturePermissionsDialog import Ui_FeaturePermissionsDialog 16 from .Ui_FeaturePermissionsDialog import Ui_FeaturePermissionsDialog
20 18
21 class FeaturePermissionsDialog(QDialog, Ui_FeaturePermissionsDialog): 19 class FeaturePermissionsDialog(QDialog, Ui_FeaturePermissionsDialog):
22 """ 20 """
23 Class implementing the feature permission dialog. 21 Class implementing the feature permission dialog.
24 """ 22 """
23
25 def __init__(self, featurePermissions, parent=None): 24 def __init__(self, featurePermissions, parent=None):
26 """ 25 """
27 Constructor 26 Constructor
28 27
29 @param featurePermissions dictionary with remembered feature 28 @param featurePermissions dictionary with remembered feature
30 permissions 29 permissions
31 @type dict of dict of list 30 @type dict of dict of list
32 @param parent reference to the parent widget 31 @param parent reference to the parent widget
33 @type QWidget 32 @type QWidget
34 """ 33 """
35 super().__init__(parent) 34 super().__init__(parent)
36 self.setupUi(self) 35 self.setupUi(self)
37 36
38 # add the various lists 37 # add the various lists
39 38
40 self.notifList = QTreeWidget() 39 self.notifList = QTreeWidget()
41 self.notifList.setAlternatingRowColors(True) 40 self.notifList.setAlternatingRowColors(True)
42 self.notifList.setSelectionMode( 41 self.notifList.setSelectionMode(
43 QAbstractItemView.SelectionMode.ExtendedSelection) 42 QAbstractItemView.SelectionMode.ExtendedSelection
43 )
44 self.notifList.setRootIsDecorated(False) 44 self.notifList.setRootIsDecorated(False)
45 self.notifList.setItemsExpandable(False) 45 self.notifList.setItemsExpandable(False)
46 self.notifList.setAllColumnsShowFocus(True) 46 self.notifList.setAllColumnsShowFocus(True)
47 self.notifList.setObjectName("notifList") 47 self.notifList.setObjectName("notifList")
48 self.notifList.setSortingEnabled(True) 48 self.notifList.setSortingEnabled(True)
49 self.notifList.headerItem().setText(0, self.tr("Host")) 49 self.notifList.headerItem().setText(0, self.tr("Host"))
50 self.notifList.headerItem().setText(1, self.tr("Permission")) 50 self.notifList.headerItem().setText(1, self.tr("Permission"))
51 self.tabWidget.addTab( 51 self.tabWidget.addTab(
52 self.notifList, 52 self.notifList,
53 UI.PixmapCache.getIcon("notification"), 53 UI.PixmapCache.getIcon("notification"),
54 self.tr("Notifications")) 54 self.tr("Notifications"),
55 55 )
56
56 self.geoList = QTreeWidget() 57 self.geoList = QTreeWidget()
57 self.geoList.setAlternatingRowColors(True) 58 self.geoList.setAlternatingRowColors(True)
58 self.geoList.setSelectionMode( 59 self.geoList.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
59 QAbstractItemView.SelectionMode.ExtendedSelection)
60 self.geoList.setRootIsDecorated(False) 60 self.geoList.setRootIsDecorated(False)
61 self.geoList.setItemsExpandable(False) 61 self.geoList.setItemsExpandable(False)
62 self.geoList.setAllColumnsShowFocus(True) 62 self.geoList.setAllColumnsShowFocus(True)
63 self.geoList.setObjectName("geoList") 63 self.geoList.setObjectName("geoList")
64 self.geoList.setSortingEnabled(True) 64 self.geoList.setSortingEnabled(True)
65 self.geoList.headerItem().setText(0, self.tr("Host")) 65 self.geoList.headerItem().setText(0, self.tr("Host"))
66 self.geoList.headerItem().setText(1, self.tr("Permission")) 66 self.geoList.headerItem().setText(1, self.tr("Permission"))
67 self.tabWidget.addTab( 67 self.tabWidget.addTab(
68 self.geoList, 68 self.geoList, UI.PixmapCache.getIcon("geolocation"), self.tr("Geolocation")
69 UI.PixmapCache.getIcon("geolocation"), 69 )
70 self.tr("Geolocation")) 70
71
72 self.micList = QTreeWidget() 71 self.micList = QTreeWidget()
73 self.micList.setAlternatingRowColors(True) 72 self.micList.setAlternatingRowColors(True)
74 self.micList.setSelectionMode( 73 self.micList.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
75 QAbstractItemView.SelectionMode.ExtendedSelection)
76 self.micList.setRootIsDecorated(False) 74 self.micList.setRootIsDecorated(False)
77 self.micList.setItemsExpandable(False) 75 self.micList.setItemsExpandable(False)
78 self.micList.setAllColumnsShowFocus(True) 76 self.micList.setAllColumnsShowFocus(True)
79 self.micList.setObjectName("micList") 77 self.micList.setObjectName("micList")
80 self.micList.setSortingEnabled(True) 78 self.micList.setSortingEnabled(True)
81 self.micList.headerItem().setText(0, self.tr("Host")) 79 self.micList.headerItem().setText(0, self.tr("Host"))
82 self.micList.headerItem().setText(1, self.tr("Permission")) 80 self.micList.headerItem().setText(1, self.tr("Permission"))
83 self.tabWidget.addTab( 81 self.tabWidget.addTab(
84 self.micList, 82 self.micList, UI.PixmapCache.getIcon("audiocapture"), self.tr("Microphone")
85 UI.PixmapCache.getIcon("audiocapture"), 83 )
86 self.tr("Microphone")) 84
87
88 self.camList = QTreeWidget() 85 self.camList = QTreeWidget()
89 self.camList.setAlternatingRowColors(True) 86 self.camList.setAlternatingRowColors(True)
90 self.camList.setSelectionMode( 87 self.camList.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
91 QAbstractItemView.SelectionMode.ExtendedSelection)
92 self.camList.setRootIsDecorated(False) 88 self.camList.setRootIsDecorated(False)
93 self.camList.setItemsExpandable(False) 89 self.camList.setItemsExpandable(False)
94 self.camList.setAllColumnsShowFocus(True) 90 self.camList.setAllColumnsShowFocus(True)
95 self.camList.setObjectName("camList") 91 self.camList.setObjectName("camList")
96 self.camList.setSortingEnabled(True) 92 self.camList.setSortingEnabled(True)
97 self.camList.headerItem().setText(0, self.tr("Host")) 93 self.camList.headerItem().setText(0, self.tr("Host"))
98 self.camList.headerItem().setText(1, self.tr("Permission")) 94 self.camList.headerItem().setText(1, self.tr("Permission"))
99 self.tabWidget.addTab( 95 self.tabWidget.addTab(
100 self.camList, 96 self.camList, UI.PixmapCache.getIcon("camera"), self.tr("Camera")
101 UI.PixmapCache.getIcon("camera"), 97 )
102 self.tr("Camera")) 98
103
104 self.micCamList = QTreeWidget() 99 self.micCamList = QTreeWidget()
105 self.micCamList.setAlternatingRowColors(True) 100 self.micCamList.setAlternatingRowColors(True)
106 self.micCamList.setSelectionMode( 101 self.micCamList.setSelectionMode(
107 QAbstractItemView.SelectionMode.ExtendedSelection) 102 QAbstractItemView.SelectionMode.ExtendedSelection
103 )
108 self.micCamList.setRootIsDecorated(False) 104 self.micCamList.setRootIsDecorated(False)
109 self.micCamList.setItemsExpandable(False) 105 self.micCamList.setItemsExpandable(False)
110 self.micCamList.setAllColumnsShowFocus(True) 106 self.micCamList.setAllColumnsShowFocus(True)
111 self.micCamList.setObjectName("micCamList") 107 self.micCamList.setObjectName("micCamList")
112 self.micCamList.setSortingEnabled(True) 108 self.micCamList.setSortingEnabled(True)
113 self.micCamList.headerItem().setText(0, self.tr("Host")) 109 self.micCamList.headerItem().setText(0, self.tr("Host"))
114 self.micCamList.headerItem().setText(1, self.tr("Permission")) 110 self.micCamList.headerItem().setText(1, self.tr("Permission"))
115 self.tabWidget.addTab( 111 self.tabWidget.addTab(
116 self.micCamList, 112 self.micCamList,
117 UI.PixmapCache.getIcon("audio-video"), 113 UI.PixmapCache.getIcon("audio-video"),
118 self.tr("Microphone && Camera")) 114 self.tr("Microphone && Camera"),
119 115 )
116
120 self.mouseLockList = QTreeWidget() 117 self.mouseLockList = QTreeWidget()
121 self.mouseLockList.setAlternatingRowColors(True) 118 self.mouseLockList.setAlternatingRowColors(True)
122 self.mouseLockList.setSelectionMode( 119 self.mouseLockList.setSelectionMode(
123 QAbstractItemView.SelectionMode.ExtendedSelection) 120 QAbstractItemView.SelectionMode.ExtendedSelection
121 )
124 self.mouseLockList.setRootIsDecorated(False) 122 self.mouseLockList.setRootIsDecorated(False)
125 self.mouseLockList.setItemsExpandable(False) 123 self.mouseLockList.setItemsExpandable(False)
126 self.mouseLockList.setAllColumnsShowFocus(True) 124 self.mouseLockList.setAllColumnsShowFocus(True)
127 self.mouseLockList.setObjectName("mouseLockList") 125 self.mouseLockList.setObjectName("mouseLockList")
128 self.mouseLockList.setSortingEnabled(True) 126 self.mouseLockList.setSortingEnabled(True)
129 self.mouseLockList.headerItem().setText(0, self.tr("Host")) 127 self.mouseLockList.headerItem().setText(0, self.tr("Host"))
130 self.mouseLockList.headerItem().setText(1, self.tr("Permission")) 128 self.mouseLockList.headerItem().setText(1, self.tr("Permission"))
131 self.tabWidget.addTab( 129 self.tabWidget.addTab(
132 self.mouseLockList, 130 self.mouseLockList, UI.PixmapCache.getIcon("mouse"), self.tr("Mouse Lock")
133 UI.PixmapCache.getIcon("mouse"), 131 )
134 self.tr("Mouse Lock")) 132
135
136 self.deskVidList = QTreeWidget() 133 self.deskVidList = QTreeWidget()
137 self.deskVidList.setAlternatingRowColors(True) 134 self.deskVidList.setAlternatingRowColors(True)
138 self.deskVidList.setSelectionMode( 135 self.deskVidList.setSelectionMode(
139 QAbstractItemView.SelectionMode.ExtendedSelection) 136 QAbstractItemView.SelectionMode.ExtendedSelection
137 )
140 self.deskVidList.setRootIsDecorated(False) 138 self.deskVidList.setRootIsDecorated(False)
141 self.deskVidList.setItemsExpandable(False) 139 self.deskVidList.setItemsExpandable(False)
142 self.deskVidList.setAllColumnsShowFocus(True) 140 self.deskVidList.setAllColumnsShowFocus(True)
143 self.deskVidList.setObjectName("deskVidList") 141 self.deskVidList.setObjectName("deskVidList")
144 self.deskVidList.setSortingEnabled(True) 142 self.deskVidList.setSortingEnabled(True)
145 self.deskVidList.headerItem().setText(0, self.tr("Host")) 143 self.deskVidList.headerItem().setText(0, self.tr("Host"))
146 self.deskVidList.headerItem().setText(1, self.tr("Permission")) 144 self.deskVidList.headerItem().setText(1, self.tr("Permission"))
147 self.tabWidget.addTab( 145 self.tabWidget.addTab(
148 self.deskVidList, 146 self.deskVidList,
149 UI.PixmapCache.getIcon("desktopVideoCapture"), 147 UI.PixmapCache.getIcon("desktopVideoCapture"),
150 self.tr("Desktop Video")) 148 self.tr("Desktop Video"),
151 149 )
150
152 self.deskAudVidList = QTreeWidget() 151 self.deskAudVidList = QTreeWidget()
153 self.deskAudVidList.setAlternatingRowColors(True) 152 self.deskAudVidList.setAlternatingRowColors(True)
154 self.deskAudVidList.setSelectionMode( 153 self.deskAudVidList.setSelectionMode(
155 QAbstractItemView.SelectionMode.ExtendedSelection) 154 QAbstractItemView.SelectionMode.ExtendedSelection
155 )
156 self.deskAudVidList.setRootIsDecorated(False) 156 self.deskAudVidList.setRootIsDecorated(False)
157 self.deskAudVidList.setItemsExpandable(False) 157 self.deskAudVidList.setItemsExpandable(False)
158 self.deskAudVidList.setAllColumnsShowFocus(True) 158 self.deskAudVidList.setAllColumnsShowFocus(True)
159 self.deskAudVidList.setObjectName("deskAudVidList") 159 self.deskAudVidList.setObjectName("deskAudVidList")
160 self.deskAudVidList.setSortingEnabled(True) 160 self.deskAudVidList.setSortingEnabled(True)
161 self.deskAudVidList.headerItem().setText(0, self.tr("Host")) 161 self.deskAudVidList.headerItem().setText(0, self.tr("Host"))
162 self.deskAudVidList.headerItem().setText(1, self.tr("Permission")) 162 self.deskAudVidList.headerItem().setText(1, self.tr("Permission"))
163 self.tabWidget.addTab( 163 self.tabWidget.addTab(
164 self.deskAudVidList, 164 self.deskAudVidList,
165 UI.PixmapCache.getIcon("desktopAudioVideoCapture"), 165 UI.PixmapCache.getIcon("desktopAudioVideoCapture"),
166 self.tr("Desktop Audio && Video")) 166 self.tr("Desktop Audio && Video"),
167 167 )
168
168 self.setTabOrder(self.tabWidget, self.notifList) 169 self.setTabOrder(self.tabWidget, self.notifList)
169 self.setTabOrder(self.notifList, self.geoList) 170 self.setTabOrder(self.notifList, self.geoList)
170 self.setTabOrder(self.geoList, self.micList) 171 self.setTabOrder(self.geoList, self.micList)
171 self.setTabOrder(self.micList, self.camList) 172 self.setTabOrder(self.micList, self.camList)
172 self.setTabOrder(self.camList, self.micCamList) 173 self.setTabOrder(self.camList, self.micCamList)
173 self.setTabOrder(self.micCamList, self.mouseLockList) 174 self.setTabOrder(self.micCamList, self.mouseLockList)
174 self.setTabOrder(self.mouseLockList, self.deskVidList) 175 self.setTabOrder(self.mouseLockList, self.deskVidList)
175 self.setTabOrder(self.deskVidList, self.deskAudVidList) 176 self.setTabOrder(self.deskVidList, self.deskAudVidList)
176 self.setTabOrder(self.deskAudVidList, self.removeButton) 177 self.setTabOrder(self.deskAudVidList, self.removeButton)
177 self.setTabOrder(self.removeButton, self.removeAllButton) 178 self.setTabOrder(self.removeButton, self.removeAllButton)
178 179
179 self.__permissionStrings = { 180 self.__permissionStrings = {
180 QWebEnginePage.PermissionPolicy.PermissionGrantedByUser: 181 QWebEnginePage.PermissionPolicy.PermissionGrantedByUser: self.tr("Allow"),
181 self.tr("Allow"), 182 QWebEnginePage.PermissionPolicy.PermissionDeniedByUser: self.tr("Deny"),
182 QWebEnginePage.PermissionPolicy.PermissionDeniedByUser:
183 self.tr("Deny"),
184 } 183 }
185 184
186 self.__permissionsLists = { 185 self.__permissionsLists = {
187 QWebEnginePage.Feature.Geolocation: self.geoList, 186 QWebEnginePage.Feature.Geolocation: self.geoList,
188 QWebEnginePage.Feature.MediaAudioCapture: self.micList, 187 QWebEnginePage.Feature.MediaAudioCapture: self.micList,
189 QWebEnginePage.Feature.MediaVideoCapture: self.camList, 188 QWebEnginePage.Feature.MediaVideoCapture: self.camList,
190 QWebEnginePage.Feature.MediaAudioVideoCapture: self.micCamList, 189 QWebEnginePage.Feature.MediaAudioVideoCapture: self.micCamList,
191 QWebEnginePage.Feature.MouseLock: self.mouseLockList, 190 QWebEnginePage.Feature.MouseLock: self.mouseLockList,
192 QWebEnginePage.Feature.DesktopVideoCapture: self.deskVidList, 191 QWebEnginePage.Feature.DesktopVideoCapture: self.deskVidList,
193 QWebEnginePage.Feature.DesktopAudioVideoCapture: 192 QWebEnginePage.Feature.DesktopAudioVideoCapture: self.deskAudVidList,
194 self.deskAudVidList,
195 QWebEnginePage.Feature.Notifications: self.notifList, 193 QWebEnginePage.Feature.Notifications: self.notifList,
196 } 194 }
197 195
198 for feature, permissionsList in self.__permissionsLists.items(): 196 for feature, permissionsList in self.__permissionsLists.items():
199 for permission in featurePermissions[feature]: 197 for permission in featurePermissions[feature]:
200 for host in featurePermissions[feature][permission]: 198 for host in featurePermissions[feature][permission]:
201 itm = QTreeWidgetItem( 199 itm = QTreeWidgetItem(
202 permissionsList, 200 permissionsList, [host, self.__permissionStrings[permission]]
203 [host, self.__permissionStrings[permission]]) 201 )
204 itm.setData(0, Qt.ItemDataRole.UserRole, permission) 202 itm.setData(0, Qt.ItemDataRole.UserRole, permission)
205 203
206 self.__previousCurrent = -1 204 self.__previousCurrent = -1
207 self.tabWidget.currentChanged.connect(self.__currentTabChanged) 205 self.tabWidget.currentChanged.connect(self.__currentTabChanged)
208 self.tabWidget.setCurrentIndex(0) 206 self.tabWidget.setCurrentIndex(0)
209 207
210 @pyqtSlot(int) 208 @pyqtSlot(int)
211 def __currentTabChanged(self, index): 209 def __currentTabChanged(self, index):
212 """ 210 """
213 Private slot handling changes of the selected tab. 211 Private slot handling changes of the selected tab.
214 212
215 @param index index of the current tab 213 @param index index of the current tab
216 @type int 214 @type int
217 """ 215 """
218 if self.__previousCurrent >= 0: 216 if self.__previousCurrent >= 0:
219 previousList = self.tabWidget.widget(self.__previousCurrent) 217 previousList = self.tabWidget.widget(self.__previousCurrent)
220 previousList.itemSelectionChanged.disconnect( 218 previousList.itemSelectionChanged.disconnect(self.__itemSelectionChanged)
221 self.__itemSelectionChanged) 219
222 220 self.__updateButtons()
223 self.__updateButtons() 221
224
225 currentList = self.tabWidget.currentWidget() 222 currentList = self.tabWidget.currentWidget()
226 currentList.itemSelectionChanged.connect(self.__itemSelectionChanged) 223 currentList.itemSelectionChanged.connect(self.__itemSelectionChanged)
227 self.__previousCurrent = index 224 self.__previousCurrent = index
228 225
229 def __updateButtons(self): 226 def __updateButtons(self):
230 """ 227 """
231 Private method to update the buttons. 228 Private method to update the buttons.
232 """ 229 """
233 currentList = self.tabWidget.currentWidget() 230 currentList = self.tabWidget.currentWidget()
234 self.removeAllButton.setEnabled( 231 self.removeAllButton.setEnabled(currentList.topLevelItemCount() > 0)
235 currentList.topLevelItemCount() > 0) 232 self.removeButton.setEnabled(len(currentList.selectedItems()) > 0)
236 self.removeButton.setEnabled( 233
237 len(currentList.selectedItems()) > 0)
238
239 @pyqtSlot() 234 @pyqtSlot()
240 def __itemSelectionChanged(self): 235 def __itemSelectionChanged(self):
241 """ 236 """
242 Private slot handling changes in the current list of selected items. 237 Private slot handling changes in the current list of selected items.
243 """ 238 """
244 self.__updateButtons() 239 self.__updateButtons()
245 240
246 @pyqtSlot() 241 @pyqtSlot()
247 def on_removeButton_clicked(self): 242 def on_removeButton_clicked(self):
248 """ 243 """
249 Private slot to remove selected entries. 244 Private slot to remove selected entries.
250 """ 245 """
252 for itm in currentList.selectedItems(): 247 for itm in currentList.selectedItems():
253 row = currentList.indexOfTopLevelItem(itm) 248 row = currentList.indexOfTopLevelItem(itm)
254 itm = currentList.takeTopLevelItem(row) 249 itm = currentList.takeTopLevelItem(row)
255 del itm 250 del itm
256 self.__updateButtons() 251 self.__updateButtons()
257 252
258 @pyqtSlot() 253 @pyqtSlot()
259 def on_removeAllButton_clicked(self): 254 def on_removeAllButton_clicked(self):
260 """ 255 """
261 Private slot to remove all entries. 256 Private slot to remove all entries.
262 """ 257 """
263 currentList = self.tabWidget.currentWidget() 258 currentList = self.tabWidget.currentWidget()
264 while currentList.topLevelItemCount() > 0: 259 while currentList.topLevelItemCount() > 0:
265 itm = currentList.takeTopLevelItem(0) # __IGNORE_WARNING__ 260 itm = currentList.takeTopLevelItem(0) # __IGNORE_WARNING__
266 del itm 261 del itm
267 self.__updateButtons() 262 self.__updateButtons()
268 263
269 def getData(self): 264 def getData(self):
270 """ 265 """
271 Public method to retrieve the dialog contents. 266 Public method to retrieve the dialog contents.
272 267
273 @return new feature permission settings 268 @return new feature permission settings
274 @rtype dict of dict of list 269 @rtype dict of dict of list
275 """ 270 """
276 featurePermissions = {} 271 featurePermissions = {}
277 for feature, permissionsList in self.__permissionsLists.items(): 272 for feature, permissionsList in self.__permissionsLists.items():
282 for row in range(permissionsList.topLevelItemCount()): 277 for row in range(permissionsList.topLevelItemCount()):
283 itm = permissionsList.topLevelItem(row) 278 itm = permissionsList.topLevelItem(row)
284 host = itm.text(0) 279 host = itm.text(0)
285 permission = itm.data(0, Qt.ItemDataRole.UserRole) 280 permission = itm.data(0, Qt.ItemDataRole.UserRole)
286 featurePermissions[feature][permission].append(host) 281 featurePermissions[feature][permission].append(host)
287 282
288 return featurePermissions 283 return featurePermissions

eric ide

mercurial