WebBrowser/Network/SslErrorExceptionsDialog.py

branch
QtWebEngine
changeset 4817
0a4e2fb0e93c
child 4820
f38e4fb83ecd
equal deleted inserted replaced
4816:4f5ca06fa93a 4817:0a4e2fb0e93c
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to edit the SSL error exceptions.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, QPoint
13 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QMenu
14 from PyQt5.QtWebEngineWidgets import QWebEngineCertificateError
15
16 from .Ui_SslErrorExceptionsDialog import Ui_SslErrorExceptionsDialog
17
18
19 class SslErrorExceptionsDialog(QDialog, Ui_SslErrorExceptionsDialog):
20 """
21 Class implementing a dialog to edit the SSL error exceptions.
22 """
23 def __init__(self, errorsDict, parent=None):
24 """
25 Constructor
26
27 @param errorsDict error exceptions
28 @type dict of list of int
29 @param parent reference to the parent widget
30 @type QWidget
31 """
32 super(SslErrorExceptionsDialog, self).__init__(parent)
33 self.setupUi(self)
34
35 self.__errorDescriptions = {
36 QWebEngineCertificateError.SslPinnedKeyNotInCertificateChain:
37 self.tr("The certificate did not match the built-in public"
38 " keys pinned for the host name."),
39 QWebEngineCertificateError.CertificateCommonNameInvalid:
40 self.tr("The certificate's common name did not match the"
41 " host name."),
42 QWebEngineCertificateError.CertificateDateInvalid:
43 self.tr("The certificate is not valid at the current date"
44 " and time."),
45 QWebEngineCertificateError.CertificateAuthorityInvalid:
46 self.tr("The certificate is not signed by a trusted"
47 " authority."),
48 QWebEngineCertificateError.CertificateContainsErrors:
49 self.tr("The certificate contains errors."),
50 QWebEngineCertificateError.CertificateNoRevocationMechanism:
51 self.tr("The certificate has no mechanism for determining if"
52 " it has been revoked."),
53 QWebEngineCertificateError.CertificateUnableToCheckRevocation:
54 self.tr("Revocation information for the certificate is"
55 " not available."),
56 QWebEngineCertificateError.CertificateRevoked:
57 self.tr("The certificate has been revoked."),
58 QWebEngineCertificateError.CertificateInvalid:
59 self.tr("The certificate is invalid."),
60 QWebEngineCertificateError.CertificateWeakSignatureAlgorithm:
61 self.tr("The certificate is signed using a weak signature"
62 " algorithm."),
63 QWebEngineCertificateError.CertificateNonUniqueName:
64 self.tr("The host name specified in the certificate is"
65 " not unique."),
66 QWebEngineCertificateError.CertificateWeakKey:
67 self.tr("The certificate contains a weak key."),
68 QWebEngineCertificateError.CertificateNameConstraintViolation:
69 self.tr("The certificate claimed DNS names that are in"
70 " violation of name constraints."),
71 }
72
73 for host, errors in errorsDict.items():
74 itm = QTreeWidgetItem(self.errorsTree, [host])
75 self.errorsTree.setFirstItemColumnSpanned(itm, True)
76 for error in errors:
77 try:
78 errorDesc = self.__errorDescriptions[error]
79 except KeyError:
80 errorDesc = self.tr("No error description available.")
81 QTreeWidgetItem(itm, [str(error), errorDesc])
82
83 self.errorsTree.expandAll()
84 for i in range(self.errorsTree.columnCount()):
85 self.errorsTree.resizeColumnToContents(i)
86
87 self.__setRemoveButtons()
88
89 def __setRemoveButtons(self):
90 """
91 Private method to set the state of the 'remove' buttons.
92 """
93 if self.errorsTree.topLevelItemCount() == 0:
94 self.removeButton.setEnabled(False)
95 self.removeAllButton.setEnabled(False)
96 else:
97 self.removeAllButton.setEnabled(True)
98 self.removeButton.setEnabled(
99 len(self.errorsTree.selectedItems()) > 0)
100
101 @pyqtSlot(QPoint)
102 def on_errorsTree_customContextMenuRequested(self, pos):
103 """
104 Private slot to show the context menu.
105
106 @param pos cursor position
107 @type QPoint
108 """
109 menu = QMenu()
110 menu.addAction(
111 self.tr("Remove Selected"),
112 self.on_removeButton_clicked).setEnabled(
113 self.errorsTree.topLevelItemCount() > 0 and
114 len(self.errorsTree.selectedItems()) > 0)
115 menu.addAction(
116 self.tr("Remove All"),
117 self.on_removeAllButton_clicked).setEnabled(
118 self.errorsTree.topLevelItemCount() > 0)
119
120 menu.exec_(self.errorsTree.mapToGlobal(pos))
121
122 @pyqtSlot()
123 def on_errorsTree_itemSelectionChanged(self):
124 """
125 Private slot handling the selection of entries.
126 """
127 self.__setRemoveButtons()
128
129 @pyqtSlot()
130 def on_removeButton_clicked(self):
131 """
132 Private slot to remove the selected items.
133 """
134 for itm in self.errorsTree.selectedItems():
135 pitm = itm.parent()
136 if pitm:
137 pitm.removeChild(itm)
138 else:
139 index = self.errorsTree.indexOfTopLevelItem(itm)
140 self.errorsTree.takeTopLevelItem(index)
141 del itm
142
143 @pyqtSlot()
144 def on_removeAllButton_clicked(self):
145 """
146 Private slot to remove all entries.
147 """
148 self.errorsTree.clear()
149
150 def getSslErrorExceptions(self):
151 """
152 Public method to retrieve the list of SSL error exceptions.
153
154 @return error exceptions
155 @rtype dict of list of int
156 """
157 errors = {}
158
159 for index in range(self.errorsTree.topLevelItemCount()):
160 itm = self.errorsTree.topLevelItem(index)
161 host = itm.text(0)
162 errors[host] = []
163 for cindex in range(itm.childCount()):
164 citm = itm.child(cindex)
165 errors[host].append(int(citm.text(0)))
166
167 return errors

eric ide

mercurial