Mercurial > trustbridge
changeset 582:88c9bdc74175 trustbridge-refactor
New widgets to display certificates in lists.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 27 May 2014 16:16:21 +0200 |
parents | ab622e094786 |
children | 7d6026424f37 |
files | ui/certificateitemwidget.cpp ui/certificateitemwidget.h ui/certificatelistwidget.cpp ui/certificatelistwidget.h |
diffstat | 4 files changed, 241 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/certificateitemwidget.cpp Tue May 27 16:16:21 2014 +0200 @@ -0,0 +1,41 @@ +/* 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) : QWidget(parent) +{ + mCertificate = cert; + setupGUI(); +} + +void CertificateItemWidget::setupGUI() +{ + mLabel = new QLabel(mCertificate.subjectCN()); + mComboBox = new QComboBox; + mComboBox->setFixedWidth(46); + + if (mCertificate.isInstallCert()) { + mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true")); + mComboBox->addItem(QIcon(":/img/list-remove.png"), + tr("remove"), QVariant("false")); + } + else { + mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true")); + mComboBox->addItem(QIcon(":/img/list-remove.png"), + tr("remove"), QVariant("false")); + } + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(mComboBox); + layout->addWidget(mLabel); + this->setLayout(layout); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/certificateitemwidget.h Tue May 27 16:16:21 2014 +0200 @@ -0,0 +1,34 @@ +/* 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. + */ +#ifndef CERTIFICATELISTITEM_H +#define CERTIFICATELISTITEM_H +/** + * @file certificateitemdelegate.h + * @brief Item delegate drawing custom certificate items in list views. + * + */ +#include <QWidget> +#include <QLabel> +#include <QComboBox> + +#include "certificate.h" + +class CertificateItemWidget : public QWidget +{ + +public: + CertificateItemWidget(QWidget *parent = 0, const Certificate &cert = Certificate()); + +private: + void setupGUI(); + + Certificate mCertificate; + QLabel *mLabel; + QComboBox *mComboBox; +}; +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/certificatelistwidget.cpp Tue May 27 16:16:21 2014 +0200 @@ -0,0 +1,115 @@ +/* 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 "certificatelistwidget.h" +#include <QDebug> +#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QGroupBox> +#include <QLabel> + +#include "certificateitemwidget.h" + +CertificateListWidget::CertificateListWidget(QWidget *parent, Qt::WindowFlags flags) : + QWidget(parent, flags) +{ + setupGUI(); +} + +void CertificateListWidget::setupGUI() +{ + QHBoxLayout *mainLayout = new QHBoxLayout; + mCertificateList = new QListWidget; + mCertificateList->setFixedWidth(250); + connect(mCertificateList, + SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), + this, + SLOT(updateDetails(QListWidgetItem*))); + + QHBoxLayout *detailLayout = new QHBoxLayout; + QVBoxLayout *detailLabelLayout = new QVBoxLayout; + QVBoxLayout *detailContentLayout = new QVBoxLayout; + QGroupBox *detailBox = new QGroupBox(); + QLabel *subjectCN = new QLabel(tr("Subject Common Name:")); + QLabel *subjectOU = new QLabel(tr("Subject Organisation:")); + QLabel *issuerCN = new QLabel(tr("Issuer Common Name:")); + QLabel *issuerOU = new QLabel(tr("Issuer Organisation:")); + QLabel *validFrom = new QLabel(tr("Valid from:")); + QLabel *validTo = new QLabel(tr("Valid to:")); + QLabel *fingerprint = new QLabel(tr("Fingerprint:")); + detailLabelLayout->addWidget(subjectCN); + detailLabelLayout->addWidget(subjectOU); + detailLabelLayout->addWidget(issuerCN); + detailLabelLayout->addWidget(issuerOU); + detailLabelLayout->addWidget(validFrom); + detailLabelLayout->addWidget(validTo); + detailLabelLayout->addWidget(fingerprint); + mSubjectCN = new QLabel(tr("")); + mSubjectO = new QLabel(tr("")); + mIssuerCN = new QLabel(tr("")); + mIssuerO = new QLabel(tr("")); + mValidFrom = new QLabel(tr("")); + mValidTo = new QLabel(tr("")); + mFingerprint = new QLabel(tr("")); + mFingerprint->setFont(QFont("DejaVu Sans Mono")); + detailContentLayout->addWidget(mSubjectCN); + detailContentLayout->addWidget(mSubjectO); + detailContentLayout->addWidget(mIssuerCN); + detailContentLayout->addWidget(mIssuerO); + detailContentLayout->addWidget(mValidFrom); + detailContentLayout->addWidget(mValidTo); + detailContentLayout->addWidget(mFingerprint); + detailLayout->addLayout(detailLabelLayout); + detailLayout->addLayout(detailContentLayout); + detailBox->setLayout(detailLayout); + + mainLayout->addWidget(mCertificateList); + mainLayout->addWidget(detailBox); + this->setLayout(mainLayout); +} + +void CertificateListWidget::addCertificate(const Certificate &certificate) +{ + QListWidgetItem* item = new QListWidgetItem(mCertificateList); + item->setData(Qt::UserRole, + QVariant::fromValue(certificate)); + mCertificateList->addItem(item); + CertificateItemWidget *widget = + new CertificateItemWidget(mCertificateList, certificate); + item->setSizeHint(widget->minimumSizeHint()); + mCertificateList->setItemWidget(item, widget); +} + +void CertificateListWidget::addCertificates(const QList<Certificate> &list) +{ + +} + +void CertificateListWidget::removeCertificate(int ndx) +{ + +} + +QList<Certificate> CertificateListWidget::getCertificates() +{ + return QList<Certificate>(); +} + +void CertificateListWidget::updateDetails(QListWidgetItem *item) +{ + if (item == NULL) { + return; + } + Certificate cert = item->data(Qt::UserRole).value<Certificate>(); + mSubjectCN->setText(cert.subjectCN()); + mSubjectO->setText(cert.subjectO()); + mIssuerCN->setText(cert.issuerCN()); + mIssuerO->setText(cert.issuerO()); + mValidFrom->setText(cert.validFrom().toString()); + mValidTo->setText(cert.validTo().toString()); + mFingerprint->setText(cert.fingerprint()); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/certificatelistwidget.h Tue May 27 16:16:21 2014 +0200 @@ -0,0 +1,51 @@ +/* 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. + */ +#ifndef CERTIFICATELISTWIDGET_H +#define CERTIFICATELISTWIDGET_H + +#include <QWidget> +#include <QMainWindow> +#include <QLabel> +#include <QListWidget> + +#include "certificate.h" +/** + * @file certificatelistwidget.h + * @brief Displays a list of certificates and a details panel for a selected + * certificate. + */ + +Q_DECLARE_METATYPE(Certificate); +class CertificateListWidget : public QWidget +{ + Q_OBJECT +public: + CertificateListWidget(QWidget *parent, Qt::WindowFlags flags = 0); + + void addCertificate(const Certificate &certificate); + void addCertificates(const QList<Certificate> &list); + void removeCertificate(int ndx); + QList<Certificate> getCertificates(); + +private: + void setupGUI(); + + QListWidget *mCertificateList; + QLabel *mSubjectCN; + QLabel *mSubjectO; + QLabel *mIssuerCN; + QLabel *mIssuerO; + QLabel *mValidFrom; + QLabel *mValidTo; + QLabel *mFingerprint; + +private slots: + void updateDetails(QListWidgetItem *item); + +}; +#endif // CERTIFICATELISTWIDGET_H