• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 <klocale.h>
00033 #include <kglobalsettings.h>
00034 #include <kpushbutton.h>
00035 #include <kseparator.h>
00036 #include <kdebug.h>
00037 
00038 
00039 class KSSLCertDialog::KSSLCertDialogPrivate {
00040 private:
00041     friend class KSSLCertDialog;
00042     QLabel *p_message;
00043     QPushButton *p_pb_dontsend;
00044     bool p_send_flag;
00045 };
00046 
00047 KSSLCertDialog::KSSLCertDialog(QWidget *parent, const char *name, bool modal)
00048  : KDialog(parent), d(new KSSLCertDialogPrivate) {
00049    setObjectName(name);
00050    setModal(modal);
00051 
00052    QBoxLayout * grid = new QVBoxLayout( this );
00053 
00054    d->p_message = new QLabel(QString(), this);
00055    grid->addWidget(d->p_message);
00056    setHost(_host);
00057 
00058    QLabel* lblCertificate = new QLabel(i18n("Certificate"));
00059    grid->addWidget(lblCertificate);
00060 
00061    _certs = new QListWidget(this);
00062    QFontMetrics fm( KGlobalSettings::generalFont() );
00063    _certs->setMinimumHeight(4*fm.height());
00064    grid->addWidget(_certs);
00065 
00066    _save = new QCheckBox(i18n("Save selection for this host."), this);
00067    grid->addWidget(_save);
00068 
00069    grid->addWidget(new KSeparator(Qt::Horizontal, this));
00070 
00071    QBoxLayout * h = new QHBoxLayout(this);
00072    h->insertStretch(0);
00073    grid->addLayout(h);
00074 
00075    _ok = new KPushButton(i18n("Send certificate"), this);
00076    h->addWidget(_ok);
00077    connect(_ok, SIGNAL(clicked()), 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, SIGNAL(clicked()), SLOT(slotDont()));
00082 
00083 #ifndef QT_NO_WIDGET_TOPEXTRA
00084    setCaption(i18n("KDE SSL Certificate Dialog"));
00085 #endif
00086 }
00087 
00088 
00089 KSSLCertDialog::~KSSLCertDialog() {
00090     delete d;
00091 }
00092 
00093 
00094 #ifndef KDE_NO_DEPRECATED
00095 void KSSLCertDialog::setup(QStringList certs, bool saveChecked, bool sendChecked) {
00096     setupDialog(certs, saveChecked, sendChecked);
00097 }
00098 #endif
00099 
00100 void KSSLCertDialog::setupDialog(const QStringList& certs, bool saveChecked, bool sendChecked) {
00101   _save->setChecked(saveChecked);
00102   d->p_send_flag = sendChecked;
00103 
00104   if (sendChecked)
00105     _ok->setDefault(true); // "do send" is the "default action".
00106   else
00107     d->p_pb_dontsend->setDefault(true); // "do not send" is the "default action".
00108 
00109   for (QStringList::ConstIterator i = certs.begin(); i != certs.end(); ++i) {
00110     if ((*i).isEmpty())
00111       continue;
00112 
00113     new QListWidgetItem(*i, _certs);
00114   }
00115 
00116   _certs->setCurrentItem(_certs->item(0));
00117 }
00118 
00119 
00120 bool KSSLCertDialog::saveChoice() {
00121   return _save->isChecked();
00122 }
00123 
00124 
00125 bool KSSLCertDialog::wantsToSend() {
00126   return d->p_send_flag;
00127 }
00128 
00129 
00130 QString KSSLCertDialog::getChoice() {
00131    QListWidgetItem *selected = _certs->currentItem();
00132    if (selected && d->p_send_flag)
00133     return selected->text();
00134    else
00135     return QString();
00136 }
00137 
00138 
00139 void KSSLCertDialog::setHost(const QString& host) {
00140    _host = host;
00141    d->p_message->setText(i18n("The server <b>%1</b> requests a certificate.<br /><br />"
00142                   "Select a certificate to use from the list below:",
00143                   _host));
00144 }
00145 
00146 
00147 void KSSLCertDialog::slotSend() {
00148    d->p_send_flag = true;
00149    accept();
00150 }
00151 
00152 
00153 void KSSLCertDialog::slotDont() {
00154    d->p_send_flag = false;
00155    reject();
00156 }
00157 
00158 
00159 QDataStream& operator<<(QDataStream& s, const KSSLCertDialogRet& r) {
00160    s << qint8(r.ok?1:0) <<  r.choice << qint8(r.save?1:0) << qint8(r.send?1:0);
00161    return s;
00162 }
00163 
00164 
00165 QDataStream& operator>>(QDataStream& s, KSSLCertDialogRet& r) {
00166    qint8 tmp;
00167    s >> tmp; r.ok = (tmp == 1);
00168    s >> r.choice;
00169    s >> tmp; r.save = (tmp == 1);
00170    s >> tmp; r.send = (tmp == 1);
00171    return s;
00172 }
00173 
00174 
00175 #include "ksslcertdialog.moc"
00176 

KIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
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