# HG changeset patch # User Raimund Renkert # Date 1395907724 -3600 # Node ID 3ebebd055d3aa4d1421a45a8faf812e4fa50d675 # Parent f7176140d20d7195993cd7d7a404af7125c9df55 Refactored the list update dialog. Now it looks a bit more like the mainwindow. diff -r f7176140d20d -r 3ebebd055d3a ui/listupdatedialog.cpp --- 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 #include #include +#include #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("

" + tr("Update Certificate") + "

"); + 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); +} diff -r f7176140d20d -r 3ebebd055d3a ui/listupdatedialog.h --- a/ui/listupdatedialog.h Thu Mar 27 09:07:24 2014 +0100 +++ b/ui/listupdatedialog.h Thu Mar 27 09:08:44 2014 +0100 @@ -4,6 +4,8 @@ #include "certificatelist.h" #include #include +#include +#include /** * @file listupdatedialog.h * @brief The dialog for certificate selection. @@ -13,6 +15,7 @@ class ListUpdateDialog : public QDialog { + Q_OBJECT public: /** @brief Create a list update dialog for the listToInstall */ ListUpdateDialog(QMainWindow *parent, const CertificateList &listToInstall); @@ -21,11 +24,12 @@ CertificateList mCertificateList; void setupGUI(); - QListWidget *mInstallListWidget; - QListWidget *mRemoveListWidget; + QListWidget *mCertListWidget; + QTextEdit *mDetailWidget; private slots: void executeUpdate(); + void showDetails(QListWidgetItem*); }; #endif // LISTUPDATEDIALOG_H