Helpviewer/FeaturePermissions/FeaturePermissionsDialog.py

changeset 4356
975993ebd7fb
child 4554
f3428ddd577c
child 4632
ca310db386ed
equal deleted inserted replaced
4355:40ec6bef4c22 4356:975993ebd7fb
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the feature permission dialog.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, Qt
13 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem
14 from PyQt5.QtWebKitWidgets import QWebPage
15
16 from .Ui_FeaturePermissionsDialog import Ui_FeaturePermissionsDialog
17
18
19 class FeaturePermissionsDialog(QDialog, Ui_FeaturePermissionsDialog):
20 """
21 Class implementing the feature permission dialog.
22 """
23 def __init__(self, featurePermissions, parent=None):
24 """
25 Constructor
26
27 @param featurePermissions dictionary with remembered feature
28 permissions
29 @type dict of dict of list
30 @param parent reference to the parent widget
31 @type QWidget
32 """
33 super(FeaturePermissionsDialog, self).__init__(parent)
34 self.setupUi(self)
35
36 self.__permissionStrings = {
37 QWebPage.PermissionGrantedByUser: self.tr("Allow"),
38 QWebPage.PermissionDeniedByUser: self.tr("Deny"),
39 }
40
41 # Notifications
42 for permission in featurePermissions[QWebPage.Notifications]:
43 for host in featurePermissions[QWebPage.Notifications][permission]:
44 itm = QTreeWidgetItem(
45 self.notifList,
46 [host, self.__permissionStrings[permission]])
47 itm.setData(0, Qt.UserRole, permission)
48 self.__updateNotifButtons()
49
50 # Geolocation
51 for permission in featurePermissions[QWebPage.Geolocation]:
52 for host in featurePermissions[QWebPage.Geolocation][permission]:
53 itm = QTreeWidgetItem(
54 self.geoList,
55 [host, self.__permissionStrings[permission]])
56 itm.setData(0, Qt.UserRole, permission)
57 self.__updateGeoButtons()
58
59 def __updateNotifButtons(self):
60 """
61 Private method to update the notifications buttons.
62 """
63 self.notifRemoveAllButton.setEnabled(
64 self.notifList.topLevelItemCount() > 0)
65 self.notifRemoveButton.setEnabled(
66 len(self.notifList.selectedItems()) > 0)
67
68 def __updateGeoButtons(self):
69 """
70 Private method to update the geolocation buttons.
71 """
72 self.geoRemoveAllButton.setEnabled(
73 self.geoList.topLevelItemCount() > 0)
74 self.geoRemoveButton.setEnabled(
75 len(self.geoList.selectedItems()) > 0)
76
77 @pyqtSlot()
78 def on_geoList_itemSelectionChanged(self):
79 """
80 Private slot handling changes in the list of selected geolocation
81 items.
82 """
83 self.__updateGeoButtons()
84
85 @pyqtSlot()
86 def on_geoRemoveButton_clicked(self):
87 """
88 Private slot to remove selected geolocation entries.
89 """
90 for itm in self.geoList.selectedItems():
91 row = self.geoList.indexOfTopLevelItem(itm)
92 itm = self.geoList.takeTopLevelItem(row)
93 del itm
94 self.__updateGeoButtons()
95
96 @pyqtSlot()
97 def on_geoRemoveAllButton_clicked(self):
98 """
99 Private slot to remove all geolocation entries.
100 """
101 while self.geoList.topLevelItemCount() > 0:
102 itm = self.geoList.takeTopLevelItem(0)
103 del itm
104 self.__updateGeoButtons()
105
106 @pyqtSlot()
107 def on_notifList_itemSelectionChanged(self):
108 """
109 Private slot handling changes in the list of selected notifications
110 items.
111 """
112 self.__updateNotifButtons()
113
114 @pyqtSlot()
115 def on_notifRemoveButton_clicked(self):
116 """
117 Private slot to remove selected notification entries.
118 """
119 for itm in self.notifList.selectedItems():
120 row = self.notifList.indexOfTopLevelItem(itm)
121 itm = self.notifList.takeTopLevelItem(row)
122 del itm
123 self.__updateNotifButtons()
124
125 @pyqtSlot()
126 def on_notifRemoveAllButton_clicked(self):
127 """
128 Private slot to remove all notification entries.
129 """
130 while self.notifList.topLevelItemCount() > 0:
131 itm = self.notifList.takeTopLevelItem(0)
132 del itm
133 self.__updateNotifButtons()
134
135 def getData(self):
136 """
137 Public method to retrieve the dialog contents.
138
139 @return new feature permission settings
140 @rtype dict of dict of list
141 """
142 featurePermissions = {
143 QWebPage.Notifications: {
144 QWebPage.PermissionGrantedByUser: [],
145 QWebPage.PermissionDeniedByUser: [],
146 },
147 QWebPage.Geolocation: {
148 QWebPage.PermissionGrantedByUser: [],
149 QWebPage.PermissionDeniedByUser: [],
150 },
151 }
152
153 # Notifications
154 for row in range(self.notifList.topLevelItemCount()):
155 itm = self.notifList.topLevelItem(row)
156 host = itm.text(0)
157 permission = itm.data(0, Qt.UserRole)
158 featurePermissions[QWebPage.Notifications][permission].append(host)
159
160 # Geolocation
161 for row in range(self.geoList.topLevelItemCount()):
162 itm = self.geoList.topLevelItem(row)
163 host = itm.text(0)
164 permission = itm.data(0, Qt.UserRole)
165 featurePermissions[QWebPage.Geolocation][permission].append(host)
166
167 return featurePermissions

eric ide

mercurial