kabc Library API Documentation

resourceldapkioconfig.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2002 - 2003 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 "resourceldapkio.h"
00036 
00037 #include "resourceldapkioconfig.h"
00038 
00039 using namespace KABC;
00040 
00041 ResourceLDAPKIOConfig::ResourceLDAPKIOConfig( 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( "Distinguished Name", "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 ResourceLDAPKIOConfig::loadSettings( KRES::Resource *res )
00100 {
00101   ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
00102   
00103   if ( !resource ) {
00104     kdDebug(5700) << "ResourceLDAPKIOConfig::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 ResourceLDAPKIOConfig::saveSettings( KRES::Resource *res )
00119 {
00120   ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
00121   
00122   if ( !resource ) {
00123     kdDebug(5700) << "ResourceLDAPKIOConfig::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   resource->init();
00136 }
00137 
00138 void ResourceLDAPKIOConfig::editAttributes()
00139 {
00140   AttributesDialog dlg( mAttributes, this );
00141   if ( dlg.exec() )
00142     mAttributes = dlg.attributes();
00143 }
00144 
00145 AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes,
00146                                     QWidget *parent, const char *name )
00147   : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel,
00148                  Ok, parent, name, true, true )
00149 {
00150   mNameDict.setAutoDelete( true );
00151   mNameDict.insert( "commonName", new QString( i18n( "Common name" ) ) );
00152   mNameDict.insert( "formattedName", new QString( i18n( "Formatted name" ) ) );
00153   mNameDict.insert( "familyName", new QString( i18n( "Family name" ) ) );
00154   mNameDict.insert( "givenName", new QString( i18n( "Given name" ) ) );
00155   mNameDict.insert( "mail", new QString( i18n( "Email" ) ) );
00156   mNameDict.insert( "mailAlias", new QString( i18n( "Email alias" ) ) );
00157   mNameDict.insert( "phoneNumber", new QString( i18n( "Telephone number" ) ) );
00158   mNameDict.insert( "uid", new QString( i18n( "UID" ) ) );
00159 
00160   // overwrite the default values here
00161   QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap;
00162 
00163   // kolab
00164   kolabMap.insert( "formattedName", "display-name" );
00165   kolabMap.insert( "mailAlias", "mailalias" );
00166 
00167   // evolution
00168   evolutionMap.insert( "formattedName", "fileAs" );
00169 
00170   mMapList.append( attributes );
00171   mMapList.append( kolabMap );
00172   mMapList.append( netscapeMap );
00173   mMapList.append( evolutionMap );
00174   mMapList.append( outlookMap );
00175 
00176   QFrame *page = plainPage();
00177   QGridLayout *layout = new QGridLayout( page, 2, attributes.count() + 1,
00178                                          0, spacingHint() );
00179 
00180   QLabel *label = new QLabel( i18n( "Template:" ), page );
00181   layout->addWidget( label, 0, 0 );
00182   mMapCombo = new KComboBox( page );
00183   layout->addWidget( mMapCombo, 0, 1 );
00184 
00185   mMapCombo->insertItem( i18n( "User Defined" ) );
00186   mMapCombo->insertItem( i18n( "Kolab" ) );
00187   mMapCombo->insertItem( i18n( "Netscape" ) );
00188   mMapCombo->insertItem( i18n( "Evolution" ) );
00189   mMapCombo->insertItem( i18n( "Outlook" ) );
00190   connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) );
00191 
00192   QMap<QString, QString>::ConstIterator it;
00193   int i;
00194   for ( i = 1, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
00195     if ( mNameDict[ it.key() ] == 0 )
00196       continue;
00197     label = new QLabel( *mNameDict[ it.key() ] + ":", page );
00198     KLineEdit *lineedit = new KLineEdit( page );
00199     mLineEditDict.insert( it.key(), lineedit );
00200     lineedit->setText( it.data() );
00201     label->setBuddy( lineedit );
00202     layout->addWidget( label, i, 0 );
00203     layout->addWidget( lineedit, i, 1 );
00204   }
00205 
00206   KAcceleratorManager::manage( this );
00207 }
00208 
00209 AttributesDialog::~AttributesDialog()
00210 {
00211 }
00212 
00213 QMap<QString, QString> AttributesDialog::attributes() const
00214 {
00215   QMap<QString, QString> map;
00216 
00217   QDictIterator<KLineEdit> it( mLineEditDict );
00218   for ( ; it.current(); ++it )
00219     map.insert( it.currentKey(), it.current()->text() );
00220 
00221   return map;
00222 }
00223 
00224 void AttributesDialog::mapChanged( int pos )
00225 {
00226   // default map
00227   QMap<QString, QString> defaultMap;
00228   defaultMap.insert( "commonName", "cn" );
00229   defaultMap.insert( "formattedName", "displayName" );
00230   defaultMap.insert( "familyName", "sn" );
00231   defaultMap.insert( "givenName", "givenName" );
00232   defaultMap.insert( "mail", "mail" );
00233   defaultMap.insert( "mailAlias", "" );
00234   defaultMap.insert( "phoneNumber", "telephoneNumber" );
00235   defaultMap.insert( "uid", "uid" );
00236 
00237   // apply first the default and than the spezific changes
00238   QMap<QString, QString>::Iterator it;
00239   for ( it = defaultMap.begin(); it != defaultMap.end(); ++it )
00240     mLineEditDict[ it.key() ]->setText( it.data() );
00241 
00242   for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
00243     if ( !it.data().isEmpty() )
00244       mLineEditDict[ it.key() ]->setText( it.data() );
00245   }
00246 }
00247 
00248 #include "resourceldapkioconfig.moc"
KDE Logo
This file is part of the documentation for kabc Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed May 12 09:09:04 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003