KIO
ksslcertdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 grid->setMargin(KDialog::marginHint());
00057 grid->setSpacing(KDialog::spacingHint());
00058
00059 d->p_message = new QLabel(QString(), this);
00060 grid->addWidget(d->p_message);
00061 setHost(_host);
00062
00063 QLabel* lblCertificate = new QLabel(i18n("Certificate"));
00064 grid->addWidget(lblCertificate);
00065
00066 _certs = new QListWidget(this);
00067 QFontMetrics fm( KGlobalSettings::generalFont() );
00068 _certs->setMinimumHeight(4*fm.height());
00069 grid->addWidget(_certs);
00070
00071 _save = new QCheckBox(i18n("Save selection for this host."), this);
00072 grid->addWidget(_save);
00073
00074 grid->addWidget(new KSeparator(Qt::Horizontal, this));
00075
00076 QBoxLayout * h = new QHBoxLayout(this);
00077 h->insertStretch(0);
00078 grid->addLayout(h);
00079
00080 _ok = new KPushButton(i18n("Send certificate"), this);
00081 h->addWidget(_ok);
00082 connect(_ok, SIGNAL(clicked()), SLOT(slotSend()));
00083
00084 d->p_pb_dontsend = new KPushButton(i18n("Do not send a certificate"), this);
00085 h->addWidget(d->p_pb_dontsend);
00086 connect(d->p_pb_dontsend, SIGNAL(clicked()), SLOT(slotDont()));
00087
00088 #ifndef QT_NO_WIDGET_TOPEXTRA
00089 setCaption(i18n("KDE SSL Certificate Dialog"));
00090 #endif
00091 }
00092
00093
00094 KSSLCertDialog::~KSSLCertDialog() {
00095 delete d;
00096 }
00097
00098
00099 void KSSLCertDialog::setup(QStringList certs, bool saveChecked, bool sendChecked) {
00100 setupDialog(certs, saveChecked, sendChecked);
00101 }
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);
00109 else
00110 d->p_pb_dontsend->setDefault(true);
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