| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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 #include <qapplication.h>
    00021
    00022 #include <qcheckbox.h>
    00023 #include <qlabel.h>
    00024 #include <qlayout.h>
    00025 #include <qpushbutton.h>
    00026 #include <qspinbox.h>
    00027 #include <qvbox.h>
    00028 #include <qvgroupbox.h>
    00029 #include <qhbuttongroup.h>
    00030 #include <qradiobutton.h>
    00031
    00032 #include <kaccelmanager.h>
    00033 #include <kcombobox.h>
    00034 #include <kdebug.h>
    00035 #include <kdialogbase.h>
    00036 #include <klocale.h>
    00037 #include <klineedit.h>
    00038 #include <kmessagebox.h>
    00039 #include <kio/netaccess.h>
    00040
    00041 #include "resourceldapkio.h"
    00042
    00043 #include "resourceldapkioconfig.h"
    00044 #include "resourceldapkioconfig.moc"
    00045
    00046 using namespace KABC;
    00047
    00048 ResourceLDAPKIOConfig::ResourceLDAPKIOConfig( QWidget* parent,  const char* name )
    00049   : KRES::ConfigWidget( parent, name )
    00050 {
    00051   QBoxLayout *mainLayout = new QVBoxLayout( this );
    00052   mainLayout->setAutoAdd( true );
    00053   cfg = new LdapConfigWidget( LdapConfigWidget::W_ALL, this );
    00054
    00055   mSubTree = new QCheckBox( i18n( "Sub-tree query" ), this );
    00056   QHBox *box = new QHBox( this );
    00057   box->setSpacing( KDialog::spacingHint() );
    00058   mEditButton = new QPushButton( i18n( "Edit Attributes..." ), box );
    00059   mCacheButton = new QPushButton( i18n( "Offline Use..." ), box );
    00060
    00061   connect( mEditButton, SIGNAL( clicked() ), SLOT( editAttributes() ) );
    00062   connect( mCacheButton, SIGNAL( clicked() ), SLOT( editCache() ) );
    00063 }
    00064
    00065 void ResourceLDAPKIOConfig::loadSettings( KRES::Resource *res )
    00066 {
    00067   ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
    00068
    00069   if ( !resource ) {
    00070     kdDebug(5700) << "ResourceLDAPKIOConfig::loadSettings(): cast failed" << endl;
    00071     return;
    00072   }
    00073
    00074   cfg->setUser( resource->user() );
    00075   cfg->setPassword( resource->password() );
    00076   cfg->setRealm( resource->realm() );
    00077   cfg->setBindDN( resource->bindDN() );
    00078   cfg->setHost( resource->host() );
    00079   cfg->setPort(  resource->port() );
    00080   cfg->setVer(  resource->ver() );
    00081   cfg->setTimeLimit( resource->timeLimit() );
    00082   cfg->setSizeLimit( resource->sizeLimit() );
    00083   cfg->setDn( resource->dn() );
    00084   cfg->setFilter( resource->filter() );
    00085   cfg->setMech( resource->mech() );
    00086   if ( resource->isTLS() ) cfg->setSecTLS();
    00087   else if ( resource->isSSL() ) cfg->setSecSSL();
    00088   else cfg->setSecNO();
    00089   if ( resource->isAnonymous() ) cfg->setAuthAnon();
    00090   else if ( resource->isSASL() ) cfg->setAuthSASL();
    00091   else cfg->setAuthSimple();
    00092
    00093   mSubTree->setChecked( resource->isSubTree() );
    00094   mAttributes = resource->attributes();
    00095   mRDNPrefix = resource->RDNPrefix();
    00096   mCachePolicy = resource->cachePolicy();
    00097   mCacheDst = resource->cacheDst();
    00098   mAutoCache = resource->autoCache();
    00099 }
    00100
    00101 void ResourceLDAPKIOConfig::saveSettings( KRES::Resource *res )
    00102 {
    00103   ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
    00104
    00105   if ( !resource ) {
    00106     kdDebug(5700) << "ResourceLDAPKIOConfig::saveSettings(): cast failed" << endl;
    00107     return;
    00108   }
    00109
    00110   resource->setUser( cfg->user() );
    00111   resource->setPassword( cfg->password() );
    00112   resource->setRealm( cfg->realm() );
    00113   resource->setBindDN( cfg->bindDN() );
    00114   resource->setHost( cfg->host() );
    00115   resource->setPort( cfg->port() );
    00116   resource->setVer( cfg->ver() );
    00117   resource->setTimeLimit( cfg->timeLimit() );
    00118   resource->setSizeLimit( cfg->sizeLimit() );
    00119   resource->setDn( cfg->dn() );
    00120   resource->setFilter( cfg->filter() );
    00121   resource->setIsAnonymous( cfg->isAuthAnon() );
    00122   resource->setIsSASL( cfg->isAuthSASL() );
    00123   resource->setMech( cfg->mech() );
    00124   resource->setIsTLS( cfg->isSecTLS() );
    00125   resource->setIsSSL( cfg->isSecSSL() );
    00126   resource->setIsSubTree( mSubTree->isChecked() );
    00127   resource->setAttributes( mAttributes );
    00128   resource->setRDNPrefix( mRDNPrefix );
    00129   resource->setCachePolicy( mCachePolicy );
    00130   resource->init();
    00131
    00132 }
    00133
    00134 void ResourceLDAPKIOConfig::editAttributes()
    00135 {
    00136   AttributesDialog dlg( mAttributes, mRDNPrefix, this );
    00137   if ( dlg.exec() ) {
    00138     mAttributes = dlg.attributes();
    00139     mRDNPrefix = dlg.rdnprefix();
    00140   }
    00141 }
    00142
    00143 void ResourceLDAPKIOConfig::editCache()
    00144 {
    00145   LDAPUrl src;
    00146   QStringList attr;
    00147
    00148   src = cfg->url();
    00149   src.setScope( mSubTree->isChecked() ? LDAPUrl::Sub : LDAPUrl::One );
    00150   if (!mAttributes.empty()) {
    00151     QMap<QString,QString>::Iterator it;
    00152     QStringList attr;
    00153     for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
    00154       if ( !it.data().isEmpty() && it.key() != "objectClass" )
    00155         attr.append( it.data() );
    00156     }
    00157     src.setAttributes( attr );
    00158   }
    00159   src.setExtension( "x-dir", "base" );
    00160   OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this );
    00161   if ( dlg.exec() ) {
    00162     mCachePolicy = dlg.cachePolicy();
    00163     mAutoCache = dlg.autoCache();
    00164   }
    00165
    00166 }
    00167
    00168 AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes,
    00169                                     int rdnprefix,
    00170                                     QWidget *parent, const char *name )
    00171   : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel,
    00172                  Ok, parent, name, true, true )
    00173 {
    00174   mNameDict.setAutoDelete( true );
    00175   mNameDict.insert( "objectClass", new QString( i18n( "Object classes" ) ) );
    00176   mNameDict.insert( "commonName", new QString( i18n( "Common name" ) ) );
    00177   mNameDict.insert( "formattedName", new QString( i18n( "Formatted name" ) ) );
    00178   mNameDict.insert( "familyName", new QString( i18n( "Family name" ) ) );
    00179   mNameDict.insert( "givenName", new QString( i18n( "Given name" ) ) );
    00180   mNameDict.insert( "organization", new QString( i18n( "Organization" ) ) );
    00181   mNameDict.insert( "title", new QString( i18n( "Title" ) ) );
    00182   mNameDict.insert( "street", new QString( i18n( "Street" ) ) );
    00183   mNameDict.insert( "state", new QString( i18n( "State" ) ) );
    00184   mNameDict.insert( "city", new QString( i18n( "City" ) ) );
    00185   mNameDict.insert( "postalcode", new QString( i18n( "Postal code" ) ) );
    00186   mNameDict.insert( "mail", new QString( i18n( "Email" ) ) );
    00187   mNameDict.insert( "mailAlias", new QString( i18n( "Email alias" ) ) );
    00188   mNameDict.insert( "phoneNumber", new QString( i18n( "Telephone number" ) ) );
    00189   mNameDict.insert( "telephoneNumber", new QString( i18n( "Work telephone number" ) ) );
    00190   mNameDict.insert( "facsimileTelephoneNumber", new QString( i18n( "Fax number" ) ) );
    00191   mNameDict.insert( "mobile", new QString( i18n( "Cell phone number" ) ) );
    00192   mNameDict.insert( "pager", new QString( i18n( "Pager" ) ) );
    00193   mNameDict.insert( "description", new QString( i18n( "Note" ) ) );
    00194   mNameDict.insert( "uid", new QString( i18n( "UID" ) ) );
    00195   mNameDict.insert( "jpegPhoto", new QString( i18n( "Photo" ) ) );
    00196
    00197   // default map
    00198   mDefaultMap.insert( "objectClass", "inetOrgPerson" );
    00199   mDefaultMap.insert( "commonName", "cn" );
    00200   mDefaultMap.insert( "formattedName", "displayName" );
    00201   mDefaultMap.insert( "familyName", "sn" );
    00202   mDefaultMap.insert( "givenName", "givenName" );
    00203   mDefaultMap.insert( "title", "title" );
    00204   mDefaultMap.insert( "street", "street" );
    00205   mDefaultMap.insert( "state", "st" );
    00206   mDefaultMap.insert( "city", "l" );
    00207   mDefaultMap.insert( "organization", "o" );
    00208   mDefaultMap.insert( "postalcode", "postalCode" );
    00209   mDefaultMap.insert( "mail", "mail" );
    00210   mDefaultMap.insert( "mailAlias", "" );
    00211   mDefaultMap.insert( "phoneNumber", "homePhone" );
    00212   mDefaultMap.insert( "telephoneNumber", "telephoneNumber" );
    00213   mDefaultMap.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" );
    00214   mDefaultMap.insert( "mobile", "mobile" );
    00215   mDefaultMap.insert( "pager", "pager" );
    00216   mDefaultMap.insert( "description", "description" );
    00217   mDefaultMap.insert( "uid", "uid" );
    00218   mDefaultMap.insert( "jpegPhoto", "jpegPhoto" );
    00219
    00220   // overwrite the default values here
    00221   QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap;
    00222
    00223   // kolab
    00224   kolabMap.insert( "formattedName", "display-name" );
    00225   kolabMap.insert( "mailAlias", "mailalias" );
    00226
    00227   // evolution
    00228   evolutionMap.insert( "formattedName", "fileAs" );
    00229
    00230   mMapList.append( attributes );
    00231   mMapList.append( kolabMap );
    00232   mMapList.append( netscapeMap );
    00233   mMapList.append( evolutionMap );
    00234   mMapList.append( outlookMap );
    00235
    00236   QFrame *page = plainPage();
    00237   QGridLayout *layout = new QGridLayout( page, 4, ( attributes.count() + 4 ) >> 1,
    00238                                          0, spacingHint() );
    00239
    00240   QLabel *label = new QLabel( i18n( "Template:" ), page );
    00241   layout->addWidget( label, 0, 0 );
    00242   mMapCombo = new KComboBox( page );
    00243   layout->addWidget( mMapCombo, 0, 1 );
    00244
    00245   mMapCombo->insertItem( i18n( "User Defined" ) );
    00246   mMapCombo->insertItem( i18n( "Kolab" ) );
    00247   mMapCombo->insertItem( i18n( "Netscape" ) );
    00248   mMapCombo->insertItem( i18n( "Evolution" ) );
    00249   mMapCombo->insertItem( i18n( "Outlook" ) );
    00250   connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) );
    00251
    00252   label = new QLabel( i18n( "RDN prefix attribute:" ), page );
    00253   layout->addWidget( label, 1, 0 );
    00254   mRDNCombo = new KComboBox( page );
    00255   layout->addWidget( mRDNCombo, 1, 1 );
    00256   mRDNCombo->insertItem( i18n( "commonName" ) );
    00257   mRDNCombo->insertItem( i18n( "UID" ) );
    00258   mRDNCombo->setCurrentItem( rdnprefix );
    00259
    00260   QMap<QString, QString>::ConstIterator it;
    00261   int i, j = 0;
    00262   for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
    00263     if ( mNameDict[ it.key() ] == 0 ) {
    00264       i--;
    00265       continue;
    00266     }
    00267     if ( (uint)(i - 2) == ( mNameDict.count()  >> 1 ) ) {
    00268       i = 0;
    00269       j = 2;
    00270     }
    00271     kdDebug(7125) << "itkey: " << it.key() << " i: " << i << endl;
    00272     label = new QLabel( *mNameDict[ it.key() ] + ":", page );
    00273     KLineEdit *lineedit = new KLineEdit( page );
    00274     mLineEditDict.insert( it.key(), lineedit );
    00275     lineedit->setText( it.data() );
    00276     label->setBuddy( lineedit );
    00277     layout->addWidget( label, i, j );
    00278     layout->addWidget( lineedit, i, j+1 );
    00279   }
    00280
    00281   for ( i = 1; i < mMapCombo->count(); i++ ) {
    00282     QDictIterator<KLineEdit> it2( mLineEditDict );
    00283     for ( ; it2.current(); ++it2 ) {
    00284       if ( mMapList[ i ].contains( it2.currentKey() ) ) {
    00285         if ( mMapList[ i ][ it2.currentKey() ] != it2.current()->text() ) break;
    00286       } else {
    00287         if ( mDefaultMap[ it2.currentKey() ] != it2.current()->text() ) break;
    00288       }
    00289     }
    00290     if ( !it2.current() ) {
    00291       mMapCombo->setCurrentItem( i );
    00292       break;
    00293     }
    00294   }
    00295
    00296   KAcceleratorManager::manage( this );
    00297 }
    00298
    00299 AttributesDialog::~AttributesDialog()
    00300 {
    00301 }
    00302
    00303 QMap<QString, QString> AttributesDialog::attributes() const
    00304 {
    00305   QMap<QString, QString> map;
    00306
    00307   QDictIterator<KLineEdit> it( mLineEditDict );
    00308   for ( ; it.current(); ++it )
    00309     map.insert( it.currentKey(), it.current()->text() );
    00310
    00311   return map;
    00312 }
    00313
    00314 int AttributesDialog::rdnprefix() const
    00315 {
    00316   return mRDNCombo->currentItem();
    00317 }
    00318
    00319 void AttributesDialog::mapChanged( int pos )
    00320 {
    00321
    00322   // apply first the default and than the spezific changes
    00323   QMap<QString, QString>::Iterator it;
    00324   for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it )
    00325     mLineEditDict[ it.key() ]->setText( it.data() );
    00326
    00327   for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
    00328     if ( !it.data().isEmpty() ) {
    00329       KLineEdit *le = mLineEditDict[ it.key() ];
    00330       if ( le ) le->setText( it.data() );
    00331     }
    00332   }
    00333 }
    00334
    00335 OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KURL &src,
    00336   const QString &dst, QWidget *parent, const char *name )
    00337   : KDialogBase( Plain, i18n( "Offline Configuration" ), Ok | Cancel,
    00338                  Ok, parent, name, true, true )
    00339 {
    00340   QFrame *page = plainPage();
    00341   QVBoxLayout *layout = new QVBoxLayout( page );
    00342   layout->setAutoAdd( true );
    00343
    00344   mSrc = src; mDst = dst;
    00345   mCacheGroup = new QButtonGroup( 1, Qt::Horizontal,
    00346     i18n("Offline Cache Policy"), page );
    00347
    00348   QRadioButton *bt;
    00349   new QRadioButton( i18n("Do not use offline cache"), mCacheGroup );
    00350   bt = new QRadioButton( i18n("Use local copy if no connection"), mCacheGroup );
    00351   new QRadioButton( i18n("Always use local copy"), mCacheGroup );
    00352   mCacheGroup->setButton( cachePolicy );
    00353
    00354   mAutoCache = new QCheckBox( i18n("Refresh offline cache automatically"),
    00355     page );
    00356   mAutoCache->setChecked( autoCache );
    00357   mAutoCache->setEnabled( bt->isChecked() );
    00358
    00359   connect( bt, SIGNAL(toggled(bool)), mAutoCache, SLOT(setEnabled(bool)) );
    00360
    00361   QPushButton *lcache = new QPushButton( i18n("Load into Cache"), page );
    00362   connect( lcache, SIGNAL( clicked() ), SLOT( loadCache() ) );
    00363 }
    00364
    00365 OfflineDialog::~OfflineDialog()
    00366 {
    00367 }
    00368
    00369 bool OfflineDialog::autoCache() const
    00370 {
    00371   return mAutoCache->isChecked();
    00372 }
    00373
    00374 int OfflineDialog::cachePolicy() const
    00375 {
    00376   return mCacheGroup->selectedId();
    00377 }
    00378
    00379 void OfflineDialog::loadCache()
    00380 {
    00381   if ( KIO::NetAccess::download( mSrc, mDst, this ) ) {
    00382     KMessageBox::information( this,
    00383       i18n("Successfully downloaded directory server contents!") );
    00384   } else {
    00385     KMessageBox::error( this,
    00386       i18n("An error occurred downloading directory server contents into file %1.").arg(mDst) );
    00387   }
    00388 }

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:31 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003