[PATCH 2 of 2] (issue111) Keep manually changed certificates in the manually changed list

Wald Commits scm-commit at wald.intevation.org
Mon Sep 15 13:56:00 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1410782147 -7200
# Node ID 2b3526ef2d696dfdb868116bbf43d5009e57f6fe
# Parent  77afafd23a1b7c42860dde3da0f47d9ec75dc14c
(issue111) Keep manually changed certificates in the manually changed list.

    This invents the new property "active certificate"
    an inactive certificate is a certificate that is displayed but
    has no impact on the store.

diff -r 77afafd23a1b -r 2b3526ef2d69 ui/certificate.cpp
--- a/ui/certificate.cpp	Mon Sep 15 12:50:26 2014 +0200
+++ b/ui/certificate.cpp	Mon Sep 15 13:55:47 2014 +0200
@@ -88,7 +88,8 @@
 
 Certificate::Certificate(const QByteArray& derData) :
     mValid(false),
-    mEditable(false)
+    mEditable(false),
+    mActive(true)
 {
     if (derData.isEmpty()) {
         return;
diff -r 77afafd23a1b -r 2b3526ef2d69 ui/certificate.h
--- a/ui/certificate.h	Mon Sep 15 12:50:26 2014 +0200
+++ b/ui/certificate.h	Mon Sep 15 13:55:47 2014 +0200
@@ -136,6 +136,21 @@
     friend inline bool operator==(const Certificate& lhs, const Certificate& rhs) {
         return lhs.base64Line() == rhs.base64Line();
     }
+
+    /** @brief Wether or not the certificate is Active.
+     *
+     * This property is mainly for the manually changed certificate list.
+     * A certificate is active if it should be counted as change in a list
+     * and if it should be written to a certificate store.
+     *
+     * An inctive certificate will only be shown in the manual changes list
+     * but not counted as a changed or changed in the certificate list. */
+    bool isActive() const { return mActive; }
+
+    /** @brief set the active state of a certificate.
+     *
+     * See isActive() for details. */
+    void setActive(bool active) { mActive = active; }
 private:
     /** @brief Helper function to parse the details of a certificate **/
     void parseDetails(const QByteArray& cert);
@@ -143,6 +158,7 @@
     bool mValid;
     /* bool mInstCert; */
     bool mEditable;
+    bool mActive;
 
     QString mSubjectOU,
             mSubjectCN,
diff -r 77afafd23a1b -r 2b3526ef2d69 ui/certificateitemwidget.cpp
--- a/ui/certificateitemwidget.cpp	Mon Sep 15 12:50:26 2014 +0200
+++ b/ui/certificateitemwidget.cpp	Mon Sep 15 13:55:47 2014 +0200
@@ -139,9 +139,9 @@
         this, SLOT(currentStateChanged(int)));
 }
 
-Certificate CertificateItemWidget::certificate()
+Certificate* CertificateItemWidget::certificate()
 {
-    return mCertificate;
+    return &mCertificate;
 }
 
 void CertificateItemWidget::currentStateChanged(int)
diff -r 77afafd23a1b -r 2b3526ef2d69 ui/certificateitemwidget.h
--- a/ui/certificateitemwidget.h	Mon Sep 15 12:50:26 2014 +0200
+++ b/ui/certificateitemwidget.h	Mon Sep 15 13:55:47 2014 +0200
@@ -43,7 +43,7 @@
 
     bool state();
     void setState(bool state);
-    Certificate certificate();
+    Certificate *certificate();
 
 private:
     void setupGUI();
diff -r 77afafd23a1b -r 2b3526ef2d69 ui/certificatelistwidget.cpp
--- a/ui/certificatelistwidget.cpp	Mon Sep 15 12:50:26 2014 +0200
+++ b/ui/certificatelistwidget.cpp	Mon Sep 15 13:55:47 2014 +0200
@@ -40,10 +40,43 @@
     emit certListChanged(-1);
 }
 
