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

kabc

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

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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