source: psi/trunk/src/sslcertdlg.cpp@ 47

Last change on this file since 47 was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 2.7 KB
Line 
1#include"sslcertdlg.h"
2
3#include<qtextbrowser.h>
4#include<qdatetime.h>
5#include<qlabel.h>
6#include<qpushbutton.h>
7#include<qdict.h>
8#include<qca.h>
9#include"common.h"
10#include"iconwidget.h"
11
12static void setLabelStatus(QLabel *l, bool ok)
13{
14 if(ok)
15 l->setPaletteForegroundColor(QColor("#2A993B"));
16 else
17 l->setPaletteForegroundColor(QColor("#810000"));
18}
19
20static QString getPropValue(const QCA::CertProperties &list, const QString &var)
21{
22 QString val;
23 for(QCA::CertProperties::ConstIterator it = list.begin(); it != list.end(); ++it) {
24 if(it.key() == var) {
25 if(!val.isEmpty())
26 val += "<br>";
27 val += it.data();
28 }
29 }
30 return val;
31}
32
33static QString makePropEntry(const QString &var, const QString &name, const QCA::CertProperties &list)
34{
35 QString val = getPropValue(list, var);
36 if(val.isEmpty())
37 return "";
38 else
39 return QString("<tr><td><nobr><b>") + name + "</b></nobr></td><td>" + val + "</td></tr>";
40}
41
42QString SSLCertDlg::makePropTable(const QString &heading, const QCA::CertProperties &list)
43{
44 QString str;
45 str += "<tr><td><i>" + heading + "</i><br>";
46 str += "<table>";
47 str += makePropEntry("O", tr("Organization:"), list);
48 str += makePropEntry("OU", tr("Organizational unit:"), list);
49 str += makePropEntry("L", tr("Locality:"), list);
50 str += makePropEntry("ST", tr("State:"), list);
51 str += makePropEntry("C", tr("Country:"), list);
52 str += makePropEntry("CN", tr("Common name:"), list);
53 str += makePropEntry("Email", tr("Email:"), list);
54 str += "</table></td></tr>";
55 return str;
56}
57
58SSLCertDlg::SSLCertDlg(QWidget *parent, const char *name)
59:SSLCertUI(parent, name, true)
60{
61 setCaption(CAP(caption()));
62
63 connect(pb_close, SIGNAL(clicked()), SLOT(close()));
64 pb_close->setDefault(true);
65 pb_close->setFocus();
66}
67
68void SSLCertDlg::setCert(const QCA::Cert &cert, int result)
69{
70 if(cert.isNull())
71 return;
72
73 if(result == QCA::TLS::Valid) {
74 lb_valid->setText(tr("The certificate is valid."));
75 setLabelStatus(lb_valid, true);
76 }
77 else {
78 lb_valid->setText(tr("The certificate is NOT valid!"));
79 setLabelStatus(lb_valid, false);
80 }
81
82 QDateTime now = QDateTime::currentDateTime();
83 QDateTime notBefore = cert.notBefore();
84 QDateTime notAfter = cert.notAfter();
85 lb_notBefore->setText(cert.notBefore().toString());
86 setLabelStatus(lb_notBefore, now > notBefore);
87 lb_notAfter->setText(cert.notAfter().toString());
88 setLabelStatus(lb_notAfter, now < notAfter);
89
90 lb_sn->setText(cert.serialNumber());
91
92 QString str;
93 str += "<table>";
94 str += makePropTable(tr("Subject Details:"), cert.subject());
95 str += makePropTable(tr("Issuer Details:"), cert.issuer());
96 str += "</table>";
97 tb_cert->setText(str);
98}
99
100void SSLCertDlg::showCert(const QCA::Cert &cert, int result)
101{
102 SSLCertDlg *w = new SSLCertDlg(0);
103 w->setCert(cert, result);
104 w->exec();
105 delete w;
106}
Note: See TracBrowser for help on using the repository browser.