+int CertificateListWidget::activeCertificates()
+{
+    int ret = 0;
+    for (int i = 0; i < mCertificateWidgets.size(); i++) {
+        if (mCertificateWidgets[i]->certificate()->isActive()) {
+            ret++;
+        }
+    }
+    return ret;
+}
+
+void CertificateListWidget::activateCertificate(const Certificate &cert)
+{
+    for (int i = 0; i < mCertificateWidgets.size(); i++) {
+        if (*(mCertificateWidgets[i]->certificate()) == cert) {
+            mCertificateWidgets[i]->certificate()->setActive(true);
+            break;
+        }
+    }
+    emit certListChanged(-1);
+}
+
+void CertificateListWidget::deactivateCertificate(const Certificate &cert)
+{
+    for (int i = 0; i < mCertificateWidgets.size(); i++) {
+        if (*(mCertificateWidgets[i]->certificate()) == cert) {
+            mCertificateWidgets[i]->certificate()->setActive(false);
+            break;
+        }
+    }
+    emit certListChanged(-1);
+}
+
 void CertificateListWidget::removeCertificate(const Certificate &cert)
 {
     for (int i = 0; i < mCertificateWidgets.size(); i++) {
-        if (mCertificateWidgets[i]->certificate() == cert) {
+        if (*(mCertificateWidgets[i]->certificate()) == cert) {
             mLayout.removeWidget(mCertificateWidgets[i]);
             mCertificateWidgets[i]->deleteLater();
             mCertificateWidgets.removeAt(i);
@@ -66,7 +99,7 @@
 {
     QStringList list;
     foreach (CertificateItemWidget * item, mCertificateWidgets) {
-        list <<  item->certificate().base64Line();
+        list <<  item->certificate()->base64Line();
     }
     return list;
 }
@@ -75,7 +108,7 @@
     QStringList list;
     foreach (CertificateItemWidget * item, mCertificateWidgets) {
         if (item->state()) {
-            list << item->certificate().base64Line();
+            list << item->certificate()->base64Line();
         }
     }
     return list;
@@ -85,7 +118,7 @@
     QStringList list;
     foreach (CertificateItemWidget * item, mCertificateWidgets) {
         if (!item->state()) {
-            list << item->certificate().base64Line();
+            list << item->certificate()->base64Line();
         }
     }
     return list;
@@ -95,7 +128,7 @@
 {
     QList<Certificate> list;
     foreach (CertificateItemWidget * item, mCertificateWidgets) {
-        list <<  item->certificate();
+        list <<  *(item->certificate());
     }
     return list;
 }
@@ -103,7 +136,7 @@
 void CertificateListWidget::setCertState(bool state, const Certificate &cert)
 {
     foreach (CertificateItemWidget * item, mCertificateWidgets) {
-        if (item->certificate() == cert &&
+        if (*(item->certificate()) == cert &&
             item->state() != state) {
             item->setState(state);
         }
@@ -131,7 +164,7 @@
 bool CertificateListWidget::contains(const Certificate &cert)
 {
     foreach (CertificateItemWidget * item, mCertificateWidgets) {
-        if (item->certificate() == cert) {
+        if (*(item->certificate()) == cert) {
             return true;
         }
     }
diff -r 77afafd23a1b -r 2b3526ef2d69 ui/certificatelistwidget.h
--- a/ui/certificatelistwidget.h	Mon Sep 15 12:50:26 2014 +0200
+++ b/ui/certificatelistwidget.h	Mon Sep 15 13:55:47 2014 +0200
@@ -35,6 +35,8 @@
                         const QString& installLabel = QString(),
                         const QString& removeLabel = QString());
     void removeCertificate(const Certificate &cert);
+    void activateCertificate(const Certificate &cert);
+    void deactivateCertificate(const Certificate &cert);
     void setCertState(bool state, const Certificate &cert);
     void clear();
     QStringList certificates();
@@ -42,6 +44,7 @@
     QStringList unselectedCertificates();
     QList<Certificate> certificateList();
     int selectedCertCount();
+    int activeCertificates();
     bool contains(const Certificate &cert);
 
 private:


More information about the Trustbridge-commits mailing list