diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/certificateitemwidget.cpp	Wed Jun 25 15:16:24 2014 +0200
@@ -0,0 +1,97 @@
+/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=2)
+ * and comes with ABSOLUTELY NO WARRANTY!
+ * See LICENSE.txt for details.
+ */
+#include "certificateitemwidget.h"
+
+#include <QHBoxLayout>
+#include <QDebug>
+
+CertificateItemWidget::CertificateItemWidget(
+    QWidget *parent,
+    const Certificate &cert,
+    bool state,
+    bool editable) : QWidget(parent)
+{
+    mCertificate = cert;
+    mState = state;
+    mEditable = editable;
+    setupGUI();
+}
+
+void CertificateItemWidget::setupGUI()
+{
+    mLabel = new QLabel(mCertificate.subjectCN());
+    mComboBox = new QComboBox;
+    mComboBox->setFixedWidth(46);
+    connect(mComboBox, SIGNAL(currentIndexChanged(int)),
+        this, SLOT(currentStateChanged(int)));
+
+    QHBoxLayout *layout = new QHBoxLayout;
+    if (mCertificate.isInstallCert()) {
+        mComboBox->addItem(QIcon(":/img/security-high.png"), tr("install"), QVariant("true"));
+        mComboBox->addItem(QIcon(":/img/security-low.png"),
+            tr("remove"), QVariant("false"));
+        if (mState)
+            mComboBox->setCurrentIndex(0);
+        else {
+            mComboBox->setCurrentIndex(1);
+        }
+        layout->addWidget(mComboBox);
+    }
+    else if (!mCertificate.isInstallCert() && !mEditable){
+        QImage *img = new QImage(":/img/trash-empty.png");
+        QLabel *imgLabel = new QLabel;
+        imgLabel->setPixmap(QPixmap::fromImage(*img));
+        imgLabel->setFixedSize(28, 28);
+        imgLabel->setMargin(2);
+        layout->addWidget(imgLabel);
+    }
+    else {
+        mComboBox->addItem(QIcon(":/img/trash-empty.png"), tr("deinstall"), QVariant("true"));
+        mComboBox->addItem(QIcon(":/img/security-medium.png"),
+            tr("leave"), QVariant("false"));
+        if (mState)
+            mComboBox->setCurrentIndex(0);
+        else {
+            mComboBox->setCurrentIndex(1);
+        }
+        layout->addWidget(mComboBox);
+    }
+    layout->addWidget(mLabel);
+    this->setLayout(layout);
+}
+
+bool CertificateItemWidget::state()
+{
+    return mComboBox->currentData().toBool();
+}
+
+void CertificateItemWidget::setState(bool state)
+{
+    disconnect(mComboBox, SIGNAL(currentIndexChanged(int)),
+        this, SLOT(currentStateChanged(int)));
+
+    if (state) {
+        mComboBox->setCurrentIndex(0);
+    }
+    else {
+        mComboBox->setCurrentIndex(1);
+    }
+    connect(mComboBox, SIGNAL(currentIndexChanged(int)),
+        this, SLOT(currentStateChanged(int)));
+}
+
+Certificate CertificateItemWidget::certificate()
+{
+    return mCertificate;
+}
+
+void CertificateItemWidget::currentStateChanged(int)
+{
+    bool state = mComboBox->currentData().toBool();
+    emit stateChanged(state, mCertificate);
+}

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