KIO
ksslcertdialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2001-2003 George Staikos <staikos@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "ksslcertdialog.h" 00022 00023 #include <kssl.h> 00024 00025 #include <QtGui/QLayout> 00026 #include <QtGui/QRadioButton> 00027 #include <QtGui/QCheckBox> 00028 #include <QtGui/QFrame> 00029 #include <QtGui/QLabel> 00030 #include <QtGui/QListWidget> 00031 00032 #include <kapplication.h> 00033 #include <kglobal.h> 00034 #include <klocale.h> 00035 #include <kglobalsettings.h> 00036 #include <kpushbutton.h> 00037 #include <kstandardguiitem.h> 00038 #include <kseparator.h> 00039 #include <kdebug.h> 00040 00041 00042 class KSSLCertDialog::KSSLCertDialogPrivate { 00043 private: 00044 friend class KSSLCertDialog; 00045 QLabel *p_message; 00046 QPushButton *p_pb_dontsend; 00047 bool p_send_flag; 00048 }; 00049 00050 KSSLCertDialog::KSSLCertDialog(QWidget *parent, const char *name, bool modal) 00051 : KDialog(parent), d(new KSSLCertDialogPrivate) { 00052 setObjectName(name); 00053 setModal(modal); 00054 00055 QBoxLayout * grid = new QVBoxLayout( this ); 00056 00057 d->p_message = new QLabel(QString(), this); 00058 grid->addWidget(d->p_message); 00059 setHost(_host); 00060 00061 QLabel* lblCertificate = new QLabel(i18n("Certificate")); 00062 grid->addWidget(lblCertificate); 00063 00064 _certs = new QListWidget(this); 00065 QFontMetrics fm( KGlobalSettings::generalFont() ); 00066 _certs->setMinimumHeight(4*fm.height()); 00067 grid->addWidget(_certs); 00068 00069 _save = new QCheckBox(i18n("Save selection for this host."), this); 00070 grid->addWidget(_save); 00071 00072 grid->addWidget(new KSeparator(Qt::Horizontal, this)); 00073 00074 QBoxLayout * h = new QHBoxLayout(this); 00075 h->insertStretch(0); 00076 grid->addLayout(h); 00077 00078 _ok = new KPushButton(i18n("Send certificate"), this); 00079 h->addWidget(_ok); 00080 connect(_ok, SIGNAL(clicked()), SLOT(slotSend())); 00081 00082 d->p_pb_dontsend = new KPushButton(i18n("Do not send a certificate"), this); 00083 h->addWidget(d->p_pb_dontsend); 00084 connect(d->p_pb_dontsend, SIGNAL(clicked()), SLOT(slotDont())); 00085 00086 #ifndef QT_NO_WIDGET_TOPEXTRA 00087 setCaption(i18n("KDE SSL Certificate Dialog")); 00088 #endif 00089 } 00090 00091 00092 KSSLCertDialog::~KSSLCertDialog() { 00093 delete d; 00094 } 00095 00096 00097 #ifndef KDE_NO_DEPRECATED 00098 void KSSLCertDialog::setup(QStringList certs, bool saveChecked, bool sendChecked) { 00099 setupDialog(certs, saveChecked, sendChecked); 00100 } 00101 #endif 00102 00103 void KSSLCertDialog::setupDialog(const QStringList& certs, bool saveChecked, bool sendChecked) { 00104 _save->setChecked(saveChecked); 00105 d->p_send_flag = sendChecked; 00106 00107 if (sendChecked) 00108 _ok->setDefault(true); // "do send" is the "default action". 00109 else 00110 d->p_pb_dontsend->setDefault(true); // "do not send" is the "default action". 00111 00112 for (QStringList::ConstIterator i = certs.begin(); i != certs.end(); ++i) { 00113 if ((*i).isEmpty()) 00114 continue; 00115 00116 new QListWidgetItem(*i, _certs); 00117 } 00118 00119 _certs->setCurrentItem(_certs->item(0)); 00120 } 00121 00122 00123 bool KSSLCertDialog::saveChoice() { 00124 return _save->isChecked(); 00125 } 00126 00127 00128 bool KSSLCertDialog::wantsToSend() { 00129 return d->p_send_flag; 00130 } 00131 00132 00133 QString KSSLCertDialog::getChoice() { 00134 QListWidgetItem *selected = _certs->currentItem(); 00135 if (selected && d->p_send_flag) 00136 return selected->text(); 00137 else 00138 return QString(); 00139 } 00140 00141 00142 void KSSLCertDialog::setHost(const QString& host) { 00143 _host = host; 00144 d->p_message->setText(i18n("The server <b>%1</b> requests a certificate.<br /><br />" 00145 "Select a certificate to use from the list below:", 00146 _host)); 00147 } 00148 00149 00150 void KSSLCertDialog::slotSend() { 00151 d->p_send_flag = true; 00152 accept(); 00153 } 00154 00155 00156 void KSSLCertDialog::slotDont() { 00157 d->p_send_flag = false; 00158 reject(); 00159 } 00160 00161 00162 QDataStream& operator<<(QDataStream& s, const KSSLCertDialogRet& r) { 00163 s << qint8(r.ok?1:0) << r.choice << qint8(r.save?1:0) << qint8(r.send?1:0); 00164 return s; 00165 } 00166 00167 00168 QDataStream& operator>>(QDataStream& s, KSSLCertDialogRet& r) { 00169 qint8 tmp; 00170 s >> tmp; r.ok = (tmp == 1); 00171 s >> r.choice; 00172 s >> tmp; r.save = (tmp == 1); 00173 s >> tmp; r.send = (tmp == 1); 00174 return s; 00175 } 00176 00177 00178 #include "ksslcertdialog.moc" 00179
KDE 4.6 API Reference