Mercurial > trustbridge
comparison ui/certificatelistwidget.cpp @ 743:a467204a35f5
Rework User Interface.
Certificate lists are now plain lists of widgets and no longer
a ListWidget. Details are no longer shown extra but included
in the list. List entries are somewhat larger accordingly.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 04 Jul 2014 16:15:59 +0200 |
parents | 3d669400104a |
children | 9bfaced5cf59 |
comparison
equal
deleted
inserted
replaced
742:627e8d678b6d | 743:a467204a35f5 |
---|---|
6 * See LICENSE.txt for details. | 6 * See LICENSE.txt for details. |
7 */ | 7 */ |
8 #include "certificatelistwidget.h" | 8 #include "certificatelistwidget.h" |
9 #include <QDebug> | 9 #include <QDebug> |
10 #include <QVBoxLayout> | 10 #include <QVBoxLayout> |
11 #include <QHBoxLayout> | |
12 #include <QGroupBox> | 11 #include <QGroupBox> |
13 #include <QLabel> | 12 #include <QLabel> |
13 #include <QApplication> | |
14 | 14 |
15 #include "certificateitemwidget.h" | 15 #include "certificateitemwidget.h" |
16 | 16 |
17 CertificateListWidget::CertificateListWidget(QWidget *parent, Qt::WindowFlags flags) : | 17 CertificateListWidget::CertificateListWidget(QWidget *parent, Qt::WindowFlags flags) : |
18 QWidget(parent, flags) | 18 QWidget(parent, flags) |
19 { | 19 { |
20 setupGUI(); | 20 setLayout(&mLayout); |
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 *validFrom = new QLabel(tr("Valid from:")); | |
41 QLabel *validTo = new QLabel(tr("Valid to:")); | |
42 QLabel *fingerprint = new QLabel(tr("Fingerprint (SHA1):")); | |
43 detailLabelLayout->addWidget(subjectCN); | |
44 detailLabelLayout->addWidget(subjectOU); | |
45 detailLabelLayout->addWidget(validFrom); | |
46 detailLabelLayout->addWidget(validTo); | |
47 detailLabelLayout->addWidget(fingerprint); | |
48 mSubjectCN = new QLabel(tr("")); | |
49 mSubjectO = new QLabel(tr("")); | |
50 mValidFrom = new QLabel(tr("")); | |
51 mValidTo = new QLabel(tr("")); | |
52 mFingerprint = new QLabel(tr("")); | |
53 mFingerprint->setFont(QFont("DejaVu Sans Mono")); | |
54 detailContentLayout->addWidget(mSubjectCN); | |
55 detailContentLayout->addWidget(mSubjectO); | |
56 detailContentLayout->addWidget(mValidFrom); | |
57 detailContentLayout->addWidget(mValidTo); | |
58 detailContentLayout->addWidget(mFingerprint); | |
59 detailLayout->addLayout(detailLabelLayout); | |
60 detailLayout->addLayout(detailContentLayout); | |
61 detailBox->setLayout(detailLayout); | |
62 detailMainLayout->addWidget(detailBox); | |
63 detailMainLayout->addStretch(1); | |
64 | |
65 mainLayout->addWidget(mCertificateList); | |
66 mainLayout->addLayout(detailMainLayout); | |
67 this->setLayout(mainLayout); | |
68 } | 21 } |
69 | 22 |
70 void CertificateListWidget::addCertificate( | 23 void CertificateListWidget::addCertificate( |
71 const Certificate &certificate, | 24 const Certificate &certificate, |
72 bool state, | 25 bool state, |
73 bool editable, | 26 bool editable, |
74 const QString &installLabel, | 27 const QString &installLabel, |
75 const QString &removeLabel) | 28 const QString &removeLabel) |
76 { | 29 { |
77 QListWidgetItem* item = new QListWidgetItem(mCertificateList); | |
78 item->setData(Qt::UserRole, | |
79 QVariant::fromValue(certificate)); | |
80 mCertificateList->addItem(item); | |
81 CertificateItemWidget *widget = | 30 CertificateItemWidget *widget = |
82 new CertificateItemWidget(mCertificateList, certificate, state, editable, | 31 new CertificateItemWidget(this, certificate, state, editable, |
83 installLabel, removeLabel); | 32 installLabel, removeLabel); |
84 connect(widget, SIGNAL(stateChanged(bool, const Certificate&)), | 33 connect(widget, SIGNAL(stateChanged(bool, const Certificate&)), |
85 this, SLOT(certStateChanged(bool, const Certificate&))); | 34 this, SLOT(certStateChanged(bool, const Certificate&))); |
86 item->setSizeHint(widget->minimumSizeHint()); | 35 |
87 mCertificateList->setItemWidget(item, widget); | 36 mCertificateWidgets << widget; |
37 mLayout.addWidget(widget); | |
88 emit certListChanged(-1); | 38 emit certListChanged(-1); |
89 } | |
90 | |
91 void CertificateListWidget::addCertificates(const QList<Certificate> &list) | |
92 { | |
93 | |
94 } | 39 } |
95 | 40 |
96 void CertificateListWidget::removeCertificate(const Certificate &cert) | 41 void CertificateListWidget::removeCertificate(const Certificate &cert) |
97 { | 42 { |
98 for (int i = 0; i < mCertificateList->count(); i++) { | 43 for (int i = 0; i < mCertificateWidgets.size(); i++) { |
99 QListWidgetItem *item = mCertificateList->item(i); | 44 if (mCertificateWidgets[i]->certificate() == cert) { |
100 CertificateItemWidget *itemWidget = | 45 mLayout.removeWidget(mCertificateWidgets[i]); |
101 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | 46 delete(mCertificateWidgets[i]); |
102 if (itemWidget->certificate() == cert) { | 47 mCertificateWidgets.removeAt(i); |
103 QListWidgetItem* item = mCertificateList->takeItem(i); | 48 break; |
104 delete(item); | |
105 } | 49 } |
106 } | 50 } |
107 emit certListChanged(-1); | 51 emit certListChanged(-1); |
108 } | 52 } |
109 | 53 |
110 void CertificateListWidget::clear() | 54 void CertificateListWidget::clear() |
111 { | 55 { |
112 mCertificateList->clear(); | 56 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
57 mLayout.removeWidget(item); | |
58 delete item; | |
59 } | |
60 mCertificateWidgets.clear(); | |
113 } | 61 } |
114 | 62 |
115 QStringList CertificateListWidget::certificates() | 63 QStringList CertificateListWidget::certificates() |
116 { | 64 { |
117 QStringList list; | 65 QStringList list; |
118 for (int i = 0; i < mCertificateList->count(); i++) { | 66 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
119 QListWidgetItem *item = mCertificateList->item(i); | 67 list << item->certificate().base64Line(); |
120 CertificateItemWidget *itemWidget = | |
121 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
122 list << itemWidget->certificate().base64Line(); | |
123 } | 68 } |
124 return list; | 69 return list; |
125 } | 70 } |
126 | 71 |
127 QStringList CertificateListWidget::selectedCertificates() { | 72 QStringList CertificateListWidget::selectedCertificates() { |
128 QStringList list; | 73 QStringList list; |
129 for (int i = 0; i < mCertificateList->count(); i++) { | 74 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
130 QListWidgetItem *item = mCertificateList->item(i); | 75 if (item->state()) { |
131 CertificateItemWidget *itemWidget = | 76 list << item->certificate().base64Line(); |
132 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
133 if (itemWidget->state()) { | |
134 list << itemWidget->certificate().base64Line(); | |
135 } | 77 } |
136 } | 78 } |
137 return list; | 79 return list; |
138 } | 80 } |
139 | 81 |
140 QStringList CertificateListWidget::unselectedCertificates() { | 82 QStringList CertificateListWidget::unselectedCertificates() { |
141 QStringList list; | 83 QStringList list; |
142 for (int i = 0; i < mCertificateList->count(); i++) { | 84 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
143 QListWidgetItem *item = mCertificateList->item(i); | 85 if (!item->state()) { |
144 CertificateItemWidget *itemWidget = | 86 list << item->certificate().base64Line(); |
145 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
146 if (!itemWidget->state()) { | |
147 list << itemWidget->certificate().base64Line(); | |
148 } | 87 } |
149 } | 88 } |
150 return list; | 89 return list; |
151 } | 90 } |
152 | 91 |
153 QList<Certificate> CertificateListWidget::certificateList() | 92 QList<Certificate> CertificateListWidget::certificateList() |
154 { | 93 { |
155 QList<Certificate> list; | 94 QList<Certificate> list; |
156 for (int i = 0; i < mCertificateList->count(); i++) { | 95 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
157 QListWidgetItem *item = mCertificateList->item(i); | 96 list << item->certificate(); |
158 CertificateItemWidget *itemWidget = | |
159 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
160 list << itemWidget->certificate(); | |
161 } | 97 } |
162 | |
163 return list; | 98 return list; |
164 } | 99 } |
165 | 100 |
166 void CertificateListWidget::setCertState(bool state, const Certificate &cert) | 101 void CertificateListWidget::setCertState(bool state, const Certificate &cert) |
167 { | 102 { |
168 for (int i = 0; i < mCertificateList->count(); i++) { | 103 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
169 QListWidgetItem *item = mCertificateList->item(i); | 104 if (item->certificate() == cert && |
170 CertificateItemWidget *itemWidget = | 105 item->state() != state) { |
171 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | 106 item->setState(state); |
172 if (itemWidget->certificate() == cert && | |
173 itemWidget->state() != state) { | |
174 itemWidget->setState(state); | |
175 } | 107 } |
176 } | 108 } |
177 } | 109 } |
178 | 110 |
179 void CertificateListWidget::updateDetails(QListWidgetItem *item) | |
180 { | |
181 if (item == NULL) { | |
182 return; | |
183 } | |
184 Certificate cert = item->data(Qt::UserRole).value<Certificate>(); | |
185 mSubjectCN->setText(cert.subjectCN()); | |
186 mSubjectO->setText(cert.subjectO()); | |
187 mValidFrom->setText(cert.validFrom().toString()); | |
188 mValidTo->setText(cert.validTo().toString()); | |
189 mFingerprint->setText(cert.fingerprint()); | |
190 } | |
191 | 111 |
192 void CertificateListWidget::certStateChanged(bool state, const Certificate &cert) | 112 void CertificateListWidget::certStateChanged(bool state, const Certificate &cert) |
193 { | 113 { |
194 int selected = 0; | 114 emit certListChanged(-1); |
195 for (int i = 0; i < mCertificateList->count(); i++) { | |
196 QListWidgetItem *item = mCertificateList->item(i); | |
197 CertificateItemWidget *itemWidget = | |
198 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
199 if (itemWidget->state()) { | |
200 selected++; | |
201 } | |
202 } | |
203 emit certListChanged(selected); | |
204 emit certChanged(state, cert); | 115 emit certChanged(state, cert); |
205 } | 116 } |
206 | 117 |
207 int CertificateListWidget::selectedCertCount() | 118 int CertificateListWidget::selectedCertCount() |
208 { | 119 { |
209 int selected = 0; | 120 int selected = 0; |
210 for (int i = 0; i < mCertificateList->count(); i++) { | 121 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
211 QListWidgetItem *item = mCertificateList->item(i); | 122 if (item->state()) { |
212 CertificateItemWidget *itemWidget = | |
213 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
214 if (itemWidget->state()) { | |
215 selected++; | 123 selected++; |
216 } | 124 } |
217 } | 125 } |
218 return selected; | 126 return selected; |
219 } | 127 } |
220 | 128 |
221 bool CertificateListWidget::contains(const Certificate &cert) | 129 bool CertificateListWidget::contains(const Certificate &cert) |
222 { | 130 { |
223 for (int i = 0; i < mCertificateList->count(); i++) { | 131 foreach (CertificateItemWidget * item, mCertificateWidgets) { |
224 QListWidgetItem *item = mCertificateList->item(i); | 132 if (item->certificate() == cert) { |
225 CertificateItemWidget *itemWidget = | |
226 static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); | |
227 if (itemWidget->certificate() == cert) { | |
228 return true; | 133 return true; |
229 } | 134 } |
230 } | 135 } |
231 return false; | 136 return false; |
232 } | 137 } |
233 | |
234 void CertificateListWidget::setSelected(int index) | |
235 { | |
236 if (index <= 0) { | |
237 index = 0; | |
238 } | |
239 mCertificateList->setFocus(); | |
240 mCertificateList->item(index)->setSelected(true); | |
241 mCertificateList->setCurrentRow(index); | |
242 } |