TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ksslcertdlg.cc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2001-2003 George Staikos <staikos@kde.org>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include "ksslcertdlg.h"
  21. #include <kssl.h>
  22. #include <tqlayout.h>
  23. #include <tqradiobutton.h>
  24. #include <tqcheckbox.h>
  25. #include <tqlistview.h>
  26. #include <tqframe.h>
  27. #include <tqlabel.h>
  28. #include <tdeapplication.h>
  29. #include <tdeglobal.h>
  30. #include <tdelocale.h>
  31. #include <tdeglobalsettings.h>
  32. #include <kpushbutton.h>
  33. #include <kstdguiitem.h>
  34. #include <kseparator.h>
  35. #include <kdebug.h>
  36. class KSSLCertDlg::KSSLCertDlgPrivate {
  37. private:
  38. friend class KSSLCertDlg;
  39. TQLabel *p_message;
  40. TQPushButton *p_pb_dontsend;
  41. bool p_send_flag;
  42. };
  43. KSSLCertDlg::KSSLCertDlg(TQWidget *parent, const char *name, bool modal)
  44. : KDialog(parent, name, modal), d(new KSSLCertDlgPrivate) {
  45. TQBoxLayout * grid = new TQVBoxLayout( this, KDialog::marginHint(),
  46. KDialog::spacingHint() );
  47. d->p_message = new TQLabel(TQString::null, this);
  48. grid->addWidget(d->p_message);
  49. setHost(_host);
  50. _certs = new TQListView(this);
  51. _certs->addColumn(i18n("Certificate"));
  52. _certs->setResizeMode(TQListView::LastColumn);
  53. TQFontMetrics fm( TDEGlobalSettings::generalFont() );
  54. _certs->setMinimumHeight(4*fm.height());
  55. grid->addWidget(_certs);
  56. _save = new TQCheckBox(i18n("Save selection for this host."), this);
  57. grid->addWidget(_save);
  58. grid->addWidget(new KSeparator(KSeparator::HLine, this));
  59. TQBoxLayout * h = new TQHBoxLayout( grid );
  60. h->insertStretch(0);
  61. _ok = new KPushButton(i18n("Send certificate"), this);
  62. h->addWidget(_ok);
  63. connect(_ok, TQT_SIGNAL(clicked()), TQT_SLOT(slotSend()));
  64. d->p_pb_dontsend = new KPushButton(i18n("Do not send a certificate"), this);
  65. h->addWidget(d->p_pb_dontsend);
  66. connect(d->p_pb_dontsend, TQT_SIGNAL(clicked()), TQT_SLOT(slotDont()));
  67. #ifndef TQT_NO_WIDGET_TOPEXTRA
  68. setCaption(i18n("TDE SSL Certificate Dialog"));
  69. #endif
  70. }
  71. KSSLCertDlg::~KSSLCertDlg() {
  72. delete d;
  73. }
  74. void KSSLCertDlg::setup(TQStringList certs, bool saveChecked, bool sendChecked) {
  75. setupDialog(certs, saveChecked, sendChecked);
  76. }
  77. void KSSLCertDlg::setupDialog(const TQStringList& certs, bool saveChecked, bool sendChecked) {
  78. _save->setChecked(saveChecked);
  79. d->p_send_flag = sendChecked;
  80. if (sendChecked)
  81. _ok->setDefault(true); // "do send" is the "default action".
  82. else
  83. d->p_pb_dontsend->setDefault(true); // "do not send" is the "default action".
  84. for (TQStringList::ConstIterator i = certs.begin(); i != certs.end(); ++i) {
  85. if ((*i).isEmpty())
  86. continue;
  87. new TQListViewItem(_certs, *i);
  88. }
  89. _certs->setSelected(_certs->firstChild(), true);
  90. }
  91. bool KSSLCertDlg::saveChoice() {
  92. return _save->isChecked();
  93. }
  94. bool KSSLCertDlg::wantsToSend() {
  95. return d->p_send_flag;
  96. }
  97. TQString KSSLCertDlg::getChoice() {
  98. TQListViewItem *selected = _certs->selectedItem();
  99. if (selected && d->p_send_flag)
  100. return selected->text(0);
  101. else
  102. return TQString::null;
  103. }
  104. void KSSLCertDlg::setHost(const TQString& host) {
  105. _host = host;
  106. d->p_message->setText(i18n("The server <b>%1</b> requests a certificate.<p>"
  107. "Select a certificate to use from the list below:")
  108. .arg(_host));
  109. }
  110. void KSSLCertDlg::slotSend() {
  111. d->p_send_flag = true;
  112. accept();
  113. }
  114. void KSSLCertDlg::slotDont() {
  115. d->p_send_flag = false;
  116. reject();
  117. }
  118. TQDataStream& operator<<(TQDataStream& s, const KSSLCertDlgRet& r) {
  119. s << TQ_INT8(r.ok?1:0) << r.choice << TQ_INT8(r.save?1:0) << TQ_INT8(r.send?1:0);
  120. return s;
  121. }
  122. TQDataStream& operator>>(TQDataStream& s, KSSLCertDlgRet& r) {
  123. TQ_INT8 tmp;
  124. s >> tmp; r.ok = (tmp == 1);
  125. s >> r.choice;
  126. s >> tmp; r.save = (tmp == 1);
  127. s >> tmp; r.send = (tmp == 1);
  128. return s;
  129. }
  130. #include "ksslcertdlg.moc"