diff ui/certificatelistwidget.cpp @ 639:c1b35edb097f trustbridge-refactor

New methods to modify and use the certificate list.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 Jun 2014 17:03:59 +0200
parents 566ee111e331
children 7cd6602e3fa2
line wrap: on
line diff
--- a/ui/certificatelistwidget.cpp	Tue Jun 24 16:59:52 2014 +0200
+++ b/ui/certificatelistwidget.cpp	Tue Jun 24 17:03:59 2014 +0200
@@ -72,14 +72,17 @@
     this->setLayout(mainLayout);
 }
 
-void CertificateListWidget::addCertificate(const Certificate &certificate)
+void CertificateListWidget::addCertificate(
+    const Certificate &certificate,
+    bool state,
+    bool editable)
 {
     QListWidgetItem* item = new QListWidgetItem(mCertificateList);
     item->setData(Qt::UserRole,
         QVariant::fromValue(certificate));
     mCertificateList->addItem(item);
     CertificateItemWidget *widget =
-        new CertificateItemWidget(mCertificateList, certificate);
+        new CertificateItemWidget(mCertificateList, certificate, state, editable);
     connect(widget, SIGNAL(stateChanged(bool, const Certificate&)),
         this, SLOT(certStateChanged(bool, const Certificate&)));
     item->setSizeHint(widget->minimumSizeHint());
@@ -91,9 +94,17 @@
 
 }
 
-void CertificateListWidget::removeCertificate(int ndx)
+void CertificateListWidget::removeCertificate(const Certificate &cert)
 {
-
+    for (int i = 0; i < mCertificateList->count(); i++) {
+        QListWidgetItem *item = mCertificateList->item(i);
+        CertificateItemWidget *itemWidget =
+            static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+        if (itemWidget->certificate() == cert) {
+            QListWidgetItem* item = mCertificateList->takeItem(i);
+            delete(item);
+        }
+    }
 }
 
 void CertificateListWidget::clear()
@@ -108,19 +119,63 @@
         QListWidgetItem *item = mCertificateList->item(i);
         CertificateItemWidget *itemWidget =
             static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+        list <<  itemWidget->certificate().base64Line();
+    }
+    return list;
+}
+
+QStringList CertificateListWidget::selectedCertificates() {
+    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;
 }
 
+QStringList CertificateListWidget::unselectedCertificates() {
+    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();
+        }
+    }
+    return list;
+}
+
+QList<Certificate> CertificateListWidget::certificateList()
+{
+    QList<Certificate> list;
+    for (int i = 0; i < mCertificateList->count(); i++) {
+        QListWidgetItem *item = mCertificateList->item(i);
+        CertificateItemWidget *itemWidget =
+            static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+        list << itemWidget->certificate();
+    }
+
+    return list;
+}
+
+void CertificateListWidget::setCertState(bool state, const Certificate &cert)
+{
+    for (int i = 0; i < mCertificateList->count(); i++) {
+        QListWidgetItem *item = mCertificateList->item(i);
+        CertificateItemWidget *itemWidget =
+            static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+        if (itemWidget->certificate() == cert &&
+            itemWidget->state() != state) {
+            itemWidget->setState(state);
+        }
+    }
+}
+
 void CertificateListWidget::updateDetails(QListWidgetItem *item)
 {
     if (item == NULL) {
@@ -148,6 +203,7 @@
         }
     }
     emit certListChanged(selected);
+    emit certChanged(state, cert);
 }
 
 int CertificateListWidget::selectedCertCount()
@@ -163,3 +219,16 @@
     }
     return selected;
 }
+
+bool CertificateListWidget::contains(const Certificate &cert)
+{
+    for (int i = 0; i < mCertificateList->count(); i++) {
+        QListWidgetItem *item = mCertificateList->item(i);
+        CertificateItemWidget *itemWidget =
+            static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item));
+        if (itemWidget->certificate() == cert) {
+            return true;
+        }
+    }
+    return false;
+}

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