diff ui/listupdatedialog.cpp @ 213:3ebebd055d3a

Refactored the list update dialog. Now it looks a bit more like the mainwindow.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 27 Mar 2014 09:08:44 +0100
parents 252ffe6e27fd
children aab742690bee
line wrap: on
line diff
--- a/ui/listupdatedialog.cpp	Thu Mar 27 09:07:24 2014 +0100
+++ b/ui/listupdatedialog.cpp	Thu Mar 27 09:08:44 2014 +0100
@@ -9,6 +9,7 @@
 #include <QHBoxLayout>
 #include <QListWidget>
 #include <QVBoxLayout>
+#include <QLabel>
 #include "certificate.h"
 
 ListUpdateDialog::ListUpdateDialog(QMainWindow *parent,
@@ -24,17 +25,55 @@
 {
     /* Top level layout / widgets */
     QVBoxLayout *topLayout = new QVBoxLayout;
+    QHBoxLayout *headerLayout = new QHBoxLayout;
     QHBoxLayout *listLayout = new QHBoxLayout;
+    QHBoxLayout *bottomLayout = new QHBoxLayout;
+
+    QImage *logoImage = new QImage(":/img/logo-small.png");
+    QLabel *logo = new QLabel;
+    logo->setBackgroundRole(QPalette::Base);
+    logo->setPixmap(QPixmap::fromImage(*logoImage));
+    QLabel *title = new QLabel("<h3>" + tr("Update Certificate") + "</h3>");
+    headerLayout->addWidget(logo);
+    headerLayout->addWidget(title);
+    headerLayout->setStretch(0, 0);
+    headerLayout->setStretch(1, 10);
+
     QPushButton *executeUpdate = new QPushButton(tr("Update Stores"));
     connect(executeUpdate, &QPushButton::clicked,
             this, &ListUpdateDialog::executeUpdate);
+    QPushButton *install = new QPushButton(tr("Install selected"));
+    QPushButton *later = new QPushButton(tr("Remind me later"));
+    bottomLayout->insertStretch(0, 10);
+    bottomLayout->addWidget(executeUpdate);
+    bottomLayout->addWidget(install);
+    bottomLayout->addWidget(later);
 
-    /* The remove groups */
-    QVBoxLayout *removeGroupLayout = new QVBoxLayout;
-    mRemoveListWidget = new QListWidget;
-    removeGroupLayout->addWidget(mRemoveListWidget);
-    QGroupBox *removeGroup = new QGroupBox(tr("Select certificates to be removed"));
-    removeGroup->setLayout(removeGroupLayout);
+    /* The certificate groups */
+    mCertListWidget = new QListWidget;
+    connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
+        this, SLOT(showDetails(QListWidgetItem*)));
+    mDetailWidget = new QTextEdit;
+    mDetailWidget->setReadOnly(true);
+    listLayout->addWidget(mCertListWidget);
+    listLayout->addWidget(mDetailWidget);
+    QGroupBox *certGroup = new QGroupBox(tr("Select certificates"));
+    certGroup->setLayout(listLayout);
+
+    foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) {
+        if (!cert.isValid()) {
+            qWarning() << "Invalid certificate in list";
+            continue;
+        }
+        QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
+        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
+        item->setData(Qt::ToolTipRole, cert.details());
+        item->setData(Qt::UserRole, cert.base64Line());
+        item->setCheckState(Qt::Checked);
+        QIcon *certIcon = new QIcon(":/img/list-add.png");
+        item->setIcon(*certIcon);
+        mCertListWidget->addItem(item);
+    }
 
     foreach (const Certificate& cert, mCertificateList.getRemoveCertificates()) {
         if (!cert.isValid()) {
@@ -46,36 +85,16 @@
         item->setData(Qt::ToolTipRole, cert.details());
         item->setData(Qt::UserRole, cert.base64Line());
         item->setCheckState(Qt::Checked);
-        mRemoveListWidget->addItem(item);
+        QIcon *certIcon = new QIcon(":/img/list-remove.png");
+        item->setIcon(*certIcon);
+        mCertListWidget->addItem(item);
     }
 
-    /* The install group */
-    QVBoxLayout *installGroupLayout = new QVBoxLayout;
-    mInstallListWidget = new QListWidget;
-    QGroupBox *installGroup = new QGroupBox(tr("Select certificates to install"));
-    installGroupLayout->addWidget(mInstallListWidget);
-    installGroup->setLayout(installGroupLayout);
-
-    foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) {
-        if (!cert.isValid()) {
-            qWarning() << "Invalid certificate in list";
-            continue;
-        }
-        QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
-        item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
-        item->setData(Qt::ToolTipRole, cert.details());
-        item->setData(Qt::UserRole, cert.base64Line());
-        item->setCheckState(Qt::Checked);
-        mInstallListWidget->addItem(item);
-    }
-
-    /* Add groups to layout */
-    listLayout->addWidget(installGroup);
-    listLayout->addWidget(removeGroup);
 
     /* Fill top level layout */
-    topLayout->addLayout(listLayout);
-    topLayout->addWidget(executeUpdate);
+    topLayout->addLayout(headerLayout);
+    topLayout->addWidget(certGroup);
+    topLayout->addLayout(bottomLayout);
 
     setLayout(topLayout);
 
@@ -107,9 +126,10 @@
     installerProcess.write("-----END CERTIFICATE LIST-----\r\n");
 
     /* Items to install */
-    for (int i = 0; i < mInstallListWidget->count(); i++) {
-        QListWidgetItem *item = mInstallListWidget->item(i);
-        if (!item->checkState() == Qt::Checked) {
+    for (int i = 0; i < mCertListWidget->count(); i++) {
+        QListWidgetItem *item = mCertListWidget->item(i);
+        if (!item->checkState() == Qt::Checked &&
+            item->data(Qt::UserRole).toString().startsWith("I:")) {
             continue;
         }
         installerProcess.write(item->data(Qt::UserRole).toString().toLatin1());
@@ -117,9 +137,10 @@
     }
 
     /* Items to remove */
-    for (int i = 0; i < mRemoveListWidget->count(); i++) {
-        QListWidgetItem *item = mRemoveListWidget->item(i);
-        if (!item->checkState() == Qt::Checked) {
+    for (int i = 0; i < mCertListWidget->count(); i++) {
+        QListWidgetItem *item = mCertListWidget->item(i);
+        if (!item->checkState() == Qt::Checked &&
+            item->data(Qt::UserRole).toString().startsWith("R:")) {
             continue;
         }
         installerProcess.write(item->data(Qt::UserRole).toString().toLatin1());
@@ -149,3 +170,9 @@
         return;
     }
 }
+
+void ListUpdateDialog::showDetails(QListWidgetItem *item)
+{
+    QString details = item->data(Qt::ToolTipRole).toString();
+    mDetailWidget->setPlainText(details);
+}

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