configguildap.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2007 Tobias Koenig <tokoe@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00019 USA. 00020 */ 00021 00022 #include "configguildap.h" 00023 00024 #include <tqcheckbox.h> 00025 #include <tqdom.h> 00026 #include <tqlabel.h> 00027 #include <tqlayout.h> 00028 #include <tqspinbox.h> 00029 00030 #include <kcombobox.h> 00031 #include <kdialog.h> 00032 #include <klineedit.h> 00033 #include <klocale.h> 00034 00035 ConfigGuiLdap::ConfigGuiLdap( const QSync::Member &member, TQWidget *parent ) 00036 : ConfigGui( member, parent ) 00037 { 00038 initGUI(); 00039 00040 mSearchScope->insertItem( i18n( "Base" ) ); 00041 mSearchScope->insertItem( i18n( "One" ) ); 00042 mSearchScope->insertItem( i18n( "Sub" ) ); 00043 } 00044 00045 void ConfigGuiLdap::load( const TQString &xml ) 00046 { 00047 TQDomDocument doc; 00048 doc.setContent( xml ); 00049 TQDomElement docElement = doc.documentElement(); 00050 TQDomNode node; 00051 for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) { 00052 TQDomElement element = node.toElement(); 00053 if ( element.tagName() == "servername" ) { 00054 mLdapWidget->setHost( element.text() ); 00055 } else if ( element.tagName() == "serverport" ) { 00056 mLdapWidget->setPort( element.text().toInt() ); 00057 } else if ( element.tagName() == "binddn" ) { 00058 mLdapWidget->setBindDN( element.text() ); 00059 } else if ( element.tagName() == "password" ) { 00060 mLdapWidget->setPassword( element.text() ); 00061 } else if ( element.tagName() == "anonymous" ) { 00062 mLdapWidget->setAuthAnon( element.text().toInt() == 1 ); 00063 } else if ( element.tagName() == "searchbase" ) { 00064 mLdapWidget->setDn( element.text() ); 00065 } else if ( element.tagName() == "searchfilter" ) { 00066 mLdapWidget->setFilter( element.text() ); 00067 } else if ( element.tagName() == "storebase" ) { 00068 mLdapWidget->setDn( element.text() ); 00069 } else if ( element.tagName() == "keyattr" ) { 00070 mKeyAttribute->setText( element.text() ); 00071 } else if ( element.tagName() == "scope" ) { 00072 TQStringList list; 00073 list << "base" << "one" << "sub"; 00074 for ( uint i = 0; i < list.count(); ++i ) 00075 if ( list[ i ] == element.text() ) 00076 mSearchScope->setCurrentItem( i ); 00077 00078 } else if ( element.tagName() == "authmech" ) { 00079 if ( element.text() == "SIMPLE" ) { 00080 mLdapWidget->setAuthSimple( true ); 00081 } 00082 } else if ( element.tagName() == "encryption" ) { 00083 mEncryption->setChecked( element.text().toInt() == 1 ); 00084 } else if ( element.tagName() == "ldap_read" ) { 00085 mReadLdap->setChecked( element.text().toInt() == 1 ); 00086 } else if ( element.tagName() == "ldap_write" ) { 00087 mWriteLdap->setChecked( element.text().toInt() == 1 ); 00088 } 00089 } 00090 } 00091 00092 TQString ConfigGuiLdap::save() const 00093 { 00094 TQString config = "<config>\n"; 00095 00096 config += TQString( "<servername>%1</servername>\n" ).arg( mLdapWidget->host() ); 00097 config += TQString( "<serverport>%1</serverport>\n" ).arg( mLdapWidget->port() ); 00098 config += TQString( "<binddn>%1</binddn>\n" ).arg( mLdapWidget->bindDN() ); 00099 config += TQString( "<password>%1</password>\n" ).arg( mLdapWidget->password() ); 00100 config += TQString( "<anonymous>%1</anonymous>\n" ).arg( mLdapWidget->isAuthAnon() ? "1" : "0" ); 00101 config += TQString( "<searchbase>%1</searchbase>\n" ).arg( mLdapWidget->dn() ); 00102 config += TQString( "<searchfilter>%1</searchfilter>\n" ).arg( mLdapWidget->filter() ); 00103 config += TQString( "<storebase>%1</storebase>\n" ).arg( mLdapWidget->dn() ); 00104 config += TQString( "<keyattr>%1</keyattr>\n" ).arg( mKeyAttribute->text() ); 00105 00106 TQStringList scopes; 00107 scopes << "base" << "one" << "sub"; 00108 00109 config += TQString( "<scope>%1</scope>\n" ).arg( scopes[ mSearchScope->currentItem() ] ); 00110 00111 config += TQString( "<authmech>SIMPLE</authmech>\n" ); 00112 config += TQString( "<encryption>%1</encryption>\n" ).arg( mEncryption->isChecked() ? "1" : "0" ); 00113 00114 config += TQString( "<ldap_read>%1</ldap_read>\n" ).arg( mReadLdap->isChecked() ? "1" : "0" ); 00115 config += TQString( "<ldap_write>%1</ldap_write>\n" ).arg( mWriteLdap->isChecked() ? "1" : "0" ); 00116 00117 config += "</config>"; 00118 00119 return config; 00120 } 00121 00122 void ConfigGuiLdap::initGUI() 00123 { 00124 TQGridLayout *layout = new TQGridLayout( topLayout(), 12, 4, KDialog::spacingHint() ); 00125 layout->setMargin( KDialog::marginHint() ); 00126 00127 mLdapWidget = new KABC::LdapConfigWidget( KABC::LdapConfigWidget::W_HOST | 00128 KABC::LdapConfigWidget::W_PORT | 00129 KABC::LdapConfigWidget::W_USER | 00130 KABC::LdapConfigWidget::W_PASS | 00131 KABC::LdapConfigWidget::W_BINDDN | 00132 KABC::LdapConfigWidget::W_DN | 00133 KABC::LdapConfigWidget::W_FILTER | 00134 KABC::LdapConfigWidget::W_AUTHBOX, this ); 00135 00136 mKeyAttribute = new KLineEdit( this ); 00137 mSearchScope = new KComboBox( this ); 00138 mEncryption = new TQCheckBox( i18n( "Use encryption" ), this ); 00139 mReadLdap = new TQCheckBox( i18n( "Load data from LDAP" ), this ); 00140 mWriteLdap = new TQCheckBox( i18n( "Save data to LDAP" ), this ); 00141 00142 layout->addMultiCellWidget( mLdapWidget, 0, 9, 0, 3 ); 00143 layout->addWidget( new TQLabel( i18n( "Key Attribute:" ), this ), 10, 0 ); 00144 layout->addMultiCellWidget( mKeyAttribute, 10, 10, 1, 2 ); 00145 layout->addWidget( new TQLabel( i18n( "Search Scope:" ), this ), 11, 0 ); 00146 layout->addMultiCellWidget( mSearchScope, 11, 11, 1, 2 ); 00147 layout->addWidget( mEncryption, 12, 0 ); 00148 layout->addWidget( mReadLdap, 13, 0 ); 00149 layout->addWidget( mWriteLdap, 13, 3 ); 00150 00151 } 00152 00153 #include "configguildap.moc"