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, QByteArray, QFile, QFileInfo, QIODevice |
10 from PyQt4.QtCore import pyqtSlot, Qt, QByteArray, QFile, QFileInfo, QIODevice |
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem, QFileDialog |
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem |
12 try: |
12 try: |
13 from PyQt4.QtNetwork import QSslCertificate, QSslSocket, QSslConfiguration, QSsl |
13 from PyQt4.QtNetwork import QSslCertificate, QSslSocket, QSslConfiguration, QSsl |
14 except ImportError: |
14 except ImportError: |
15 pass |
15 pass |
16 |
16 |
17 from E5Gui import E5MessageBox |
17 from E5Gui import E5MessageBox, E5FileDialog |
18 |
18 |
19 from .Ui_SslCertificatesDialog import Ui_SslCertificatesDialog |
19 from .Ui_SslCertificatesDialog import Ui_SslCertificatesDialog |
20 |
20 |
21 from .SslInfoDialog import SslInfoDialog |
21 from .SslInfoDialog import SslInfoDialog |
22 |
22 |
369 |
369 |
370 @param name default file name without extension (string) |
370 @param name default file name without extension (string) |
371 @param cert certificate to be exported (QSslCertificate) |
371 @param cert certificate to be exported (QSslCertificate) |
372 """ |
372 """ |
373 if cert is not None: |
373 if cert is not None: |
374 fname, selectedFilter = QFileDialog.getSaveFileNameAndFilter( |
374 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
375 self, |
375 self, |
376 self.trUtf8("Export Certificate"), |
376 self.trUtf8("Export Certificate"), |
377 name, |
377 name, |
378 self.trUtf8("Certificate File (PEM) (*.pem);;" |
378 self.trUtf8("Certificate File (PEM) (*.pem);;" |
379 "Certificate File (DER) (*.der)"), |
379 "Certificate File (DER) (*.der)"), |
380 None, |
380 None, |
381 QFileDialog.Options(QFileDialog.DontConfirmOverwrite | |
381 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
382 QFileDialog.DontUseNativeDialog)) |
|
383 |
382 |
384 if fname: |
383 if fname: |
385 ext = QFileInfo(fname).suffix() |
384 ext = QFileInfo(fname).suffix() |
386 if not ext or ext not in ["pem", "der"]: |
385 if not ext or ext not in ["pem", "der"]: |
387 ex = selectedFilter.split("(*")[1].split(")")[0] |
386 ex = selectedFilter.split("(*")[1].split(")")[0] |
416 """ |
415 """ |
417 Private method to read a certificate. |
416 Private method to read a certificate. |
418 |
417 |
419 @return certificates read (list of QSslCertificate) |
418 @return certificates read (list of QSslCertificate) |
420 """ |
419 """ |
421 fname = QFileDialog.getOpenFileName( |
420 fname = E5FileDialog.getOpenFileName( |
422 self, |
421 self, |
423 self.trUtf8("Import Certificate"), |
422 self.trUtf8("Import Certificate"), |
424 "", |
423 "", |
425 self.trUtf8("Certificate Files (*.pem *.crt *.der *.cer *.ca);;" |
424 self.trUtf8("Certificate Files (*.pem *.crt *.der *.cer *.ca);;" |
426 "All Files (*)"), |
425 "All Files (*)")) |
427 QFileDialog.DontUseNativeDialog) |
|
428 |
426 |
429 if fname: |
427 if fname: |
430 f = QFile(fname) |
428 f = QFile(fname) |
431 if not f.open(QIODevice.ReadOnly): |
429 if not f.open(QIODevice.ReadOnly): |
432 E5MessageBox.critical(self, |
430 E5MessageBox.critical(self, |