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

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
  • 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