kitchensync

configguildap.cpp
1/*
2 This file is part of KitchenSync.
3
4 Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 USA.
20*/
21
22#include "configguildap.h"
23
24#include <tqcheckbox.h>
25#include <tqdom.h>
26#include <tqlabel.h>
27#include <tqlayout.h>
28#include <tqspinbox.h>
29
30#include <kcombobox.h>
31#include <kdialog.h>
32#include <klineedit.h>
33#include <tdelocale.h>
34
35ConfigGuiLdap::ConfigGuiLdap( const QSync::Member &member, TQWidget *parent )
36 : ConfigGui( member, parent )
37{
38 initGUI();
39
40 mSearchScope->insertItem( i18n( "Base" ) );
41 mSearchScope->insertItem( i18n( "One" ) );
42 mSearchScope->insertItem( i18n( "Sub" ) );
43}
44
45void ConfigGuiLdap::load( const TQString &xml )
46{
47 TQDomDocument doc;
48 doc.setContent( xml );
49 TQDomElement docElement = doc.documentElement();
50 TQDomNode node;
51 for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
52 TQDomElement element = node.toElement();
53 if ( element.tagName() == "servername" ) {
54 mLdapWidget->setHost( element.text() );
55 } else if ( element.tagName() == "serverport" ) {
56 mLdapWidget->setPort( element.text().toInt() );
57 } else if ( element.tagName() == "binddn" ) {
58 mLdapWidget->setBindDN( element.text() );
59 } else if ( element.tagName() == "password" ) {
60 mLdapWidget->setPassword( element.text() );
61 } else if ( element.tagName() == "anonymous" ) {
62 mLdapWidget->setAuthAnon( element.text().toInt() == 1 );
63 } else if ( element.tagName() == "searchbase" ) {
64 mLdapWidget->setDn( element.text() );
65 } else if ( element.tagName() == "searchfilter" ) {
66 mLdapWidget->setFilter( element.text() );
67 } else if ( element.tagName() == "storebase" ) {
68 mLdapWidget->setDn( element.text() );
69 } else if ( element.tagName() == "keyattr" ) {
70 mKeyAttribute->setText( element.text() );
71 } else if ( element.tagName() == "scope" ) {
72 TQStringList list;
73 list << "base" << "one" << "sub";
74 for ( uint i = 0; i < list.count(); ++i )
75 if ( list[ i ] == element.text() )
76 mSearchScope->setCurrentItem( i );
77
78 } else if ( element.tagName() == "authmech" ) {
79 if ( element.text() == "SIMPLE" ) {
80 mLdapWidget->setAuthSimple( true );
81 }
82 } else if ( element.tagName() == "encryption" ) {
83 mEncryption->setChecked( element.text().toInt() == 1 );
84 } else if ( element.tagName() == "ldap_read" ) {
85 mReadLdap->setChecked( element.text().toInt() == 1 );
86 } else if ( element.tagName() == "ldap_write" ) {
87 mWriteLdap->setChecked( element.text().toInt() == 1 );
88 }
89 }
90}
91
92TQString ConfigGuiLdap::save() const
93{
94 TQString config = "<config>\n";
95
96 config += TQString( "<servername>%1</servername>\n" ).arg( mLdapWidget->host() );
97 config += TQString( "<serverport>%1</serverport>\n" ).arg( mLdapWidget->port() );
98 config += TQString( "<binddn>%1</binddn>\n" ).arg( mLdapWidget->bindDN() );
99 config += TQString( "<password>%1</password>\n" ).arg( mLdapWidget->password() );
100 config += TQString( "<anonymous>%1</anonymous>\n" ).arg( mLdapWidget->isAuthAnon() ? "1" : "0" );
101 config += TQString( "<searchbase>%1</searchbase>\n" ).arg( mLdapWidget->dn() );
102 config += TQString( "<searchfilter>%1</searchfilter>\n" ).arg( mLdapWidget->filter() );
103 config += TQString( "<storebase>%1</storebase>\n" ).arg( mLdapWidget->dn() );
104 config += TQString( "<keyattr>%1</keyattr>\n" ).arg( mKeyAttribute->text() );
105
106 TQStringList scopes;
107 scopes << "base" << "one" << "sub";
108
109 config += TQString( "<scope>%1</scope>\n" ).arg( scopes[ mSearchScope->currentItem() ] );
110
111 config += TQString( "<authmech>SIMPLE</authmech>\n" );
112 config += TQString( "<encryption>%1</encryption>\n" ).arg( mEncryption->isChecked() ? "1" : "0" );
113
114 config += TQString( "<ldap_read>%1</ldap_read>\n" ).arg( mReadLdap->isChecked() ? "1" : "0" );
115 config += TQString( "<ldap_write>%1</ldap_write>\n" ).arg( mWriteLdap->isChecked() ? "1" : "0" );
116
117 config += "</config>";
118
119 return config;
120}
121
122void ConfigGuiLdap::initGUI()
123{
124 TQGridLayout *layout = new TQGridLayout( topLayout(), 12, 4, KDialog::spacingHint() );
125 layout->setMargin( KDialog::marginHint() );
126
127 mLdapWidget = new TDEABC::LdapConfigWidget( TDEABC::LdapConfigWidget::W_HOST |
128 TDEABC::LdapConfigWidget::W_PORT |
129 TDEABC::LdapConfigWidget::W_USER |
130 TDEABC::LdapConfigWidget::W_PASS |
131 TDEABC::LdapConfigWidget::W_BINDDN |
132 TDEABC::LdapConfigWidget::W_DN |
133 TDEABC::LdapConfigWidget::W_FILTER |
134 TDEABC::LdapConfigWidget::W_AUTHBOX, this );
135
136 mKeyAttribute = new KLineEdit( this );
137 mSearchScope = new KComboBox( this );
138 mEncryption = new TQCheckBox( i18n( "Use encryption" ), this );
139 mReadLdap = new TQCheckBox( i18n( "Load data from LDAP" ), this );
140 mWriteLdap = new TQCheckBox( i18n( "Save data to LDAP" ), this );
141
142 layout->addMultiCellWidget( mLdapWidget, 0, 9, 0, 3 );
143 layout->addWidget( new TQLabel( i18n( "Key Attribute:" ), this ), 10, 0 );
144 layout->addMultiCellWidget( mKeyAttribute, 10, 10, 1, 2 );
145 layout->addWidget( new TQLabel( i18n( "Search Scope:" ), this ), 11, 0 );
146 layout->addMultiCellWidget( mSearchScope, 11, 11, 1, 2 );
147 layout->addWidget( mEncryption, 12, 0 );
148 layout->addWidget( mReadLdap, 13, 0 );
149 layout->addWidget( mWriteLdap, 13, 3 );
150
151}
152
153#include "configguildap.moc"