20 #include <tqapplication.h>
22 #include <tqcheckbox.h>
25 #include <tqpushbutton.h>
26 #include <tqspinbox.h>
28 #include <tqvgroupbox.h>
29 #include <tqhbuttongroup.h>
30 #include <tqradiobutton.h>
32 #include <tdeaccelmanager.h>
33 #include <kcombobox.h>
35 #include <kdialogbase.h>
37 #include <klineedit.h>
38 #include <tdemessagebox.h>
39 #include <tdeio/netaccess.h>
41 #include "resourceldaptdeio.h"
43 #include "resourceldaptdeioconfig.h"
44 #include "resourceldaptdeioconfig.moc"
48 ResourceLDAPTDEIOConfig::ResourceLDAPTDEIOConfig( TQWidget* parent,
const char* name )
49 : KRES::ConfigWidget( parent,
name )
51 TQBoxLayout *mainLayout =
new TQVBoxLayout(
this );
52 mainLayout->setAutoAdd(
true );
55 mSubTree =
new TQCheckBox( i18n(
"Sub-tree query" ),
this );
56 TQHBox *box =
new TQHBox(
this );
58 mEditButton =
new TQPushButton( i18n(
"Edit Attributes..." ), box );
59 mCacheButton =
new TQPushButton( i18n(
"Offline Use..." ), box );
61 connect( mEditButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editAttributes() ) );
62 connect( mCacheButton, TQ_SIGNAL( clicked() ), TQ_SLOT( editCache() ) );
65 void ResourceLDAPTDEIOConfig::loadSettings( KRES::Resource *res )
67 ResourceLDAPTDEIO *resource =
dynamic_cast<ResourceLDAPTDEIO*
>( res );
70 kdDebug(5700) <<
"ResourceLDAPTDEIOConfig::loadSettings(): cast failed" <<
endl;
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();
89 if ( resource->isAnonymous() ) cfg->setAuthAnon();
90 else if ( resource->isSASL() ) cfg->setAuthSASL();
91 else cfg->setAuthSimple();
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();
101 void ResourceLDAPTDEIOConfig::saveSettings( KRES::Resource *res )
103 ResourceLDAPTDEIO *resource =
dynamic_cast<ResourceLDAPTDEIO*
>( res );
106 kdDebug(5700) <<
"ResourceLDAPTDEIOConfig::saveSettings(): cast failed" <<
endl;
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 );
134 void ResourceLDAPTDEIOConfig::editAttributes()
136 AttributesDialog dlg( mAttributes, mRDNPrefix,
this );
138 mAttributes = dlg.attributes();
139 mRDNPrefix = dlg.rdnprefix();
143 void ResourceLDAPTDEIOConfig::editCache()
149 src.
setScope( mSubTree->isChecked() ? LDAPUrl::Sub : LDAPUrl::One );
150 if (!mAttributes.empty()) {
151 TQMap<TQString,TQString>::Iterator it;
153 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
154 if ( !it.data().isEmpty() && it.key() !=
"objectClass" )
155 attr.append( it.data() );
160 OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst,
this );
162 mCachePolicy = dlg.cachePolicy();
163 mAutoCache = dlg.autoCache();
168 AttributesDialog::AttributesDialog(
const TQMap<TQString, TQString> &attributes,
170 TQWidget *parent,
const char *name )
171 :
KDialogBase( Plain, i18n(
"Attributes Configuration" ), Ok | Cancel,
172 Ok, parent,
name, true, true )
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" ) ) );
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" );
221 TQMap<TQString, TQString> kolabMap, netscapeMap, evolutionMap, outlookMap;
224 kolabMap.insert(
"formattedName",
"display-name" );
225 kolabMap.insert(
"mailAlias",
"mailalias" );
228 evolutionMap.insert(
"formattedName",
"fileAs" );
230 mMapList.append( attributes );
231 mMapList.append( kolabMap );
232 mMapList.append( netscapeMap );
233 mMapList.append( evolutionMap );
234 mMapList.append( outlookMap );
236 TQFrame *page = plainPage();
237 TQGridLayout *layout =
new TQGridLayout( page, 4, ( attributes.count() + 4 ) >> 1,
240 TQLabel *
label =
new TQLabel( i18n(
"Template:" ), page );
241 layout->addWidget( label, 0, 0 );
243 layout->addWidget( mMapCombo, 0, 1 );
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 ) ) );
252 label =
new TQLabel( i18n(
"RDN prefix attribute:" ), page );
253 layout->addWidget( label, 1, 0 );
255 layout->addWidget( mRDNCombo, 1, 1 );
256 mRDNCombo->insertItem( i18n(
"commonName" ) );
257 mRDNCombo->insertItem( i18n(
"UID" ) );
258 mRDNCombo->setCurrentItem( rdnprefix );
260 TQMap<TQString, TQString>::ConstIterator it;
262 for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
263 if ( mNameDict[ it.key() ] == 0 ) {
267 if ( (uint)(i - 2) == ( mNameDict.count() >> 1 ) ) {
271 kdDebug(7125) <<
"itkey: " << it.key() <<
" i: " << i <<
endl;
272 label =
new TQLabel( *mNameDict[ it.key() ] +
":", 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 );
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;
287 if ( mDefaultMap[ it2.currentKey() ] != it2.current()->text() )
break;
290 if ( !it2.current() ) {
291 mMapCombo->setCurrentItem( i );
299 AttributesDialog::~AttributesDialog()
303 TQMap<TQString, TQString> AttributesDialog::attributes()
const
305 TQMap<TQString, TQString> map;
307 TQDictIterator<KLineEdit> it( mLineEditDict );
308 for ( ; it.current(); ++it )
309 map.insert( it.currentKey(), it.current()->text() );
314 int AttributesDialog::rdnprefix()
const
316 return mRDNCombo->currentItem();
319 void AttributesDialog::mapChanged(
int pos )
323 TQMap<TQString, TQString>::Iterator it;
324 for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it )
325 mLineEditDict[ it.key() ]->setText( it.data() );
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() );
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 )
340 TQFrame *page = plainPage();
341 TQVBoxLayout *layout =
new TQVBoxLayout( page );
342 layout->setAutoAdd(
true );
344 mSrc = src; mDst = dst;
345 mCacheGroup =
new TQButtonGroup( 1, TQt::Horizontal,
346 i18n(
"Offline Cache Policy"), page );
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 );
354 mAutoCache =
new TQCheckBox( i18n(
"Refresh offline cache automatically"),
356 mAutoCache->setChecked( autoCache );
357 mAutoCache->setEnabled( bt->isChecked() );
359 connect( bt, TQ_SIGNAL(toggled(
bool)), mAutoCache, TQ_SLOT(setEnabled(
bool)) );
361 TQPushButton *lcache =
new TQPushButton( i18n(
"Load into Cache"), page );
362 connect( lcache, TQ_SIGNAL( clicked() ), TQ_SLOT( loadCache() ) );
365 OfflineDialog::~OfflineDialog()
369 bool OfflineDialog::autoCache()
const
371 return mAutoCache->isChecked();
374 int OfflineDialog::cachePolicy()
const
376 return mCacheGroup->selectedId();
379 void OfflineDialog::loadCache()
381 if ( TDEIO::NetAccess::download( mSrc, mDst,
this ) ) {
383 i18n(
"Successfully downloaded directory server contents!") );
386 i18n(
"An error occurred downloading directory server contents into file %1.").arg(mDst) );
virtual void setText(const TQString &)
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
TQString url(int _trailing=0, int encoding_hint=0) const
void setScope(Scope scope)
Sets the scope part of the LDAP Url.
void setAttributes(const TQStringList &attributes)
Sets the attributes part of the LDAP Url.
void setExtension(const TQString &key, const Extension &ext)
Sets the specified extension key with the value and criticality in ext.
static void manage(TQWidget *widget)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
static data, shared by ALL addressee objects
TQString name(StdAccel id)
TQString label(StdAccel id)