• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
  • plugins
  • ldaptdeio
resourceldaptdeioconfig.cpp
1 /*
2  This file is part of libtdeabc.
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 #include <tqapplication.h>
21 
22 #include <tqcheckbox.h>
23 #include <tqlabel.h>
24 #include <tqlayout.h>
25 #include <tqpushbutton.h>
26 #include <tqspinbox.h>
27 #include <tqvbox.h>
28 #include <tqvgroupbox.h>
29 #include <tqhbuttongroup.h>
30 #include <tqradiobutton.h>
31 
32 #include <tdeaccelmanager.h>
33 #include <kcombobox.h>
34 #include <kdebug.h>
35 #include <kdialogbase.h>
36 #include <tdelocale.h>
37 #include <klineedit.h>
38 #include <tdemessagebox.h>
39 #include <tdeio/netaccess.h>
40 
41 #include "resourceldaptdeio.h"
42 
43 #include "resourceldaptdeioconfig.h"
44 #include "resourceldaptdeioconfig.moc"
45 
46 using namespace TDEABC;
47 
48 ResourceLDAPTDEIOConfig::ResourceLDAPTDEIOConfig( TQWidget* parent, const char* name )
49  : KRES::ConfigWidget( parent, name )
50 {
51  TQBoxLayout *mainLayout = new TQVBoxLayout( this );
52  mainLayout->setAutoAdd( true );
53  cfg = new LdapConfigWidget( LdapConfigWidget::W_ALL, this );
54 
55  mSubTree = new TQCheckBox( i18n( "Sub-tree query" ), this );
56  TQHBox *box = new TQHBox( this );
57  box->setSpacing( KDialog::spacingHint() );
58  mEditButton = new TQPushButton( i18n( "Edit Attributes..." ), box );
59  mCacheButton = new TQPushButton( i18n( "Offline Use..." ), box );
60 
61  connect( mEditButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editAttributes() ) );
62  connect( mCacheButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editCache() ) );
63 }
64 
65 void ResourceLDAPTDEIOConfig::loadSettings( KRES::Resource *res )
66 {
67  ResourceLDAPTDEIO *resource = dynamic_cast<ResourceLDAPTDEIO*>( res );
68 
69  if ( !resource ) {
70  kdDebug(5700) << "ResourceLDAPTDEIOConfig::loadSettings(): cast failed" << endl;
71  return;
72  }
73 
74  cfg->setUser( resource->user() );
75  cfg->setPassword( resource->password() );
76  cfg->setRealm( resource->realm() );
77  cfg->setBindDN( resource->bindDN() );
78  cfg->setHost( resource->host() );
79  cfg->setPort( resource->port() );
80  cfg->setVer( resource->ver() );
81  cfg->setTimeLimit( resource->timeLimit() );
82  cfg->setSizeLimit( resource->sizeLimit() );
83  cfg->setDn( resource->dn() );
84  cfg->setFilter( resource->filter() );
85  cfg->setMech( resource->mech() );
86  if ( resource->isTLS() ) cfg->setSecTLS();
87  else if ( resource->isSSL() ) cfg->setSecSSL();
88  else cfg->setSecNO();
89  if ( resource->isAnonymous() ) cfg->setAuthAnon();
90  else if ( resource->isSASL() ) cfg->setAuthSASL();
91  else cfg->setAuthSimple();
92 
93  mSubTree->setChecked( resource->isSubTree() );
94  mAttributes = resource->attributes();
95  mRDNPrefix = resource->RDNPrefix();
96  mCachePolicy = resource->cachePolicy();
97  mCacheDst = resource->cacheDst();
98  mAutoCache = resource->autoCache();
99 }
100 
101 void ResourceLDAPTDEIOConfig::saveSettings( KRES::Resource *res )
102 {
103  ResourceLDAPTDEIO *resource = dynamic_cast<ResourceLDAPTDEIO*>( res );
104 
105  if ( !resource ) {
106  kdDebug(5700) << "ResourceLDAPTDEIOConfig::saveSettings(): cast failed" << endl;
107  return;
108  }
109 
110  resource->setUser( cfg->user() );
111  resource->setPassword( cfg->password() );
112  resource->setRealm( cfg->realm() );
113  resource->setBindDN( cfg->bindDN() );
114  resource->setHost( cfg->host() );
115  resource->setPort( cfg->port() );
116  resource->setVer( cfg->ver() );
117  resource->setTimeLimit( cfg->timeLimit() );
118  resource->setSizeLimit( cfg->sizeLimit() );
119  resource->setDn( cfg->dn() );
120  resource->setFilter( cfg->filter() );
121  resource->setIsAnonymous( cfg->isAuthAnon() );
122  resource->setIsSASL( cfg->isAuthSASL() );
123  resource->setMech( cfg->mech() );
124  resource->setIsTLS( cfg->isSecTLS() );
125  resource->setIsSSL( cfg->isSecSSL() );
126  resource->setIsSubTree( mSubTree->isChecked() );
127  resource->setAttributes( mAttributes );
128  resource->setRDNPrefix( mRDNPrefix );
129  resource->setCachePolicy( mCachePolicy );
130  resource->init();
131 
132 }
133 
134 void ResourceLDAPTDEIOConfig::editAttributes()
135 {
136  AttributesDialog dlg( mAttributes, mRDNPrefix, this );
137  if ( dlg.exec() ) {
138  mAttributes = dlg.attributes();
139  mRDNPrefix = dlg.rdnprefix();
140  }
141 }
142 
143 void ResourceLDAPTDEIOConfig::editCache()
144 {
145  LDAPUrl src;
146  TQStringList attr;
147 
148  src = cfg->url();
149  src.setScope( mSubTree->isChecked() ? LDAPUrl::Sub : LDAPUrl::One );
150  if (!mAttributes.empty()) {
151  TQMap<TQString,TQString>::Iterator it;
152  TQStringList attr;
153  for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
154  if ( !it.data().isEmpty() && it.key() != "objectClass" )
155  attr.append( it.data() );
156  }
157  src.setAttributes( attr );
158  }
159  src.setExtension( "x-dir", "base" );
160  OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this );
161  if ( dlg.exec() ) {
162  mCachePolicy = dlg.cachePolicy();
163  mAutoCache = dlg.autoCache();
164  }
165 
166 }
167 
168 AttributesDialog::AttributesDialog( const TQMap<TQString, TQString> &attributes,
169  int rdnprefix,
170  TQWidget *parent, const char *name )
171  : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel,
172  Ok, parent, name, true, true )
173 {
174  mNameDict.setAutoDelete( true );
175  mNameDict.insert( "objectClass", new TQString( i18n( "Object classes" ) ) );
176  mNameDict.insert( "commonName", new TQString( i18n( "Common name" ) ) );
177  mNameDict.insert( "formattedName", new TQString( i18n( "Formatted name" ) ) );
178  mNameDict.insert( "familyName", new TQString( i18n( "Family name" ) ) );
179  mNameDict.insert( "givenName", new TQString( i18n( "Given name" ) ) );
180  mNameDict.insert( "organization", new TQString( i18n( "Organization" ) ) );
181  mNameDict.insert( "title", new TQString( i18n( "Title" ) ) );
182  mNameDict.insert( "street", new TQString( i18n( "Street" ) ) );
183  mNameDict.insert( "state", new TQString( i18n( "State" ) ) );
184  mNameDict.insert( "city", new TQString( i18n( "City" ) ) );
185  mNameDict.insert( "postalcode", new TQString( i18n( "Postal code" ) ) );
186  mNameDict.insert( "mail", new TQString( i18n( "Email" ) ) );
187  mNameDict.insert( "mailAlias", new TQString( i18n( "Email alias" ) ) );
188  mNameDict.insert( "phoneNumber", new TQString( i18n( "Telephone number" ) ) );
189  mNameDict.insert( "telephoneNumber", new TQString( i18n( "Work telephone number" ) ) );
190  mNameDict.insert( "facsimileTelephoneNumber", new TQString( i18n( "Fax number" ) ) );
191  mNameDict.insert( "mobile", new TQString( i18n( "Cell phone number" ) ) );
192  mNameDict.insert( "pager", new TQString( i18n( "Pager" ) ) );
193  mNameDict.insert( "description", new TQString( i18n( "Note" ) ) );
194  mNameDict.insert( "uid", new TQString( i18n( "UID" ) ) );
195  mNameDict.insert( "jpegPhoto", new TQString( i18n( "Photo" ) ) );
196 
197  // default map
198  mDefaultMap.insert( "objectClass", "inetOrgPerson" );
199  mDefaultMap.insert( "commonName", "cn" );
200  mDefaultMap.insert( "formattedName", "displayName" );
201  mDefaultMap.insert( "familyName", "sn" );
202  mDefaultMap.insert( "givenName", "givenName" );
203  mDefaultMap.insert( "title", "title" );
204  mDefaultMap.insert( "street", "street" );
205  mDefaultMap.insert( "state", "st" );
206  mDefaultMap.insert( "city", "l" );
207  mDefaultMap.insert( "organization", "o" );
208  mDefaultMap.insert( "postalcode", "postalCode" );
209  mDefaultMap.insert( "mail", "mail" );
210  mDefaultMap.insert( "mailAlias", "" );
211  mDefaultMap.insert( "phoneNumber", "homePhone" );
212  mDefaultMap.insert( "telephoneNumber", "telephoneNumber" );
213  mDefaultMap.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" );
214  mDefaultMap.insert( "mobile", "mobile" );
215  mDefaultMap.insert( "pager", "pager" );
216  mDefaultMap.insert( "description", "description" );
217  mDefaultMap.insert( "uid", "uid" );
218  mDefaultMap.insert( "jpegPhoto", "jpegPhoto" );
219 
220  // overwrite the default values here
221  TQMap<TQString, TQString> kolabMap, netscapeMap, evolutionMap, outlookMap;
222 
223  // kolab
224  kolabMap.insert( "formattedName", "display-name" );
225  kolabMap.insert( "mailAlias", "mailalias" );
226 
227  // evolution
228  evolutionMap.insert( "formattedName", "fileAs" );
229 
230  mMapList.append( attributes );
231  mMapList.append( kolabMap );
232  mMapList.append( netscapeMap );
233  mMapList.append( evolutionMap );
234  mMapList.append( outlookMap );
235 
236  TQFrame *page = plainPage();
237  TQGridLayout *layout = new TQGridLayout( page, 4, ( attributes.count() + 4 ) >> 1,
238  0, spacingHint() );
239 
240  TQLabel *label = new TQLabel( i18n( "Template:" ), page );
241  layout->addWidget( label, 0, 0 );
242  mMapCombo = new KComboBox( page );
243  layout->addWidget( mMapCombo, 0, 1 );
244 
245  mMapCombo->insertItem( i18n( "User Defined" ) );
246  mMapCombo->insertItem( i18n( "Kolab" ) );
247  mMapCombo->insertItem( i18n( "Netscape" ) );
248  mMapCombo->insertItem( i18n( "Evolution" ) );
249  mMapCombo->insertItem( i18n( "Outlook" ) );
250  connect( mMapCombo, TQ_SIGNAL( activated( int ) ), TQ_SLOT( mapChanged( int ) ) );
251 
252  label = new TQLabel( i18n( "RDN prefix attribute:" ), page );
253  layout->addWidget( label, 1, 0 );
254  mRDNCombo = new KComboBox( page );
255  layout->addWidget( mRDNCombo, 1, 1 );
256  mRDNCombo->insertItem( i18n( "commonName" ) );
257  mRDNCombo->insertItem( i18n( "UID" ) );
258  mRDNCombo->setCurrentItem( rdnprefix );
259 
260  TQMap<TQString, TQString>::ConstIterator it;
261  int i, j = 0;
262  for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
263  if ( mNameDict[ it.key() ] == 0 ) {
264  i--;
265  continue;
266  }
267  if ( (uint)(i - 2) == ( mNameDict.count() >> 1 ) ) {
268  i = 0;
269  j = 2;
270  }
271  kdDebug(7125) << "itkey: " << it.key() << " i: " << i << endl;
272  label = new TQLabel( *mNameDict[ it.key() ] + ":", page );
273  KLineEdit *lineedit = new KLineEdit( page );
274  mLineEditDict.insert( it.key(), lineedit );
275  lineedit->setText( it.data() );
276  label->setBuddy( lineedit );
277  layout->addWidget( label, i, j );
278  layout->addWidget( lineedit, i, j+1 );
279  }
280 
281  for ( i = 1; i < mMapCombo->count(); i++ ) {
282  TQDictIterator<KLineEdit> it2( mLineEditDict );
283  for ( ; it2.current(); ++it2 ) {
284  if ( mMapList[ i ].contains( it2.currentKey() ) ) {
285  if ( mMapList[ i ][ it2.currentKey() ] != it2.current()->text() ) break;
286  } else {
287  if ( mDefaultMap[ it2.currentKey() ] != it2.current()->text() ) break;
288  }
289  }
290  if ( !it2.current() ) {
291  mMapCombo->setCurrentItem( i );
292  break;
293  }
294  }
295 
296  TDEAcceleratorManager::manage( this );
297 }
298 
299 AttributesDialog::~AttributesDialog()
300 {
301 }
302 
303 TQMap<TQString, TQString> AttributesDialog::attributes() const
304 {
305  TQMap<TQString, TQString> map;
306 
307  TQDictIterator<KLineEdit> it( mLineEditDict );
308  for ( ; it.current(); ++it )
309  map.insert( it.currentKey(), it.current()->text() );
310 
311  return map;
312 }
313 
314 int AttributesDialog::rdnprefix() const
315 {
316  return mRDNCombo->currentItem();
317 }
318 
319 void AttributesDialog::mapChanged( int pos )
320 {
321 
322  // apply first the default and than the spezific changes
323  TQMap<TQString, TQString>::Iterator it;
324  for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it )
325  mLineEditDict[ it.key() ]->setText( it.data() );
326 
327  for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
328  if ( !it.data().isEmpty() ) {
329  KLineEdit *le = mLineEditDict[ it.key() ];
330  if ( le ) le->setText( it.data() );
331  }
332  }
333 }
334 
335 OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KURL &src,
336  const TQString &dst, TQWidget *parent, const char *name )
337  : KDialogBase( Plain, i18n( "Offline Configuration" ), Ok | Cancel,
338  Ok, parent, name, true, true )
339 {
340  TQFrame *page = plainPage();
341  TQVBoxLayout *layout = new TQVBoxLayout( page );
342  layout->setAutoAdd( true );
343 
344  mSrc = src; mDst = dst;
345  mCacheGroup = new TQButtonGroup( 1, TQt::Horizontal,
346  i18n("Offline Cache Policy"), page );
347 
348  TQRadioButton *bt;
349  new TQRadioButton( i18n("Do not use offline cache"), mCacheGroup );
350  bt = new TQRadioButton( i18n("Use local copy if no connection"), mCacheGroup );
351  new TQRadioButton( i18n("Always use local copy"), mCacheGroup );
352  mCacheGroup->setButton( cachePolicy );
353 
354  mAutoCache = new TQCheckBox( i18n("Refresh offline cache automatically"),
355  page );
356  mAutoCache->setChecked( autoCache );
357  mAutoCache->setEnabled( bt->isChecked() );
358 
359  connect( bt, TQ_SIGNAL(toggled(bool)), mAutoCache, TQ_SLOT(setEnabled(bool)) );
360 
361  TQPushButton *lcache = new TQPushButton( i18n("Load into Cache"), page );
362  connect( lcache, TQ_SIGNAL( clicked() ), TQ_SLOT( loadCache() ) );
363 }
364 
365 OfflineDialog::~OfflineDialog()
366 {
367 }
368 
369 bool OfflineDialog::autoCache() const
370 {
371  return mAutoCache->isChecked();
372 }
373 
374 int OfflineDialog::cachePolicy() const
375 {
376  return mCacheGroup->selectedId();
377 }
378 
379 void OfflineDialog::loadCache()
380 {
381  if ( TDEIO::NetAccess::download( mSrc, mDst, this ) ) {
382  KMessageBox::information( this,
383  i18n("Successfully downloaded directory server contents!") );
384  } else {
385  KMessageBox::error( this,
386  i18n("An error occurred downloading directory server contents into file %1.").arg(mDst) );
387  }
388 }
KComboBox
KDialogBase
KDialog::spacingHint
static int spacingHint()
KLineEdit
KLineEdit::setText
virtual void setText(const TQString &)
KMessageBox::information
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
KMessageBox::error
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
KURL
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
TDEABC::LDAPUrl
LDAPUrl.
Definition: ldapurl.h:43
TDEABC::LDAPUrl::setScope
void setScope(Scope scope)
Sets the scope part of the LDAP Url.
Definition: ldapurl.h:75
TDEABC::LDAPUrl::setAttributes
void setAttributes(const TQStringList &attributes)
Sets the attributes part of the LDAP Url.
Definition: ldapurl.h:69
TDEABC::LDAPUrl::setExtension
void setExtension(const TQString &key, const Extension &ext)
Sets the specified extension key with the value and criticality in ext.
Definition: ldapurl.cpp:88
TDEABC::LdapConfigWidget
LDAP Configuration widget.
Definition: ldapconfigwidget.h:51
TDEAcceleratorManager::manage
static void manage(TQWidget *widget)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEStdAccel::name
TQString name(StdAccel id)
TDEStdAccel::label
TQString label(StdAccel id)
tdelocale.h

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.1
This website is maintained by Timothy Pearson.