comparison 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
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 "certificateitemwidget.h"
9
10 #include <QHBoxLayout>
11 #include <QDebug>
12
13 CertificateItemWidget::CertificateItemWidget(
14 QWidget *parent,
15 const Certificate &cert,
16 bool state,
17 bool editable) : QWidget(parent)
18 {
19 mCertificate = cert;
20 mState = state;
21 mEditable = editable;
22 setupGUI();
23 }
24
25 void CertificateItemWidget::setupGUI()
26 {
27 mLabel = new QLabel(mCertificate.subjectCN());
28 mComboBox = new QComboBox;
29 mComboBox->setFixedWidth(46);
30 connect(mComboBox, SIGNAL(currentIndexChanged(int)),
31 this, SLOT(currentStateChanged(int)));
32
33 QHBoxLayout *layout = new QHBoxLayout;
34 if (mCertificate.isInstallCert()) {
35 mComboBox->addItem(QIcon(":/img/security-high.png"), tr("install"), QVariant("true"));
36 mComboBox->addItem(QIcon(":/img/security-low.png"),
37 tr("remove"), QVariant("false"));
38 if (mState)
39 mComboBox->setCurrentIndex(0);
40 else {
41 mComboBox->setCurrentIndex(1);
42 }
43 layout->addWidget(mComboBox);
44 }
45 else if (!mCertificate.isInstallCert() && !mEditable){
46 QImage *img = new QImage(":/img/trash-empty.png");
47 QLabel *imgLabel = new QLabel;
48 imgLabel->setPixmap(QPixmap::fromImage(*img));
49 imgLabel->setFixedSize(28, 28);
50 imgLabel->setMargin(2);
51 layout->addWidget(imgLabel);
52 }
53 else {
54 mComboBox->addItem(QIcon(":/img/trash-empty.png"), tr("deinstall"), QVariant("true"));
55 mComboBox->addItem(QIcon(":/img/security-medium.png"),
56 tr("leave"), QVariant("false"));
57 if (mState)
58 mComboBox->setCurrentIndex(0);
59 else {
60 mComboBox->setCurrentIndex(1);
61 }
62 layout->addWidget(mComboBox);
63 }
64 layout->addWidget(mLabel);
65 this->setLayout(layout);
66 }
67
68 bool CertificateItemWidget::state()
69 {
70 return mComboBox->currentData().toBool();
71 }
72
73 void CertificateItemWidget::setState(bool state)
74 {
75 disconnect(mComboBox, SIGNAL(currentIndexChanged(int)),
76 this, SLOT(currentStateChanged(int)));
77
78 if (state) {
79 mComboBox->setCurrentIndex(0);
80 }
81 else {
82 mComboBox->setCurrentIndex(1);
83 }
84 connect(mComboBox, SIGNAL(currentIndexChanged(int)),
85 this, SLOT(currentStateChanged(int)));
86 }
87
88 Certificate CertificateItemWidget::certificate()
89 {
90 return mCertificate;
91 }
92
93 void CertificateItemWidget::currentStateChanged(int)
94 {
95 bool state = mComboBox->currentData().toBool();
96 emit stateChanged(state, mCertificate);
97 }

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