[PATCH 2 of 3] New methods to modify and use the certificate list

Wald Commits scm-commit at wald.intevation.org
Tue Jun 24 17:21:10 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1403622239 -7200
# Branch trustbridge-refactor
# Node ID c1b35edb097f60b2615544c1146d5335adb7776f
# Parent  9d806f140bd5ce65d5b543cff602722228d0b578
New methods to modify and use the certificate list.

diff -r 9d806f140bd5 -r c1b35edb097f ui/certificatelistwidget.cpp
--- 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;
+}
diff -r 9d806f140bd5 -r c1b35edb097f ui/certificatelistwidget.h
--- a/ui/certificatelistwidget.h	Tue Jun 24 16:59:52 2014 +0200
+++ b/ui/certificatelistwidget.h	Tue Jun 24 17:03:59 2014 +0200
@@ -27,12 +27,17 @@
 public:
     CertificateListWidget(QWidget *parent, Qt::WindowFlags flags = 0);
 
-    void addCertificate(const Certificate &certificate);
+    void addCertificate(const Certificate &certificate, bool state, bool editable = true);
     void addCertificates(const QList<Certificate> &list);
-    void removeCertificate(int ndx);
+    void removeCertificate(const Certificate &cert);
+    void setCertState(bool state, const Certificate &cert);
     void clear();
     QStringList certificates();
+    QStringList selectedCertificates();
+    QStringList unselectedCertificates();
+    QList<Certificate> certificateList();
     int selectedCertCount();
+    bool contains(const Certificate &cert);
 
 private:
     void setupGUI();
@@ -52,6 +57,7 @@
 
 signals:
     void certListChanged(int selected);
+    void certChanged(bool state, const Certificate &cert);
 
 };
 #endif // CERTIFICATELISTWIDGET_H


More information about the Trustbridge-commits mailing list