changeset 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 a3bde2aaabd9
children 1a66a15d0df8
files ui/mainwindow.cpp ui/mainwindow.h
diffstat 2 files changed, 54 insertions(+), 6 deletions(-) [+]
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);
+}
--- a/ui/mainwindow.h	Wed Mar 26 09:12:10 2014 +0100
+++ b/ui/mainwindow.h	Wed Mar 26 11:44:16 2014 +0100
@@ -10,6 +10,8 @@
 #include <QMainWindow>
 #include <QSettings>
 #include <QMenuBar>
+#include <QListWidget>
+#include <QTextEdit>
 
 #include "downloader.h"
 #include "certificatelist.h"
@@ -49,6 +51,7 @@
     void showSettings();
     void showHelp();
     void showAbout();
+    void showDetails(QListWidgetItem*);
 
 private:
     /** @brief check the integrity of available files.
@@ -64,6 +67,7 @@
     void createActions();
     void createMenuBar();
     void createContent();
+    void loadCertificateList();
 
     QString mCurMessage;
     QString mInstalledSWVersion;
@@ -80,6 +84,9 @@
     QMenuBar *mMenuBar;
 
     CertificateList mListToInstall;
+
+    QListWidget *certificateList;
+    QTextEdit *certificateDetails;
 };
 
 #endif // MAINWINDOW_H

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