changeset 628:3a9c0f38bbad trustbridge-refactor

Made certificate lists member of mainwindow and added some temporary debug msgs.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 23 Jun 2014 12:49:09 +0200
parents 566ee111e331
children 9d806f140bd5
files ui/mainwindow.cpp ui/mainwindow.h
diffstat 2 files changed, 91 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Mon Jun 23 12:46:53 2014 +0200
+++ b/ui/mainwindow.cpp	Mon Jun 23 12:49:09 2014 +0200
@@ -164,6 +164,7 @@
 }
 
 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) {
+    qDebug() << "new list available";
     mSettings.setValue("List/available", fileName);
     mSettings.setValue("List/availableDate", modDate);
 
@@ -452,17 +453,18 @@
     QVBoxLayout *updatesHeaderTextLayout = new QVBoxLayout;
     QVBoxLayout *updatesHeaderSettLayout = new QVBoxLayout;
 
-    QLabel *updatesHeader =
+    mUpdatesHeader =
         new QLabel("<h2>" + tr("Updates (%1/%2)").arg(2).arg(4)+ "</h2>");
-    QLabel *lastCertUpdate =
+    mLastCertUpdate =
         new QLabel(tr("Last certificate update: %1").arg("today"));
-    QLabel *lastSWupdate =
+    mLastSWupdate =
         new QLabel(tr("Last Software update: %1").arg("today"));
-    updatesHeaderTextLayout->addWidget(updatesHeader);
-    updatesHeaderTextLayout->addWidget(lastCertUpdate);
-    updatesHeaderTextLayout->addWidget(lastSWupdate);
+    updatesHeaderTextLayout->addWidget(mUpdatesHeader);
+    updatesHeaderTextLayout->addWidget(mLastCertUpdate);
+    updatesHeaderTextLayout->addWidget(mLastSWupdate);
 
     QPushButton *searchUpdates = new QPushButton(tr("Search for Updates"));
+    connect(searchUpdates, SIGNAL(clicked()), this, SLOT(checkUpdates()));
     updatesHeaderSettLayout->insertStretch(0, 10);
     updatesHeaderSettLayout->addWidget(searchUpdates);
     updatesHeaderLayout->addLayout(updatesHeaderTextLayout);
@@ -475,7 +477,7 @@
     QHBoxLayout *updatesManualLayout = new QHBoxLayout;
     QLabel *updatesTip =
         new QLabel(tr("The following certificate changes are recommended."));
-    QLabel *updatesNewCertificates =
+    mUpdatesNewCertificates =
         new QLabel("<h3>" +
             tr("Install new Certificates (%1/%2)").arg(2).arg(2) +
             "</h3>");
@@ -484,13 +486,15 @@
         SIGNAL(clicked()),
         this,
         SLOT(toggleUpdatesNew()));
-    updatesNewLayout->addWidget(updatesNewCertificates);
+    updatesNewLayout->addWidget(mUpdatesNewCertificates);
     updatesNewLayout->addWidget(updatesDetailsNew);
     updatesNewLayout->insertStretch(2, 10);
     mUpdatesNew = new CertificateListWidget(this);
+    connect(mUpdatesNew, SIGNAL(certListChanged(int)),
+        this, SLOT(listChanged(int)));
     mUpdatesNew->hide();
 
-    QLabel *updatesRemoveCertificates =
+    mUpdatesRemoveCertificates =
         new QLabel("<h3>" +
             tr("Remove insecure Certificates (%1/%2)").arg(2).arg(2) +
             "</h3>");
@@ -499,13 +503,13 @@
         SIGNAL(clicked()),
         this,
         SLOT(toggleUpdatesRemove()));
-    updatesRemoveLayout->addWidget(updatesRemoveCertificates);
+    updatesRemoveLayout->addWidget(mUpdatesRemoveCertificates);
     updatesRemoveLayout->addWidget(updatesDetailsRemove);
     updatesRemoveLayout->insertStretch(2, 10);
     mUpdatesRemove = new CertificateListWidget(this);
     mUpdatesRemove->hide();
 
