File indexing completed on 2024-04-28 15:21:51
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 Andreas Hartmetz <ahartmetz@gmail.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA. 0018 */ 0019 0020 #include "displaycertdialog_p.h" 0021 #include <QDateTime> 0022 #include <QDialogButtonBox> 0023 #include <QPushButton> 0024 #include <kstandardguiitem.h> 0025 #include <klocalizedstring.h> 0026 0027 DisplayCertDialog::DisplayCertDialog(QWidget *parent) 0028 : QDialog(parent), 0029 m_index(0) 0030 { 0031 QVBoxLayout *layout = new QVBoxLayout; 0032 setLayout(layout); 0033 0034 QWidget *mainWidget = new QWidget(this); 0035 m_ui.setupUi(mainWidget); 0036 layout->addWidget(mainWidget); 0037 0038 QPair<KGuiItem, KGuiItem> bAndF = KStandardGuiItem::backAndForward(); 0039 0040 m_previousButton = new QPushButton; 0041 KGuiItem::assign(m_previousButton, bAndF.first); 0042 connect(m_previousButton, SIGNAL(clicked()), SLOT(previousClicked())); 0043 0044 m_nextButton = new QPushButton; 0045 KGuiItem::assign(m_nextButton, bAndF.second); 0046 connect(m_nextButton, SIGNAL(clicked()), SLOT(nextClicked())); 0047 0048 QDialogButtonBox *buttonBox = new QDialogButtonBox(this); 0049 layout->addWidget(buttonBox); 0050 buttonBox->addButton(m_previousButton, QDialogButtonBox::ActionRole); 0051 buttonBox->addButton(m_nextButton, QDialogButtonBox::ActionRole); 0052 buttonBox->addButton(QDialogButtonBox::Ok); 0053 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 0054 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 0055 } 0056 0057 void DisplayCertDialog::setCertificates(const QList<QSslCertificate> &certs) 0058 { 0059 Q_ASSERT(!certs.isEmpty()); 0060 m_certs = certs; 0061 m_index = 0; 0062 showCertificate(0); 0063 m_previousButton->setEnabled(certs.size() > 1); 0064 m_nextButton->setEnabled(certs.size() > 1); 0065 } 0066 0067 void DisplayCertDialog::showCertificate(int index) 0068 { 0069 const QSslCertificate &cert = m_certs.at(index); 0070 m_ui.subjectCertBox->setCertificate(cert, KSslCertificateBox::Subject); 0071 m_ui.issuerCertBox->setCertificate(cert, KSslCertificateBox::Issuer); 0072 0073 QString vp = i18nc("%1 is the effective date of the certificate, %2 is the expiry date", "%1 to %2", 0074 cert.effectiveDate().toString(), 0075 cert.expiryDate().toString()); 0076 m_ui.validityPeriod->setText(vp); 0077 0078 m_ui.serialNumber->setText(cert.serialNumber()); 0079 m_ui.md5Digest->setText(cert.digest().toHex()); 0080 m_ui.sha1Digest->setText(cert.digest(QCryptographicHash::Sha1).toHex()); 0081 } 0082 0083 //private slot 0084 void DisplayCertDialog::nextClicked() 0085 { 0086 if (m_index == m_certs.size() - 1) { 0087 m_index = 0; 0088 } else { 0089 m_index++; 0090 } 0091 showCertificate(m_index); 0092 } 0093 0094 //private slot 0095 void DisplayCertDialog::previousClicked() 0096 { 0097 if (m_index == 0) { 0098 m_index = m_certs.size() - 1; 0099 } else { 0100 m_index--; 0101 } 0102 showCertificate(m_index); 0103 } 0104 0105 #include "moc_displaycertdialog_p.cpp"