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

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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