comparison 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
comparison
equal deleted inserted replaced
212:f7176140d20d 213:3ebebd055d3a
7 #include <QPushButton> 7 #include <QPushButton>
8 #include <QGroupBox> 8 #include <QGroupBox>
9 #include <QHBoxLayout> 9 #include <QHBoxLayout>
10 #include <QListWidget> 10 #include <QListWidget>
11 #include <QVBoxLayout> 11 #include <QVBoxLayout>
12 #include <QLabel>
12 #include "certificate.h" 13 #include "certificate.h"
13 14
14 ListUpdateDialog::ListUpdateDialog(QMainWindow *parent, 15 ListUpdateDialog::ListUpdateDialog(QMainWindow *parent,
15 const CertificateList &listToInstall) : 16 const CertificateList &listToInstall) :
16 QDialog(parent), 17 QDialog(parent),
22 23
23 void ListUpdateDialog::setupGUI() 24 void ListUpdateDialog::setupGUI()
24 { 25 {
25 /* Top level layout / widgets */ 26 /* Top level layout / widgets */
26 QVBoxLayout *topLayout = new QVBoxLayout; 27 QVBoxLayout *topLayout = new QVBoxLayout;
28 QHBoxLayout *headerLayout = new QHBoxLayout;
27 QHBoxLayout *listLayout = new QHBoxLayout; 29 QHBoxLayout *listLayout = new QHBoxLayout;
30 QHBoxLayout *bottomLayout = new QHBoxLayout;
31
32 QImage *logoImage = new QImage(":/img/logo-small.png");
33 QLabel *logo = new QLabel;
34 logo->setBackgroundRole(QPalette::Base);
35 logo->setPixmap(QPixmap::fromImage(*logoImage));
36 QLabel *title = new QLabel("<h3>" + tr("Update Certificate") + "</h3>");
37 headerLayout->addWidget(logo);
38 headerLayout->addWidget(title);
39 headerLayout->setStretch(0, 0);
40 headerLayout->setStretch(1, 10);
41
28 QPushButton *executeUpdate = new QPushButton(tr("Update Stores")); 42 QPushButton *executeUpdate = new QPushButton(tr("Update Stores"));
29 connect(executeUpdate, &QPushButton::clicked, 43 connect(executeUpdate, &QPushButton::clicked,
30 this, &ListUpdateDialog::executeUpdate); 44 this, &ListUpdateDialog::executeUpdate);
45 QPushButton *install = new QPushButton(tr("Install selected"));
46 QPushButton *later = new QPushButton(tr("Remind me later"));
47 bottomLayout->insertStretch(0, 10);
48 bottomLayout->addWidget(executeUpdate);
49 bottomLayout->addWidget(install);
50 bottomLayout->addWidget(later);
31 51
32 /* The remove groups */ 52 /* The certificate groups */
33 QVBoxLayout *removeGroupLayout = new QVBoxLayout; 53 mCertListWidget = new QListWidget;
34 mRemoveListWidget = new QListWidget; 54 connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
35 removeGroupLayout->addWidget(mRemoveListWidget); 55 this, SLOT(showDetails(QListWidgetItem*)));
36 QGroupBox *removeGroup = new QGroupBox(tr("Select certificates to be removed")); 56 mDetailWidget = new QTextEdit;
37 removeGroup->setLayout(removeGroupLayout); 57 mDetailWidget->setReadOnly(true);
58 listLayout->addWidget(mCertListWidget);
59 listLayout->addWidget(mDetailWidget);
60 QGroupBox *certGroup = new QGroupBox(tr("Select certificates"));
61 certGroup->setLayout(listLayout);
62
63 foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) {
64 if (!cert.isValid()) {
65 qWarning() << "Invalid certificate in list";
66 continue;
67 }
68 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
69 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
70 item->setData(Qt::ToolTipRole, cert.details());
71 item->setData(Qt::UserRole, cert.base64Line());
72 item->setCheckState(Qt::Checked);
73 QIcon *certIcon = new QIcon(":/img/list-add.png");
74 item->setIcon(*certIcon);
75 mCertListWidget->addItem(item);
76 }
38 77
39 foreach (const Certificate& cert, mCertificateList.getRemoveCertificates()) { 78 foreach (const Certificate& cert, mCertificateList.getRemoveCertificates()) {
40 if (!cert.isValid()) { 79 if (!cert.isValid()) {
41 qWarning() << "Invalid certificate in list"; 80 qWarning() << "Invalid certificate in list";
42 continue; 81 continue;
44 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); 83 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
45 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 84 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
46 item->setData(Qt::ToolTipRole, cert.details()); 85 item->setData(Qt::ToolTipRole, cert.details());
47 item->setData(Qt::UserRole, cert.base64Line()); 86 item->setData(Qt::UserRole, cert.base64Line());
48 item->setCheckState(Qt::Checked); 87 item->setCheckState(Qt::Checked);
49 mRemoveListWidget->addItem(item); 88 QIcon *certIcon = new QIcon(":/img/list-remove.png");
89 item->setIcon(*certIcon);
90 mCertListWidget->addItem(item);
50 } 91 }
51 92
52 /* The install group */
53 QVBoxLayout *installGroupLayout = new QVBoxLayout;
54 mInstallListWidget = new QListWidget;
55 QGroupBox *installGroup = new QGroupBox(tr("Select certificates to install"));
56 installGroupLayout->addWidget(mInstallListWidget);
57 installGroup->setLayout(installGroupLayout);
58
59 foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) {
60 if (!cert.isValid()) {
61 qWarning() << "Invalid certificate in list";
62 continue;
63 }
64 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
65 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
66 item->setData(Qt::ToolTipRole, cert.details());
67 item->setData(Qt::UserRole, cert.base64Line());
68 item->setCheckState(Qt::Checked);
69 mInstallListWidget->addItem(item);
70 }
71
72 /* Add groups to layout */
73 listLayout->addWidget(installGroup);
74 listLayout->addWidget(removeGroup);
75 93
76 /* Fill top level layout */ 94 /* Fill top level layout */
77 topLayout->addLayout(listLayout); 95 topLayout->addLayout(headerLayout);
78 topLayout->addWidget(executeUpdate); 96 topLayout->addWidget(certGroup);
97 topLayout->addLayout(bottomLayout);
79 98
80 setLayout(topLayout); 99 setLayout(topLayout);
81 100
82 return; 101 return;
83 } 102 }
105 installerProcess.write("-----BEGIN CERTIFICATE LIST-----\r\n"); 124 installerProcess.write("-----BEGIN CERTIFICATE LIST-----\r\n");
106 installerProcess.write(mCertificateList.rawData().toLatin1()); 125 installerProcess.write(mCertificateList.rawData().toLatin1());
107 installerProcess.write("-----END CERTIFICATE LIST-----\r\n"); 126 installerProcess.write("-----END CERTIFICATE LIST-----\r\n");
108 127
109 /* Items to install */ 128 /* Items to install */
110 for (int i = 0; i < mInstallListWidget->count(); i++) { 129 for (int i = 0; i < mCertListWidget->count(); i++) {
111 QListWidgetItem *item = mInstallListWidget->item(i); 130 QListWidgetItem *item = mCertListWidget->item(i);
112 if (!item->checkState() == Qt::Checked) { 131 if (!item->checkState() == Qt::Checked &&
132 item->data(Qt::UserRole).toString().startsWith("I:")) {
113 continue; 133 continue;
114 } 134 }
115 installerProcess.write(item->data(Qt::UserRole).toString().toLatin1()); 135 installerProcess.write(item->data(Qt::UserRole).toString().toLatin1());
116 installerProcess.write("\r\n"); 136 installerProcess.write("\r\n");
117 } 137 }
118 138
119 /* Items to remove */ 139 /* Items to remove */
120 for (int i = 0; i < mRemoveListWidget->count(); i++) { 140 for (int i = 0; i < mCertListWidget->count(); i++) {
121 QListWidgetItem *item = mRemoveListWidget->item(i); 141 QListWidgetItem *item = mCertListWidget->item(i);
122 if (!item->checkState() == Qt::Checked) { 142 if (!item->checkState() == Qt::Checked &&
143 item->data(Qt::UserRole).toString().startsWith("R:")) {
123 continue; 144 continue;
124 } 145 }
125 installerProcess.write(item->data(Qt::UserRole).toString().toLatin1()); 146 installerProcess.write(item->data(Qt::UserRole).toString().toLatin1());
126 installerProcess.write("\r\n"); 147 installerProcess.write("\r\n");
127 } 148 }
147 qDebug() << "Installer Process returned: " << installerProcess.exitCode(); 168 qDebug() << "Installer Process returned: " << installerProcess.exitCode();
148 qDebug() << "output: " << installerProcess.readAllStandardOutput(); 169 qDebug() << "output: " << installerProcess.readAllStandardOutput();
149 return; 170 return;
150 } 171 }
151 } 172 }
173
174 void ListUpdateDialog::showDetails(QListWidgetItem *item)
175 {
176 QString details = item->data(Qt::ToolTipRole).toString();
177 mDetailWidget->setPlainText(details);
178 }

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