-    QLabel *updatesManualCertificates =
+    mUpdatesManualCertificates =
         new QLabel("<h3>" +
             tr("Manualy changed Certificates (%1)").arg(2) +
             "</h3>");
@@ -514,7 +518,7 @@
         SIGNAL(clicked()),
         this,
         SLOT(toggleUpdatesManual()));
-    updatesManualLayout->addWidget(updatesManualCertificates);
+    updatesManualLayout->addWidget(mUpdatesManualCertificates);
     updatesManualLayout->addWidget(updatesDetailsManual);
     updatesManualLayout->insertStretch(2, 10);
     mUpdatesManual = new CertificateListWidget(this);
@@ -532,6 +536,7 @@
     quitButton = new QPushButton(tr("Quit without saving"));
     QPushButton *saveButton = new QPushButton(tr("Update"));
     connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp()));
+    connect(saveButton, SIGNAL(clicked()), this, SLOT(installCerts()));
     updatesBottomLayout->insertStretch(0, 10);
     updatesBottomLayout->addWidget(saveButton);
     updatesBottomLayout->addWidget(quitButton);
@@ -592,9 +597,11 @@
     QLabel *removeCenterText = new QLabel(tr("Please choose the certificates"
         " you want to remove. TrustBridge will remove these certificates."));
     removeCenterLayout->addWidget(removeCenterText);
+    mRemoveList = new CertificateListWidget(this);
 
     removePanelLayout->addLayout(removeHeaderLayout);
     removePanelLayout->addLayout(removeCenterLayout);
+    removePanelLayout->addWidget(mRemoveList);
     mRemovePanel->setLayout(removePanelLayout);
 
     // Info panel.
@@ -784,13 +791,36 @@
     setCentralWidget(base);
 }
 
+void MainWindow::listChanged(int selected)
+{
+    mUpdatesHeader->setText("<h2>" + tr("Updates (%1/%2)")
+            .arg(mUpdatesRemove->selectedCertCount() + mUpdatesNew->selectedCertCount())
+            .arg(mUpdatesRemove->certificates().size() + mUpdatesNew->certificates().size()) +
+            "</h2>");
+    mUpdatesNewCertificates->setText("<h3>" +
+            tr("Install new Certificates (%1/%2)")
+            .arg(mUpdatesNew->selectedCertCount())
+            .arg(mUpdatesNew->certificates().size()) +
+            "</h3>");
+    mUpdatesRemoveCertificates->setText("<h3>" +
+            tr("Remove insecure Certificates (%1/%2)")
+            .arg(mUpdatesRemove->selectedCertCount())
+            .arg(mUpdatesRemove->certificates().size()) +
+            "</h3>");
+}
+
 void MainWindow::loadCertificateList()
 {
     //mCertListWidget->clear();
     //int i = 0;
 
+    qDebug() << "loading list";
     /* TODO: if nothing is available (neither old nor new) add some progress
      * indication */
+    mInstallList->clear();
+    mUpdatesNew->clear();
+    mRemoveList->clear();
+    mUpdatesRemove->clear();
     QList<Certificate> newInstallCerts;
     QList<Certificate> newRemoveCerts;
     QList<Certificate> oldInstallCerts;
@@ -798,6 +828,7 @@
 
     if (mListToInstall.getCertificates().isEmpty()) {
         // No new list available, add old certificates.
+        qDebug() << "no new list...";
         foreach (const Certificate &cert, mInstalledList.getCertificates()) {
             if (cert.isInstallCert()) {
                 oldInstallCerts.append(cert);
@@ -805,13 +836,16 @@
             }
             else {
                 oldRemoveCerts.append(cert);
+                mRemoveList->addCertificate(cert);
             }
         }
+        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()));
+//        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()) {
             if (cert.isInstallCert()) {
@@ -819,10 +853,13 @@
                 if (mInstalledList.getCertificates().contains(cert)) {
                     // Was in the old list.
                     oldInstallCerts.append(cert);
+                    qDebug() << "add install";
+                    mInstallList->addCertificate(cert);
                 }
                 else {
                     // Is a brand new certificate
                     newInstallCerts.append(cert);
+                    qDebug() << "add new install";
                     mUpdatesNew->addCertificate(cert);
                 }
             }
