annotate ui/certificateitemwidget.cpp @ 654:129e611eaf50

Merge branch trustbridge-refactor
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Jun 2014 15:16:24 +0200
parents 9c3e7754b76b
children c7405d526ead
rev   line source
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 *
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details.
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 */
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 #include "certificateitemwidget.h"
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 #include <QHBoxLayout>
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 #include <QDebug>
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 CertificateItemWidget::CertificateItemWidget(
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 QWidget *parent,
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
15 const Certificate &cert,
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
16 bool state,
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
17 bool editable) : QWidget(parent)
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 {
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 mCertificate = cert;
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
20 mState = state;
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
21 mEditable = editable;
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 setupGUI();
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 }
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 void CertificateItemWidget::setupGUI()
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 {
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 mLabel = new QLabel(mCertificate.subjectCN());
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 mComboBox = new QComboBox;
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 mComboBox->setFixedWidth(46);
627
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
30 connect(mComboBox, SIGNAL(currentIndexChanged(int)),
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
31 this, SLOT(currentStateChanged(int)));
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
33 QHBoxLayout *layout = new QHBoxLayout;
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 if (mCertificate.isInstallCert()) {
650
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
35 mComboBox->addItem(QIcon(":/img/security-high.png"), tr("install"), QVariant("true"));
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
36 mComboBox->addItem(QIcon(":/img/security-low.png"),
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 tr("remove"), QVariant("false"));
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
38 if (mState)
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
39 mComboBox->setCurrentIndex(0);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
40 else {
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
41 mComboBox->setCurrentIndex(1);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
42 }
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
43 layout->addWidget(mComboBox);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
44 }
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
45 else if (!mCertificate.isInstallCert() && !mEditable){
650
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
46 QImage *img = new QImage(":/img/trash-empty.png");
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
47 QLabel *imgLabel = new QLabel;
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
48 imgLabel->setPixmap(QPixmap::fromImage(*img));
650
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
49 imgLabel->setFixedSize(28, 28);
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
50 imgLabel->setMargin(2);
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
51 layout->addWidget(imgLabel);
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 }
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 else {
650
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
54 mComboBox->addItem(QIcon(":/img/trash-empty.png"), tr("deinstall"), QVariant("true"));
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
55 mComboBox->addItem(QIcon(":/img/security-medium.png"),
9c3e7754b76b Use new icons in certificate lists.
Raimund Renkert <rrenkert@intevation.de>
parents: 638
diff changeset
56 tr("leave"), QVariant("false"));
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
57 if (mState)
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
58 mComboBox->setCurrentIndex(0);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
59 else {
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
60 mComboBox->setCurrentIndex(1);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
61 }
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
62 layout->addWidget(mComboBox);
582
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 }
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 layout->addWidget(mLabel);
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 this->setLayout(layout);
88c9bdc74175 New widgets to display certificates in lists.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 }
627
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
67
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
68 bool CertificateItemWidget::state()
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
69 {
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
70 return mComboBox->currentData().toBool();
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
71 }
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
72
638
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
73 void CertificateItemWidget::setState(bool state)
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
74 {
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
75 disconnect(mComboBox, SIGNAL(currentIndexChanged(int)),
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
76 this, SLOT(currentStateChanged(int)));
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
77
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
78 if (state) {
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
79 mComboBox->setCurrentIndex(0);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
80 }
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
81 else {
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
82 mComboBox->setCurrentIndex(1);
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
83 }
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
84 connect(mComboBox, SIGNAL(currentIndexChanged(int)),
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
85 this, SLOT(currentStateChanged(int)));
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
86 }
9d806f140bd5 Added state and editable flag to certificate list items.
Raimund Renkert <rrenkert@intevation.de>
parents: 627
diff changeset
87
627
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
88 Certificate CertificateItemWidget::certificate()
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
89 {
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
90 return mCertificate;
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
91 }
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
92
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
93 void CertificateItemWidget::currentStateChanged(int)
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
94 {
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
95 bool state = mComboBox->currentData().toBool();
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
96 emit stateChanged(state, mCertificate);
566ee111e331 Added state to certificate list item and updated certificate list widget.
Raimund Renkert <rrenkert@intevation.de>
parents: 582
diff changeset
97 }

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