changeset 627:566ee111e331 trustbridge-refactor

Added state to certificate list item and updated certificate list widget.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 23 Jun 2014 12:46:53 +0200
parents ebfe1128ee97
children 3a9c0f38bbad
files ui/certificateitemwidget.cpp ui/certificateitemwidget.h ui/certificatelistwidget.cpp ui/certificatelistwidget.h
diffstat 4 files changed, 87 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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);
+}
--- 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
--- 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;
+}
--- 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

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