@@ -831,18 +868,42 @@
                 if (mInstalledList.getCertificates().contains(cert)) {
                     // Was in the old list.
                     oldRemoveCerts.append(cert);
+                    qDebug() << "add remove";
+                    mRemoveList->addCertificate(cert);
                 }
                 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);
                 }
             }
         }
+        mUpdatesHeader->setText("<h2>" +
+            tr("Updates (%1/%2)")
+                .arg(newRemoveCerts.size() + newInstallCerts.size())
+                .arg(newRemoveCerts.size() + newInstallCerts.size()) + "</h2>");
+        mLastCertUpdate->setText(tr("Last certificate update: %1")
+            .arg(mInstalledList.date().toString()));
 /*        mCurrentListDate->setText(tr("Current List Date: %1")
             .arg(mInstalledList.date().toString()));
         mNewListDate->setText(tr("New List Date: %1").arg(mListToInstall.date().toString()));*/
     }
+    mUpdatesNewCertificates->setText("<h3>" +
+            tr("Install new Certificates (%1/%2)")
+            .arg(mUpdatesNew->selectedCertCount())
+            .arg(mUpdatesNew->certificates().size()) +
+            "</h3>");
+
+    mUpdatesRemoveCertificates->setText("<h3>" +
+            tr("Remove insecure Certificates (%1/%2)")
+            .arg(mUpdatesRemove->selectedCertCount())
+            .arg(mUpdatesRemove->certificates().size()) +
+            "</h3>");
+    mUpdatesManualCertificates->setText("<h3>" +
+            tr("Manualy changed Certificates (%1)").arg(0) +
+            "</h3>");
 /*
     // Add separators and certificates to list widget.
     if (!newInstallCerts.isEmpty()) {
@@ -967,13 +1028,17 @@
         mInstalledList = mListToInstall;
         mListToInstall = CertificateList();
     }
-    //loadCertificateList();
+    loadCertificateList();
 }
 
 void MainWindow::installCerts() {
     QStringList choices;
 
-    for (int i = 0; i < mCertListWidget->count(); i++) {
+    choices << mUpdatesNew->certificates();
+    choices << mUpdatesRemove->certificates();
+    choices << mUpdatesManual->certificates();
+
+/*    for (int i = 0; i < mCertListWidget->count(); i++) {
         QListWidgetItem *item = mCertListWidget->item(i);
         if (item->checkState() == Qt::Checked) {
             choices << item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line();
@@ -985,7 +1050,7 @@
             choices << certLine;
         }
     }
-
+*/
     QProgressDialog *progress = new QProgressDialog(this);
     progress->setWindowModality(Qt::WindowModal);
     progress->setLabelText(tr("Installing certificates..."));
--- a/ui/mainwindow.h	Mon Jun 23 12:46:53 2014 +0200
+++ b/ui/mainwindow.h	Mon Jun 23 12:49:09 2014 +0200
@@ -86,6 +86,7 @@
     void toggleUpdatesNew();
     void toggleUpdatesRemove();
     void toggleUpdatesManual();
+    void listChanged(int selected);
 
     /** @brief get the last modified date on the download server for
      * the current version.
@@ -230,10 +231,18 @@
     QScrollArea *mRemovePanel;
     QScrollArea *mInfoPanel;
 
+    QLabel *mUpdatesHeader;
+    QLabel *mLastCertUpdate;
+    QLabel *mLastSWupdate;
+    QLabel *mUpdatesNewCertificates;
+    QLabel *mUpdatesRemoveCertificates;
+    QLabel *mUpdatesManualCertificates;
+
     CertificateListWidget *mUpdatesNew;
     CertificateListWidget *mUpdatesRemove;
     CertificateListWidget *mUpdatesManual;
     CertificateListWidget *mInstallList;
+    CertificateListWidget *mRemoveList;
 };
 
 #endif // MAINWINDOW_H

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