CertificateInfoControl.cpp Example File
securesocketclient/src/CertificateInfoControl.cpp
#include "CertificateInfoControl.hpp"
CertificateInfoControl::CertificateInfoControl(QObject *parent)
: QObject(parent), m_visible(false)
{
}
void CertificateInfoControl::setCertificateChain(const QList<QSslCertificate> &chain)
{
m_chain = chain;
m_model.clear();
for (int i = 0; i < m_chain.size(); ++i) {
const QSslCertificate &cert = m_chain.at(i);
const QString chainInformation = tr("%1%2 (%3)").arg(!i ? QString() : tr("Issued by: "))
.arg(cert.subjectInfo(QSslCertificate::Organization))
.arg(cert.subjectInfo(QSslCertificate::CommonName));
m_model.append(chainInformation);
}
setCurrentCertificate(QVariantList() << QVariant(0));
}
bb::cascades::DataModel* CertificateInfoControl::model() const
{
return const_cast<bb::cascades::QListDataModel<QString>*>(&m_model);
}
QString CertificateInfoControl::certificateInfo() const
{
return m_certificateInfo;
}
void CertificateInfoControl::setVisible(bool visible)
{
if (m_visible == visible)
return;
m_visible = visible;
emit visibleChanged();
}
bool CertificateInfoControl::visible() const
{
return m_visible;
}
void CertificateInfoControl::show()
{
setVisible(true);
}
void CertificateInfoControl::setCurrentCertificate(const QVariantList &indexPath)
{
const int index = indexPath.at(0).toInt();
if (index >= 0 && index < m_chain.size()) {
const QSslCertificate &cert = m_chain.at(index);
QStringList lines;
lines << tr("Organization: %1").arg(cert.subjectInfo(QSslCertificate::Organization))
<< tr("Subunit: %1").arg(cert.subjectInfo(QSslCertificate::OrganizationalUnitName))
<< tr("Country: %1").arg(cert.subjectInfo(QSslCertificate::CountryName))
<< tr("Locality: %1").arg(cert.subjectInfo(QSslCertificate::LocalityName))
<< tr("State/Province: %1").arg(cert.subjectInfo(QSslCertificate::StateOrProvinceName))
<< tr("Common Name: %1").arg(cert.subjectInfo(QSslCertificate::CommonName))
<< QString()
<< tr("Issuer Organization: %1").arg(cert.issuerInfo(QSslCertificate::Organization))
<< tr("Issuer Unit Name: %1").arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName))
<< tr("Issuer Country: %1").arg(cert.issuerInfo(QSslCertificate::CountryName))
<< tr("Issuer Locality: %1").arg(cert.issuerInfo(QSslCertificate::LocalityName))
<< tr("Issuer State/Province: %1").arg(cert.issuerInfo(QSslCertificate::StateOrProvinceName))
<< tr("Issuer Common Name: %1").arg(cert.issuerInfo(QSslCertificate::CommonName));
m_certificateInfo = lines.join("\n");
} else {
m_certificateInfo.clear();
}
emit certificateInfoChanged();
}