kio Library API Documentation

ksslcertdlg.cc

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., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include "ksslcertdlg.h"
00022 
00023 #include <kssl.h>
00024 
00025 #include <qlayout.h>
00026 #include <qradiobutton.h>
00027 #include <qcheckbox.h>
00028 #include <qlistview.h>
00029 #include <qframe.h>
00030 #include <qlabel.h>
00031 
00032 #include <kapplication.h>
00033 #include <kglobal.h>
00034 #include <klocale.h>
00035 #include <kglobalsettings.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 };
00046 
00047 KSSLCertDlg::KSSLCertDlg(QWidget *parent, const char *name, bool modal)
00048  : KDialog(parent, name, modal), d(new KSSLCertDlgPrivate) {
00049    QGridLayout *grid = new QGridLayout(this, 8, 6, KDialog::marginHint(),
00050                                                    KDialog::spacingHint() );
00051 
00052    _send = new QRadioButton(i18n("Send certificate..."), this);
00053    grid->addMultiCellWidget(_send, 0, 0, 0, 2);
00054    connect(_send, SIGNAL(clicked()), SLOT(slotSend()));
00055 
00056    _dont = new QRadioButton(i18n("Do not send a certificate"), this);
00057    grid->addMultiCellWidget(_dont, 1, 1, 0, 2);
00058    connect(_dont, SIGNAL(clicked()), SLOT(slotDont()));
00059 
00060    _certs = new QListView(this);
00061    grid->addMultiCellWidget(_certs, 0, 4, 3, 5);
00062    _certs->addColumn(i18n("Certificate"));
00063 
00064    _save = new QCheckBox(i18n("Save selection for this host."), this);
00065    grid->addMultiCellWidget(_save, 5, 5, 0, 3);
00066 
00067    grid->addMultiCellWidget(new KSeparator(KSeparator::HLine, this), 6, 6, 0, 5);
00068 
00069    _ok = new KPushButton(KStdGuiItem::cont(), this);
00070    grid->addWidget(_ok, 7, 5);
00071    connect(_ok, SIGNAL(clicked()), SLOT(accept()));
00072 
00073 #ifndef QT_NO_WIDGET_TOPEXTRA
00074    setCaption(i18n("KDE SSL Certificate Dialog"));
00075 #endif
00076 }
00077 
00078 
00079 KSSLCertDlg::~KSSLCertDlg() {
00080     delete d;
00081 }
00082 
00083 
00084 void KSSLCertDlg::setup(QStringList certs, bool saveChecked, bool sendChecked) {
00085     setupDialog(certs, saveChecked, sendChecked);
00086 }
00087 
00088 void KSSLCertDlg::setupDialog(const QStringList& certs, bool saveChecked, bool sendChecked) {
00089   _save->setChecked(saveChecked);
00090   _send->setChecked(sendChecked);
00091   _dont->setChecked(!sendChecked);
00092   _certs->setEnabled(saveChecked);
00093 
00094   for (QStringList::ConstIterator i = certs.begin(); i != certs.end(); ++i) {
00095     if ((*i).isEmpty())
00096       continue;
00097 
00098     new QListViewItem(_certs, *i);
00099   }
00100 
00101   _certs->setSelected(_certs->firstChild(), true);
00102 }
00103 
00104 
00105 bool KSSLCertDlg::saveChoice() {
00106   return _save->isChecked();
00107 }
00108 
00109 
00110 bool KSSLCertDlg::wantsToSend() {
00111   return _send->isChecked();
00112 }
00113 
00114 
00115 QString KSSLCertDlg::getChoice() {
00116    return _certs->selectedItem()->text(0);
00117 }
00118 
00119 
00120 void KSSLCertDlg::setHost(const QString& host) {
00121    _host = host;
00122 #ifndef QT_NO_WIDGET_TOPEXTRA
00123    setCaption(i18n("KDE SSL Certificate Dialog")+" - "+host);
00124 #endif
00125 }
00126 
00127 
00128 void KSSLCertDlg::slotSend() {
00129    _dont->setChecked(false);
00130    _send->setChecked(true);
00131    _certs->setEnabled(true);
00132 }
00133 
00134 
00135 void KSSLCertDlg::slotDont() {
00136    _send->setChecked(false);
00137    _dont->setChecked(true);
00138    _certs->setEnabled(false);
00139 }
00140 
00141 
00142 QDataStream& operator<<(QDataStream& s, const KSSLCertDlgRet& r) {
00143    s << Q_INT8(r.ok?1:0) <<  r.choice << Q_INT8(r.save?1:0) << Q_INT8(r.send?1:0);
00144    return s;
00145 }
00146 
00147 
00148 QDataStream& operator>>(QDataStream& s, KSSLCertDlgRet& r) {
00149 Q_INT8 tmp;
00150    s >> tmp; r.ok = (tmp == 1);
00151    s >> r.choice;
00152    s >> tmp; r.save = (tmp == 1);
00153    s >> tmp; r.send = (tmp == 1);
00154    return s;
00155 }
00156 
00157 
00158 #include "ksslcertdlg.moc"
00159 
KDE Logo
This file is part of the documentation for kio Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 7 22:07:51 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003