Helpviewer/SslCertificatesDialog.py

changeset 752
2ec6ec7cd381
parent 751
619341e9dbb8
child 753
e19a516f0a97
equal deleted inserted replaced
751:619341e9dbb8 752:2ec6ec7cd381
5 5
6 """ 6 """
7 Module implementing a dialog to show and edit all certificates. 7 Module implementing a dialog to show and edit all certificates.
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSlot, Qt 10 from PyQt4.QtCore import pyqtSlot, Qt, QByteArray
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem 11 from PyQt4.QtGui import QDialog, QTreeWidgetItem
12 try: 12 try:
13 from PyQt4.QtNetwork import QSslCertificate, QSslSocket, QSslConfiguration 13 from PyQt4.QtNetwork import QSslCertificate, QSslSocket, QSslConfiguration
14 except ImportError: 14 except ImportError:
15 pass 15 pass
54 for i in range(self.serversCertificatesTree.columnCount()): 54 for i in range(self.serversCertificatesTree.columnCount()):
55 self.serversCertificatesTree.resizeColumnToContents(i) 55 self.serversCertificatesTree.resizeColumnToContents(i)
56 56
57 def __createServerCertificateEntry(self, server, cert): 57 def __createServerCertificateEntry(self, server, cert):
58 """ 58 """
59 Private method to create a certificate entry. 59 Private method to create a server certificate entry.
60 60
61 @param server server name of the certificate (string) 61 @param server server name of the certificate (string)
62 @param cert certificate to insert (QSslCertificate) 62 @param cert certificate to insert (QSslCertificate)
63 """ 63 """
64 # step 1: extract the info to be shown 64 # step 1: extract the info to be shown
82 itm.setData(0, self.CertRole, cert) 82 itm.setData(0, self.CertRole, cert)
83 83
84 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) 84 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
85 def on_serversCertificatesTree_currentItemChanged(self, current, previous): 85 def on_serversCertificatesTree_currentItemChanged(self, current, previous):
86 """ 86 """
87 Private slot handling a change of the current item. 87 Private slot handling a change of the current item in the
88 server certificates list.
88 89
89 @param current new current item (QTreeWidgetItem) 90 @param current new current item (QTreeWidgetItem)
90 @param previous previous current item (QTreeWidgetItem) 91 @param previous previous current item (QTreeWidgetItem)
91 """ 92 """
92 enable = current is not None and current.parent() is not None 93 enable = current is not None and current.parent() is not None
94 self.serversDeleteButton.setEnabled(enable) 95 self.serversDeleteButton.setEnabled(enable)
95 96
96 @pyqtSlot() 97 @pyqtSlot()
97 def on_serversViewButton_clicked(self): 98 def on_serversViewButton_clicked(self):
98 """ 99 """
99 Private slot to show data of the selected certificate. 100 Private slot to show data of the selected server certificate.
100 """ 101 """
101 cert = self.serversCertificatesTree.currentItem().data(0, self.CertRole) 102 cert = self.serversCertificatesTree.currentItem().data(0, self.CertRole)
102 dlg = SslInfoDialog(cert, self) 103 dlg = SslInfoDialog(cert, self)
103 dlg.exec_() 104 dlg.exec_()
104 105
105 @pyqtSlot() 106 @pyqtSlot()
106 def on_serversDeleteButton_clicked(self): 107 def on_serversDeleteButton_clicked(self):
107 """ 108 """
108 Private slot to delete the selected certificate. 109 Private slot to delete the selected server certificate.
109 """ 110 """
110 itm = self.serversCertificatesTree.currentItem() 111 itm = self.serversCertificatesTree.currentItem()
111 res = E5MessageBox.yesNo(self, 112 res = E5MessageBox.yesNo(self,
112 self.trUtf8("Delete Server Certificate"), 113 self.trUtf8("Delete Server Certificate"),
113 self.trUtf8("""<p>Shall the server certificate really be deleted?</p>""" 114 self.trUtf8("""<p>Shall the server certificate really be deleted?</p>"""
159 self.caCertificatesTree.resizeColumnToContents(i) 160 self.caCertificatesTree.resizeColumnToContents(i)
160 self.caCertificatesTree.sortItems(0, Qt.AscendingOrder) 161 self.caCertificatesTree.sortItems(0, Qt.AscendingOrder)
161 162
162 def __createCaCertificateEntry(self, cert): 163 def __createCaCertificateEntry(self, cert):
163 """ 164 """
164 Private method to create a certificate entry. 165 Private method to create a CA certificate entry.
165 166
166 @param cert certificate to insert (QSslCertificate) 167 @param cert certificate to insert (QSslCertificate)
167 """ 168 """
168 # step 1: extract the info to be shown 169 # step 1: extract the info to be shown
169 organisation = cert.subjectInfo(QSslCertificate.Organization) 170 organisation = str(
171 QByteArray(cert.subjectInfo(QSslCertificate.Organization)),
172 encoding = "utf-8")
170 if organisation is None or organisation == "": 173 if organisation is None or organisation == "":
171 organisation = self.trUtf8("(Unknown)") 174 organisation = self.trUtf8("(Unknown)")
172 commonName = cert.subjectInfo(QSslCertificate.CommonName) 175 commonName = cert.subjectInfo(QSslCertificate.CommonName)
173 if commonName is None or commonName == "": 176 if commonName is None or commonName == "":
174 commonName = self.trUtf8("(Unknown common name)") 177 commonName = self.trUtf8("(Unknown common name)")
180 if len(items) == 0: 183 if len(items) == 0:
181 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation]) 184 parent = QTreeWidgetItem(self.caCertificatesTree, [organisation])
182 else: 185 else:
183 parent = items[0] 186 parent = items[0]
184 187
185 QTreeWidgetItem(parent, [commonName, expiryDate]) 188 itm = QTreeWidgetItem(parent, [commonName, expiryDate])
189 itm.setData(0, self.CertRole, cert)
186 190
187 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) 191 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
188 def on_caCertificatesTree_currentItemChanged(self, current, previous): 192 def on_caCertificatesTree_currentItemChanged(self, current, previous):
189 """ 193 """
190 Slot documentation goes here. 194 Private slot handling a change of the current item
191 """ 195 in the CA certificates list.
192 # TODO: not implemented yet 196
193 raise NotImplementedError 197 @param current new current item (QTreeWidgetItem)
198 @param previous previous current item (QTreeWidgetItem)
199 """
200 enable = current is not None and current.parent() is not None
201 self.caViewButton.setEnabled(enable)
194 202
195 @pyqtSlot() 203 @pyqtSlot()
196 def on_caViewButton_clicked(self): 204 def on_caViewButton_clicked(self):
197 """ 205 """
198 Slot documentation goes here. 206 Private slot to show data of the selected CA certificate.
199 """ 207 """
200 # TODO: not implemented yet 208 cert = self.caCertificatesTree.currentItem().data(0, self.CertRole)
201 raise NotImplementedError 209 dlg = SslInfoDialog(cert, self)
210 dlg.exec_()

eric ide

mercurial