00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "configguildap.h"
00023
00024 #include <qcheckbox.h>
00025 #include <qdom.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qspinbox.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, QWidget *parent )
00036 : ConfigGui( member, parent )
00037 {
00038 initGUI();
00039
00040 bindModeChanged( false );
00041
00042 mSearchScope->insertItem( i18n( "Base" ) );
00043 mSearchScope->insertItem( i18n( "One" ) );
00044 mSearchScope->insertItem( i18n( "Sub" ) );
00045
00046 mAuthMech->insertItem( i18n( "Simple" ) );
00047 }
00048
00049 void ConfigGuiLdap::load( const QString &xml )
00050 {
00051 QDomDocument doc;
00052 doc.setContent( xml );
00053 QDomElement docElement = doc.documentElement();
00054 QDomNode node;
00055 for( node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
00056 QDomElement element = node.toElement();
00057 if ( element.tagName() == "servername" ) {
00058 mServerName->setText( element.text() );
00059 } else if ( element.tagName() == "serverport" ) {
00060 mPort->setValue( element.text().toInt() );
00061 } else if ( element.tagName() == "binddn" ) {
00062 mBindDn->setText( element.text() );
00063 } else if ( element.tagName() == "password" ) {
00064 mPassword->setText( element.text() );
00065 } else if ( element.tagName() == "anonymous" ) {
00066 mAnonymousBind->setChecked( element.text().toInt() == 1 );
00067 } else if ( element.tagName() == "searchbase" ) {
00068 mSearchBase->setText( element.text() );
00069 } else if ( element.tagName() == "searchfilter" ) {
00070 mSearchFilter->setText( element.text() );
00071 } else if ( element.tagName() == "storebase" ) {
00072 mStoreBase->setText( element.text() );
00073 } else if ( element.tagName() == "keyattr" ) {
00074 mKeyAttribute->setText( element.text() );
00075 } else if ( element.tagName() == "scope" ) {
00076 QStringList list;
00077 list << "base" << "one" << "sub";
00078
00079 for ( uint i = 0; i < list.count(); ++i )
00080 if ( list[ i ] == element.text() )
00081 mSearchScope->setCurrentItem( i );
00082
00083 } else if ( element.tagName() == "authmech" ) {
00084 QStringList list;
00085 list << "SIMPLE";
00086
00087 for ( uint i = 0; i < list.count(); ++i )
00088 if ( list[ i ] == element.text() )
00089 mAuthMech->setCurrentItem( i );
00090
00091 } else if ( element.tagName() == "encryption" ) {
00092 mEncryption->setChecked( element.text().toInt() == 1 );
00093 } else if ( element.tagName() == "encryption" ) {
00094 mEncryption->setChecked( element.text().toInt() == 1 );
00095 } else if ( element.tagName() == "ldap_read" ) {
00096 mReadLdap->setChecked( element.text().toInt() == 1 );
00097 } else if ( element.tagName() == "ldap_write" ) {
00098 mWriteLdap->setChecked( element.text().toInt() == 1 );
00099 }
00100 }
00101 }
00102
00103 QString ConfigGuiLdap::save() const
00104 {
00105 QString config = "<config>";
00106
00107 config += QString( "<servername>%1</servername>" ).arg( mServerName->text() );
00108 config += QString( "<serverport>%1</serverport>" ).arg( mPort->value() );
00109 config += QString( "<binddn>%1</binddn>" ).arg( mBindDn->text() );
00110 config += QString( "<password>%1</password>" ).arg( mPassword->text() );
00111 config += QString( "<anonymous>%1</anonymous>" ).arg( mAnonymousBind->isChecked() ? "1" : "0" );
00112 config += QString( "<searchbase>%1</searchbase>" ).arg( mSearchBase->text() );
00113 config += QString( "<searchfilter>%1</searchfilter>" ).arg( mSearchFilter->text() );
00114 config += QString( "<storebase>%1</storebase>" ).arg( mStoreBase->text() );
00115 config += QString( "<keyattr>%1</keyattr>" ).arg( mKeyAttribute->text() );
00116
00117 QStringList scopes;
00118 scopes << "base" << "one" << "sub";
00119
00120 config += QString( "<scope>%1</scope>" ).arg( scopes[ mSearchScope->currentItem() ] );
00121
00122 QStringList authMechs;
00123 authMechs << "SIMPLE";
00124
00125 config += QString( "<authmech>%1</authmech>" ).arg( authMechs[ mAuthMech->currentItem() ] );
00126 config += QString( "<encryption>%1</encryption>" ).arg( mEncryption->isChecked() ? "1" : "0" );
00127
00128 config += QString( "<ldap_read>%1</ldap_read>" ).arg( mReadLdap->isChecked() ? "1" : "0" );
00129 config += QString( "<ldap_write>%1</ldap_write>" ).arg( mWriteLdap->isChecked() ? "1" : "0" );
00130
00131 config += "</config>";
00132
00133 return config;
00134 }
00135
00136 void ConfigGuiLdap::bindModeChanged( bool checked )
00137 {
00138 mBindLabel->setEnabled( !checked );
00139 mBindDn->setEnabled( !checked );
00140
00141 mPasswordLabel->setEnabled( !checked );
00142 mPassword->setEnabled( !checked );
00143 }
00144
00145 void ConfigGuiLdap::initGUI()
00146 {
00147 QGridLayout *layout = new QGridLayout( topLayout(), 12, 4, KDialog::spacingHint() );
00148 layout->setMargin( KDialog::marginHint() );
00149
00150 layout->addWidget( new QLabel( i18n( "Server:" ), this ), 0, 0 );
00151 mServerName = new KLineEdit( this );
00152 layout->addWidget( mServerName, 0, 1 );
00153
00154 layout->addWidget( new QLabel( i18n( "Port:" ), this ), 0, 2, Qt::AlignRight );
00155 mPort = new QSpinBox( 1, 65536, 1, this );
00156 layout->addWidget( mPort, 0, 3 );
00157
00158 mAnonymousBind = new QCheckBox( i18n( "Use anonymous bind" ), this );
00159 layout->addMultiCellWidget( mAnonymousBind, 1, 1, 0, 1 );
00160
00161 connect( mAnonymousBind, SIGNAL( toggled( bool ) ),
00162 this, SLOT( bindModeChanged( bool ) ) );
00163
00164 mBindLabel = new QLabel( i18n( "Bind Dn:" ), this );
00165 layout->addWidget( mBindLabel, 2, 0 );
00166 mBindDn = new KLineEdit( this );
00167 layout->addMultiCellWidget( mBindDn, 2, 2, 1, 3 );
00168
00169 mPasswordLabel = new QLabel( i18n( "Password:" ), this );
00170 layout->addWidget( mPasswordLabel, 3, 0 );
00171 mPassword = new KLineEdit( this );
00172 mPassword->setEchoMode( QLineEdit::Password );
00173 layout->addMultiCellWidget( mPassword, 3, 3, 1, 3 );
00174
00175 layout->addWidget( new QLabel( i18n( "Search Base:" ), this ), 4, 0 );
00176 mSearchBase = new KLineEdit( this );
00177 layout->addMultiCellWidget( mSearchBase, 4, 4, 1, 3 );
00178
00179 layout->addWidget( new QLabel( i18n( "Search Filter:" ), this ), 5, 0 );
00180 mSearchFilter = new KLineEdit( this );
00181 layout->addMultiCellWidget( mSearchFilter, 5, 5, 1, 3 );
00182
00183 layout->addWidget( new QLabel( i18n( "Storage Base:" ), this ), 6, 0 );
00184 mStoreBase = new KLineEdit( this );
00185 layout->addMultiCellWidget( mStoreBase, 6, 6, 1, 3 );
00186
00187 layout->addWidget( new QLabel( i18n( "Key Attribute:" ), this ), 7, 0 );
00188 mKeyAttribute = new KLineEdit( this );
00189 layout->addMultiCellWidget( mKeyAttribute, 7, 7, 1, 3 );
00190
00191 layout->addWidget( new QLabel( i18n( "Search Scope:" ), this ), 8, 0 );
00192 mSearchScope = new KComboBox( this );
00193 layout->addMultiCellWidget( mSearchScope, 8, 8, 1, 3 );
00194
00195 layout->addWidget( new QLabel( i18n( "Authentication Mechanism:" ), this ), 9, 0 );
00196 mAuthMech = new KComboBox( this );
00197 layout->addMultiCellWidget( mAuthMech, 9, 9, 1, 3 );
00198
00199 mEncryption = new QCheckBox( i18n( "Use encryption" ), this );
00200 layout->addMultiCellWidget( mEncryption, 10, 10, 0, 3 );
00201
00202 mReadLdap = new QCheckBox( i18n( "Load data from LDAP" ), this );
00203 layout->addMultiCellWidget( mReadLdap, 11, 11, 0, 1 );
00204
00205 mWriteLdap = new QCheckBox( i18n( "Save data to LDAP" ), this );
00206 layout->addMultiCellWidget( mWriteLdap, 11, 11, 2, 3 );
00207 }
00208
00209 #include "configguildap.moc"