[PATCH 3 of 3] Updated mainwindow and handle certificate lists

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


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1403622469 -7200
# Branch trustbridge-refactor
# Node ID 626507197360418fe2ba0e76e96ab2d0cd25bec9
# Parent  c1b35edb097f60b2615544c1146d5335adb7776f
Updated mainwindow and handle certificate lists.

diff -r c1b35edb097f -r 626507197360 ui/mainwindow.cpp
--- a/ui/mainwindow.cpp	Tue Jun 24 17:03:59 2014 +0200
+++ b/ui/mainwindow.cpp	Tue Jun 24 17:07:49 2014 +0200
@@ -59,6 +59,9 @@
 MainWindow::MainWindow(bool trayMode):
     mTrayMode(trayMode)
 {
+    mUpdatesNewSize = 0;
+    mUpdatesRemoveSize = 0;
+    mUpdatesManualSize = 0;
     createActions();
     createTrayIcon();
     createContent();
@@ -523,14 +526,8 @@
     updatesManualLayout->insertStretch(2, 10);
     mUpdatesManual = new CertificateListWidget(this);
     mUpdatesManual->hide();
-
-    updatesCenterLayout->addWidget(updatesTip);
-    updatesCenterLayout->addLayout(updatesNewLayout);
-    updatesCenterLayout->addWidget(mUpdatesNew);
-    updatesCenterLayout->addLayout(updatesRemoveLayout);
-    updatesCenterLayout->addWidget(mUpdatesRemove);
-    updatesCenterLayout->addLayout(updatesManualLayout);
-    updatesCenterLayout->addWidget(mUpdatesManual);
+    connect(mUpdatesManual, SIGNAL(certChanged(bool, const Certificate&)),
+        this, SLOT(removeFromManual(bool, const Certificate&)));
 
     QHBoxLayout *updatesBottomLayout = new QHBoxLayout;
     quitButton = new QPushButton(tr("Quit without saving"));
@@ -540,6 +537,24 @@
     updatesBottomLayout->insertStretch(0, 10);
     updatesBottomLayout->addWidget(saveButton);
     updatesBottomLayout->addWidget(quitButton);
+    updatesBottomLayout->setAlignment(Qt::AlignBottom);
+
+    updatesNewLayout->setAlignment(Qt::AlignTop);
+    updatesRemoveLayout->setAlignment(Qt::AlignTop);
+    updatesManualLayout->setAlignment(Qt::AlignTop);
+    updatesCenterLayout->addWidget(updatesTip, 0, Qt::AlignTop);
+    updatesCenterLayout->addLayout(updatesNewLayout);
+//    updatesCenterLayout->setStretchFactor(updatesNewLayout, 100);
+    updatesCenterLayout->addWidget(mUpdatesNew, 1, Qt::AlignTop);
+    updatesCenterLayout->addLayout(updatesRemoveLayout);
+//    updatesCenterLayout->setStretchFactor(updatesRemoveLayout, 100);
+    updatesCenterLayout->addWidget(mUpdatesRemove, 1, Qt::AlignTop);
+    updatesCenterLayout->addLayout(updatesManualLayout);
+//    updatesCenterLayout->setStretchFactor(updatesManualLayout, 100);
+    updatesCenterLayout->addWidget(mUpdatesManual, 1, Qt::AlignTop);
+    updatesCenterLayout->insertStretch(7, 0);
+    updatesCenterLayout->addLayout(updatesBottomLayout);
+
 
     QFrame *updatesPanelSeparator = new QFrame();
     updatesPanelSeparator->setFrameShape(QFrame::HLine);
@@ -547,8 +562,9 @@
     updatesPanelLayout->addLayout(updatesHeaderLayout);
     updatesPanelLayout->addWidget(updatesPanelSeparator);
     updatesPanelLayout->addLayout(updatesCenterLayout);
-    updatesPanelLayout->insertStretch(3, 10);
-    updatesPanelLayout->addLayout(updatesBottomLayout);
+    updatesPanelLayout->setStretchFactor(updatesCenterLayout, 1);
+    //updatesPanelLayout->insertStretch(3, 2);
+    //updatesPanelLayout->addLayout(updatesBottomLayout);
     mUpdatesWidget->setLayout(updatesPanelLayout);
     mUpdatesWidget->setMinimumSize(QSize(820, 440));
     mUpdatesPanel->setWidget(mUpdatesWidget);
@@ -574,6 +590,8 @@
         " Thunderbird)"));
     installCenterLayout->addWidget(installCenterText);
     mInstallList = new CertificateListWidget(this);
