00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ksslcertdlg.h"
00022
00023 #include <kssl.h>
00024
00025 #include <tqlayout.h>
00026 #include <tqradiobutton.h>
00027 #include <tqcheckbox.h>
00028 #include <tqlistview.h>
00029 #include <tqframe.h>
00030 #include <tqlabel.h>
00031
00032 #include <tdeapplication.h>
00033 #include <tdeglobal.h>
00034 #include <tdelocale.h>
00035 #include <tdeglobalsettings.h>
00036 #include <kpushbutton.h>
00037 #include <kstdguiitem.h>
00038 #include <kseparator.h>
00039 #include <kdebug.h>
00040
00041
00042 class KSSLCertDlg::KSSLCertDlgPrivate {
00043 private:
00044 friend class KSSLCertDlg;
00045 TQLabel *p_message;
00046 TQPushButton *p_pb_dontsend;
00047 bool p_send_flag;
00048 };
00049
00050 KSSLCertDlg::KSSLCertDlg(TQWidget *parent, const char *name, bool modal)
00051 : KDialog(parent, name, modal), d(new KSSLCertDlgPrivate) {
00052
00053 TQBoxLayout * grid = new TQVBoxLayout( this, KDialog::marginHint(),
00054 KDialog::spacingHint() );
00055
00056 d->p_message = new TQLabel(TQString::null, this);
00057 grid->addWidget(d->p_message);
00058 setHost(_host);
00059
00060 _certs = new TQListView(this);
00061 _certs->addColumn(i18n("Certificate"));
00062 _certs->setResizeMode(TQListView::LastColumn);
00063 TQFontMetrics fm( TDEGlobalSettings::generalFont() );
00064 _certs->setMinimumHeight(4*fm.height());
00065 grid->addWidget(_certs);
00066
00067 _save = new TQCheckBox(i18n("Save selection for this host."), this);
00068 grid->addWidget(_save);
00069
00070 grid->addWidget(new KSeparator(KSeparator::HLine, this));
00071
00072 TQBoxLayout * h = new TQHBoxLayout( grid );
00073 h->insertStretch(0);
00074
00075 _ok = new KPushButton(i18n("Send certificate"), this);
00076 h->addWidget(_ok);
00077 connect(_ok, TQT_SIGNAL(clicked()), TQT_SLOT(slotSend()));
00078
00079 d->p_pb_dontsend = new KPushButton(i18n("Do not send a certificate"), this);
00080 h->addWidget(d->p_pb_dontsend);
00081 connect(d->p_pb_dontsend, TQT_SIGNAL(clicked()), TQT_SLOT(slotDont()));
00082
00083 #ifndef QT_NO_WIDGET_TOPEXTRA
00084 setCaption(i18n("KDE SSL Certificate Dialog"));
00085 #endif
00086 }
00087
00088
00089 KSSLCertDlg::~KSSLCertDlg() {
00090 delete d;
00091 }
00092
00093
00094 void KSSLCertDlg::setup(TQStringList certs, bool saveChecked, bool sendChecked) {
00095 setupDialog(certs, saveChecked, sendChecked);
00096 }
00097
00098 void KSSLCertDlg::setupDialog(const TQStringList& certs, bool saveChecked, bool sendChecked) {
00099 _save->setChecked(saveChecked);
00100 d->p_send_flag = sendChecked;
00101
00102 if (sendChecked)
00103 _ok->setDefault(true);
00104 else
00105 d->p_pb_dontsend->setDefault(true);
00106
00107 for (TQStringList::ConstIterator i = certs.begin(); i != certs.end(); ++i) {
00108 if ((*i).isEmpty())
00109 continue;
00110
00111 new TQListViewItem(_certs, *i);
00112 }
00113
00114 _certs->setSelected(_certs->firstChild(), true);
00115 }
00116
00117
00118 bool KSSLCertDlg::saveChoice() {
00119 return _save->isChecked();
00120 }
00121
00122
00123 bool KSSLCertDlg::wantsToSend() {
00124 return d->p_send_flag;
00125 }
00126
00127
00128 TQString KSSLCertDlg::getChoice() {
00129 TQListViewItem *selected = _certs->selectedItem();
00130 if (selected && d->p_send_flag)
00131 return selected->text(0);
00132 else
00133 return TQString::null;
00134 }
00135
00136
00137 void KSSLCertDlg::setHost(const TQString& host) {
00138 _host = host;
00139 d->p_message->setText(i18n("The server <b>%1</b> requests a certificate.<p>"
00140 "Select a certificate to use from the list below:")
00141 .arg(_host));
00142 }
00143
00144
00145 void KSSLCertDlg::slotSend() {
00146 d->p_send_flag = true;
00147 accept();
00148 }
00149
00150
00151 void KSSLCertDlg::slotDont() {
00152 d->p_send_flag = false;
00153 reject();
00154 }
00155
00156
00157 TQDataStream& operator<<(TQDataStream& s, const KSSLCertDlgRet& r) {
00158 s << TQ_INT8(r.ok?1:0) << r.choice << TQ_INT8(r.save?1:0) << TQ_INT8(r.send?1:0);
00159 return s;
00160 }
00161
00162
00163 TQDataStream& operator>>(TQDataStream& s, KSSLCertDlgRet& r) {
00164 TQ_INT8 tmp;
00165 s >> tmp; r.ok = (tmp == 1);
00166 s >> r.choice;
00167 s >> tmp; r.save = (tmp == 1);
00168 s >> tmp; r.send = (tmp == 1);
00169 return s;
00170 }
00171
00172
00173 #include "ksslcertdlg.moc"
00174