kaddressbook

addhostdialog.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program 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
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqlabel.h>
25 #include <tqlayout.h>
26 #include <tqpushbutton.h>
27 #include <tqspinbox.h>
28 #include <tqtooltip.h>
29 
30 #include <tdeaccelmanager.h>
31 #include <kbuttonbox.h>
32 #include <klineedit.h>
33 #include <tdelocale.h>
34 #include "addhostdialog.h"
35 
36 AddHostDialog::AddHostDialog( KPIM::LdapServer *server, TQWidget* parent, const char* name )
37  : KDialogBase( Plain, i18n( "Add Host" ), Ok | Cancel, Ok, parent, name, true, true )
38 {
39  mServer = server;
40 
41  TQWidget *page = plainPage();
42  TQHBoxLayout *layout = new TQHBoxLayout( page, marginHint(), spacingHint() );
43 
44  mCfg = new TDEABC::LdapConfigWidget(
45  TDEABC::LdapConfigWidget::W_USER |
46  TDEABC::LdapConfigWidget::W_PASS |
47  TDEABC::LdapConfigWidget::W_BINDDN |
48  TDEABC::LdapConfigWidget::W_REALM |
49  TDEABC::LdapConfigWidget::W_HOST |
50  TDEABC::LdapConfigWidget::W_PORT |
51  TDEABC::LdapConfigWidget::W_VER |
52  TDEABC::LdapConfigWidget::W_TIMELIMIT |
53  TDEABC::LdapConfigWidget::W_SIZELIMIT |
54  TDEABC::LdapConfigWidget::W_DN |
55  TDEABC::LdapConfigWidget::W_SECBOX |
56  TDEABC::LdapConfigWidget::W_AUTHBOX,
57  page );
58 
59  layout->addWidget( mCfg );
60  mCfg->setHost( mServer->host() );
61  mCfg->setPort( mServer->port() );
62  mCfg->setDn( mServer->baseDN() );
63  mCfg->setUser( mServer->user() );
64  mCfg->setBindDN( mServer->bindDN() );
65  mCfg->setPassword( mServer->pwdBindDN() );
66  mCfg->setTimeLimit( mServer->timeLimit() );
67  mCfg->setSizeLimit( mServer->sizeLimit() );
68  mCfg->setVer( mServer->version() );
69 
70  switch ( mServer->security() ) {
71  case KPIM::LdapServer::TLS:
72  mCfg->setSecTLS();
73  break;
74  case KPIM::LdapServer::SSL:
75  mCfg->setSecSSL();
76  break;
77  default:
78  mCfg->setSecNO();
79  }
80 
81  switch ( mServer->auth() ) {
82  case KPIM::LdapServer::Simple:
83  mCfg->setAuthSimple();
84  break;
85  case KPIM::LdapServer::SASL:
86  mCfg->setAuthSASL();
87  break;
88  default:
89  mCfg->setAuthAnon();
90  }
91  mCfg->setMech( mServer->mech() );
92 
93  TDEAcceleratorManager::manage( this );
94 
95 }
96 
97 AddHostDialog::~AddHostDialog()
98 {
99 }
100 
101 void AddHostDialog::slotHostEditChanged( const TQString &text )
102 {
103  enableButtonOK( !text.isEmpty() );
104 }
105 
106 void AddHostDialog::slotOk()
107 {
108  mServer->setHost( mCfg->host() );
109  mServer->setPort( mCfg->port() );
110  mServer->setBaseDN( mCfg->dn().stripWhiteSpace() );
111  mServer->setUser( mCfg->user() );
112  mServer->setBindDN( mCfg->bindDN() );
113  mServer->setPwdBindDN( mCfg->password() );
114  mServer->setTimeLimit( mCfg->timeLimit() );
115  mServer->setSizeLimit( mCfg->sizeLimit() );
116  mServer->setVersion( mCfg->ver() );
117  mServer->setSecurity( KPIM::LdapServer::Sec_None );
118  if ( mCfg->isSecTLS() ) mServer->setSecurity( KPIM::LdapServer::TLS );
119  if ( mCfg->isSecSSL() ) mServer->setSecurity( KPIM::LdapServer::SSL );
120  mServer->setAuth( KPIM::LdapServer::Anonymous );
121  if ( mCfg->isAuthSimple() ) mServer->setAuth( KPIM::LdapServer::Simple );
122  if ( mCfg->isAuthSASL() ) mServer->setAuth( KPIM::LdapServer::SASL );
123  mServer->setMech( mCfg->mech() );
124  KDialog::accept();
125 }
126 
127 #include "addhostdialog.moc"