Mercurial > trustbridge
view ui/certificateitemwidget.cpp @ 1108:9bb9932bb819
Revert commit 1101 the inactive manual changes were a bad idea
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 15 Sep 2014 17:47:12 +0200 |
parents | 6f7b7d88f048 |
children | 6594e8e63a25 |
line wrap: on
line source
/* 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> #include <QStyleFactory> #include <QToolButton> CertificateItemWidget::CertificateItemWidget(QWidget *parent, const Certificate &cert, bool state, QToolButton *btn) : QWidget(parent), mButton(btn) { mCertificate = cert; mState = state; /* We carry the state explicitly to be better prepared for future * changes */ btn->setCheckable(true); btn->setChecked(!state); setupGUI(); } void CertificateItemWidget::setupGUI() { mLabel = new QLabel; setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); const QString validity = tr("Validity: %1 until %2").arg( QLocale::system().toString(mCertificate.validFrom().date(), QLocale::ShortFormat)).arg( QLocale::system().toString(mCertificate.validTo().date(), QLocale::ShortFormat)); const QString fpstring = tr("Fingerprint (SHA1): <code>%1</code>").arg(mCertificate.fingerprint()); mLabel->setText(QString::fromLatin1("<big><b>%1</b></big><br/>%2<br/>%3<br/>%4").arg (mCertificate.subjectCN()).arg(mCertificate.subjectO()).arg(validity).arg (fpstring)); mLabel->setTextFormat(Qt::RichText); mLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); mLabel->setTextInteractionFlags( Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); mButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); connect(mButton, SIGNAL(toggled (bool)), this, SLOT(currentStateChanged(bool))); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(mButton); mButton->setFixedSize(64, 64); mButton->setIconSize(QSize(48, 48)); /* if (mCertificate.isInstallCert()) { mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel); mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel); if (mState) { mComboBox->setCurrentIndex(0); mComboBox->setToolTip(tr("This certificate is currently installed.")); } else { mComboBox->setCurrentIndex(1); mComboBox->setToolTip(tr("This certificate is currently not installed.")); } 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(64, 64); imgLabel->setMargin(8); imgLabel->setToolTip(tr("This certificate was uninstalled.")); layout->addWidget(imgLabel); } else { mComboBox->addItem(QIcon(":/img/trash-empty.png"), QString(), tr("uninstall")); mComboBox->addItem(QIcon(":/img/security-medium.png"), QString(), tr("keep")); mComboBox->setToolTip(tr("This certificate is currently installed.")); if (mState) mComboBox->setCurrentIndex(0); else { mComboBox->setCurrentIndex(1); } layout->addWidget(mComboBox); } */ layout->addWidget(mLabel); this->setLayout(layout); } bool CertificateItemWidget::state() { if (!mButton->isEnabled()) { return true; } /* const QString currentString = mComboBox->currentData().toString(); if (!mCertificate.isInstallCert()) { return currentString == tr("uninstall"); } return currentString == mInstallLabel; */ return mState; } void CertificateItemWidget::setState(bool state) { mState = state; mButton->setChecked(!state); } Certificate CertificateItemWidget::certificate() { return mCertificate; } void CertificateItemWidget::currentStateChanged(bool state) { mState = !state; emit stateChanged(mState, mCertificate); }