[PATCH 1 of 2] Added state to certificate list item and updated certificate list widget
Wald Commits
scm-commit at wald.intevation.org
Mon Jun 23 12:51:28 CEST 2014
# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1403520413 -7200
# Branch trustbridge-refactor
# Node ID 566ee111e331f15402d9056c8c47450b777cd676
# Parent ebfe1128ee97264e3bcad68efa50251eaff78407
Added state to certificate list item and updated certificate list widget.
diff -r ebfe1128ee97 -r 566ee111e331 ui/certificateitemwidget.cpp
--- a/ui/certificateitemwidget.cpp Tue May 27 16:25:33 2014 +0200
+++ b/ui/certificateitemwidget.cpp Mon Jun 23 12:46:53 2014 +0200
@@ -23,6 +23,8 @@
mLabel = new QLabel(mCertificate.subjectCN());
mComboBox = new QComboBox;
mComboBox->setFixedWidth(46);
+ connect(mComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(currentStateChanged(int)));
if (mCertificate.isInstallCert()) {
mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true"));
@@ -39,3 +41,19 @@
layout->addWidget(mLabel);
this->setLayout(layout);
}
+
+bool CertificateItemWidget::state()
+{
+ return mComboBox->currentData().toBool();
+}
+
+Certificate CertificateItemWidget::certificate()
+{
+ return mCertificate;
+}
+
+void CertificateItemWidget::currentStateChanged(int)
+{
+ bool state = mComboBox->currentData().toBool();
+ emit stateChanged(state, mCertificate);
+}
diff -r ebfe1128ee97 -r 566ee111e331 ui/certificateitemwidget.h
--- a/ui/certificateitemwidget.h Tue May 27 16:25:33 2014 +0200
+++ b/ui/certificateitemwidget.h Mon Jun 23 12:46:53 2014 +0200
@@ -20,15 +20,24 @@
class CertificateItemWidget : public QWidget
{
-
+Q_OBJECT
public:
CertificateItemWidget(QWidget *parent = 0, const Certificate &cert = Certificate());
+ bool state();
+ Certificate certificate();
+
private:
void setupGUI();
Certificate mCertificate;
QLabel *mLabel;
QComboBox *mComboBox;
+
+private slots:
+ void currentStateChanged(int ndx);
+
+signals:
+ void stateChanged(bool state, const Certificate &cert);
};
#endif
diff -r ebfe1128ee97 -r 566ee111e331 ui/certificatelistwidget.cpp
--- a/ui/certificatelistwidget.cpp Tue May 27 16:25:33 2014 +0200
+++ b/ui/certificatelistwidget.cpp Mon Jun 23 12:46:53 2014 +0200
@@ -80,6 +80,8 @@
mCertificateList->addItem(item);
CertificateItemWidget *widget =
new CertificateItemWidget(mCertificateList, certificate);
+ connect(widget, SIGNAL(stateChanged(bool, const Certificate&)),
+ this, SLOT(certStateChanged(bool, const Certificate&)));
item->setSizeHint(widget->minimumSizeHint());
mCertificateList->setItemWidget(item, widget);
}
@@ -94,9 +96,29 @@
}
-QList<Certificate> CertificateListWidget::getCertificates()
+void CertificateListWidget::clear()
{
- return QList<Certificate>();
+ mCertificateList->clear();
+}
+
+QStringList CertificateListWidget::certificates()
+{
+ QStringList list;
+ for (int i = 0; i < mCertificateList->count(); i++) {
+ QListWidgetItem *item = mCertificateList->item(i);
+ CertificateItemWidget *itemWidget =
+ static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+ if (itemWidget->state()) {
+ list << itemWidget->certificate().base64Line();
+ continue;
+ }
+ QString b64Line = itemWidget->certificate().base64Line();
+ if (b64Line.startsWith("I:")) {
+ b64Line[0] = 'R';
+ list << b64Line;
+ }
+ }
+ return list;
}
void CertificateListWidget::updateDetails(QListWidgetItem *item)
@@ -113,3 +135,31 @@
mValidTo->setText(cert.validTo().toString());
mFingerprint->setText(cert.fingerprint());
}
+
+void CertificateListWidget::certStateChanged(bool state, const Certificate &cert)
+{
+ int selected = 0;
+ for (int i = 0; i < mCertificateList->count(); i++) {
+ QListWidgetItem *item = mCertificateList->item(i);
+ CertificateItemWidget *itemWidget =
+ static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+ if (itemWidget->state()) {
+ selected++;
+ }
+ }
+ emit certListChanged(selected);
+}
+
+int CertificateListWidget::selectedCertCount()
+{
+ int selected = 0;
+ for (int i = 0; i < mCertificateList->count(); i++) {
+ QListWidgetItem *item = mCertificateList->item(i);
+ CertificateItemWidget *itemWidget =
+ static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+ if (itemWidget->state()) {
+ selected++;
+ }
+ }
+ return selected;
+}
diff -r ebfe1128ee97 -r 566ee111e331 ui/certificatelistwidget.h
--- a/ui/certificatelistwidget.h Tue May 27 16:25:33 2014 +0200
+++ b/ui/certificatelistwidget.h Mon Jun 23 12:46:53 2014 +0200
@@ -30,7 +30,9 @@
void addCertificate(const Certificate &certificate);
void addCertificates(const QList<Certificate> &list);
void removeCertificate(int ndx);
- QList<Certificate> getCertificates();
+ void clear();
+ QStringList certificates();
+ int selectedCertCount();
private:
void setupGUI();
@@ -46,6 +48,10 @@
private slots:
void updateDetails(QListWidgetItem *item);
+ void certStateChanged(bool state, const Certificate &cert);
+
+signals:
+ void certListChanged(int selected);
};
#endif // CERTIFICATELISTWIDGET_H
More information about the Trustbridge-commits
mailing list