diff ui/certificatelistwidget.cpp @ 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 88c9bdc74175
children c1b35edb097f
line wrap: on
line diff
--- 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;
+}

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