+    connect(mInstallList, SIGNAL(certChanged(bool, const Certificate&)),
+        this, SLOT(toggleInManual(bool, const Certificate&)));
 
     installPanelLayout->addLayout(installHeaderLayout);
     installPanelLayout->addLayout(installCenterLayout);
@@ -598,6 +616,8 @@
         " you want to remove. TrustBridge will remove these certificates."));
     removeCenterLayout->addWidget(removeCenterText);
     mRemoveList = new CertificateListWidget(this);
+    connect(mRemoveList, SIGNAL(certChanged(bool, const Certificate&)),
+        this, SLOT(toggleInManual(bool, const Certificate&)));
 
     removePanelLayout->addLayout(removeHeaderLayout);
     removePanelLayout->addLayout(removeCenterLayout);
@@ -814,7 +834,6 @@
     //mCertListWidget->clear();
     //int i = 0;
 
-    qDebug() << "loading list";
     /* TODO: if nothing is available (neither old nor new) add some progress
      * indication */
     mInstallList->clear();
@@ -828,39 +847,36 @@
 
     if (mListToInstall.getCertificates().isEmpty()) {
         // No new list available, add old certificates.
-        qDebug() << "no new list...";
         foreach (const Certificate &cert, mInstalledList.getCertificates()) {
+            bool state = !mPreviouslyUnselected.contains(cert.base64Line());
             if (cert.isInstallCert()) {
                 oldInstallCerts.append(cert);
-                mInstallList->addCertificate(cert);
+                mInstallList->addCertificate(cert, state);
             }
             else {
                 oldRemoveCerts.append(cert);
-                mRemoveList->addCertificate(cert);
+                mRemoveList->addCertificate(cert, state, !state);
             }
         }
-        qDebug() << "old list date: " << mInstalledList.date().toString();
         // Set the date of the old list.
 //        mCurrentListDate->setText(tr("Current List Date: %1")
 //            .arg(mInstalledList.date().toString()));
     }
     else {
-        qDebug() << "new list available";
         // Sort and filter both lists.
         foreach (const Certificate &cert, mListToInstall.getCertificates()) {
+            bool state = !mPreviouslyUnselected.contains(cert.base64Line());
             if (cert.isInstallCert()) {
                 // Certificate with status "install".
                 if (mInstalledList.getCertificates().contains(cert)) {
                     // Was in the old list.
                     oldInstallCerts.append(cert);
-                    qDebug() << "add install";
-                    mInstallList->addCertificate(cert);
+                    mInstallList->addCertificate(cert, state);
                 }
                 else {
                     // Is a brand new certificate
                     newInstallCerts.append(cert);
-                    qDebug() << "add new install";
-                    mUpdatesNew->addCertificate(cert);
+                    mUpdatesNew->addCertificate(cert, state);
                 }
             }
             else {
@@ -868,21 +884,20 @@
                 if (mInstalledList.getCertificates().contains(cert)) {
                     // Was in the old list.
                     oldRemoveCerts.append(cert);
-                    qDebug() << "add remove";
-                    mRemoveList->addCertificate(cert);
+                    // Is removed, so set editable to false.
+                    mRemoveList->addCertificate(cert, state, !state);
                 }
                 else {
                     // Was in the old list with status "install" and now has the
                     // status "remove".
                     newRemoveCerts.append(cert);
-                    qDebug() << "add new remove";
-                    mUpdatesRemove->addCertificate(cert);
+                    mUpdatesRemove->addCertificate(cert, state);
                 }
             }
         }
         mUpdatesHeader->setText("<h2>" +
             tr("Updates (%1/%2)")
-                .arg(newRemoveCerts.size() + newInstallCerts.size())
+                .arg(mUpdatesNew->selectedCertCount() + mUpdatesRemove->selectedCertCount())
                 .arg(newRemoveCerts.size() + newInstallCerts.size()) + "</h2>");
         mLastCertUpdate->setText(tr("Last certificate update: %1")
             .arg(mInstalledList.date().toString()));
@@ -1033,10 +1048,25 @@
 
 void MainWindow::installCerts() {
     QStringList choices;
+    QStringList unselected;
 
-    choices << mUpdatesNew->certificates();
-    choices << mUpdatesRemove->certificates();
-    choices << mUpdatesManual->certificates();
+    choices << mUpdatesNew->selectedCertificates();
+    choices << mUpdatesRemove->selectedCertificates();
+
+    choices <<  mUpdatesManual->selectedCertificates();
+    QStringList unselectedManuals = mUpdatesManual->unselectedCertificates();
+    for(int i = 0; i < unselectedManuals.size(); i++) {
+        if (unselectedManuals.at(i).startsWith("I:")) {
+            QString certLine = unselectedManuals.at(i);
+            certLine[0] = 'R';
+            choices << certLine;
+        }
+    }
+
+    unselected << mUpdatesNew->unselectedCertificates();
+    unselected << mUpdatesRemove->unselectedCertificates();
+    unselected << mInstallList->unselectedCertificates();
+    unselected << mRemoveList->unselectedCertificates();
 
 /*    for (int i = 0; i < mCertListWidget->count(); i++) {
         QListWidgetItem *item = mCertListWidget->item(i);
@@ -1073,11 +1103,11 @@
     connect(instWrap, SIGNAL(error(const QString &)),
             this, SLOT(installerError(const QString &)));
     instWrap->start();
-/*
-    if (!saveUnselectedCertificates()) {
+
+    if (!saveUnselectedCertificates(unselected)) {
         qWarning() << "Failed to save previosly unselected certificates.";
     }
-*/
+
 }
 
 void MainWindow::loadUnselectedCertificates()
@@ -1091,21 +1121,16 @@
     mSettings.endGroup();
 }
 
