comparison ui/certificatelistwidget.cpp @ 654:129e611eaf50

Merge branch trustbridge-refactor
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Jun 2014 15:16:24 +0200
parents 39f03316f675
children 320a64d58e62
comparison
equal deleted inserted replaced
648:e41a2537b84d 654:129e611eaf50
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=2)
5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details.
7 */
8 #include "certificatelistwidget.h"
9 #include <QDebug>
10 #include <QVBoxLayout>
11 #include <QHBoxLayout>
12 #include <QGroupBox>
13 #include <QLabel>
14
15 #include "certificateitemwidget.h"
16
17 CertificateListWidget::CertificateListWidget(QWidget *parent, Qt::WindowFlags flags) :
18 QWidget(parent, flags)
19 {
20 setupGUI();
21 }
22
23 void CertificateListWidget::setupGUI()
24 {
25 QHBoxLayout *mainLayout = new QHBoxLayout;
26 QVBoxLayout *detailMainLayout = new QVBoxLayout;
27 mCertificateList = new QListWidget;
28 mCertificateList->setFixedWidth(250);
29 connect(mCertificateList,
30 SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
31 this,
32 SLOT(updateDetails(QListWidgetItem*)));
33
34 QHBoxLayout *detailLayout = new QHBoxLayout;
35 QVBoxLayout *detailLabelLayout = new QVBoxLayout;
36 QVBoxLayout *detailContentLayout = new QVBoxLayout;
37 QGroupBox *detailBox = new QGroupBox(tr("Details"));
38 QLabel *subjectCN = new QLabel(tr("Subject Common Name:"));
39 QLabel *subjectOU = new QLabel(tr("Subject Organisation:"));
40 QLabel *issuerCN = new QLabel(tr("Issuer Common Name:"));
41 QLabel *issuerOU = new QLabel(tr("Issuer Organisation:"));
42 QLabel *validFrom = new QLabel(tr("Valid from:"));
43 QLabel *validTo = new QLabel(tr("Valid to:"));
44 QLabel *fingerprint = new QLabel(tr("Fingerprint:"));
45 detailLabelLayout->addWidget(subjectCN);
46 detailLabelLayout->addWidget(subjectOU);
47 detailLabelLayout->addWidget(issuerCN);
48 detailLabelLayout->addWidget(issuerOU);
49 detailLabelLayout->addWidget(validFrom);
50 detailLabelLayout->addWidget(validTo);
51 detailLabelLayout->addWidget(fingerprint);
52 mSubjectCN = new QLabel(tr(""));
53 mSubjectO = new QLabel(tr(""));
54 mIssuerCN = new QLabel(tr(""));
55 mIssuerO = new QLabel(tr(""));
56 mValidFrom = new QLabel(tr(""));
57 mValidTo = new QLabel(tr(""));
58 mFingerprint = new QLabel(tr(""));
59 mFingerprint->setFont(QFont("DejaVu Sans Mono"));
60 detailContentLayout->addWidget(mSubjectCN);
61 detailContentLayout->addWidget(mSubjectO);
62 detailContentLayout->addWidget(mIssuerCN);
63 detailContentLayout->addWidget(mIssuerO);
64 detailContentLayout->addWidget(mValidFrom);
65 detailContentLayout->addWidget(mValidTo);
66 detailContentLayout->addWidget(mFingerprint);
67 detailLayout->addLayout(detailLabelLayout);
68 detailLayout->addLayout(detailContentLayout);
69 detailBox->setLayout(detailLayout);
70 detailMainLayout->addWidget(detailBox);
71 detailMainLayout->addStretch(1);
72
73 mainLayout->addWidget(mCertificateList);
74 mainLayout->addLayout(detailMainLayout);
75 this->setLayout(mainLayout);
76 }
77
78 void CertificateListWidget::addCertificate(
79 const Certificate &certificate,
80 bool state,
81 bool editable)
82 {
83 QListWidgetItem* item = new QListWidgetItem(mCertificateList);
84 item->setData(Qt::UserRole,
85 QVariant::fromValue(certificate));
86 mCertificateList->addItem(item);
87 CertificateItemWidget *widget =
88 new CertificateItemWidget(mCertificateList, certificate, state, editable);
89 connect(widget, SIGNAL(stateChanged(bool, const Certificate&)),
90 this, SLOT(certStateChanged(bool, const Certificate&)));
91 item->setSizeHint(widget->minimumSizeHint());
92 mCertificateList->setItemWidget(item, widget);
93 }
94
95 void CertificateListWidget::addCertificates(const QList<Certificate> &list)
96 {
97
98 }
99
100 void CertificateListWidget::removeCertificate(const Certificate &cert)
101 {
102 for (int i = 0; i < mCertificateList->count(); i++) {
103 QListWidgetItem *item = mCertificateList->item(i);
104 CertificateItemWidget *itemWidget =
105 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
106 if (itemWidget->certificate() == cert) {
107 QListWidgetItem* item = mCertificateList->takeItem(i);
108 delete(item);
109 }
110 }
111 }
112
113 void CertificateListWidget::clear()
114 {
115 mCertificateList->clear();
116 }
117
118 QStringList CertificateListWidget::certificates()
119 {
120 QStringList list;
121 for (int i = 0; i < mCertificateList->count(); i++) {
122 QListWidgetItem *item = mCertificateList->item(i);
123 CertificateItemWidget *itemWidget =
124 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
125 list << itemWidget->certificate().base64Line();
126 }
127 return list;
128 }
129
130 QStringList CertificateListWidget::selectedCertificates() {
131 QStringList list;
132 for (int i = 0; i < mCertificateList->count(); i++) {
133 QListWidgetItem *item = mCertificateList->item(i);
134 CertificateItemWidget *itemWidget =
135 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
136 if (itemWidget->state()) {
137 list << itemWidget->certificate().base64Line();
138 }
139 }
140 return list;
141 }
142
143 QStringList CertificateListWidget::unselectedCertificates() {
144 QStringList list;
145 for (int i = 0; i < mCertificateList->count(); i++) {
146 QListWidgetItem *item = mCertificateList->item(i);
147 CertificateItemWidget *itemWidget =
148 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
149 if (!itemWidget->state()) {
150 list << itemWidget->certificate().base64Line();
151 }
152 }
153 return list;
154 }
155
156 QList<Certificate> CertificateListWidget::certificateList()
157 {
158 QList<Certificate> list;
159 for (int i = 0; i < mCertificateList->count(); i++) {
160 QListWidgetItem *item = mCertificateList->item(i);
161 CertificateItemWidget *itemWidget =
162 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
163 list << itemWidget->certificate();
164 }
165
166 return list;
167 }
168
169 void CertificateListWidget::setCertState(bool state, const Certificate &cert)
170 {
171 for (int i = 0; i < mCertificateList->count(); i++) {
172 QListWidgetItem *item = mCertificateList->item(i);
173 CertificateItemWidget *itemWidget =
174 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
175 if (itemWidget->certificate() == cert &&
176 itemWidget->state() != state) {
177 itemWidget->setState(state);
178 }
179 }
180 }
181
182 void CertificateListWidget::updateDetails(QListWidgetItem *item)
183 {
184 if (item == NULL) {
185 return;
186 }
187 Certificate cert = item->data(Qt::UserRole).value<Certificate>();
188 mSubjectCN->setText(cert.subjectCN());
189 mSubjectO->setText(cert.subjectO());
190 mIssuerCN->setText(cert.issuerCN());
191 mIssuerO->setText(cert.issuerO());
192 mValidFrom->setText(cert.validFrom().toString());
193 mValidTo->setText(cert.validTo().toString());
194 mFingerprint->setText(cert.fingerprint());
195 }
196
197 void CertificateListWidget::certStateChanged(bool state, const Certificate &cert)
198 {
199 int selected = 0;
200 for (int i = 0; i < mCertificateList->count(); i++) {
201 QListWidgetItem *item = mCertificateList->item(i);
202 CertificateItemWidget *itemWidget =
203 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
204 if (itemWidget->state()) {
205 selected++;
206 }
207 }
208 emit certListChanged(selected);
209 emit certChanged(state, cert);
210 }
211
212 int CertificateListWidget::selectedCertCount()
213 {
214 int selected = 0;
215 for (int i = 0; i < mCertificateList->count(); i++) {
216 QListWidgetItem *item = mCertificateList->item(i);
217 CertificateItemWidget *itemWidget =
218 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
219 if (itemWidget->state()) {
220 selected++;
221 }
222 }
223 return selected;
224 }
225
226 bool CertificateListWidget::contains(const Certificate &cert)
227 {
228 for (int i = 0; i < mCertificateList->count(); i++) {
229 QListWidgetItem *item = mCertificateList->item(i);
230 CertificateItemWidget *itemWidget =
231 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
232 if (itemWidget->certificate() == cert) {
233 return true;
234 }
235 }
236 return false;
237 }
238
239 void CertificateListWidget::setSelected(int index)
240 {
241 mCertificateList->setFocus();
242 if (mCertificateList->count() > 0) {
243 mCertificateList->item(0)->setSelected(true);
244 }
245 }

http://wald.intevation.org/projects/trustbridge/