• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kabc

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., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "resourceldapkioconfig.h"
00022 #include "resourceldapkio.h"
00023 
00024 #include <kio/netaccess.h>
00025 #include <kacceleratormanager.h>
00026 #include <kcombobox.h>
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029 #include <klineedit.h>
00030 #include <kmessagebox.h>
00031 #include <kpagewidget.h>
00032 #include <kvbox.h>
00033 
00034 #include <QtGui/QCheckBox>
00035 #include <QtGui/QLabel>
00036 #include <QtGui/QLayout>
00037 #include <QtGui/QPushButton>
00038 #include <QtGui/QSpinBox>
00039 #include <QtGui/QRadioButton>
00040 
00041 #include "resourceldapkioconfig.moc"
00042 
00043 using namespace KABC;
00044 
00045 ResourceLDAPKIOConfig::ResourceLDAPKIOConfig( QWidget *parent )
00046   : KRES::ConfigWidget( parent )
00047 {
00048   QBoxLayout *mainLayout = new QVBoxLayout( this );
00049   mainLayout->setMargin( 0 );
00050   mainLayout->setSpacing( KDialog::spacingHint() );
00051 
00052   KPageWidget *pageWidget = new KPageWidget( this );
00053   pageWidget->setFaceType( KPageView::Tabbed );
00054 
00055   mCfg = new KLDAP::LdapConfigWidget(
00056         KLDAP::LdapConfigWidget::W_USER |
00057         KLDAP::LdapConfigWidget::W_PASS |
00058         KLDAP::LdapConfigWidget::W_BINDDN |
00059         KLDAP::LdapConfigWidget::W_REALM |
00060         KLDAP::LdapConfigWidget::W_HOST |
00061         KLDAP::LdapConfigWidget::W_PORT |
00062         KLDAP::LdapConfigWidget::W_VER |
00063         KLDAP::LdapConfigWidget::W_DN |
00064         KLDAP::LdapConfigWidget::W_FILTER |
00065         KLDAP::LdapConfigWidget::W_TIMELIMIT |
00066         KLDAP::LdapConfigWidget::W_SIZELIMIT,
00067         this );
00068 
00069   mSecurityCfg = new KLDAP::LdapConfigWidget(
00070         KLDAP::LdapConfigWidget::W_SECBOX |
00071         KLDAP::LdapConfigWidget::W_AUTHBOX,
00072         this );
00073 
00074   pageWidget->addPage( mCfg,
00075                        i18nc( "@title:tab general account settings", "General" ) );
00076 
00077   pageWidget->addPage( mSecurityCfg,
00078                        i18nc( "@title:tab account security settings", "Security" ) );
00079 
00080   mSubTree = new QCheckBox( i18n( "Sub-tree query" ), this );
00081   KHBox *box = new KHBox( this );
00082   box->setSpacing( KDialog::spacingHint() );
00083   mEditButton = new QPushButton( i18n( "Edit Attributes..." ), box );
00084   mCacheButton = new QPushButton( i18n( "Offline Use..." ), box );
00085 
00086   mainLayout->addWidget( pageWidget );
00087   mainLayout->addWidget( mSubTree );
00088   mainLayout->addWidget( box );
00089 
00090   connect( mEditButton, SIGNAL( clicked() ), SLOT( editAttributes() ) );
00091   connect( mCacheButton, SIGNAL( clicked() ), SLOT( editCache() ) );
00092 }
00093 
00094 void ResourceLDAPKIOConfig::loadSettings( KRES::Resource *res )
00095 {
00096   ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
00097 
00098   if ( !resource ) {
00099     kDebug() << "cast failed";
00100     return;
00101   }
00102 
00103   mCfg->setUser( resource->user() );
00104   mCfg->setPassword( resource->password() );
00105   mCfg->setRealm( resource->realm() );
00106   mCfg->setBindDn( resource->bindDN() );
00107   mCfg->setHost( resource->host() );
00108   mCfg->setPort( resource->port() );
00109   mCfg->setVersion( resource->ver() );
00110   mCfg->setTimeLimit( resource->timeLimit() );
00111   mCfg->setSizeLimit( resource->sizeLimit() );
00112   mCfg->setDn( KLDAP::LdapDN( resource->dn() ) );
00113   mCfg->setFilter( resource->filter() );
00114   mSecurityCfg->setMech( resource->mech() );
00115   if ( resource->isTLS() ) {
00116     mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::TLS );
00117   } else if ( resource->isSSL() ) {
00118     mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::SSL );
00119   } else {
00120     mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::None );
00121   }
00122   if ( resource->isAnonymous() ) {
00123     mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::Anonymous );
00124   } else if ( resource->isSASL() ) {
00125     mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::SASL );
00126   } else {
00127     mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::Simple );
00128   }
00129   mSubTree->setChecked( resource->isSubTree() );
00130   mAttributes = resource->attributes();
00131   mRDNPrefix = resource->RDNPrefix();
00132   mCachePolicy = resource->cachePolicy();
00133   mCacheDst = resource->cacheDst();
00134   mAutoCache = resource->autoCache();
00135 }
00136 
00137 void ResourceLDAPKIOConfig::saveSettings( KRES::Resource *res )
00138 {
00139   ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
00140 
00141   if ( !resource ) {
00142     kDebug() << "cast failed";
00143     return;
00144   }
00145 
00146   resource->setUser( mCfg->user() );
00147   resource->setPassword( mCfg->password() );
00148   resource->setRealm( mCfg->realm() );
00149   resource->setBindDN( mCfg->bindDn() );
00150   resource->setHost( mCfg->host() );
00151   resource->setPort( mCfg->port() );
00152   resource->setVer( mCfg->version() );
00153   resource->setTimeLimit( mCfg->timeLimit() );
00154   resource->setSizeLimit( mCfg->sizeLimit() );
00155   resource->setDn( mCfg->dn().toString() );
00156   resource->setFilter( mCfg->filter() );
00157   resource->setIsAnonymous( mSecurityCfg->auth() ==
00158                             KLDAP::LdapConfigWidget::Anonymous );
00159   resource->setIsSASL( mSecurityCfg->auth() == KLDAP::LdapConfigWidget::SASL );
00160   resource->setMech( mSecurityCfg->mech() );
00161   resource->setIsTLS( mSecurityCfg->security() == KLDAP::LdapConfigWidget::TLS );
00162   resource->setIsSSL( mSecurityCfg->security() == KLDAP::LdapConfigWidget::SSL );
00163   resource->setIsSubTree( mSubTree->isChecked() );
00164   resource->setAttributes( mAttributes );
00165   resource->setRDNPrefix( mRDNPrefix );
00166   resource->setCachePolicy( mCachePolicy );
00167   resource->init();
00168 
00169 }
00170 
00171 void ResourceLDAPKIOConfig::editAttributes()
00172 {
00173   AttributesDialog dlg( mAttributes, mRDNPrefix, this );
00174   if ( dlg.exec() ) {
00175     mAttributes = dlg.attributes();
00176     mRDNPrefix = dlg.rdnprefix();
00177   }
00178 }
00179 
00180 void ResourceLDAPKIOConfig::editCache()
00181 {
00182   KLDAP::LdapUrl src;
00183   QStringList attr;
00184 
00185   src = mCfg->url();
00186   src.setScope( mSubTree->isChecked() ? KLDAP::LdapUrl::Sub : KLDAP::LdapUrl::One );
00187   if ( !mAttributes.empty() ) {
00188     QMap<QString,QString>::Iterator it;
00189     QStringList attr;
00190     for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
00191       if ( !it.value().isEmpty() && it.key() != "objectClass" ) {
00192         attr.append( it.value() );
00193       }
00194     }
00195     src.setAttributes( attr );
00196   }
00197   src.setExtension( "x-dir", "base" );
00198   OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this );
00199   if ( dlg.exec() ) {
00200     mCachePolicy = dlg.cachePolicy();
00201     mAutoCache = dlg.autoCache();
00202   }
00203 
00204 }
00205 
00206 AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes,
00207                                     int rdnprefix,
00208                                     QWidget *parent )
00209   : KDialog( parent )
00210 {
00211   setCaption( i18n( "Attributes Configuration" ) );
00212   setButtons( Ok | Cancel );
00213   setDefaultButton( Ok );
00214   setModal( true );
00215   showButtonSeparator( true );
00216 
00217   mNameDict.insert( "objectClass", i18n( "Object classes" ) );
00218   mNameDict.insert( "commonName", i18n( "Common name" ) );
00219   mNameDict.insert( "formattedName", i18n( "Formatted name" ) );
00220   mNameDict.insert( "familyName", i18n( "Family name" ) );
00221   mNameDict.insert( "givenName", i18n( "Given name" ) );
00222   mNameDict.insert( "organization", i18n( "Organization" ) );
00223   mNameDict.insert( "title", i18nc( "job title", "Title" ) );
00224   mNameDict.insert( "street", i18n( "Street" ) );
00225   mNameDict.insert( "state", i18nc( "state/province", "State" ) );
00226   mNameDict.insert( "city", i18n( "City" ) );
00227   mNameDict.insert( "postalcode", i18n( "Postal code" ) );
00228   mNameDict.insert( "mail", i18nc( "email address", "Email" ) );
00229   mNameDict.insert( "mailAlias", i18n( "Email alias" ) );
00230   mNameDict.insert( "phoneNumber", i18n( "Telephone number" ) );
00231   mNameDict.insert( "telephoneNumber", i18n( "Work telephone number" ) );
00232   mNameDict.insert( "facsimileTelephoneNumber", i18n( "Fax number" ) );
00233   mNameDict.insert( "mobile", i18n( "Cell phone number" ) );
00234   mNameDict.insert( "pager", i18n( "Pager" ) );
00235   mNameDict.insert( "description", i18n( "Note" ) );
00236   mNameDict.insert( "uid", i18n( "UID" ) );
00237   mNameDict.insert( "jpegPhoto", i18n( "Photo" ) );
00238 
00239   // default map
00240   mDefaultMap.insert( "objectClass", "inetOrgPerson" );
00241   mDefaultMap.insert( "commonName", "cn" );
00242   mDefaultMap.insert( "formattedName", "displayName" );
00243   mDefaultMap.insert( "familyName", "sn" );
00244   mDefaultMap.insert( "givenName", "givenName" );
00245   mDefaultMap.insert( "title", "title" );
00246   mDefaultMap.insert( "street", "street" );
00247   mDefaultMap.insert( "state", "st" );
00248   mDefaultMap.insert( "city", "l" );
00249   mDefaultMap.insert( "organization", "o" );
00250   mDefaultMap.insert( "postalcode", "postalCode" );
00251   mDefaultMap.insert( "mail", "mail" );
00252   mDefaultMap.insert( "mailAlias", "" );
00253   mDefaultMap.insert( "phoneNumber", "homePhone" );
00254   mDefaultMap.insert( "telephoneNumber", "telephoneNumber" );
00255   mDefaultMap.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" );
00256   mDefaultMap.insert( "mobile", "mobile" );
00257   mDefaultMap.insert( "pager", "pager" );
00258   mDefaultMap.insert( "description", "description" );
00259   mDefaultMap.insert( "uid", "uid" );
00260   mDefaultMap.insert( "jpegPhoto", "jpegPhoto" );
00261 
00262   // overwrite the default values here
00263   QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap;
00264 
00265   // kolab
00266   kolabMap.insert( "formattedName", "display-name" );
00267   kolabMap.insert( "mailAlias", "mailalias" );
00268 
00269   // evolution
00270   evolutionMap.insert( "formattedName", "fileAs" );
00271 
00272   mMapList.append( attributes );
00273   mMapList.append( kolabMap );
00274   mMapList.append( netscapeMap );
00275   mMapList.append( evolutionMap );
00276   mMapList.append( outlookMap );
00277 
00278   QFrame *page = new QFrame( this );
00279   setMainWidget( page );
00280   QGridLayout *layout = new QGridLayout( page );
00281 
00282   QLabel *label = new QLabel( i18n( "Template:" ), page );
00283   layout->addWidget( label, 0, 0 );
00284   mMapCombo = new KComboBox( page );
00285   layout->addWidget( mMapCombo, 0, 1 );
00286 
00287   mMapCombo->addItem( i18n( "User Defined" ) );
00288   mMapCombo->addItem( i18n( "Kolab" ) );
00289   mMapCombo->addItem( i18n( "Netscape" ) );
00290   mMapCombo->addItem( i18n( "Evolution" ) );
00291   mMapCombo->addItem( i18n( "Outlook" ) );
00292   connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) );
00293 
00294   label = new QLabel( i18n( "RDN prefix attribute:" ), page );
00295   layout->addWidget( label, 1, 0 );
00296   mRDNCombo = new KComboBox( page );
00297   layout->addWidget( mRDNCombo, 1, 1 );
00298   mRDNCombo->addItem( i18n( "commonName" ) );
00299   mRDNCombo->addItem( i18n( "UID" ) );
00300   mRDNCombo->setCurrentIndex( rdnprefix );
00301 
00302   QMap<QString, QString>::ConstIterator it;
00303   int i, j = 0;
00304   for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
00305     if ( mNameDict[ it.key() ] == 0 ) {
00306       i--;
00307       continue;
00308     }
00309     if ( ( i - 2 ) == ( mNameDict.count() >> 1 ) ) {
00310       i = 0;
00311       j = 2;
00312     }
00313     kDebug() << "itkey:" << it.key() << "i:" << i;
00314     label = new QLabel( mNameDict[ it.key() ] + ':', page );
00315     KLineEdit *lineedit = new KLineEdit( page );
00316     mLineEditDict.insert( it.key(), lineedit );
00317     lineedit->setText( it.value() );
00318     label->setBuddy( lineedit );
00319     layout->addWidget( label, i, j );
00320     layout->addWidget( lineedit, i, j+1 );
00321   }
00322 
00323   for ( i = 1; i < mMapCombo->count(); ++i ) {
00324     QHash<QString,KLineEdit*>::const_iterator it2 = mLineEditDict.constBegin();
00325     while ( it2 != mLineEditDict.constEnd() ) {
00326       if ( mMapList[ i ].contains( it2.key() ) ) {
00327         if ( mMapList[ i ][ it2.key() ] != it2.value()->text() ) {
00328           break;
00329         }
00330       } else {
00331         if ( mDefaultMap[ it2.key() ] != it2.value()->text() ) {
00332           break;
00333         }
00334       }
00335       ++it2;
00336     }
00337     if ( it2 != mLineEditDict.constEnd() ) {
00338       mMapCombo->setCurrentIndex( i );
00339       break;
00340     }
00341   }
00342 
00343   KAcceleratorManager::manage( this );
00344 }
00345 
00346 AttributesDialog::~AttributesDialog()
00347 {
00348   mNameDict.clear();
00349 }
00350 
00351 QMap<QString, QString> AttributesDialog::attributes() const
00352 {
00353   QMap<QString, QString> map;
00354 
00355   QHash<QString,KLineEdit*>::const_iterator it = mLineEditDict.constBegin();
00356   while ( it != mLineEditDict.constEnd() ) {
00357     map.insert( it.key(), it.value()->text() );
00358     ++it;
00359   }
00360   return map;
00361 }
00362 
00363 int AttributesDialog::rdnprefix() const
00364 {
00365   return mRDNCombo->currentIndex();
00366 }
00367 
00368 void AttributesDialog::mapChanged( int pos )
00369 {
00370 
00371   // apply first the default and than the spezific changes
00372   QMap<QString, QString>::Iterator it;
00373   for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it ) {
00374     mLineEditDict[ it.key() ]->setText( it.value() );
00375   }
00376 
00377   for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
00378     if ( !it.value().isEmpty() ) {
00379       KLineEdit *le = mLineEditDict[ it.key() ];
00380       if ( le ) {
00381         le->setText( it.value() );
00382       }
00383     }
00384   }
00385 }
00386 
00387 OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KUrl &src,
00388   const QString &dst, QWidget *parent )
00389   : KDialog( parent )
00390 {
00391   setCaption( i18n( "Offline Configuration" ) );
00392   setButtons( Ok | Cancel );
00393   setDefaultButton( Ok );
00394   setModal( true );
00395   showButtonSeparator( true );
00396 
00397   QFrame *page = new QFrame( this );
00398   setMainWidget( page );
00399   QVBoxLayout *layout = new QVBoxLayout( page );
00400 
00401   mSrc = src;
00402   mDst = dst;
00403   mCacheBox = new QGroupBox( i18n( "Offline Cache Policy" ), page );
00404   QVBoxLayout *cacheBoxLayout = new QVBoxLayout( mCacheBox );
00405 
00406   mCacheGroup = new QButtonGroup( this );
00407 
00408   QRadioButton *bt;
00409   bt = new QRadioButton( i18n( "Do not use offline cache" ), mCacheBox );
00410   cacheBoxLayout->addWidget( bt );
00411   bt->setDown(true);
00412   mCacheGroup->addButton( bt );
00413 
00414   bt = new QRadioButton( i18n( "Use local copy if no connection" ), mCacheBox );
00415   cacheBoxLayout->addWidget( bt );
00416   mCacheGroup->addButton( bt );
00417 
00418   bt = new QRadioButton( i18n( "Always use local copy" ), mCacheBox );
00419   cacheBoxLayout->addWidget( bt );
00420   mCacheGroup->addButton( bt );
00421 
00422   if ( mCacheGroup->button( cachePolicy ) ) {
00423     mCacheGroup->button( cachePolicy )->setDown( true );
00424   }
00425 
00426   mAutoCache = new QCheckBox( i18n( "Refresh offline cache automatically" ),
00427     page );
00428   mAutoCache->setChecked( autoCache );
00429   mAutoCache->setEnabled( bt->isChecked() );
00430 
00431   connect( bt, SIGNAL(toggled(bool)), mAutoCache, SLOT(setEnabled(bool)) );
00432 
00433   QPushButton *lcache = new QPushButton( i18n( "Load into Cache" ), page );
00434   connect( lcache, SIGNAL( clicked() ), SLOT( loadCache() ) );
00435 
00436   layout->addWidget( mCacheBox );
00437   layout->addWidget( mAutoCache );
00438   layout->addWidget( lcache );
00439 }
00440 
00441 OfflineDialog::~OfflineDialog()
00442 {
00443 }
00444 
00445 bool OfflineDialog::autoCache() const
00446 {
00447   return mAutoCache->isChecked();
00448 }
00449 
00450 int OfflineDialog::cachePolicy() const
00451 {
00452   return mCacheGroup->checkedId();
00453 }
00454 
00455 void OfflineDialog::loadCache()
00456 {
00457   if ( KIO::NetAccess::download( mSrc, mDst, this ) ) {
00458     KMessageBox::information( this,
00459       i18n( "Successfully downloaded directory server contents." ) );
00460   } else {
00461     KMessageBox::error( this,
00462       i18n( "An error occurred downloading directory server contents into file %1.", mDst ) );
00463   }
00464 }

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal