• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

kabc

  • kabc
  • plugins
  • ldapkio
resourceldapkioconfig.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2002 - 2003 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "resourceldapkioconfig.h"
22 #include "resourceldapkio.h"
23 
24 #include <kio/netaccess.h>
25 #include <kacceleratormanager.h>
26 #include <kcombobox.h>
27 #include <kdebug.h>
28 #include <klocale.h>
29 #include <klineedit.h>
30 #include <kmessagebox.h>
31 #include <kpagewidget.h>
32 #include <kvbox.h>
33 
34 #include <QtCore/QPointer>
35 #include <QtGui/QCheckBox>
36 #include <QtGui/QLabel>
37 #include <QtGui/QLayout>
38 #include <QtGui/QPushButton>
39 #include <QtGui/QSpinBox>
40 #include <QtGui/QRadioButton>
41 
42 #include "resourceldapkioconfig.moc"
43 
44 using namespace KABC;
45 
46 ResourceLDAPKIOConfig::ResourceLDAPKIOConfig( QWidget *parent )
47  : KRES::ConfigWidget( parent )
48 {
49  QBoxLayout *mainLayout = new QVBoxLayout( this );
50  mainLayout->setMargin( 0 );
51 
52  KPageWidget *pageWidget = new KPageWidget( this );
53  pageWidget->setFaceType( KPageView::Tabbed );
54 
55  mCfg = new KLDAP::LdapConfigWidget(
56  KLDAP::LdapConfigWidget::W_USER |
57  KLDAP::LdapConfigWidget::W_PASS |
58  KLDAP::LdapConfigWidget::W_BINDDN |
59  KLDAP::LdapConfigWidget::W_REALM |
60  KLDAP::LdapConfigWidget::W_HOST |
61  KLDAP::LdapConfigWidget::W_PORT |
62  KLDAP::LdapConfigWidget::W_VER |
63  KLDAP::LdapConfigWidget::W_DN |
64  KLDAP::LdapConfigWidget::W_FILTER |
65  KLDAP::LdapConfigWidget::W_TIMELIMIT |
66  KLDAP::LdapConfigWidget::W_SIZELIMIT,
67  this );
68 
69  mSecurityCfg = new KLDAP::LdapConfigWidget(
70  KLDAP::LdapConfigWidget::W_SECBOX |
71  KLDAP::LdapConfigWidget::W_AUTHBOX,
72  this );
73 
74  pageWidget->addPage( mCfg,
75  i18nc( "@title:tab general account settings", "General" ) );
76 
77  pageWidget->addPage( mSecurityCfg,
78  i18nc( "@title:tab account security settings", "Security" ) );
79 
80  mSubTree = new QCheckBox( i18n( "Sub-tree query" ), this );
81  KHBox *box = new KHBox( this );
82  box->setSpacing( -1 );
83  mEditButton = new QPushButton( i18n( "Edit Attributes..." ), box );
84  mCacheButton = new QPushButton( i18n( "Offline Use..." ), box );
85 
86  mainLayout->addWidget( pageWidget );
87  mainLayout->addWidget( mSubTree );
88  mainLayout->addWidget( box );
89 
90  connect( mEditButton, SIGNAL(clicked()), SLOT(editAttributes()) );
91  connect( mCacheButton, SIGNAL(clicked()), SLOT(editCache()) );
92 }
93 
94 void ResourceLDAPKIOConfig::loadSettings( KRES::Resource *res )
95 {
96  ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
97 
98  if ( !resource ) {
99  kDebug() << "cast failed";
100  return;
101  }
102 
103  mCfg->setUser( resource->user() );
104  mCfg->setPassword( resource->password() );
105  mCfg->setRealm( resource->realm() );
106  mCfg->setBindDn( resource->bindDN() );
107  mCfg->setHost( resource->host() );
108  mCfg->setPort( resource->port() );
109  mCfg->setVersion( resource->ver() );
110  mCfg->setTimeLimit( resource->timeLimit() );
111  mCfg->setSizeLimit( resource->sizeLimit() );
112  mCfg->setDn( KLDAP::LdapDN( resource->dn() ) );
113  mCfg->setFilter( resource->filter() );
114  mSecurityCfg->setMech( resource->mech() );
115  if ( resource->isTLS() ) {
116  mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::TLS );
117  } else if ( resource->isSSL() ) {
118  mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::SSL );
119  } else {
120  mSecurityCfg->setSecurity( KLDAP::LdapConfigWidget::None );
121  }
122  if ( resource->isAnonymous() ) {
123  mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::Anonymous );
124  } else if ( resource->isSASL() ) {
125  mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::SASL );
126  } else {
127  mSecurityCfg->setAuth( KLDAP::LdapConfigWidget::Simple );
128  }
129  mSubTree->setChecked( resource->isSubTree() );
130  mAttributes = resource->attributes();
131  mRDNPrefix = resource->RDNPrefix();
132  mCachePolicy = resource->cachePolicy();
133  mCacheDst = resource->cacheDst();
134  mAutoCache = resource->autoCache();
135 }
136 
137 void ResourceLDAPKIOConfig::saveSettings( KRES::Resource *res )
138 {
139  ResourceLDAPKIO *resource = dynamic_cast<ResourceLDAPKIO*>( res );
140 
141  if ( !resource ) {
142  kDebug() << "cast failed";
143  return;
144  }
145 
146  resource->setUser( mCfg->user() );
147  resource->setPassword( mCfg->password() );
148  resource->setRealm( mCfg->realm() );
149  resource->setBindDN( mCfg->bindDn() );
150  resource->setHost( mCfg->host() );
151  resource->setPort( mCfg->port() );
152  resource->setVer( mCfg->version() );
153  resource->setTimeLimit( mCfg->timeLimit() );
154  resource->setSizeLimit( mCfg->sizeLimit() );
155  resource->setDn( mCfg->dn().toString() );
156  resource->setFilter( mCfg->filter() );
157  resource->setIsAnonymous( mSecurityCfg->auth() ==
158  KLDAP::LdapConfigWidget::Anonymous );
159  resource->setIsSASL( mSecurityCfg->auth() == KLDAP::LdapConfigWidget::SASL );
160  resource->setMech( mSecurityCfg->mech() );
161  resource->setIsTLS( mSecurityCfg->security() == KLDAP::LdapConfigWidget::TLS );
162  resource->setIsSSL( mSecurityCfg->security() == KLDAP::LdapConfigWidget::SSL );
163  resource->setIsSubTree( mSubTree->isChecked() );
164  resource->setAttributes( mAttributes );
165  resource->setRDNPrefix( mRDNPrefix );
166  resource->setCachePolicy( mCachePolicy );
167  resource->init();
168 
169 }
170 
171 void ResourceLDAPKIOConfig::editAttributes()
172 {
173  QPointer<AttributesDialog> dlg = new AttributesDialog( mAttributes, mRDNPrefix, this );
174  if ( dlg->exec() && dlg ) {
175  mAttributes = dlg->attributes();
176  mRDNPrefix = dlg->rdnprefix();
177  }
178 
179  delete dlg;
180 }
181 
182 void ResourceLDAPKIOConfig::editCache()
183 {
184  KLDAP::LdapUrl src;
185  QStringList attr;
186 
187  src = mCfg->url();
188  src.setScope( mSubTree->isChecked() ? KLDAP::LdapUrl::Sub : KLDAP::LdapUrl::One );
189  if ( !mAttributes.empty() ) {
190  QMap<QString,QString>::Iterator it;
191  QStringList attr;
192  for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
193  if ( !it.value().isEmpty() && it.key() != QLatin1String( "objectClass" ) ) {
194  attr.append( it.value() );
195  }
196  }
197  src.setAttributes( attr );
198  }
199  src.setExtension( QLatin1String( "x-dir" ), QLatin1String( "base" ) );
200 
201  QPointer<OfflineDialog> dlg = new OfflineDialog( mAutoCache, mCachePolicy, src, mCacheDst, this );
202  if ( dlg->exec() && dlg ) {
203  mCachePolicy = dlg->cachePolicy();
204  mAutoCache = dlg->autoCache();
205  }
206 
207  delete dlg;
208 }
209 
210 AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes,
211  int rdnprefix,
212  QWidget *parent )
213  : KDialog( parent )
214 {
215  setCaption( i18n( "Attributes Configuration" ) );
216  setButtons( Ok | Cancel );
217  setDefaultButton( Ok );
218  setModal( true );
219  showButtonSeparator( true );
220 
221  mNameDict.insert( QLatin1String( "objectClass" ), i18n( "Object classes" ) );
222  mNameDict.insert( QLatin1String( "commonName" ), i18n( "Common name" ) );
223  mNameDict.insert( QLatin1String( "formattedName" ), i18n( "Formatted name" ) );
224  mNameDict.insert( QLatin1String( "familyName" ), i18n( "Family name" ) );
225  mNameDict.insert( QLatin1String( "givenName" ), i18n( "Given name" ) );
226  mNameDict.insert( QLatin1String( "organization" ), i18n( "Organization" ) );
227  mNameDict.insert( QLatin1String( "title" ), i18nc( "job title", "Title" ) );
228  mNameDict.insert( QLatin1String( "street" ), i18n( "Street" ) );
229  mNameDict.insert( QLatin1String( "state" ), i18nc( "state/province", "State" ) );
230  mNameDict.insert( QLatin1String( "city" ), i18n( "City" ) );
231  mNameDict.insert( QLatin1String( "postalcode" ), i18n( "Postal code" ) );
232  mNameDict.insert( QLatin1String( "mail" ), i18nc( "email address", "Email" ) );
233  mNameDict.insert( QLatin1String( "mailAlias" ), i18n( "Email alias" ) );
234  mNameDict.insert( QLatin1String( "phoneNumber" ), i18n( "Telephone number" ) );
235  mNameDict.insert( QLatin1String( "telephoneNumber" ), i18n( "Work telephone number" ) );
236  mNameDict.insert( QLatin1String( "facsimileTelephoneNumber" ), i18n( "Fax number" ) );
237  mNameDict.insert( QLatin1String( "mobile" ), i18n( "Cell phone number" ) );
238  mNameDict.insert( QLatin1String( "pager" ), i18n( "Pager" ) );
239  mNameDict.insert( QLatin1String( "description" ), i18n( "Note" ) );
240  mNameDict.insert( QLatin1String( "uid" ), i18n( "UID" ) );
241  mNameDict.insert( QLatin1String( "jpegPhoto" ), i18n( "Photo" ) );
242 
243  // default map
244  mDefaultMap.insert( QLatin1String( "objectClass" ), QLatin1String( "inetOrgPerson" ) );
245  mDefaultMap.insert( QLatin1String( "commonName" ), QLatin1String( "cn" ) );
246  mDefaultMap.insert( QLatin1String( "formattedName" ), QLatin1String( "displayName" ) );
247  mDefaultMap.insert( QLatin1String( "familyName" ), QLatin1String( "sn" ) );
248  mDefaultMap.insert( QLatin1String( "givenName" ), QLatin1String( "givenName" ) );
249  mDefaultMap.insert( QLatin1String( "title" ), QLatin1String( "title" ) );
250  mDefaultMap.insert( QLatin1String( "street" ), QLatin1String( "street" ) );
251  mDefaultMap.insert( QLatin1String( "state" ), QLatin1String( "st" ) );
252  mDefaultMap.insert( QLatin1String( "city" ), QLatin1String( "l" ) );
253  mDefaultMap.insert( QLatin1String( "organization" ), QLatin1String( "o" ) );
254  mDefaultMap.insert( QLatin1String( "postalcode" ), QLatin1String( "postalCode" ) );
255  mDefaultMap.insert( QLatin1String( "mail" ), QLatin1String( "mail" ) );
256  mDefaultMap.insert( QLatin1String( "mailAlias" ), QString() );
257  mDefaultMap.insert( QLatin1String( "phoneNumber" ), QLatin1String( "homePhone" ) );
258  mDefaultMap.insert( QLatin1String( "telephoneNumber" ), QLatin1String( "telephoneNumber" ) );
259  mDefaultMap.insert( QLatin1String( "facsimileTelephoneNumber" ),
260  QLatin1String( "facsimileTelephoneNumber" ) );
261  mDefaultMap.insert( QLatin1String( "mobile" ), QLatin1String( "mobile" ) );
262  mDefaultMap.insert( QLatin1String( "pager" ), QLatin1String( "pager" ) );
263  mDefaultMap.insert( QLatin1String( "description" ), QLatin1String( "description" ) );
264  mDefaultMap.insert( QLatin1String( "uid" ), QLatin1String( "uid" ) );
265  mDefaultMap.insert( QLatin1String( "jpegPhoto" ), QLatin1String( "jpegPhoto" ) );
266 
267  // overwrite the default values here
268  QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap;
269 
270  // kolab
271  kolabMap.insert( QLatin1String( "formattedName" ), QLatin1String( "display-name" ) );
272  kolabMap.insert( QLatin1String( "mailAlias" ), QLatin1String( "mailalias" ) );
273 
274  // evolution
275  evolutionMap.insert( QLatin1String( "formattedName" ), QLatin1String( "fileAs" ) );
276 
277  mMapList.append( attributes );
278  mMapList.append( kolabMap );
279  mMapList.append( netscapeMap );
280  mMapList.append( evolutionMap );
281  mMapList.append( outlookMap );
282 
283  QFrame *page = new QFrame( this );
284  setMainWidget( page );
285  QGridLayout *layout = new QGridLayout( page );
286 
287  QLabel *label = new QLabel( i18n( "Template:" ), page );
288  layout->addWidget( label, 0, 0 );
289  mMapCombo = new KComboBox( page );
290  layout->addWidget( mMapCombo, 0, 1 );
291 
292  mMapCombo->addItem( i18n( "User Defined" ) );
293  mMapCombo->addItem( i18n( "Kolab" ) );
294  mMapCombo->addItem( i18n( "Netscape" ) );
295  mMapCombo->addItem( i18n( "Evolution" ) );
296  mMapCombo->addItem( i18n( "Outlook" ) );
297  connect( mMapCombo, SIGNAL(activated(int)), SLOT(mapChanged(int)) );
298 
299  label = new QLabel( i18n( "RDN prefix attribute:" ), page );
300  layout->addWidget( label, 1, 0 );
301  mRDNCombo = new KComboBox( page );
302  layout->addWidget( mRDNCombo, 1, 1 );
303  mRDNCombo->addItem( i18n( "commonName" ) );
304  mRDNCombo->addItem( i18n( "UID" ) );
305  mRDNCombo->setCurrentIndex( rdnprefix );
306 
307  QMap<QString, QString>::ConstIterator it;
308  int i, j = 0;
309  for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
310  if ( mNameDict[ it.key() ].isEmpty() ) {
311  i--;
312  continue;
313  }
314  if ( ( i - 2 ) == ( mNameDict.count() >> 1 ) ) {
315  i = 0;
316  j = 2;
317  }
318  kDebug() << "itkey:" << it.key() << "i:" << i;
319  label = new QLabel( mNameDict[ it.key() ] + QLatin1Char( ':' ), page );
320  KLineEdit *lineedit = new KLineEdit( page );
321  mLineEditDict.insert( it.key(), lineedit );
322  lineedit->setText( it.value() );
323  label->setBuddy( lineedit );
324  layout->addWidget( label, i, j );
325  layout->addWidget( lineedit, i, j+1 );
326  }
327 
328  for ( i = 1; i < mMapCombo->count(); ++i ) {
329  QHash<QString,KLineEdit*>::const_iterator it2 = mLineEditDict.constBegin();
330  while ( it2 != mLineEditDict.constEnd() ) {
331  if ( mMapList[ i ].contains( it2.key() ) ) {
332  if ( mMapList[ i ][ it2.key() ] != it2.value()->text() ) {
333  break;
334  }
335  } else {
336  if ( mDefaultMap[ it2.key() ] != it2.value()->text() ) {
337  break;
338  }
339  }
340  ++it2;
341  }
342  if ( it2 != mLineEditDict.constEnd() ) {
343  mMapCombo->setCurrentIndex( i );
344  break;
345  }
346  }
347 
348  KAcceleratorManager::manage( this );
349 }
350 
351 AttributesDialog::~AttributesDialog()
352 {
353  mNameDict.clear();
354 }
355 
356 QMap<QString, QString> AttributesDialog::attributes() const
357 {
358  QMap<QString, QString> map;
359 
360  QHash<QString,KLineEdit*>::const_iterator it = mLineEditDict.constBegin();
361  while ( it != mLineEditDict.constEnd() ) {
362  map.insert( it.key(), it.value()->text() );
363  ++it;
364  }
365  return map;
366 }
367 
368 int AttributesDialog::rdnprefix() const
369 {
370  return mRDNCombo->currentIndex();
371 }
372 
373 void AttributesDialog::mapChanged( int pos )
374 {
375 
376  // apply first the default and than the spezific changes
377  QMap<QString, QString>::Iterator it;
378  for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it ) {
379  mLineEditDict[ it.key() ]->setText( it.value() );
380  }
381 
382  for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
383  if ( !it.value().isEmpty() ) {
384  KLineEdit *le = mLineEditDict[ it.key() ];
385  if ( le ) {
386  le->setText( it.value() );
387  }
388  }
389  }
390 }
391 
392 OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KUrl &src,
393  const QString &dst, QWidget *parent )
394  : KDialog( parent )
395 {
396  setCaption( i18n( "Offline Configuration" ) );
397  setButtons( Ok | Cancel );
398  setDefaultButton( Ok );
399  setModal( true );
400  showButtonSeparator( true );
401 
402  QFrame *page = new QFrame( this );
403  setMainWidget( page );
404  QVBoxLayout *layout = new QVBoxLayout( page );
405 
406  mSrc = src;
407  mDst = dst;
408  mCacheBox = new QGroupBox( i18n( "Offline Cache Policy" ), page );
409  QVBoxLayout *cacheBoxLayout = new QVBoxLayout( mCacheBox );
410 
411  mCacheGroup = new QButtonGroup( this );
412 
413  QRadioButton *bt;
414  bt = new QRadioButton( i18n( "Do not use offline cache" ), mCacheBox );
415  cacheBoxLayout->addWidget( bt );
416  bt->setDown(true);
417  mCacheGroup->addButton( bt );
418 
419  bt = new QRadioButton( i18n( "Use local copy if no connection" ), mCacheBox );
420  cacheBoxLayout->addWidget( bt );
421  mCacheGroup->addButton( bt );
422 
423  bt = new QRadioButton( i18n( "Always use local copy" ), mCacheBox );
424  cacheBoxLayout->addWidget( bt );
425  mCacheGroup->addButton( bt );
426 
427  if ( mCacheGroup->button( cachePolicy ) ) {
428  mCacheGroup->button( cachePolicy )->setDown( true );
429  }
430 
431  mAutoCache = new QCheckBox( i18n( "Refresh offline cache automatically" ),
432  page );
433  mAutoCache->setChecked( autoCache );
434  mAutoCache->setEnabled( bt->isChecked() );
435 
436  connect( bt, SIGNAL(toggled(bool)), mAutoCache, SLOT(setEnabled(bool)) );
437 
438  QPushButton *lcache = new QPushButton( i18n( "Load into Cache" ), page );
439  connect( lcache, SIGNAL(clicked()), SLOT(loadCache()) );
440 
441  layout->addWidget( mCacheBox );
442  layout->addWidget( mAutoCache );
443  layout->addWidget( lcache );
444 }
445 
446 OfflineDialog::~OfflineDialog()
447 {
448 }
449 
450 bool OfflineDialog::autoCache() const
451 {
452  return mAutoCache->isChecked();
453 }
454 
455 int OfflineDialog::cachePolicy() const
456 {
457  return mCacheGroup->checkedId();
458 }
459 
460 void OfflineDialog::loadCache()
461 {
462  if ( KIO::NetAccess::download( mSrc, mDst, this ) ) {
463  KMessageBox::information( this,
464  i18n( "Successfully downloaded directory server contents." ) );
465  } else {
466  KMessageBox::error( this,
467  i18n( "An error occurred downloading directory server contents into file %1.", mDst ) );
468  }
469 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Nov 26 2012 16:49:46 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

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

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal