File indexing completed on 2025-01-26 04:52:16
0001 /* 0002 This file is part of libkldap. 0003 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "ldapconfigwidget.h" 0009 #include "ldapsearch.h" 0010 0011 #include "ldap_widgets_debug.h" 0012 #include <KAuthorized> 0013 #include <KLocalizedString> 0014 #include <KMessageBox> 0015 #include <KPasswordLineEdit> 0016 #include <QComboBox> 0017 #include <QProgressDialog> 0018 0019 #include <QCheckBox> 0020 #include <QFormLayout> 0021 #include <QObject> 0022 #include <QPushButton> 0023 #include <QRadioButton> 0024 #include <QSpinBox> 0025 0026 using namespace KLDAPWidgets; 0027 0028 class Q_DECL_HIDDEN LdapConfigWidget::LdapConfigWidgetPrivate 0029 { 0030 public: 0031 LdapConfigWidgetPrivate(LdapConfigWidget *parent) 0032 : mParent(parent) 0033 { 0034 mainLayout = new QFormLayout(mParent); 0035 mainLayout->setContentsMargins(10, 0, 10, 0); 0036 } 0037 0038 void setLDAPPort(); 0039 void setLDAPSPort(); 0040 void setAnonymous(bool on); 0041 void setSimple(bool on); 0042 void setSASL(bool on); 0043 void queryDNClicked(); 0044 void queryMechClicked(); 0045 void loadData(KLDAPCore::LdapSearch *search, const KLDAPCore::LdapObject &object); 0046 void loadResult(KLDAPCore::LdapSearch *search); 0047 void sendQuery(); 0048 void initWidget(); 0049 0050 LdapConfigWidget *const mParent; 0051 QStringList mQResult; 0052 QString mAttr; 0053 0054 QLineEdit *mUser = nullptr; 0055 KPasswordLineEdit *mPassword = nullptr; 0056 QLineEdit *mHost = nullptr; 0057 QSpinBox *mPort = nullptr; 0058 QSpinBox *mVersion = nullptr; 0059 QSpinBox *mSizeLimit = nullptr; 0060 QSpinBox *mTimeLimit = nullptr; 0061 QSpinBox *mPageSize = nullptr; 0062 QLineEdit *mDn = nullptr; 0063 QLineEdit *mBindDn = nullptr; 0064 QLineEdit *mRealm = nullptr; 0065 QLineEdit *mFilter = nullptr; 0066 QRadioButton *mAnonymous = nullptr; 0067 QRadioButton *mSimple = nullptr; 0068 QRadioButton *mSASL = nullptr; 0069 QCheckBox *mSubTree = nullptr; 0070 QPushButton *mEditButton = nullptr; 0071 QPushButton *mQueryMech = nullptr; 0072 QRadioButton *mSecNo = nullptr; 0073 QRadioButton *mSecTLS = nullptr; 0074 QRadioButton *mSecSSL = nullptr; 0075 QComboBox *mMech = nullptr; 0076 0077 QProgressDialog *mProg = nullptr; 0078 0079 QFormLayout *mainLayout = nullptr; 0080 WinFlags mFeatures = W_ALL; 0081 bool mCancelled = false; 0082 }; 0083 0084 void LdapConfigWidget::LdapConfigWidgetPrivate::initWidget() 0085 { 0086 if (mFeatures & W_USER) { 0087 mUser = new QLineEdit(mParent); 0088 mUser->setObjectName(QLatin1StringView("kcfg_ldapuser")); 0089 0090 mainLayout->addRow(i18n("User:"), mUser); 0091 } 0092 0093 if (mFeatures & W_BINDDN) { 0094 mBindDn = new QLineEdit(mParent); 0095 mBindDn->setObjectName(QLatin1StringView("kcfg_ldapbinddn")); 0096 0097 mainLayout->addRow(i18n("Bind DN:"), mBindDn); 0098 } 0099 0100 if (mFeatures & W_REALM) { 0101 mRealm = new QLineEdit(mParent); 0102 mRealm->setObjectName(QLatin1StringView("kcfg_ldaprealm")); 0103 0104 mainLayout->addRow(i18n("Realm:"), mRealm); 0105 } 0106 0107 if (mFeatures & W_PASS) { 0108 mPassword = new KPasswordLineEdit(mParent); 0109 mPassword->setObjectName(QLatin1StringView("kcfg_ldappassword")); 0110 mPassword->setRevealPasswordAvailable(KAuthorized::authorize(QStringLiteral("lineedit_reveal_password"))); 0111 0112 mainLayout->addRow(i18n("Password:"), mPassword); 0113 } 0114 0115 if (mFeatures & W_HOST) { 0116 mHost = new QLineEdit(mParent); 0117 mHost->setObjectName(QLatin1StringView("kcfg_ldaphost")); 0118 mParent->connect(mHost, &QLineEdit::textChanged, mParent, &LdapConfigWidget::hostNameChanged); 0119 mainLayout->addRow(i18n("Host:"), mHost); 0120 } 0121 0122 if (mFeatures & W_PORT) { 0123 mPort = new QSpinBox(mParent); 0124 mPort->setRange(0, 65535); 0125 mPort->setObjectName(QLatin1StringView("kcfg_ldapport")); 0126 mPort->setValue(389); 0127 0128 mainLayout->addRow(i18n("Port:"), mPort); 0129 } 0130 0131 if (mFeatures & W_VER) { 0132 mVersion = new QSpinBox(mParent); 0133 mVersion->setRange(2, 3); 0134 mVersion->setObjectName(QLatin1StringView("kcfg_ldapver")); 0135 mVersion->setValue(3); 0136 mainLayout->addRow(i18n("LDAP version:"), mVersion); 0137 } 0138 0139 if (mFeatures & W_SIZELIMIT) { 0140 mSizeLimit = new QSpinBox(mParent); 0141 mSizeLimit->setRange(0, 9999999); 0142 mSizeLimit->setObjectName(QLatin1StringView("kcfg_ldapsizelimit")); 0143 mSizeLimit->setValue(0); 0144 mSizeLimit->setSpecialValueText(i18nc("default ldap size limit", "Default")); 0145 mainLayout->addRow(i18n("Size limit:"), mSizeLimit); 0146 } 0147 0148 if (mFeatures & W_TIMELIMIT) { 0149 mTimeLimit = new QSpinBox(mParent); 0150 mTimeLimit->setRange(0, 9999999); 0151 mTimeLimit->setObjectName(QLatin1StringView("kcfg_ldaptimelimit")); 0152 mTimeLimit->setValue(0); 0153 mTimeLimit->setSuffix(i18n(" sec")); 0154 mTimeLimit->setSpecialValueText(i18nc("default ldap time limit", "Default")); 0155 mainLayout->addRow(i18n("Time limit:"), mTimeLimit); 0156 } 0157 0158 if (mFeatures & W_PAGESIZE) { 0159 mPageSize = new QSpinBox(mParent); 0160 mPageSize->setRange(0, 9999999); 0161 mPageSize->setObjectName(QLatin1StringView("kcfg_ldappagesize")); 0162 mPageSize->setValue(0); 0163 mPageSize->setSpecialValueText(i18n("No paging")); 0164 mainLayout->addRow(i18n("Page size:"), mPageSize); 0165 } 0166 0167 if (mFeatures & W_DN) { 0168 auto horizontalLayout = new QHBoxLayout; 0169 mDn = new QLineEdit(mParent); 0170 mDn->setObjectName(QLatin1StringView("kcfg_ldapdn")); 0171 horizontalLayout->addWidget(mDn); 0172 0173 // without host query doesn't make sense 0174 if (mHost) { 0175 auto dnquery = new QPushButton(i18n("Query Server"), mParent); 0176 dnquery->setEnabled(false); 0177 connect(dnquery, &QPushButton::clicked, mParent, [this]() { 0178 queryDNClicked(); 0179 }); 0180 connect(mDn, &QLineEdit::textChanged, mParent, [dnquery](const QString &text) { 0181 dnquery->setEnabled(!text.trimmed().isEmpty()); 0182 }); 0183 horizontalLayout->addWidget(dnquery); 0184 } 0185 mainLayout->addRow(i18nc("Distinguished Name", "DN:"), horizontalLayout); 0186 } 0187 0188 if (mFeatures & W_FILTER) { 0189 mFilter = new QLineEdit(mParent); 0190 mFilter->setObjectName(QLatin1StringView("kcfg_ldapfilter")); 0191 0192 mainLayout->addRow(i18n("Filter:"), mFilter); 0193 } 0194 0195 if (mFeatures & W_SECBOX) { 0196 auto btgroup = new QWidget(mParent); 0197 btgroup->setContentsMargins({0, 0, 0, 0}); 0198 0199 auto hbox = new QHBoxLayout(btgroup); 0200 0201 mSecNo = new QRadioButton(i18nc("@option:radio set no security", "No"), btgroup); 0202 mSecNo->setObjectName(QLatin1StringView("kcfg_ldapnosec")); 0203 hbox->addWidget(mSecNo); 0204 mSecTLS = new QRadioButton(i18nc("@option:radio use TLS security", "TLS"), btgroup); 0205 mSecTLS->setObjectName(QLatin1StringView("kcfg_ldaptls")); 0206 hbox->addWidget(mSecTLS); 0207 mSecSSL = new QRadioButton(i18nc("@option:radio use SSL security", "SSL"), btgroup); 0208 mSecSSL->setObjectName(QLatin1StringView("kcfg_ldapssl")); 0209 hbox->addWidget(mSecSSL); 0210 0211 connect(mSecNo, &QRadioButton::clicked, mParent, [this]() { 0212 setLDAPPort(); 0213 }); 0214 connect(mSecTLS, &QRadioButton::clicked, mParent, [this]() { 0215 setLDAPPort(); 0216 }); 0217 connect(mSecSSL, &QRadioButton::clicked, mParent, [this]() { 0218 setLDAPSPort(); 0219 }); 0220 0221 mSecNo->setChecked(true); 0222 mainLayout->addRow(i18n("Security:"), btgroup); 0223 } 0224 0225 if (mFeatures & W_AUTHBOX) { 0226 // invisible QWidget for auto-exclusive radiobutton 0227 auto authbox = new QWidget(mParent); 0228 authbox->setContentsMargins({0, 0, 0, 0}); 0229 0230 auto hbox = new QHBoxLayout(authbox); 0231 0232 mAnonymous = new QRadioButton(i18nc("@option:radio anonymous authentication", "Anonymous"), authbox); 0233 mAnonymous->setObjectName(QLatin1StringView("kcfg_ldapanon")); 0234 hbox->addWidget(mAnonymous); 0235 mSimple = new QRadioButton(i18nc("@option:radio simple authentication", "Simple"), authbox); 0236 mSimple->setObjectName(QLatin1StringView("kcfg_ldapsimple")); 0237 hbox->addWidget(mSimple); 0238 mSASL = new QRadioButton(i18nc("@option:radio SASL authentication", "SASL"), authbox); 0239 mSASL->setObjectName(QLatin1StringView("kcfg_ldapsasl")); 0240 hbox->addWidget(mSASL); 0241 mainLayout->addRow(i18n("Authentication:"), authbox); 0242 0243 hbox = new QHBoxLayout; 0244 mMech = new QComboBox(mParent); 0245 mMech->setObjectName(QLatin1StringView("kcfg_ldapsaslmech")); 0246 mMech->addItem(QStringLiteral("DIGEST-MD5")); 0247 mMech->addItem(QStringLiteral("GSSAPI")); 0248 mMech->addItem(QStringLiteral("PLAIN")); 0249 hbox->addWidget(mMech); 0250 0251 // without host query doesn't make sense 0252 if (mHost) { 0253 mQueryMech = new QPushButton(i18n("Query Server"), authbox); 0254 hbox->addWidget(mQueryMech); 0255 connect(mQueryMech, &QPushButton::clicked, mParent, [this]() { 0256 queryMechClicked(); 0257 }); 0258 } 0259 mainLayout->addRow(i18n("SASL mechanism:"), hbox); 0260 0261 connect(mAnonymous, &QRadioButton::toggled, mParent, [this](bool b) { 0262 setAnonymous(b); 0263 }); 0264 connect(mSimple, &QRadioButton::toggled, mParent, [this](bool b) { 0265 setSimple(b); 0266 }); 0267 connect(mSASL, &QRadioButton::toggled, mParent, [this](bool b) { 0268 setSASL(b); 0269 }); 0270 0271 mAnonymous->setChecked(true); 0272 } 0273 } 0274 0275 void LdapConfigWidget::LdapConfigWidgetPrivate::sendQuery() 0276 { 0277 KLDAPCore::LdapServer _server(mParent->server()); 0278 0279 mQResult.clear(); 0280 mCancelled = true; 0281 0282 if (mAttr == QLatin1StringView("supportedsaslmechanisms")) { 0283 _server.setAuth(KLDAPCore::LdapServer::Anonymous); 0284 } 0285 0286 KLDAPCore::LdapUrl _url(_server.url()); 0287 0288 _url.setDn(KLDAPCore::LdapDN(QLatin1StringView(""))); 0289 _url.setAttributes(QStringList(mAttr)); 0290 _url.setScope(KLDAPCore::LdapUrl::Base); 0291 0292 qCDebug(LDAP_LOG) << "sendQuery url:" << _url.toDisplayString(); 0293 0294 KLDAPCore::LdapSearch search; 0295 connect(&search, &KLDAPCore::LdapSearch::data, mParent, [this](KLDAPCore::LdapSearch *s, const KLDAPCore::LdapObject &obj) { 0296 loadData(s, obj); 0297 }); 0298 connect(&search, &KLDAPCore::LdapSearch::result, mParent, [this](KLDAPCore::LdapSearch *s) { 0299 loadResult(s); 0300 }); 0301 0302 if (!search.search(_url)) { 0303 KMessageBox::error(mParent, search.errorString(), i18n("Check server")); 0304 return; 0305 } 0306 0307 if (!mProg) { 0308 mProg = new QProgressDialog(mParent); 0309 mProg->setWindowTitle(i18nc("@title:window", "LDAP Query")); 0310 mProg->setModal(true); 0311 } 0312 mProg->setLabelText(_url.toDisplayString()); 0313 mProg->setMaximum(1); 0314 mProg->setMinimum(0); 0315 mProg->setValue(0); 0316 mProg->exec(); 0317 if (mCancelled) { 0318 qCDebug(LDAP_LOG) << "query canceled!"; 0319 search.abandon(); 0320 } else { 0321 if (search.error()) { 0322 if (search.errorString().isEmpty()) { 0323 KMessageBox::error(mParent, i18nc("%1 is a url to ldap server", "Unknown error connecting %1", _url.toDisplayString())); 0324 } else { 0325 KMessageBox::error(mParent, search.errorString()); 0326 } 0327 } 0328 } 0329 } 0330 0331 void LdapConfigWidget::LdapConfigWidgetPrivate::queryMechClicked() 0332 { 0333 mAttr = QStringLiteral("supportedsaslmechanisms"); 0334 sendQuery(); 0335 if (!mQResult.isEmpty()) { 0336 mQResult.sort(); 0337 mMech->clear(); 0338 mMech->addItems(mQResult); 0339 } 0340 } 0341 0342 void LdapConfigWidget::LdapConfigWidgetPrivate::queryDNClicked() 0343 { 0344 mAttr = QStringLiteral("namingcontexts"); 0345 sendQuery(); 0346 if (!mQResult.isEmpty()) { 0347 mDn->setText(mQResult.constFirst()); 0348 } 0349 } 0350 0351 void LdapConfigWidget::LdapConfigWidgetPrivate::loadData(KLDAPCore::LdapSearch *, const KLDAPCore::LdapObject &object) 0352 { 0353 qCDebug(LDAP_LOG) << "object:" << object.toString(); 0354 mProg->setValue(mProg->value() + 1); 0355 KLDAPCore::LdapAttrMap::ConstIterator end(object.attributes().constEnd()); 0356 for (KLDAPCore::LdapAttrMap::ConstIterator it = object.attributes().constBegin(); it != end; ++it) { 0357 KLDAPCore::LdapAttrValue::ConstIterator end2((*it).constEnd()); 0358 for (KLDAPCore::LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2) { 0359 mQResult.push_back(QString::fromUtf8(*it2)); 0360 } 0361 } 0362 } 0363 0364 void LdapConfigWidget::LdapConfigWidgetPrivate::loadResult(KLDAPCore::LdapSearch *search) 0365 { 0366 Q_UNUSED(search) 0367 mCancelled = false; 0368 mProg->close(); 0369 } 0370 0371 void LdapConfigWidget::LdapConfigWidgetPrivate::setAnonymous(bool on) 0372 { 0373 if (!on) { 0374 return; 0375 } 0376 if (mUser) { 0377 mUser->setEnabled(false); 0378 } 0379 if (mPassword) { 0380 mPassword->setEnabled(false); 0381 } 0382 if (mBindDn) { 0383 mBindDn->setEnabled(false); 0384 } 0385 if (mRealm) { 0386 mRealm->setEnabled(false); 0387 } 0388 if (mMech) { 0389 mMech->setEnabled(false); 0390 } 0391 if (mQueryMech) { 0392 mQueryMech->setEnabled(false); 0393 } 0394 } 0395 0396 void LdapConfigWidget::LdapConfigWidgetPrivate::setSimple(bool on) 0397 { 0398 if (!on) { 0399 return; 0400 } 0401 if (mUser) { 0402 mUser->setEnabled(false); 0403 } 0404 if (mPassword) { 0405 mPassword->setEnabled(true); 0406 } 0407 if (mBindDn) { 0408 mBindDn->setEnabled(true); 0409 } 0410 if (mRealm) { 0411 mRealm->setEnabled(false); 0412 } 0413 if (mMech) { 0414 mMech->setEnabled(false); 0415 } 0416 if (mQueryMech) { 0417 mQueryMech->setEnabled(false); 0418 } 0419 } 0420 0421 void LdapConfigWidget::LdapConfigWidgetPrivate::setSASL(bool on) 0422 { 0423 if (!on) { 0424 return; 0425 } 0426 if (mUser) { 0427 mUser->setEnabled(true); 0428 } 0429 if (mPassword) { 0430 mPassword->setEnabled(true); 0431 } 0432 if (mBindDn) { 0433 mBindDn->setEnabled(true); 0434 } 0435 if (mRealm) { 0436 mRealm->setEnabled(true); 0437 } 0438 if (mMech) { 0439 mMech->setEnabled(true); 0440 } 0441 if (mQueryMech) { 0442 mQueryMech->setEnabled(true); 0443 } 0444 } 0445 0446 void LdapConfigWidget::LdapConfigWidgetPrivate::setLDAPPort() 0447 { 0448 if (mPort) { 0449 mPort->setValue(389); 0450 } 0451 } 0452 0453 void LdapConfigWidget::LdapConfigWidgetPrivate::setLDAPSPort() 0454 { 0455 if (mPort) { 0456 mPort->setValue(636); 0457 } 0458 } 0459 0460 LdapConfigWidget::LdapConfigWidget(QWidget *parent, Qt::WindowFlags fl) 0461 : QWidget(parent, fl) 0462 , d(new LdapConfigWidgetPrivate(this)) 0463 { 0464 } 0465 0466 LdapConfigWidget::LdapConfigWidget(LdapConfigWidget::WinFlags flags, QWidget *parent, Qt::WindowFlags fl) 0467 : QWidget(parent, fl) 0468 , d(new LdapConfigWidgetPrivate(this)) 0469 { 0470 d->mFeatures = flags; 0471 0472 d->initWidget(); 0473 } 0474 0475 LdapConfigWidget::~LdapConfigWidget() = default; 0476 0477 KLDAPCore::LdapUrl LdapConfigWidget::url() const 0478 { 0479 return server().url(); 0480 } 0481 0482 void LdapConfigWidget::setUrl(const KLDAPCore::LdapUrl &url) 0483 { 0484 KLDAPCore::LdapServer _server; 0485 _server.setUrl(url); 0486 setServer(_server); 0487 } 0488 0489 KLDAPCore::LdapServer LdapConfigWidget::server() const 0490 { 0491 KLDAPCore::LdapServer _server; 0492 if (d->mSecSSL && d->mSecSSL->isChecked()) { 0493 _server.setSecurity(KLDAPCore::LdapServer::SSL); 0494 } else if (d->mSecTLS && d->mSecTLS->isChecked()) { 0495 _server.setSecurity(KLDAPCore::LdapServer::TLS); 0496 } else { 0497 _server.setSecurity(KLDAPCore::LdapServer::None); 0498 } 0499 0500 if (d->mUser) { 0501 _server.setUser(d->mUser->text()); 0502 } 0503 if (d->mBindDn) { 0504 _server.setBindDn(d->mBindDn->text()); 0505 } 0506 if (d->mPassword) { 0507 _server.setPassword(d->mPassword->password()); 0508 } 0509 if (d->mRealm) { 0510 _server.setRealm(d->mRealm->text()); 0511 } 0512 if (d->mHost) { 0513 _server.setHost(d->mHost->text()); 0514 } 0515 if (d->mPort) { 0516 _server.setPort(d->mPort->value()); 0517 } 0518 if (d->mDn) { 0519 _server.setBaseDn(KLDAPCore::LdapDN(d->mDn->text())); 0520 } 0521 if (d->mFilter) { 0522 _server.setFilter(d->mFilter->text()); 0523 } 0524 if (d->mVersion) { 0525 _server.setVersion(d->mVersion->value()); 0526 } 0527 if (d->mSizeLimit && d->mSizeLimit->value() != 0) { 0528 _server.setSizeLimit(d->mSizeLimit->value()); 0529 } 0530 if (d->mTimeLimit && d->mTimeLimit->value() != 0) { 0531 _server.setTimeLimit(d->mTimeLimit->value()); 0532 } 0533 if (d->mPageSize && d->mPageSize->value() != 0) { 0534 _server.setPageSize(d->mPageSize->value()); 0535 } 0536 if (d->mAnonymous && d->mAnonymous->isChecked()) { 0537 _server.setAuth(KLDAPCore::LdapServer::Anonymous); 0538 } else if (d->mSimple && d->mSimple->isChecked()) { 0539 _server.setAuth(KLDAPCore::LdapServer::Simple); 0540 } else if (d->mSASL && d->mSASL->isChecked()) { 0541 _server.setAuth(KLDAPCore::LdapServer::SASL); 0542 _server.setMech(d->mMech->currentText()); 0543 } 0544 return _server; 0545 } 0546 0547 void LdapConfigWidget::setServer(const KLDAPCore::LdapServer &server) 0548 { 0549 switch (server.security()) { 0550 case KLDAPCore::LdapServer::SSL: 0551 if (d->mSecSSL) { 0552 d->mSecSSL->setChecked(true); 0553 } 0554 break; 0555 case KLDAPCore::LdapServer::TLS: 0556 if (d->mSecTLS) { 0557 d->mSecTLS->setChecked(true); 0558 } 0559 break; 0560 case KLDAPCore::LdapServer::None: 0561 if (d->mSecNo) { 0562 d->mSecNo->setChecked(true); 0563 } 0564 break; 0565 } 0566 0567 switch (server.auth()) { 0568 case KLDAPCore::LdapServer::Anonymous: 0569 if (d->mAnonymous) { 0570 d->mAnonymous->setChecked(true); 0571 } 0572 break; 0573 case KLDAPCore::LdapServer::Simple: 0574 if (d->mSimple) { 0575 d->mSimple->setChecked(true); 0576 } 0577 break; 0578 case KLDAPCore::LdapServer::SASL: 0579 if (d->mSASL) { 0580 d->mSASL->setChecked(true); 0581 } 0582 break; 0583 } 0584 0585 setUser(server.user()); 0586 setBindDn(server.bindDn()); 0587 setPassword(server.password()); 0588 setRealm(server.realm()); 0589 setHost(server.host()); 0590 setPort(server.port()); 0591 setFilter(server.filter()); 0592 setDn(server.baseDn()); 0593 setVersion(server.version()); 0594 setSizeLimit(server.sizeLimit()); 0595 setTimeLimit(server.timeLimit()); 0596 setPageSize(server.pageSize()); 0597 setMech(server.mech()); 0598 } 0599 0600 void LdapConfigWidget::setUser(const QString &user) 0601 { 0602 if (d->mUser) { 0603 d->mUser->setText(user); 0604 } 0605 } 0606 0607 QString LdapConfigWidget::user() const 0608 { 0609 return d->mUser ? d->mUser->text() : QString(); 0610 } 0611 0612 void LdapConfigWidget::setPassword(const QString &password) 0613 { 0614 if (d->mPassword) { 0615 d->mPassword->setPassword(password); 0616 } 0617 } 0618 0619 QString LdapConfigWidget::password() const 0620 { 0621 return d->mPassword ? d->mPassword->password() : QString(); 0622 } 0623 0624 void LdapConfigWidget::setBindDn(const QString &binddn) 0625 { 0626 if (d->mBindDn) { 0627 d->mBindDn->setText(binddn); 0628 } 0629 } 0630 0631 QString LdapConfigWidget::bindDn() const 0632 { 0633 return d->mBindDn ? d->mBindDn->text() : QString(); 0634 } 0635 0636 void LdapConfigWidget::setRealm(const QString &realm) 0637 { 0638 if (d->mRealm) { 0639 d->mRealm->setText(realm); 0640 } 0641 } 0642 0643 QString LdapConfigWidget::realm() const 0644 { 0645 return d->mRealm ? d->mRealm->text() : QString(); 0646 } 0647 0648 void LdapConfigWidget::setHost(const QString &host) 0649 { 0650 if (d->mHost) { 0651 d->mHost->setText(host); 0652 } 0653 } 0654 0655 QString LdapConfigWidget::host() const 0656 { 0657 return d->mHost ? d->mHost->text() : QString(); 0658 } 0659 0660 void LdapConfigWidget::setPort(int port) 0661 { 0662 if (d->mPort) { 0663 d->mPort->setValue(port); 0664 } 0665 } 0666 0667 int LdapConfigWidget::port() const 0668 { 0669 return d->mPort ? d->mPort->value() : 389; 0670 } 0671 0672 void LdapConfigWidget::setVersion(int version) 0673 { 0674 if (d->mVersion) { 0675 d->mVersion->setValue(version); 0676 } 0677 } 0678 0679 int LdapConfigWidget::version() const 0680 { 0681 return d->mVersion ? d->mVersion->value() : 3; 0682 } 0683 0684 void LdapConfigWidget::setDn(const KLDAPCore::LdapDN &dn) 0685 { 0686 if (d->mDn) { 0687 d->mDn->setText(dn.toString()); 0688 } 0689 } 0690 0691 KLDAPCore::LdapDN LdapConfigWidget::dn() const 0692 { 0693 return d->mDn ? KLDAPCore::LdapDN(d->mDn->text()) : KLDAPCore::LdapDN(); 0694 } 0695 0696 void LdapConfigWidget::setFilter(const QString &filter) 0697 { 0698 if (d->mFilter) { 0699 d->mFilter->setText(filter); 0700 } 0701 } 0702 0703 QString LdapConfigWidget::filter() const 0704 { 0705 return d->mFilter ? d->mFilter->text() : QString(); 0706 } 0707 0708 void LdapConfigWidget::setMech(const QString &mech) 0709 { 0710 if (d->mMech == nullptr) { 0711 return; 0712 } 0713 if (!mech.isEmpty()) { 0714 int i = 0; 0715 while (i < d->mMech->count()) { 0716 if (d->mMech->itemText(i) == mech) { 0717 break; 0718 } 0719 i++; 0720 } 0721 if (i == d->mMech->count()) { 0722 d->mMech->addItem(mech); 0723 } 0724 d->mMech->setCurrentIndex(i); 0725 } 0726 } 0727 0728 QString LdapConfigWidget::mech() const 0729 { 0730 return d->mMech ? d->mMech->currentText() : QString(); 0731 } 0732 0733 void LdapConfigWidget::setSecurity(Security security) 0734 { 0735 switch (security) { 0736 case None: 0737 d->mSecNo->setChecked(true); 0738 break; 0739 case SSL: 0740 d->mSecSSL->setChecked(true); 0741 break; 0742 case TLS: 0743 d->mSecTLS->setChecked(true); 0744 break; 0745 } 0746 } 0747 0748 LdapConfigWidget::Security LdapConfigWidget::security() const 0749 { 0750 if (d->mSecTLS->isChecked()) { 0751 return TLS; 0752 } 0753 if (d->mSecSSL->isChecked()) { 0754 return SSL; 0755 } 0756 return None; 0757 } 0758 0759 void LdapConfigWidget::setAuth(Auth auth) 0760 { 0761 switch (auth) { 0762 case Anonymous: 0763 d->mAnonymous->setChecked(true); 0764 break; 0765 case Simple: 0766 d->mSimple->setChecked(true); 0767 break; 0768 case SASL: 0769 d->mSASL->setChecked(true); 0770 break; 0771 } 0772 } 0773 0774 LdapConfigWidget::Auth LdapConfigWidget::auth() const 0775 { 0776 if (d->mSimple->isChecked()) { 0777 return Simple; 0778 } 0779 if (d->mSASL->isChecked()) { 0780 return SASL; 0781 } 0782 return Anonymous; 0783 } 0784 0785 void LdapConfigWidget::setSizeLimit(int sizelimit) 0786 { 0787 if (d->mSizeLimit) { 0788 d->mSizeLimit->setValue(sizelimit); 0789 } 0790 } 0791 0792 int LdapConfigWidget::sizeLimit() const 0793 { 0794 return d->mSizeLimit ? d->mSizeLimit->value() : 0; 0795 } 0796 0797 void LdapConfigWidget::setTimeLimit(int timelimit) 0798 { 0799 if (d->mTimeLimit) { 0800 d->mTimeLimit->setValue(timelimit); 0801 } 0802 } 0803 0804 int LdapConfigWidget::timeLimit() const 0805 { 0806 return d->mTimeLimit ? d->mTimeLimit->value() : 0; 0807 } 0808 0809 void LdapConfigWidget::setPageSize(int pagesize) 0810 { 0811 if (d->mPageSize) { 0812 d->mPageSize->setValue(pagesize); 0813 } 0814 } 0815 0816 int LdapConfigWidget::pageSize() const 0817 { 0818 return d->mPageSize ? d->mPageSize->value() : 0; 0819 } 0820 0821 LdapConfigWidget::WinFlags LdapConfigWidget::features() const 0822 { 0823 return d->mFeatures; 0824 } 0825 0826 void LdapConfigWidget::setFeatures(LdapConfigWidget::WinFlags features) 0827 { 0828 d->mFeatures = features; 0829 0830 // First delete all the child widgets. 0831 // FIXME: I hope it's correct 0832 QList<QObject *> ch = children(); 0833 const int numberOfChild(ch.count()); 0834 for (int i = 0; i < numberOfChild; ++i) { 0835 QWidget *widget = qobject_cast<QWidget *>(ch[i]); 0836 if (widget && widget->parent() == this) { 0837 delete (widget); 0838 } 0839 } 0840 0841 // Re-create child widgets according to the new flags 0842 d->initWidget(); 0843 } 0844 0845 #include "moc_ldapconfigwidget.cpp"