File indexing completed on 2024-04-14 03:53:37

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "ksslcertificatebox.h"
0009 
0010 #include "ui_certificateparty.h"
0011 
0012 #include <QSslCertificate>
0013 
0014 class KSslCertificateBoxPrivate
0015 {
0016 public:
0017     Ui::CertificateParty ui;
0018 };
0019 
0020 KSslCertificateBox::KSslCertificateBox(QWidget *parent)
0021     : QWidget(parent)
0022     , d(new KSslCertificateBoxPrivate())
0023 {
0024     d->ui.setupUi(this);
0025     // No fooling us with html tags
0026     const QList<QLabel *> labels = findChildren<QLabel *>();
0027     for (QLabel *label : labels) {
0028         label->setTextFormat(Qt::PlainText);
0029     }
0030 }
0031 
0032 KSslCertificateBox::~KSslCertificateBox() = default;
0033 
0034 void KSslCertificateBox::setCertificate(const QSslCertificate &cert, CertificateParty party)
0035 {
0036     if (party == Subject) {
0037         d->ui.commonName->setText(cert.subjectInfo(QSslCertificate::CommonName).join(QLatin1String(", ")));
0038         d->ui.organization->setText(cert.subjectInfo(QSslCertificate::Organization).join(QLatin1String(", ")));
0039         d->ui.organizationalUnit->setText(cert.subjectInfo(QSslCertificate::OrganizationalUnitName).join(QLatin1String(", ")));
0040         d->ui.country->setText(cert.subjectInfo(QSslCertificate::CountryName).join(QLatin1String(", ")));
0041         d->ui.state->setText(cert.subjectInfo(QSslCertificate::StateOrProvinceName).join(QLatin1String(", ")));
0042         d->ui.city->setText(cert.subjectInfo(QSslCertificate::LocalityName).join(QLatin1String(", ")));
0043     } else if (party == Issuer) {
0044         d->ui.commonName->setText(cert.issuerInfo(QSslCertificate::CommonName).join(QLatin1String(", ")));
0045         d->ui.organization->setText(cert.issuerInfo(QSslCertificate::Organization).join(QLatin1String(", ")));
0046         d->ui.organizationalUnit->setText(cert.issuerInfo(QSslCertificate::OrganizationalUnitName).join(QLatin1String(", ")));
0047         d->ui.country->setText(cert.issuerInfo(QSslCertificate::CountryName).join(QLatin1String(", ")));
0048         d->ui.state->setText(cert.issuerInfo(QSslCertificate::StateOrProvinceName).join(QLatin1String(", ")));
0049         d->ui.city->setText(cert.issuerInfo(QSslCertificate::LocalityName).join(QLatin1String(", ")));
0050     }
0051 }
0052 
0053 void KSslCertificateBox::clear()
0054 {
0055     d->ui.commonName->clear();
0056     d->ui.organization->clear();
0057     d->ui.organizationalUnit->clear();
0058     d->ui.country->clear();
0059     d->ui.state->clear();
0060     d->ui.city->clear();
0061 }
0062 
0063 #include "moc_ksslcertificatebox.cpp"