rrenkert@582: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik rrenkert@582: * Software engineering by Intevation GmbH rrenkert@582: * rrenkert@582: * This file is Free Software under the GNU GPL (v>=2) rrenkert@582: * and comes with ABSOLUTELY NO WARRANTY! rrenkert@582: * See LICENSE.txt for details. rrenkert@582: */ rrenkert@582: #include "certificateitemwidget.h" rrenkert@582: rrenkert@582: #include rrenkert@582: #include andre@701: #include andre@1106: #include rrenkert@582: andre@687: CertificateItemWidget::CertificateItemWidget(QWidget *parent, andre@687: const Certificate &cert, andre@687: bool state, andre@1106: QToolButton *btn) : andre@687: QWidget(parent), andre@1106: mButton(btn) rrenkert@582: { rrenkert@582: mCertificate = cert; rrenkert@638: mState = state; andre@1106: /* We carry the state explicitly to be better prepared for future andre@1106: * changes */ andre@1106: btn->setCheckable(true); andre@1106: btn->setChecked(!state); rrenkert@582: setupGUI(); rrenkert@582: } rrenkert@582: rrenkert@582: void CertificateItemWidget::setupGUI() rrenkert@582: { andre@743: mLabel = new QLabel; andre@743: andre@786: setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); andre@786: emanuel@842: const QString validity = tr("Validity: %1 until %2").arg( andre@743: QLocale::system().toString(mCertificate.validFrom().date(), QLocale::ShortFormat)).arg( andre@743: QLocale::system().toString(mCertificate.validTo().date(), QLocale::ShortFormat)); emanuel@842: const QString fpstring = tr("Fingerprint (SHA1): %1").arg(mCertificate.fingerprint()); emanuel@842: mLabel->setText(QString::fromLatin1("%1
%2
%3
%4").arg andre@743: (mCertificate.subjectCN()).arg(mCertificate.subjectO()).arg(validity).arg andre@743: (fpstring)); andre@743: mLabel->setTextFormat(Qt::RichText); andre@701: emanuel@842: mLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); andre@780: andre@780: mLabel->setTextInteractionFlags( andre@780: Qt::TextSelectableByMouse | andre@780: Qt::TextSelectableByKeyboard); andre@1106: mButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); andre@1106: connect(mButton, SIGNAL(toggled (bool)), andre@1106: this, SLOT(currentStateChanged(bool))); rrenkert@582: rrenkert@638: QHBoxLayout *layout = new QHBoxLayout; andre@1106: layout->addWidget(mButton); andre@1106: mButton->setFixedSize(64, 64); andre@1106: mButton->setIconSize(QSize(48, 48)); andre@1106: /* rrenkert@582: if (mCertificate.isInstallCert()) { andre@701: mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel); andre@701: mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel); emanuel@842: if (mState) { rrenkert@638: mComboBox->setCurrentIndex(0); emanuel@842: mComboBox->setToolTip(tr("This certificate is currently installed.")); andre@1106: } rrenkert@638: else { rrenkert@638: mComboBox->setCurrentIndex(1); emanuel@842: mComboBox->setToolTip(tr("This certificate is currently not installed.")); rrenkert@638: } rrenkert@638: layout->addWidget(mComboBox); rrenkert@638: } rrenkert@638: else if (!mCertificate.isInstallCert() && !mEditable){ rrenkert@650: QImage *img = new QImage(":/img/trash-empty.png"); rrenkert@638: QLabel *imgLabel = new QLabel; rrenkert@638: imgLabel->setPixmap(QPixmap::fromImage(*img)); emanuel@842: imgLabel->setFixedSize(64, 64); emanuel@842: imgLabel->setMargin(8); emanuel@842: imgLabel->setToolTip(tr("This certificate was uninstalled.")); rrenkert@638: layout->addWidget(imgLabel); rrenkert@582: } rrenkert@582: else { andre@710: mComboBox->addItem(QIcon(":/img/trash-empty.png"), QString(), tr("uninstall")); andre@710: mComboBox->addItem(QIcon(":/img/security-medium.png"), QString(), tr("keep")); emanuel@842: mComboBox->setToolTip(tr("This certificate is currently installed.")); rrenkert@638: if (mState) rrenkert@638: mComboBox->setCurrentIndex(0); rrenkert@638: else { rrenkert@638: mComboBox->setCurrentIndex(1); rrenkert@638: } rrenkert@638: layout->addWidget(mComboBox); rrenkert@582: } andre@1106: */ rrenkert@582: layout->addWidget(mLabel); rrenkert@582: this->setLayout(layout); rrenkert@582: } rrenkert@627: rrenkert@627: bool CertificateItemWidget::state() rrenkert@627: { andre@1106: if (!mButton->isEnabled()) { andre@685: return true; andre@685: } andre@701: andre@1106: /* andre@701: const QString currentString = mComboBox->currentData().toString(); andre@701: andre@701: if (!mCertificate.isInstallCert()) { andre@701: return currentString == tr("uninstall"); andre@701: } andre@701: andre@701: return currentString == mInstallLabel; andre@1106: */ andre@1106: return mState; rrenkert@627: } rrenkert@627: rrenkert@638: void CertificateItemWidget::setState(bool state) rrenkert@638: { andre@1106: mState = state; andre@1106: mButton->setChecked(!state); rrenkert@638: } rrenkert@638: andre@1101: Certificate* CertificateItemWidget::certificate() rrenkert@627: { andre@1101: return &mCertificate; rrenkert@627: } rrenkert@627: andre@1106: void CertificateItemWidget::currentStateChanged(bool state) rrenkert@627: { andre@1106: mState = !state; andre@1106: emit stateChanged(mState, mCertificate); rrenkert@627: }