kabc Library API Documentation

resourceldapconfig.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <qcheckbox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qpushbutton.h>
00025 #include <qspinbox.h>
00026 #include <qvbox.h>
00027 
00028 #include <kaccelmanager.h>
00029 #include <kcombobox.h>
00030 #include <kdebug.h>
00031 #include <kdialogbase.h>
00032 #include <klocale.h>
00033 #include <klineedit.h>
00034 
00035 #include "resourceldap.h"
00036 
00037 #include "resourceldapconfig.h"
00038 
00039 using namespace KABC;
00040 
00041 ResourceLDAPConfig::ResourceLDAPConfig( QWidget* parent,  const char* name )
00042   : KRES::ConfigWidget( parent, name )
00043 {
00044   QGridLayout *mainLayout = new QGridLayout( this, 8, 2, 0,
00045       KDialog::spacingHint() );
00046 
00047   QLabel *label = new QLabel( i18n( "User:" ), this );
00048   mUser = new KLineEdit( this );
00049 
00050   mainLayout->addWidget( label, 0, 0 );
00051   mainLayout->addWidget( mUser, 0, 1 );
00052 
00053   label = new QLabel( i18n( "Password:" ), this );
00054   mPassword = new KLineEdit( this );
00055   mPassword->setEchoMode( KLineEdit::Password );
00056 
00057   mainLayout->addWidget( label, 1, 0 );
00058   mainLayout->addWidget( mPassword, 1, 1 );
00059 
00060   label = new QLabel( i18n( "Host:" ), this );
00061   mHost = new KLineEdit( this );
00062 
00063   mainLayout->addWidget( label, 2, 0 );
00064   mainLayout->addWidget( mHost, 2, 1 );
00065 
00066   label = new QLabel( i18n( "Port:" ), this );
00067   QVBox *box = new QVBox( this );
00068   mPort = new QSpinBox( 0, 65535, 1, box );
00069   mPort->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
00070   mPort->setValue( 389 );
00071   new QWidget( box, "dummy" );
00072 
00073   mainLayout->addWidget( label, 3, 0 );
00074   mainLayout->addWidget( box, 3, 1 );
00075 
00076   label = new QLabel( i18n( "Dn:" ), this );
00077   mDn = new KLineEdit( this );
00078 
00079   mainLayout->addWidget( label, 4, 0 );
00080   mainLayout->addWidget( mDn, 4, 1 );
00081 
00082   label = new QLabel( i18n( "Filter:" ), this );
00083   mFilter = new KLineEdit( this );
00084 
00085   mainLayout->addWidget( label, 5, 0 );
00086   mainLayout->addWidget( mFilter, 5, 1 );
00087 
00088   mAnonymous = new QCheckBox( i18n( "Anonymous login" ), this );
00089   mainLayout->addMultiCellWidget( mAnonymous, 6, 6, 0, 1 );
00090 
00091   mEditButton = new QPushButton( i18n( "Edit Attributes..." ), this );
00092   mainLayout->addMultiCellWidget( mEditButton, 7, 7, 0, 1 );
00093 
00094   connect( mAnonymous, SIGNAL( toggled(bool) ), mUser, SLOT( setDisabled(bool) ) );
00095   connect( mAnonymous, SIGNAL( toggled(bool) ), mPassword, SLOT( setDisabled(bool) ) );
00096   connect( mEditButton, SIGNAL( clicked() ), SLOT( editAttributes() ) );
00097 }
00098 
00099 void ResourceLDAPConfig::loadSettings( KRES::Resource *res )
00100 {
00101   ResourceLDAP *resource = dynamic_cast<ResourceLDAP*>( res );
00102   
00103   if ( !resource ) {
00104     kdDebug(5700) << "ResourceLDAPConfig::loadSettings(): cast failed" << endl;
00105     return;
00106   }
00107 
00108   mUser->setText( resource->user() );
00109   mPassword->setText( resource->password() );
00110   mHost->setText( resource->host() );
00111   mPort->setValue(  resource->port() );
00112   mDn->setText( resource->dn() );
00113   mFilter->setText( resource->filter() );
00114   mAnonymous->setChecked( resource->isAnonymous() );
00115   mAttributes = resource->attributes();
00116 }
00117 
00118 void ResourceLDAPConfig::saveSettings( KRES::Resource *res )
00119 {
00120   ResourceLDAP *resource = dynamic_cast<ResourceLDAP*>( res );
00121   
00122   if ( !resource ) {
00123     kdDebug(5700) << "ResourceLDAPConfig::saveSettings(): cast failed" << endl;
00124     return;
00125   }
00126 
00127   resource->setUser( mUser->text() );
00128   resource->setPassword( mPassword->text() );
00129   resource->setHost( mHost->text() );
00130   resource->setPort( mPort->value() );
00131   resource->setDn( mDn->text() );
00132   resource->setFilter( mFilter->text() );
00133   resource->setIsAnonymous( mAnonymous->isChecked() );
00134   resource->setAttributes( mAttributes );
00135 }
00136 
00137 void ResourceLDAPConfig::editAttributes()
00138 {
00139   AttributesDialog dlg( mAttributes, this );
00140   if ( dlg.exec() )
00141     mAttributes = dlg.attributes();
00142 }
00143 
00144 AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes,
00145                                     QWidget *parent, const char *name )
00146   : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel,
00147                  Ok, parent, name, true, true )
00148 {
00149   mNameDict.setAutoDelete( true );
00150   mNameDict.insert( "commonName", new QString( i18n( "Common name" ) ) );
00151   mNameDict.insert( "formattedName", new QString( i18n( "Formatted name" ) ) );
00152   mNameDict.insert( "familyName", new QString( i18n( "Family name" ) ) );
00153   mNameDict.insert( "givenName", new QString( i18n( "Given name" ) ) );
00154   mNameDict.insert( "mail", new QString( i18n( "Email" ) ) );
00155   mNameDict.insert( "mailAlias", new QString( i18n( "Email alias" ) ) );
00156   mNameDict.insert( "phoneNumber", new QString( i18n( "Telephone number" ) ) );
00157   mNameDict.insert( "uid", new QString( i18n( "UID" ) ) );
00158 
00159   // overwrite the default values here
00160   QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap;
00161 
00162   // kolab
00163   kolabMap.insert( "formattedName", "display-name" );
00164   kolabMap.insert( "mailAlias", "mailalias" );
00165 
00166   // evolution
00167   evolutionMap.insert( "formattedName", "fileAs" );
00168 
00169   mMapList.append( attributes );
00170   mMapList.append( kolabMap );
00171   mMapList.append( netscapeMap );
00172   mMapList.append( evolutionMap );
00173   mMapList.append( outlookMap );
00174 
00175   QFrame *page = plainPage();
00176   QGridLayout *layout = new QGridLayout( page, 2, attributes.count() + 1,
00177                                          0, spacingHint() );
00178 
00179   QLabel *label = new QLabel( i18n( "Template:" ), page );
00180   layout->addWidget( label, 0, 0 );
00181   mMapCombo = new KComboBox( page );
00182   layout->addWidget( mMapCombo, 0, 1 );
00183 
00184   mMapCombo->insertItem( i18n( "User Defined" ) );
00185   mMapCombo->insertItem( i18n( "Kolab" ) );
00186   mMapCombo->insertItem( i18n( "Netscape" ) );
00187   mMapCombo->insertItem( i18n( "Evolution" ) );
00188   mMapCombo->insertItem( i18n( "Outlook" ) );
00189   connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) );
00190 
00191   QMap<QString, QString>::ConstIterator it;
00192   int i;
00193   for ( i = 1, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
00194     label = new QLabel( *mNameDict[ it.key() ] + ":", page );
00195     KLineEdit *lineedit = new KLineEdit( page );
00196     mLineEditDict.insert( it.key(), lineedit );
00197     lineedit->setText( it.data() );
00198     label->setBuddy( lineedit );
00199     layout->addWidget( label, i, 0 );
00200     layout->addWidget( lineedit, i, 1 );
00201   }
00202 
00203   KAcceleratorManager::manage( this );
00204 }
00205 
00206 AttributesDialog::~AttributesDialog()
00207 {
00208 }
00209 
00210 QMap<QString, QString> AttributesDialog::attributes() const
00211 {
00212   QMap<QString, QString> map;
00213 
00214   QDictIterator<KLineEdit> it( mLineEditDict );
00215   for ( ; it.current(); ++it )
00216     map.insert( it.currentKey(), it.current()->text() );
00217 
00218   return map;
00219 }
00220 
00221 void AttributesDialog::mapChanged( int pos )
00222 {
00223   // default map
00224   QMap<QString, QString> defaultMap;
00225   defaultMap.insert( "commonName", "cn" );
00226   defaultMap.insert( "formattedName", "displayName" );
00227   defaultMap.insert( "familyName", "sn" );
00228   defaultMap.insert( "givenName", "givenName" );
00229   defaultMap.insert( "mail", "mail" );
00230   defaultMap.insert( "mailAlias", "" );
00231   defaultMap.insert( "phoneNumber", "telephoneNumber" );
00232   defaultMap.insert( "uid", "uid" );
00233 
00234   // apply first the default and than the spezific changes
00235   QMap<QString, QString>::Iterator it;
00236   for ( it = defaultMap.begin(); it != defaultMap.end(); ++it )
00237     mLineEditDict[ it.key() ]->setText( it.data() );
00238 
00239   for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
00240     if ( !it.data().isEmpty() )
00241       mLineEditDict[ it.key() ]->setText( it.data() );
00242   }
00243 }
00244 
00245 #include "resourceldapconfig.moc"
KDE Logo
This file is part of the documentation for kabc Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:36:44 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003