Mercurial > trustbridge
changeset 639:c1b35edb097f trustbridge-refactor
New methods to modify and use the certificate list.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 24 Jun 2014 17:03:59 +0200 |
parents | 9d806f140bd5 |
children | 626507197360 |
files | ui/certificatelistwidget.cpp ui/certificatelistwidget.h |
diffstat | 2 files changed, 87 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/ui/certificatelistwidget.cpp Tue Jun 24 16:59:52 2014 +0200 +++ b/ui/certificatelistwidget.cpp Tue Jun 24 17:03:59 2014 +0200 @@ -72,14 +72,17 @@ this->setLayout(mainLayout); } -void CertificateListWidget::addCertificate(const Certificate &certificate) +void CertificateListWidget::addCertificate( + const Certificate &certificate, + bool state, + bool editable) { QListWidgetItem* item = new QListWidgetItem(mCertificateList); item->setData(Qt::UserRole, QVariant::fromValue(certificate)); mCertificateList->addItem(item); CertificateItemWidget *widget = - new CertificateItemWidget(mCertificateList, certificate); + new CertificateItemWidget(mCertificateList, certificate, state, editable); connect(widget, SIGNAL(stateChanged(bool, const Certificate&)), this, SLOT(certStateChanged(bool, const Certificate&))); item->setSizeHint(widget->minimumSizeHint()); @@ -91,9 +94,17 @@ } -void CertificateListWidget::removeCertificate(int ndx) +void CertificateListWidget::removeCertificate(const Certificate &cert) { - + for (int i = 0; i < mCertificateList->count(); i++) { + QListWidgetItem *item = mCertificateList->item(i); + CertificateItemWidget *itemWidget = + static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); + if (itemWidget->certificate() == cert) { + QListWidgetItem* item = mCertificateList->takeItem(i); + delete(item); + } + } } void CertificateListWidget::clear() @@ -108,19 +119,63 @@ QListWidgetItem *item = mCertificateList->item(i); CertificateItemWidget *itemWidget = static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); + list << itemWidget->certificate().base64Line(); + } + return list; +} + +QStringList CertificateListWidget::selectedCertificates() { + QStringList list; + for (int i = 0; i < mCertificateList->count(); i++) { + QListWidgetItem *item = mCertificateList->item(i); + CertificateItemWidget *itemWidget = + static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); if (itemWidget->state()) { list << itemWidget->certificate().base64Line(); - continue; - } - QString b64Line = itemWidget->certificate().base64Line(); - if (b64Line.startsWith("I:")) { - b64Line[0] = 'R'; - list << b64Line; } } return list; } +QStringList CertificateListWidget::unselectedCertificates() { + QStringList list; + for (int i = 0; i < mCertificateList->count(); i++) { + QListWidgetItem *item = mCertificateList->item(i); + CertificateItemWidget *itemWidget = + static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); + if (!itemWidget->state()) { + list << itemWidget->certificate().base64Line(); + } + } + return list; +} + +QList<Certificate> CertificateListWidget::certificateList() +{ + QList<Certificate> list; + for (int i = 0; i < mCertificateList->count(); i++) { + QListWidgetItem *item = mCertificateList->item(i); + CertificateItemWidget *itemWidget = + static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); + list << itemWidget->certificate(); + } + + return list; +} + +void CertificateListWidget::setCertState(bool state, const Certificate &cert) +{ + for (int i = 0; i < mCertificateList->count(); i++) { + QListWidgetItem *item = mCertificateList->item(i); + CertificateItemWidget *itemWidget = + static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); + if (itemWidget->certificate() == cert && + itemWidget->state() != state) { + itemWidget->setState(state); + } + } +} + void CertificateListWidget::updateDetails(QListWidgetItem *item) { if (item == NULL) { @@ -148,6 +203,7 @@ } } emit certListChanged(selected); + emit certChanged(state, cert); } int CertificateListWidget::selectedCertCount() @@ -163,3 +219,16 @@ } return selected; } + +bool CertificateListWidget::contains(const Certificate &cert) +{ + for (int i = 0; i < mCertificateList->count(); i++) { + QListWidgetItem *item = mCertificateList->item(i); + CertificateItemWidget *itemWidget = + static_cast<CertificateItemWidget*>(mCertificateList->itemWidget(item)); + if (itemWidget->certificate() == cert) { + return true; + } + } + return false; +}
--- a/ui/certificatelistwidget.h Tue Jun 24 16:59:52 2014 +0200 +++ b/ui/certificatelistwidget.h Tue Jun 24 17:03:59 2014 +0200 @@ -27,12 +27,17 @@ public: CertificateListWidget(QWidget *parent, Qt::WindowFlags flags = 0); - void addCertificate(const Certificate &certificate); + void addCertificate(const Certificate &certificate, bool state, bool editable = true); void addCertificates(const QList<Certificate> &list); - void removeCertificate(int ndx); + void removeCertificate(const Certificate &cert); + void setCertState(bool state, const Certificate &cert); void clear(); QStringList certificates(); + QStringList selectedCertificates(); + QStringList unselectedCertificates(); + QList<Certificate> certificateList(); int selectedCertCount(); + bool contains(const Certificate &cert); private: void setupGUI(); @@ -52,6 +57,7 @@ signals: void certListChanged(int selected); + void certChanged(bool state, const Certificate &cert); }; #endif // CERTIFICATELISTWIDGET_H