/** @id $Id$ This file has been added: - by bootstrap.sh - on Thu, 08 October 2015 11:56:48 +0200 */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #ifndef CERTMAN_HXX #define CERTMAN_HXX #include #include #include #include #include #include #include #include /// Main Window /** Main window for certman */ class CertMan: public QMainWindow, protected Ui::CertMan { Q_OBJECT; public: explicit CertMan(QWidget *parent = 0): QMainWindow(parent), _openFromURL(this) { setupUi(this); connect(&_openFromURL, SIGNAL(certificate(QUrl, QSslCertificate)), SLOT(certificate(QUrl, QSslCertificate))); } virtual ~CertMan() {} protected slots: void on__actionOpenCertificate_triggered() { QString fileName = QFileDialog::getOpenFileName(this); if (fileName.isEmpty()) return; QFile file(fileName); file.open(QIODevice::ReadOnly); QSslCertificate c(&file); file.close(); if (c.isNull()) { qDebug()<addSubWindow(win)->setWindowTitle(QFileInfo(fileName).fileName()); win->show(); win->certificate(c); } void on__actionOpenFromURL_triggered() { if (_openFromURL.exec()==QDialog::Accepted) { _openFromURL.read(); } } void certificate(QUrl url, QSslCertificate cert) { qDebug()<<"got certificate: "<addSubWindow(win)->setWindowTitle (url.host()+" - "+ cert.subjectInfo(QSslCertificate::CommonName).join("/")); win->show(); win->certificate(cert); } void on__actionSaveAs_triggered() { QMdiSubWindow* win(_mdi->currentSubWindow()); if (!win) return; Certificate* cert(dynamic_cast(win->widget())); QString fileName(QFileDialog::getSaveFileName (this, win->windowTitle(), win->windowTitle() .replace(" ", "_").replace(QRegExp("\.(pem|der)$"), "") +".pem", tr("Certificates (*.der *.pem *.txt)"))); if (fileName.isEmpty()) return; QFile file(fileName); file.open(QIODevice::WriteOnly); QFileInfo fileInfo(fileName); if (fileInfo.suffix()=="der") { QDataStream out(&file); out<certificate().toDer(); } else if (fileInfo.suffix()=="pem") { QDataStream out(&file); out<certificate().toPem(); } else if (fileInfo.suffix()=="txt") { QTextStream out(&file); out<certificate().toText(); } else { // defaults to pem QDataStream out(&file); out<certificate().toPem(); } file.close(); } private: OpenFromURL _openFromURL; }; #endif