-bool MainWindow::saveUnselectedCertificates()
+bool MainWindow::saveUnselectedCertificates(QStringList unselected)
 {
     mPreviouslyUnselected.clear();
     mSettings.beginGroup("unselected");
     mSettings.remove(""); /* Clears old choices */
-    for (int i = 0; i < mCertListWidget->count(); i++) {
-        QListWidgetItem *item = mCertListWidget->item(i);
-        if (item->checkState() != Qt::Checked &&
-            (item->flags() & Qt::ItemIsUserCheckable)) {
-            QString key = QString::fromLatin1("cert%1").arg(i);
-            QString value =
-                item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line();
-            mSettings.setValue(key, value);
-            mPreviouslyUnselected << value;
-        }
+    for (int i = 0; i < unselected.size(); i++) {
+        QString key = QString::fromLatin1("cert%1").arg(i);
+        QString value = unselected.at(i);
+        mSettings.setValue(key, value);
+        mPreviouslyUnselected << value;
     }
     mSettings.endGroup();
     mSettings.sync();
@@ -1126,9 +1151,40 @@
     mSettings.endGroup();
 }
 
+void MainWindow::toggleInManual(bool state, const Certificate &cert)
+{
+    if (!mUpdatesManual->contains(cert)) {
+        mUpdatesManual->addCertificate(cert, state);
+    }
+    else {
+        mUpdatesManual->removeCertificate(cert);
+    }
+
+    mUpdatesManualCertificates->setText("<h3>" +
+            tr("Manualy changed Certificates (%1)")
+                .arg(mUpdatesManual->certificates().size()) +
+            "</h3>");
+}
+
+void MainWindow::removeFromManual(bool state, const Certificate &cert)
+{
+    mUpdatesManual->removeCertificate(cert);
+
+    mUpdatesManualCertificates->setText("<h3>" +
+            tr("Manualy changed Certificates (%1)")
+                .arg(mUpdatesManual->certificates().size()) +
+            "</h3>");
+
+    if (cert.isInstallCert()) {
+        mInstallList->setCertState(state, cert);
+    }
+    else {
+        mRemoveList->setCertState(state, cert);
+    }
+}
+
 void MainWindow::closeApp()
 {
-    //saveUnselectedCertificates();
     qApp->quit();
 }
 
@@ -1151,8 +1207,11 @@
 void MainWindow::toggleUpdatesNew() {
     QSize old = mUpdatesWidget->size();
     if (!mUpdatesNew->isVisible()) {
-        mUpdatesWidget->resize(old.width(), old.height() + mUpdatesNew->height());
         mUpdatesNew->show();
+        if (mUpdatesNewSize == 0) {
+            mUpdatesNewSize = mUpdatesNew->height();
+        }
+        mUpdatesWidget->resize(old.width(), old.height() + mUpdatesNewSize);
     }
     else {
         mUpdatesWidget->resize(old.width(), old.height() - mUpdatesNew->height());
@@ -1163,8 +1222,11 @@
 void MainWindow::toggleUpdatesRemove() {
     QSize old = mUpdatesWidget->size();
     if (!mUpdatesRemove->isVisible()) {
-        mUpdatesWidget->resize(old.width(), old.height() + mUpdatesRemove->height());
         mUpdatesRemove->show();
+        if (mUpdatesRemoveSize == 0) {
+            mUpdatesRemoveSize = mUpdatesRemove->height();
+        }
+        mUpdatesWidget->resize(old.width(), old.height() + mUpdatesRemoveSize);
     }
     else {
         mUpdatesWidget->resize(old.width(), old.height() - mUpdatesRemove->height());
@@ -1175,11 +1237,14 @@
 void MainWindow::toggleUpdatesManual() {
     QSize old = mUpdatesWidget->size();
     if (!mUpdatesManual->isVisible()) {
-        mUpdatesWidget->resize(old.width(), old.height() + mUpdatesManual->height());
         mUpdatesManual->show();
+        if (mUpdatesManualSize == 0) {
+            mUpdatesManualSize = mUpdatesManual->height();
+        }
+        mUpdatesWidget->resize(old.width(), old.height() + mUpdatesManualSize);
     }
     else {
+        mUpdatesWidget->resize(old.width(), old.height() - mUpdatesManual->height());
         mUpdatesManual->hide();
-        mUpdatesWidget->resize(old.width(), old.height() - mUpdatesManual->height());
     }
 }
diff -r c1b35edb097f -r 626507197360 ui/mainwindow.h
--- a/ui/mainwindow.h	Tue Jun 24 17:03:59 2014 +0200
+++ b/ui/mainwindow.h	Tue Jun 24 17:07:49 2014 +0200
@@ -78,6 +78,8 @@
     void installerError(const QString& errMsg);
     void installerSuccess();
     void installCerts();
+    void toggleInManual(bool state, const Certificate &cert);
+    void removeFromManual(bool state, const Certificate &cert);
 
     void saveAutoUpdate(int state);
     void saveAutoStart(int state);
@@ -117,7 +119,7 @@
      *
      * Returns false on error.
      */
-    bool saveUnselectedCertificates();
+    bool saveUnselectedCertificates(QStringList unselected);
 
     /** @brief loads previously unselected certificates from settings
      *
@@ -243,6 +245,9 @@
     CertificateListWidget *mUpdatesManual;
     CertificateListWidget *mInstallList;
     CertificateListWidget *mRemoveList;
+    int mUpdatesNewSize;
+    int mUpdatesRemoveSize;
+    int mUpdatesManualSize;
 };
 
 #endif // MAINWINDOW_H


More information about the Trustbridge-commits mailing list