diff ui/mainwindow.cpp @ 189:5f0d45ca9de4

Show certificates in the list view and details in the textfield.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 26 Mar 2014 11:44:16 +0100
parents 0c06a608e15f
children 246c21b1727f
line wrap: on
line diff
--- a/ui/mainwindow.cpp	Wed Mar 26 09:12:10 2014 +0100
+++ b/ui/mainwindow.cpp	Wed Mar 26 11:44:16 2014 +0100
@@ -10,10 +10,10 @@
 #include <QFile>
 #include <QTimer>
 #include <QHBoxLayout>
-#include <QListWidget>
 #include <QVBoxLayout>
 #include <QGroupBox>
 #include <QPushButton>
+#include <QSplitter>
 
 // The amount of time in minutes stay silent if we have
 // something to say
@@ -124,6 +124,7 @@
         mCurMessage = tr("An updated certificate list is available. Click here to install.");
         setState(NewListAvailable);
         showMessage();
+        loadCertificateList();
     }
 }
 
@@ -229,10 +230,15 @@
     QHBoxLayout *bottomLayout = new QHBoxLayout;
 
     QGroupBox *certBox = new QGroupBox(tr("Managed Certificates"));
-    QListWidget *certificates = new QListWidget;
-    QListWidget *details = new QListWidget;
-    certLayout->addWidget(certificates);
-    certLayout->addWidget(details);
+    certificateList = new QListWidget;
+    connect(certificateList, SIGNAL(itemClicked(QListWidgetItem*)),
+        this, SLOT(showDetails(QListWidgetItem*)));
+    certificateDetails = new QTextEdit;
+    certificateDetails->setReadOnly(true);
+    QSplitter *splitter = new QSplitter(certBox);
+    splitter->addWidget(certificateList);
+    splitter->addWidget(certificateDetails);
+    certLayout->addWidget(splitter);
     certBox->setLayout(certLayout);
 
     QPushButton *update = new QPushButton("Search for Updates");
@@ -248,7 +254,36 @@
     setCentralWidget(base);
 }
 
-void MainWindow::showSettings() {
+void MainWindow::loadCertificateList()
+{
+    qDebug() << "display certificates";
+    certificateList->clear();
+    foreach (const Certificate &cert, mListToInstall.getInstallCertificates()) {
+        if (!cert.isValid()) {
+            qWarning() << "Invalid certificate in list";
+            continue;
+        }
+        QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
+        item->setData(Qt::UserRole, cert.details());
+        QIcon *certIcon = new QIcon(":/img/tray_22.png");
+        item->setIcon(*certIcon);
+        certificateList->addItem(item);
+    }
+    foreach (const Certificate& cert, mListToInstall.getRemoveCertificates()) {
+        if (!cert.isValid()) {
+            qWarning() << "Invalid certificate in list";
+            continue;
+        }
+        QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
+        item->setData(Qt::UserRole, cert.details());
+        QIcon *certIcon = new QIcon(":/img/tray_22.png");
+        item->setIcon(*certIcon);
+        certificateList->addItem(item);
+    }
+}
+
+void MainWindow::showSettings()
+{
     qDebug() << "show settingsdialog";
 }
 
@@ -262,3 +297,9 @@
     qDebug() << "show aboutdialog";
 }
 
+void MainWindow::showDetails(QListWidgetItem *item)
+{
+    qDebug() << "show details";
+    QString details = item->data(Qt::UserRole).toString();
+    certificateDetails->setPlainText(details);
+}

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