rrenkert@582: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik rrenkert@582: * Software engineering by Intevation GmbH rrenkert@582: * rrenkert@582: * This file is Free Software under the GNU GPL (v>=2) rrenkert@582: * and comes with ABSOLUTELY NO WARRANTY! rrenkert@582: * See LICENSE.txt for details. rrenkert@582: */ rrenkert@582: #include "certificatelistwidget.h" rrenkert@582: #include rrenkert@582: #include rrenkert@582: #include rrenkert@582: #include andre@743: #include rrenkert@582: rrenkert@582: #include "certificateitemwidget.h" rrenkert@582: rrenkert@582: CertificateListWidget::CertificateListWidget(QWidget *parent, Qt::WindowFlags flags) : rrenkert@582: QWidget(parent, flags) rrenkert@582: { emanuel@842: QVBoxLayout *outerLayout = new QVBoxLayout(this); emanuel@842: outerLayout->addLayout(&mLayout); emanuel@842: outerLayout->addStretch(); rrenkert@582: } rrenkert@582: rrenkert@639: void CertificateListWidget::addCertificate( rrenkert@639: const Certificate &certificate, rrenkert@639: bool state, andre@1106: QToolButton *button) rrenkert@582: { rrenkert@582: CertificateItemWidget *widget = andre@1106: new CertificateItemWidget(this, certificate, state, button); rrenkert@627: connect(widget, SIGNAL(stateChanged(bool, const Certificate&)), rrenkert@627: this, SLOT(certStateChanged(bool, const Certificate&))); andre@743: andre@743: mCertificateWidgets << widget; andre@743: mLayout.addWidget(widget); andre@695: emit certListChanged(-1); rrenkert@582: } rrenkert@582: andre@1101: int CertificateListWidget::activeCertificates() andre@1101: { andre@1101: int ret = 0; andre@1101: for (int i = 0; i < mCertificateWidgets.size(); i++) { andre@1101: if (mCertificateWidgets[i]->certificate()->isActive()) { andre@1101: ret++; andre@1101: } andre@1101: } andre@1101: return ret; andre@1101: } andre@1101: andre@1101: void CertificateListWidget::activateCertificate(const Certificate &cert) andre@1101: { andre@1101: for (int i = 0; i < mCertificateWidgets.size(); i++) { andre@1101: if (*(mCertificateWidgets[i]->certificate()) == cert) { andre@1101: mCertificateWidgets[i]->certificate()->setActive(true); andre@1101: break; andre@1101: } andre@1101: } andre@1101: emit certListChanged(-1); andre@1101: } andre@1101: andre@1101: void CertificateListWidget::deactivateCertificate(const Certificate &cert) andre@1101: { andre@1101: for (int i = 0; i < mCertificateWidgets.size(); i++) { andre@1101: if (*(mCertificateWidgets[i]->certificate()) == cert) { andre@1101: mCertificateWidgets[i]->certificate()->setActive(false); andre@1101: break; andre@1101: } andre@1101: } andre@1101: emit certListChanged(-1); andre@1101: } andre@1101: rrenkert@639: void CertificateListWidget::removeCertificate(const Certificate &cert) rrenkert@582: { andre@743: for (int i = 0; i < mCertificateWidgets.size(); i++) { andre@1101: if (*(mCertificateWidgets[i]->certificate()) == cert) { andre@743: mLayout.removeWidget(mCertificateWidgets[i]); andre@757: mCertificateWidgets[i]->deleteLater(); andre@743: mCertificateWidgets.removeAt(i); andre@743: break; rrenkert@639: } rrenkert@639: } andre@695: emit certListChanged(-1); rrenkert@582: } rrenkert@582: rrenkert@627: void CertificateListWidget::clear() rrenkert@582: { andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@743: mLayout.removeWidget(item); andre@743: delete item; andre@743: } andre@743: mCertificateWidgets.clear(); rrenkert@627: } rrenkert@627: rrenkert@627: QStringList CertificateListWidget::certificates() rrenkert@627: { rrenkert@627: QStringList list; andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@1101: list << item->certificate()->base64Line(); rrenkert@639: } rrenkert@639: return list; rrenkert@639: } rrenkert@639: rrenkert@639: QStringList CertificateListWidget::selectedCertificates() { rrenkert@639: QStringList list; andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@743: if (item->state()) { andre@1101: list << item->certificate()->base64Line(); rrenkert@627: } rrenkert@627: } rrenkert@627: return list; rrenkert@582: } rrenkert@582: rrenkert@639: QStringList CertificateListWidget::unselectedCertificates() { rrenkert@639: QStringList list; andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@743: if (!item->state()) { andre@1101: list << item->certificate()->base64Line(); rrenkert@639: } rrenkert@639: } rrenkert@639: return list; rrenkert@639: } rrenkert@639: rrenkert@639: QList CertificateListWidget::certificateList() rrenkert@639: { rrenkert@639: QList list; andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@1101: list << *(item->certificate()); rrenkert@639: } rrenkert@639: return list; rrenkert@639: } rrenkert@639: rrenkert@639: void CertificateListWidget::setCertState(bool state, const Certificate &cert) rrenkert@639: { andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@1101: if (*(item->certificate()) == cert && andre@743: item->state() != state) { andre@743: item->setState(state); rrenkert@639: } rrenkert@639: } rrenkert@639: } rrenkert@639: rrenkert@627: rrenkert@627: void CertificateListWidget::certStateChanged(bool state, const Certificate &cert) rrenkert@627: { andre@743: emit certListChanged(-1); rrenkert@639: emit certChanged(state, cert); rrenkert@627: } rrenkert@627: rrenkert@627: int CertificateListWidget::selectedCertCount() rrenkert@627: { rrenkert@627: int selected = 0; andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@743: if (item->state()) { rrenkert@627: selected++; rrenkert@627: } rrenkert@627: } rrenkert@627: return selected; rrenkert@627: } rrenkert@639: rrenkert@639: bool CertificateListWidget::contains(const Certificate &cert) rrenkert@639: { andre@743: foreach (CertificateItemWidget * item, mCertificateWidgets) { andre@1101: if (*(item->certificate()) == cert) { rrenkert@639: return true; rrenkert@639: } rrenkert@639: } rrenkert@639: return false; rrenkert@639: }