• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 void KSSLCertDialog::setup(QStringList certs, bool saveChecked, bool sendChecked) {
00098     setupDialog(certs, saveChecked, sendChecked);
00099 }
00100 
00101 void KSSLCertDialog::setupDialog(const QStringList& certs, bool saveChecked, bool sendChecked) {
00102   _save->setChecked(saveChecked);
00103   d->p_send_flag = sendChecked;
00104 
00105   if (sendChecked)
00106     _ok->setDefault(true); // "do send" is the "default action".
00107   else
00108     d->p_pb_dontsend->setDefault(true); // "do not send" is the "default action".
00109 
00110   for (QStringList::ConstIterator i = certs.begin(); i != certs.end(); ++i) {
00111     if ((*i).isEmpty())
00112       continue;
00113 
00114     new QListWidgetItem(*i, _certs);
00115   }
00116 
00117   _certs->setCurrentItem(_certs->item(0));
00118 }
00119 
00120 
00121 bool KSSLCertDialog::saveChoice() {
00122   return _save->isChecked();
00123 }
00124 
00125 
00126 bool KSSLCertDialog::wantsToSend() {
00127   return d->p_send_flag;
00128 }
00129 
00130 
00131 QString KSSLCertDialog::getChoice() {
00132    QListWidgetItem *selected = _certs->currentItem();
00133    if (selected && d->p_send_flag)
00134     return selected->text();
00135    else
00136     return QString();
00137 }
00138 
00139 
00140 void KSSLCertDialog::setHost(const QString& host) {
00141    _host = host;
00142    d->p_message->setText(i18n("The server <b>%1</b> requests a certificate.<br /><br />"
00143                   "Select a certificate to use from the list below:",
00144                   _host));
00145 }
00146 
00147 
00148 void KSSLCertDialog::slotSend() {
00149    d->p_send_flag = true;
00150    accept();
00151 }
00152 
00153 
00154 void KSSLCertDialog::slotDont() {
00155    d->p_send_flag = false;
00156    reject();
00157 }
00158 
00159 
00160 QDataStream& operator<<(QDataStream& s, const KSSLCertDialogRet& r) {
00161    s << qint8(r.ok?1:0) <<  r.choice << qint8(r.save?1:0) << qint8(r.send?1:0);
00162    return s;
00163 }
00164 
00165 
00166 QDataStream& operator>>(QDataStream& s, KSSLCertDialogRet& r) {
00167    qint8 tmp;
00168    s >> tmp; r.ok = (tmp == 1);
00169    s >> r.choice;
00170    s >> tmp; r.save = (tmp == 1);
00171    s >> tmp; r.send = (tmp == 1);
00172    return s;
00173 }
00174 
00175 
00176 #include "ksslcertdialog.moc"
00177 

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal