• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <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
42using namespace KABC;
43
44ResourceLDAPKIOConfig::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
80void 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
123void 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
157void 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
168void 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
196AttributesDialog::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> kolab2Map, kolab3Map, netscapeMap, evolutionMap, outlookMap;
255
256 // Kolab 2
257 kolab2Map.insert( QLatin1String( "formattedName" ), QLatin1String( "display-name" ) );
258 kolab2Map.insert( QLatin1String( "mailAlias" ), QLatin1String( "mailalias" ) );
259 // Kolab 3
260 kolab3Map.insert( QLatin1String( "mailAlias" ), QLatin1String( "alias" ) );
261
262 // evolution
263 evolutionMap.insert( QLatin1String( "formattedName" ), QLatin1String( "fileAs" ) );
264
265 mMapList.append( attributes );
266 mMapList.append( kolab2Map );
267 mMapList.append( kolab3Map );
268 mMapList.append( netscapeMap );
269 mMapList.append( evolutionMap );
270 mMapList.append( outlookMap );
271
272 QFrame *page = new QFrame( this );
273 setMainWidget( page );
274 QGridLayout *layout = new QGridLayout( page );
275
276 QLabel *label = new QLabel( i18n( "Template:" ), page );
277 layout->addWidget( label, 0, 0 );
278 mMapCombo = new KComboBox( page );
279 layout->addWidget( mMapCombo, 0, 1 );
280
281 mMapCombo->addItem( i18n( "User Defined" ) );
282 mMapCombo->addItem( i18n( "Kolab 2" ) );
283 mMapCombo->addItem( i18n( "Kolab 3" ) );
284 mMapCombo->addItem( i18n( "Netscape" ) );
285 mMapCombo->addItem( i18n( "Evolution" ) );
286 mMapCombo->addItem( i18n( "Outlook" ) );
287 connect( mMapCombo, SIGNAL(activated(int)), SLOT(mapChanged(int)) );
288
289 label = new QLabel( i18n( "RDN prefix attribute:" ), page );
290 layout->addWidget( label, 1, 0 );
291 mRDNCombo = new KComboBox( page );
292 layout->addWidget( mRDNCombo, 1, 1 );
293 mRDNCombo->addItem( i18n( "commonName" ) );
294 mRDNCombo->addItem( i18n( "UID" ) );
295 mRDNCombo->setCurrentIndex( rdnprefix );
296
297 QMap<QString, QString>::ConstIterator it;
298 int i, j = 0;
299 for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
300 if ( mNameDict[ it.key() ].isEmpty() ) {
301 --i;
302 continue;
303 }
304 if ( ( i - 2 ) == ( mNameDict.count() >> 1 ) ) {
305 i = 0;
306 j = 2;
307 }
308 kDebug() << "itkey:" << it.key() << "i:" << i;
309 label = new QLabel( mNameDict[ it.key() ] + QLatin1Char( ':' ), page );
310 KLineEdit *lineedit = new KLineEdit( page );
311 mLineEditDict.insert( it.key(), lineedit );
312 lineedit->setText( it.value() );
313 label->setBuddy( lineedit );
314 layout->addWidget( label, i, j );
315 layout->addWidget( lineedit, i, j+1 );
316 }
317
318 for ( i = 1; i < mMapCombo->count(); ++i ) {
319 QHash<QString,KLineEdit*>::const_iterator it2 = mLineEditDict.constBegin();
320 while ( it2 != mLineEditDict.constEnd() ) {
321 if ( mMapList[ i ].contains( it2.key() ) ) {
322 if ( mMapList[ i ][ it2.key() ] != it2.value()->text() ) {
323 break;
324 }
325 } else {
326 if ( mDefaultMap[ it2.key() ] != it2.value()->text() ) {
327 break;
328 }
329 }
330 ++it2;
331 }
332 if ( it2 != mLineEditDict.constEnd() ) {
333 mMapCombo->setCurrentIndex( i );
334 break;
335 }
336 }
337
338 KAcceleratorManager::manage( this );
339}
340
341AttributesDialog::~AttributesDialog()
342{
343 mNameDict.clear();
344}
345
346QMap<QString, QString> AttributesDialog::attributes() const
347{
348 QMap<QString, QString> map;
349
350 QHash<QString,KLineEdit*>::const_iterator it = mLineEditDict.constBegin();
351 while ( it != mLineEditDict.constEnd() ) {
352 map.insert( it.key(), it.value()->text() );
353 ++it;
354 }
355 return map;
356}
357
358int AttributesDialog::rdnprefix() const
359{
360 return mRDNCombo->currentIndex();
361}
362
363void AttributesDialog::mapChanged( int pos )
364{
365
366 // apply first the default and than the spezific changes
367 QMap<QString, QString>::Iterator it;
368 for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it ) {
369 mLineEditDict[ it.key() ]->setText( it.value() );
370 }
371
372 for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
373 if ( !it.value().isEmpty() ) {
374 KLineEdit *le = mLineEditDict[ it.key() ];
375 if ( le ) {
376 le->setText( it.value() );
377 }
378 }
379 }
380}
381
382OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KUrl &src,
383 const QString &dst, QWidget *parent )
384 : KDialog( parent )
385{
386 setCaption( i18n( "Offline Configuration" ) );
387 setButtons( Ok | Cancel );
388 setDefaultButton( Ok );
389 setModal( true );
390 showButtonSeparator( true );
391
392 QFrame *page = new QFrame( this );
393 setMainWidget( page );
394 QVBoxLayout *layout = new QVBoxLayout( page );
395
396 mSrc = src;
397 mDst = dst;
398 mCacheBox = new QGroupBox( i18n( "Offline Cache Policy" ), page );
399 QVBoxLayout *cacheBoxLayout = new QVBoxLayout( mCacheBox );
400
401 mCacheGroup = new QButtonGroup( this );
402
403 QRadioButton *bt;
404 bt = new QRadioButton( i18n( "Do not use offline cache" ), mCacheBox );
405 cacheBoxLayout->addWidget( bt );
406 bt->setDown( true );
407 mCacheGroup->addButton( bt );
408
409 bt = new QRadioButton( i18n( "Use local copy if no connection" ), mCacheBox );
410 cacheBoxLayout->addWidget( bt );
411 mCacheGroup->addButton( bt );
412
413 bt = new QRadioButton( i18n( "Always use local copy" ), mCacheBox );
414 cacheBoxLayout->addWidget( bt );
415 mCacheGroup->addButton( bt );
416
417 if ( mCacheGroup->button( cachePolicy ) ) {
418 mCacheGroup->button( cachePolicy )->setDown( true );
419 }
420
421 mAutoCache = new QCheckBox( i18n( "Refresh offline cache automatically" ),
422 page );
423 mAutoCache->setChecked( autoCache );
424 mAutoCache->setEnabled( bt->isChecked() );
425
426 connect( bt, SIGNAL(toggled(bool)), mAutoCache, SLOT(setEnabled(bool)) );
427
428 QPushButton *lcache = new QPushButton( i18n( "Load into Cache" ), page );
429 connect( lcache, SIGNAL(clicked()), SLOT(loadCache()) );
430
431 layout->addWidget( mCacheBox );
432 layout->addWidget( mAutoCache );
433 layout->addWidget( lcache );
434}
435
436OfflineDialog::~OfflineDialog()
437{
438}
439
440bool OfflineDialog::autoCache() const
441{
442 return mAutoCache->isChecked();
443}
444
445int OfflineDialog::cachePolicy() const
446{
447 return mCacheGroup->checkedId();
448}
449
450void OfflineDialog::loadCache()
451{
452 if ( KIO::NetAccess::download( mSrc, mDst, this ) ) {
453 KMessageBox::information( this,
454 i18n( "Successfully downloaded directory server contents." ) );
455 } else {
456 KMessageBox::error( this,
457 i18n( "An error occurred downloading directory server contents into file %1.", mDst ) );
458 }
459}
KRES
KRES::Resource
KABC
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition address.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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