20 #include <tqapplication.h>
22 #include <tqobjectlist.h>
23 #include <tqcheckbox.h>
26 #include <tqpushbutton.h>
27 #include <tqspinbox.h>
28 #include <tqvgroupbox.h>
29 #include <tqhbuttongroup.h>
30 #include <tqradiobutton.h>
32 #include <tdemessagebox.h>
33 #include <tdeaccelmanager.h>
34 #include <kdialogbase.h>
36 #include <klineedit.h>
37 #include <kcombobox.h>
38 #include <kprogress.h>
42 #include "ldapconfigwidget.h"
43 #include "ldapconfigwidget.moc"
48 const char* name, WFlags fl ) : TQWidget( parent, name, fl )
52 mainLayout =
new TQGridLayout(
this, 12, 4, 0,
57 const char* name, WFlags fl ) : TQWidget( parent, name, fl )
61 mainLayout =
new TQGridLayout(
this, 12, 4, 0,
70 void LdapConfigWidget::initWidget()
74 mUser = mPassword = mHost = mDn = mBindDN = mRealm = mFilter = 0;
75 mPort = mVer = mTimeLimit = mSizeLimit = 0;
76 mAnonymous = mSimple = mSASL = mSecNO = mSecTLS = mSecSSL = 0;
77 mEditButton = mQueryMech = 0;
82 if ( mFlags & W_USER ) {
83 label =
new TQLabel( i18n(
"User:" ),
this );
84 mUser =
new KLineEdit(
this,
"kcfg_ldapuser" );
86 mainLayout->addWidget( label, row, 0 );
87 mainLayout->addMultiCellWidget( mUser, row, row, 1, 3 );
91 if ( mFlags & W_BINDDN ) {
92 label =
new TQLabel( i18n(
"Bind DN:" ),
this );
93 mBindDN =
new KLineEdit(
this,
"kcfg_ldapbinddn" );
95 mainLayout->addWidget( label, row, 0 );
96 mainLayout->addMultiCellWidget( mBindDN, row, row, 1, 3 );
100 if ( mFlags & W_REALM ) {
101 label =
new TQLabel( i18n(
"Realm:" ),
this );
102 mRealm =
new KLineEdit(
this,
"kcfg_ldaprealm" );
104 mainLayout->addWidget( label, row, 0 );
105 mainLayout->addMultiCellWidget( mRealm, row, row, 1, 3 );
109 if ( mFlags & W_PASS ) {
110 label =
new TQLabel( i18n(
"Password:" ),
this );
111 mPassword =
new KLineEdit(
this,
"kcfg_ldappassword" );
112 mPassword->setEchoMode( KLineEdit::Password );
114 mainLayout->addWidget( label, row, 0 );
115 mainLayout->addMultiCellWidget( mPassword, row, row, 1, 3 );
119 if ( mFlags & W_HOST ) {
120 label =
new TQLabel( i18n(
"Host:" ),
this );
121 mHost =
new KLineEdit(
this,
"kcfg_ldaphost" );
123 mainLayout->addWidget( label, row, 0 );
124 mainLayout->addMultiCellWidget( mHost, row, row, 1, 3 );
129 if ( mFlags & W_PORT ) {
130 label =
new TQLabel( i18n(
"Port:" ),
this );
131 mPort =
new TQSpinBox( 0, 65535, 1,
this,
"kcfg_ldapport" );
132 mPort->setSizePolicy( TQSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Preferred ) );
133 mPort->setValue( 389 );
135 mainLayout->addWidget( label, row, col );
136 mainLayout->addWidget( mPort, row, col+1 );
140 if ( mFlags & W_VER ) {
141 label =
new TQLabel( i18n(
"LDAP version:" ),
this );
142 mVer =
new TQSpinBox( 2, 3, 1,
this,
"kcfg_ldapver" );
143 mVer->setSizePolicy( TQSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Preferred ) );
145 mainLayout->addWidget( label, row, col );
146 mainLayout->addWidget( mVer, row, col+1 );
148 if ( mFlags & ( W_PORT | W_VER ) ) row++;
151 if ( mFlags & W_SIZELIMIT ) {
152 label =
new TQLabel( i18n(
"Size limit:" ),
this );
153 mSizeLimit =
new TQSpinBox( 0, 9999999, 1,
this,
"kcfg_ldapsizelimit" );
154 mSizeLimit->setSizePolicy( TQSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Preferred ) );
155 mSizeLimit->setValue( 0 );
156 mSizeLimit->setSpecialValueText( i18n(
"Default") );
157 mainLayout->addWidget( label, row, col );
158 mainLayout->addWidget( mSizeLimit, row, col+1 );
162 if ( mFlags & W_TIMELIMIT ) {
163 label =
new TQLabel( i18n(
"Time limit:" ),
this );
164 mTimeLimit =
new TQSpinBox( 0, 9999999, 1,
this,
"kcfg_ldaptimelimit" );
165 mTimeLimit->setSizePolicy( TQSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Preferred ) );
166 mTimeLimit->setValue( 0 );
167 mTimeLimit->setSuffix( i18n(
" sec") );
168 mTimeLimit->setSpecialValueText( i18n(
"Default") );
169 mainLayout->addWidget( label, row, col );
170 mainLayout->addWidget( mTimeLimit, row, col+1 );
172 if ( mFlags & ( W_SIZELIMIT | W_TIMELIMIT ) ) row++;
174 if ( mFlags & W_DN ) {
175 label =
new TQLabel( i18n(
"Distinguished Name",
"DN:" ),
this );
176 mDn =
new KLineEdit(
this,
"kcfg_ldapdn" );
178 mainLayout->addWidget( label, row, 0 );
179 mainLayout->addMultiCellWidget( mDn, row, row, 1, 1 );
182 TQPushButton *dnquery =
new TQPushButton( i18n(
"Query Server" ),
this );
183 connect( dnquery, TQ_SIGNAL( clicked() ), TQ_SLOT( mQueryDNClicked() ) );
184 mainLayout->addMultiCellWidget( dnquery, row, row, 2, 3 );
189 if ( mFlags & W_FILTER ) {
190 label =
new TQLabel( i18n(
"Filter:" ),
this );
191 mFilter =
new KLineEdit(
this,
"kcfg_ldapfilter" );
193 mainLayout->addWidget( label, row, 0 );
194 mainLayout->addMultiCellWidget( mFilter, row, row, 1, 3 );
198 if ( mFlags & W_SECBOX ) {
199 TQHButtonGroup *btgroup =
new TQHButtonGroup( i18n(
"Security" ),
this );
200 mSecNO =
new TQRadioButton( i18n(
"No" ), btgroup,
"kcfg_ldapnosec" );
201 mSecTLS =
new TQRadioButton( i18n(
"TLS" ), btgroup,
"kcfg_ldaptls" );
202 mSecSSL =
new TQRadioButton( i18n(
"SSL" ), btgroup,
"kcfg_ldapssl" );
203 mainLayout->addMultiCellWidget( btgroup, row, row, 0, 3 );
205 connect( mSecNO, TQ_SIGNAL( clicked() ), TQ_SLOT( setLDAPPort() ) );
206 connect( mSecTLS, TQ_SIGNAL( clicked() ), TQ_SLOT( setLDAPPort() ) );
207 connect( mSecSSL, TQ_SIGNAL( clicked() ), TQ_SLOT( setLDAPSPort( ) ) );
209 mSecNO->setChecked(
true );
213 if ( mFlags & W_AUTHBOX ) {
215 TQButtonGroup *authbox =
216 new TQButtonGroup( 3, TQt::Horizontal, i18n(
"Authentication" ),
this );
218 mAnonymous =
new TQRadioButton( i18n(
"Anonymous" ), authbox,
"kcfg_ldapanon" );
219 mSimple =
new TQRadioButton( i18n(
"Simple" ), authbox,
"kcfg_ldapsimple" );
220 mSASL =
new TQRadioButton( i18n(
"SASL" ), authbox,
"kcfg_ldapsasl" );
222 label =
new TQLabel( i18n(
"SASL mechanism:" ), authbox );
223 mMech =
new KComboBox(
false, authbox,
"kcfg_ldapsaslmech" );
224 mMech->setEditable(
true );
225 mMech->insertItem(
"DIGEST-MD5" );
226 mMech->insertItem(
"GSSAPI" );
227 mMech->insertItem(
"PLAIN" );
231 mQueryMech =
new TQPushButton( i18n(
"Query Server" ), authbox );
232 connect( mQueryMech, TQ_SIGNAL( clicked() ), TQ_SLOT( mQueryMechClicked() ) );
235 mainLayout->addMultiCellWidget( authbox, row, row+1, 0, 3 );
237 connect( mAnonymous, TQ_SIGNAL( stateChanged(
int) ), TQ_SLOT( setAnonymous(
int) ) );
238 connect( mSimple, TQ_SIGNAL( stateChanged(
int) ), TQ_SLOT( setSimple(
int) ) );
239 connect( mSASL, TQ_SIGNAL( stateChanged(
int) ), TQ_SLOT( setSASL(
int) ) );
241 mAnonymous->setChecked(
true );
246 void LdapConfigWidget::loadData( TDEIO::Job*,
const TQByteArray& d )
257 if ( ret == LDIF::Item && mLdif.
attr().lower() == mAttr ) {
259 mQResult.push_back( TQString::fromUtf8( mLdif.
val(), mLdif.
val().size() ) );
261 }
while ( ret != LDIF::MoreData );
264 void LdapConfigWidget::loadResult( TDEIO::Job* job)
266 int error = job->error();
267 if ( error && error != TDEIO::ERR_USER_CANCELED )
268 mErrorMsg = job->errorString();
276 void LdapConfigWidget::sendQuery()
283 _url.
setProtocol( ( mSecSSL && mSecSSL->isChecked() ) ?
"ldaps" :
"ldap" );
284 if ( mHost ) _url.
setHost( mHost->text() );
285 if ( mPort ) _url.
setPort( mPort->value() );
289 if ( mVer ) _url.
setExtension(
"x-ver", TQString::number( mVer->value() ) );
290 if ( mSecTLS && mSecTLS->isChecked() ) _url.
setExtension(
"x-tls",
"" );
294 TDEIO::Job *job = TDEIO::get( _url,
true,
false );
295 job->addMetaData(
"no-auth-prompt",
"true");
296 connect( job, TQ_SIGNAL( data( TDEIO::Job*,
const TQByteArray& ) ),
297 this, TQ_SLOT( loadData( TDEIO::Job*,
const TQByteArray& ) ) );
298 connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ),
299 this, TQ_SLOT( loadResult( TDEIO::Job* ) ) );
316 void LdapConfigWidget::mQueryMechClicked()
318 mAttr =
"supportedsaslmechanisms";
320 if ( !mQResult.isEmpty() ) {
323 mMech->insertStringList( mQResult );
327 void LdapConfigWidget::mQueryDNClicked()
329 mAttr =
"namingcontexts";
331 if ( !mQResult.isEmpty() ) mDn->
setText( mQResult.first() );
334 void LdapConfigWidget::setAnonymous(
int state )
336 if ( state == TQButton::Off )
return;
337 if ( mUser ) mUser->setEnabled(
false);
338 if ( mPassword ) mPassword->setEnabled(
false);
339 if ( mBindDN ) mBindDN->setEnabled(
false);
340 if ( mRealm ) mRealm->setEnabled(
false);
341 if ( mMech ) mMech->setEnabled(
false);
342 if ( mQueryMech ) mQueryMech->setEnabled(
false);
345 void LdapConfigWidget::setSimple(
int state )
347 if ( state == TQButton::Off )
return;
348 if ( mUser ) mUser->setEnabled(
true);
349 if ( mPassword ) mPassword->setEnabled(
true);
350 if ( mBindDN ) mBindDN->setEnabled(
false);
351 if ( mRealm ) mRealm->setEnabled(
false);
352 if ( mMech ) mMech->setEnabled(
false);
353 if ( mQueryMech ) mQueryMech->setEnabled(
false);
356 void LdapConfigWidget::setSASL(
int state )
358 if ( state == TQButton::Off )
return;
359 if ( mUser ) mUser->setEnabled(
true);
360 if ( mPassword ) mPassword->setEnabled(
true);
361 if ( mBindDN ) mBindDN->setEnabled(
true);
362 if ( mRealm ) mRealm->setEnabled(
true);
363 if ( mMech ) mMech->setEnabled(
true);
364 if ( mQueryMech ) mQueryMech->setEnabled(
true);
367 void LdapConfigWidget::setLDAPPort()
369 mPort->setValue( 389 );
372 void LdapConfigWidget::setLDAPSPort()
374 mPort->setValue( 636 );
381 if ( mSecSSL && mSecSSL->isChecked() )
386 if ( mUser ) _url.
setUser( mUser->text() );
387 if ( mPassword ) _url.
setPass( mPassword->text() );
388 if ( mHost ) _url.
setHost( mHost->text() );
389 if ( mPort ) _url.
setPort( mPort->value() );
390 if ( mDn ) _url.
setDn( mDn->text() );
391 if ( mVer ) _url.
setExtension(
"x-ver", TQString::number( mVer->value() ) );
392 if ( mSizeLimit && mSizeLimit->value() != 0 )
393 _url.
setExtension(
"x-sizelimit", TQString::number( mSizeLimit->value() ) );
394 if ( mTimeLimit && mTimeLimit->value() != 0 )
395 _url.
setExtension(
"x-timelimit", TQString::number( mTimeLimit->value() ) );
396 if ( mSecTLS && mSecTLS->isChecked() ) _url.
setExtension(
"x-tls",
"" );
397 if ( mFilter && !mFilter->text().isEmpty() )
399 if ( mSASL && mSASL->isChecked() ) {
402 if ( mBindDN && !mBindDN->text().isEmpty() )
404 if ( mRealm && !mRealm->text().isEmpty() )
417 return ( mUser ? mUser->text() : TQString::null );
427 return ( mPassword ? mPassword->text() : TQString::null );
432 if ( mBindDN ) mBindDN->
setText( binddn );
437 return ( mBindDN ? mBindDN->text() : TQString::null );
447 return ( mRealm ? mRealm->text() : TQString::null );
457 return ( mHost ? mHost->text() : TQString::null );
462 if ( mPort ) mPort->setValue(
port );
467 return ( mPort ? mPort->value() : 389 );
472 if ( mVer ) mVer->setValue(
ver );
477 return ( mVer ? mVer->value() : 3 );
487 return ( mDn ? mDn->text() : TQString::null );
497 return ( mFilter ? mFilter->text() : TQString::null );
502 if ( mMech == 0 )
return;
503 if ( !
mech.isEmpty() ) {
505 while ( i < mMech->count() ) {
506 if ( mMech->text( i ) ==
mech )
break;
509 if ( i == mMech->count() ) mMech->insertItem(
mech );
516 return ( mMech ? mMech->currentText() : TQString::null );
521 if ( mSecNO ) mSecNO->setChecked( b );
526 return ( mSecNO ? mSecNO->isChecked() :
true );
531 if ( mSecTLS ) mSecTLS->setChecked( b );
536 return ( mSecTLS ? mSecTLS->isChecked() :
false );
541 if ( mSecSSL ) mSecSSL->setChecked( b );
546 return ( mSecSSL ? mSecSSL->isChecked() :
false );
551 if ( mAnonymous ) mAnonymous->setChecked( b );
556 return ( mAnonymous ? mAnonymous->isChecked() :
true );
561 if ( mSimple ) mSimple->setChecked( b );
566 return ( mSimple ? mSimple->isChecked() :
false );
571 if ( mSASL ) mSASL->setChecked( b );
576 return ( mSASL ? mSASL->isChecked() :
false );
581 if ( mSizeLimit ) mSizeLimit->setValue( sizelimit );
586 return ( mSizeLimit ? mSizeLimit->value() : 0 );
591 if ( mTimeLimit ) mTimeLimit->setValue( timelimit );
596 return ( mTimeLimit ? mTimeLimit->value() : 0 );
599 int LdapConfigWidget::flags()
const
604 void LdapConfigWidget::setFlags(
int flags )
610 const TQObjectList ch = childrenListObject();
611 TQObjectList ch2 = ch;
617 widget =
dynamic_cast<TQWidget*
> (obj);
618 if ( widget && widget->parent() == this ) {
619 mainLayout->remove( widget );
void setCurrentItem(const TQString &item, bool insert=false, int index=-1)
virtual void setText(const TQString &)
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
KProgress * progressBar()
void setLabel(const TQString &text)
void setValue(int progress)
void setTotalSteps(int totalSteps)
virtual void advance(int offset)
void setUser(const TQString &_txt)
void setHost(const TQString &_txt)
void setPass(const TQString &_txt)
void setPort(unsigned short int _p)
TQString prettyURL(int _trailing=0) const
void setProtocol(const TQString &_txt)
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 setDn(const TQString &dn)
Sets the the dn part of the LDAP Url.
void setFilter(TQString filter)
Sets the filter 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.
const TQByteArray & val() const
Returns the attribute value.
void setLDIF(const TQByteArray &ldif)
Sets a chunk of LDIF.
void startParsing()
Starts the parsing of a new LDIF.
void endLDIF()
Indicates the end of the LDIF file/stream.
const TQString & attr() const
Returns the attribute name.
ParseVal nextItem()
Process the LDIF until a complete item can be returned.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
static data, shared by ALL addressee objects
TQString label(StdAccel id)