diff --git a/src/ldapattributeproxymodel.cpp b/src/ldapattributeproxymodel.cpp index cb2c908..50cd09d 100644 --- a/src/ldapattributeproxymodel.cpp +++ b/src/ldapattributeproxymodel.cpp @@ -1,147 +1,147 @@ /* This file is part of libkldap. Copyright (c) 2006 Sean Harmer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ldapattributeproxymodel.h" #include "ldapmodel.h" #include "ldapmodelnode_p.h" #include "ldap_debug.h" -#include +#include using namespace KLDAP; LdapAttributeProxyModel::LdapAttributeProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { } LdapAttributeProxyModel::~LdapAttributeProxyModel() { } QVariant LdapAttributeProxyModel::data(const QModelIndex &index, int role) const { // Included just in case we decide to do any special presentation of the data // at some other point throughout the 4.x series. return sourceModel()->data(mapToSource(index), role); } bool LdapAttributeProxyModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(index); Q_UNUSED(value); Q_UNUSED(role); return false; } bool LdapAttributeProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent); LdapModelNode::NodeType nodeType = static_cast( sourceModel()->data(idx, LdapModel::NodeTypeRole).toUInt()); return nodeType == LdapModelNode::Attr; } QVariant LdapAttributeProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return QVariant(i18n("Attribute")); } else if (section == 1) { return QVariant(i18n("Value")); } } return QVariant(); } int LdapAttributeProxyModel::columnCount(const QModelIndex & /*parent*/) const { return 2; } Qt::ItemFlags LdapAttributeProxyModel::flags(const QModelIndex &index) const { // Included so as not to break BC in case we wish to use this later in 4.x return sourceModel()->flags(mapToSource(index)); } bool LdapAttributeProxyModel::hasChildren(const QModelIndex &parent) const { // We need to handle this carefully bacause of the filtering out of attributes // and the lazy population approach. LdapModel *model = static_cast(sourceModel()); return model->hasChildrenOfType(mapToSource(parent), LdapModel::Attribute); } QModelIndex LdapAttributeProxyModel::mapFromSource(const QModelIndex &sourceIndex) const { return QSortFilterProxyModel::mapFromSource(sourceIndex); } QModelIndex LdapAttributeProxyModel::mapToSource(const QModelIndex &proxyIndex) const { return QSortFilterProxyModel::mapToSource(proxyIndex); } bool LdapAttributeProxyModel::insertRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(count); Q_UNUSED(parent); return false; } bool LdapAttributeProxyModel::removeRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(count); Q_UNUSED(parent); return false; } void LdapAttributeProxyModel::sort(int column, Qt::SortOrder order) { Q_UNUSED(column); Q_UNUSED(order); } Qt::DropActions LdapAttributeProxyModel::supportedDropActions() const { return Qt::MoveAction; } QMimeData *LdapAttributeProxyModel::mimeData(const QModelIndexList &indexes) const { Q_UNUSED(indexes); return nullptr; } bool LdapAttributeProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { /** \todo Implement drag and drop for LdapModel */ Q_UNUSED(data); Q_UNUSED(action); Q_UNUSED(row); Q_UNUSED(column); Q_UNUSED(parent); return false; } diff --git a/src/ldapconfigwidget.cpp b/src/ldapconfigwidget.cpp index 886eb32..283a375 100644 --- a/src/ldapconfigwidget.cpp +++ b/src/ldapconfigwidget.cpp @@ -1,924 +1,924 @@ /* This file is part of libkldap. Copyright (c) 2004-2006 Szombathelyi György This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ldapconfigwidget.h" #include "ldapsearch.h" #include #include #include "ldap_debug.h" -#include +#include #include #include #include #include #include #include #include #include #include #include using namespace KLDAP; class Q_DECL_HIDDEN LdapConfigWidget::Private { public: Private(LdapConfigWidget *parent) : mParent(parent) { mainLayout = new QGridLayout(mParent); mainLayout->setContentsMargins(0, 0, 0, 0); } void setLDAPPort(); void setLDAPSPort(); void setAnonymous(bool on); void setSimple(bool on); void setSASL(bool on); void queryDNClicked(); void queryMechClicked(); void loadData(LdapSearch *search, const LdapObject &object); void loadResult(LdapSearch *search); void sendQuery(); void initWidget(); LdapConfigWidget *mParent = nullptr; WinFlags mFeatures = W_ALL; QStringList mQResult; QString mAttr; QLineEdit *mUser = nullptr; KPasswordLineEdit *mPassword = nullptr; QLineEdit *mHost = nullptr; QSpinBox *mPort = nullptr; QSpinBox *mVersion = nullptr; QSpinBox *mSizeLimit = nullptr; QSpinBox *mTimeLimit = nullptr; QSpinBox *mPageSize = nullptr; QLineEdit *mDn = nullptr; QLineEdit *mBindDn = nullptr; QLineEdit *mRealm = nullptr; QLineEdit *mFilter = nullptr; QRadioButton *mAnonymous = nullptr; QRadioButton *mSimple = nullptr; QRadioButton *mSASL = nullptr; QCheckBox *mSubTree = nullptr; QPushButton *mEditButton = nullptr; QPushButton *mQueryMech = nullptr; QRadioButton *mSecNo = nullptr; QRadioButton *mSecTLS = nullptr; QRadioButton *mSecSSL = nullptr; QComboBox *mMech = nullptr; bool mCancelled = false; QProgressDialog *mProg = nullptr; QGridLayout *mainLayout = nullptr; }; void LdapConfigWidget::Private::initWidget() { QLabel *label = nullptr; mUser = mHost = mDn = mBindDn = mRealm = mFilter = nullptr; mPassword = nullptr; mPort = mVersion = mTimeLimit = mSizeLimit = nullptr; mAnonymous = mSimple = mSASL = mSecNo = mSecTLS = mSecSSL = nullptr; mEditButton = mQueryMech = nullptr; mPageSize = nullptr; mMech = nullptr; int row = 0; int col; if (mFeatures & W_USER) { label = new QLabel(i18n("User:"), mParent); mUser = new QLineEdit(mParent); mUser->setObjectName(QStringLiteral("kcfg_ldapuser")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mUser, row, 1, 1, 3); row++; } if (mFeatures & W_BINDDN) { label = new QLabel(i18n("Bind DN:"), mParent); mBindDn = new QLineEdit(mParent); mBindDn->setObjectName(QStringLiteral("kcfg_ldapbinddn")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mBindDn, row, 1, 1, 3); row++; } if (mFeatures & W_REALM) { label = new QLabel(i18n("Realm:"), mParent); mRealm = new QLineEdit(mParent); mRealm->setObjectName(QStringLiteral("kcfg_ldaprealm")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mRealm, row, 1, 1, 3); row++; } if (mFeatures & W_PASS) { label = new QLabel(i18n("Password:"), mParent); mPassword = new KPasswordLineEdit(mParent); mPassword->setObjectName(QStringLiteral("kcfg_ldappassword")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mPassword, row, 1, 1, 3); row++; } if (mFeatures & W_HOST) { label = new QLabel(i18n("Host:"), mParent); mHost = new QLineEdit(mParent); mHost->setObjectName(QStringLiteral("kcfg_ldaphost")); mParent->connect(mHost, &QLineEdit::textChanged, mParent, &LdapConfigWidget::hostNameChanged); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mHost, row, 1, 1, 3); row++; } col = 0; if (mFeatures & W_PORT) { label = new QLabel(i18n("Port:"), mParent); mPort = new QSpinBox(mParent); mPort->setRange(0, 65535); mPort->setObjectName(QStringLiteral("kcfg_ldapport")); mPort->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); mPort->setValue(389); mainLayout->addWidget(label, row, col); mainLayout->addWidget(mPort, row, col + 1); col += 2; } if (mFeatures & W_VER) { label = new QLabel(i18n("LDAP version:"), mParent); mVersion = new QSpinBox(mParent); mVersion->setRange(2, 3); mVersion->setObjectName(QStringLiteral("kcfg_ldapver")); mVersion->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); mVersion->setValue(3); mainLayout->addWidget(label, row, col); mainLayout->addWidget(mVersion, row, col + 1); } if (mFeatures & (W_PORT | W_VER)) { row++; } col = 0; if (mFeatures & W_SIZELIMIT) { label = new QLabel(i18n("Size limit:"), mParent); mSizeLimit = new QSpinBox(mParent); mSizeLimit->setRange(0, 9999999); mSizeLimit->setObjectName(QStringLiteral("kcfg_ldapsizelimit")); mSizeLimit->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); mSizeLimit->setValue(0); mSizeLimit->setSpecialValueText(i18nc("default ldap size limit", "Default")); mainLayout->addWidget(label, row, col); mainLayout->addWidget(mSizeLimit, row, col + 1); col += 2; } if (mFeatures & W_TIMELIMIT) { label = new QLabel(i18n("Time limit:"), mParent); mTimeLimit = new QSpinBox(mParent); mTimeLimit->setRange(0, 9999999); mTimeLimit->setObjectName(QStringLiteral("kcfg_ldaptimelimit")); mTimeLimit->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); mTimeLimit->setValue(0); mTimeLimit->setSuffix(i18n(" sec")); mTimeLimit->setSpecialValueText(i18nc("default ldap time limit", "Default")); mainLayout->addWidget(label, row, col); mainLayout->addWidget(mTimeLimit, row, col + 1); } if (mFeatures & (W_SIZELIMIT | W_TIMELIMIT)) { row++; } if (mFeatures & W_PAGESIZE) { label = new QLabel(i18n("Page size:"), mParent); mPageSize = new QSpinBox(mParent); mPageSize->setRange(0, 9999999); mPageSize->setObjectName(QStringLiteral("kcfg_ldappagesize")); mPageSize->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); mPageSize->setValue(0); mPageSize->setSpecialValueText(i18n("No paging")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mPageSize, row++, 1); } if (mFeatures & W_DN) { label = new QLabel(i18nc("Distinguished Name", "DN:"), mParent); mDn = new QLineEdit(mParent); mDn->setObjectName(QStringLiteral("kcfg_ldapdn")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mDn, row, 1, 1, 1); //without host query doesn't make sense if (mHost) { QPushButton *dnquery = new QPushButton(i18n("Query Server"), mParent); dnquery->setEnabled(false); connect(dnquery, &QPushButton::clicked, mParent, [this]() { queryDNClicked(); }); connect(mDn, &QLineEdit::textChanged, mParent, [dnquery](const QString &text) { dnquery->setEnabled(!text.trimmed().isEmpty()); }); mainLayout->addWidget(dnquery, row, 2, 1, 1); } row++; } if (mFeatures & W_FILTER) { label = new QLabel(i18n("Filter:"), mParent); mFilter = new QLineEdit(mParent); mFilter->setObjectName(QStringLiteral("kcfg_ldapfilter")); mainLayout->addWidget(label, row, 0); mainLayout->addWidget(mFilter, row, 1, 1, 3); row++; } if (mFeatures & W_SECBOX) { QGroupBox *btgroup = new QGroupBox(i18n("Security"), mParent); QHBoxLayout *hbox = new QHBoxLayout; btgroup->setLayout(hbox); mSecNo = new QRadioButton(i18nc("@option:radio set no security", "No"), btgroup); mSecNo->setObjectName(QStringLiteral("kcfg_ldapnosec")); hbox->addWidget(mSecNo); mSecTLS = new QRadioButton(i18nc("@option:radio use TLS security", "TLS"), btgroup); mSecTLS->setObjectName(QStringLiteral("kcfg_ldaptls")); hbox->addWidget(mSecTLS); mSecSSL = new QRadioButton(i18nc("@option:radio use SSL security", "SSL"), btgroup); mSecSSL->setObjectName(QStringLiteral("kcfg_ldapssl")); hbox->addWidget(mSecSSL); mainLayout->addWidget(btgroup, row, 0, 1, 4); connect(mSecNo, &QRadioButton::clicked, mParent, [this]() { setLDAPPort(); }); connect(mSecTLS, &QRadioButton::clicked, mParent, [this]() { setLDAPPort(); }); connect(mSecSSL, &QRadioButton::clicked, mParent, [this]() { setLDAPSPort(); }); mSecNo->setChecked(true); row++; } if (mFeatures & W_AUTHBOX) { QGroupBox *authbox = new QGroupBox(i18n("Authentication"), mParent); QVBoxLayout *vbox = new QVBoxLayout; authbox->setLayout(vbox); QHBoxLayout *hbox = new QHBoxLayout; vbox->addLayout(hbox); mAnonymous = new QRadioButton(i18nc("@option:radio anonymous authentication", "Anonymous"), authbox); mAnonymous->setObjectName(QStringLiteral("kcfg_ldapanon")); hbox->addWidget(mAnonymous); mSimple = new QRadioButton(i18nc("@option:radio simple authentication", "Simple"), authbox); mSimple->setObjectName(QStringLiteral("kcfg_ldapsimple")); hbox->addWidget(mSimple); mSASL = new QRadioButton(i18nc("@option:radio SASL authentication", "SASL"), authbox); mSASL->setObjectName(QStringLiteral("kcfg_ldapsasl")); hbox->addWidget(mSASL); hbox = new QHBoxLayout; vbox->addLayout(hbox); label = new QLabel(i18n("SASL mechanism:"), authbox); hbox->addWidget(label); mMech = new QComboBox(authbox); mMech->setObjectName(QStringLiteral("kcfg_ldapsaslmech")); mMech->addItem(QStringLiteral("DIGEST-MD5")); mMech->addItem(QStringLiteral("GSSAPI")); mMech->addItem(QStringLiteral("PLAIN")); hbox->addWidget(mMech); //without host query doesn't make sense if (mHost) { mQueryMech = new QPushButton(i18n("Query Server"), authbox); hbox->addWidget(mQueryMech); connect(mQueryMech, &QPushButton::clicked, mParent, [this]() { queryMechClicked(); }); } mainLayout->addWidget(authbox, row, 0, 2, 4); connect(mAnonymous, &QRadioButton::toggled, mParent, [this](bool b) { setAnonymous(b); }); connect(mSimple, &QRadioButton::toggled, mParent, [this](bool b) { setSimple(b); }); connect(mSASL, &QRadioButton::toggled, mParent, [this](bool b) { setSASL(b); }); mAnonymous->setChecked(true); } } void LdapConfigWidget::Private::sendQuery() { LdapServer _server(mParent->server()); mQResult.clear(); mCancelled = true; if (mAttr == QLatin1String("supportedsaslmechanisms")) { _server.setAuth(LdapServer::Anonymous); } LdapUrl _url(_server.url()); _url.setDn(LdapDN(QLatin1String(""))); _url.setAttributes(QStringList(mAttr)); _url.setScope(LdapUrl::Base); qCDebug(LDAP_LOG) << "sendQuery url:" << _url.toDisplayString(); LdapSearch search; connect(&search, &LdapSearch::data, mParent, [this](KLDAP::LdapSearch *s, const KLDAP::LdapObject &obj) { loadData(s, obj); }); connect(&search, &LdapSearch::result, mParent, [this](KLDAP::LdapSearch *s) { loadResult(s); }); if (!search.search(_url)) { KMessageBox::error(mParent, search.errorString(), i18n("Check server")); return; } if (mProg == nullptr) { mProg = new QProgressDialog(mParent); mProg->setWindowTitle(i18n("LDAP Query")); mProg->setModal(true); } mProg->setLabelText(_url.toDisplayString()); mProg->setMaximum(1); mProg->setMinimum(0); mProg->setValue(0); mProg->exec(); if (mCancelled) { qCDebug(LDAP_LOG) << "query canceled!"; search.abandon(); } else { if (search.error()) { if (search.errorString().isEmpty()) { KMessageBox::error(mParent, i18nc("%1 is a url to ldap server", "Unknown error connecting %1", _url.toDisplayString())); } else { KMessageBox::error(mParent, search.errorString()); } } } } void LdapConfigWidget::Private::queryMechClicked() { mAttr = QStringLiteral("supportedsaslmechanisms"); sendQuery(); if (!mQResult.isEmpty()) { mQResult.sort(); mMech->clear(); mMech->addItems(mQResult); } } void LdapConfigWidget::Private::queryDNClicked() { mAttr = QStringLiteral("namingcontexts"); sendQuery(); if (!mQResult.isEmpty()) { mDn->setText(mQResult.constFirst()); } } void LdapConfigWidget::Private::loadData(LdapSearch *, const LdapObject &object) { qCDebug(LDAP_LOG) << "object:" << object.toString(); mProg->setValue(mProg->value() + 1); LdapAttrMap::ConstIterator end(object.attributes().constEnd()); for (LdapAttrMap::ConstIterator it = object.attributes().constBegin(); it != end; ++it) { LdapAttrValue::ConstIterator end2((*it).constEnd()); for (LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2) { mQResult.push_back(QString::fromUtf8(*it2)); } } } void LdapConfigWidget::Private::loadResult(LdapSearch *search) { Q_UNUSED(search); mCancelled = false; mProg->close(); } void LdapConfigWidget::Private::setAnonymous(bool on) { if (!on) { return; } if (mUser) { mUser->setEnabled(false); } if (mPassword) { mPassword->setEnabled(false); } if (mBindDn) { mBindDn->setEnabled(false); } if (mRealm) { mRealm->setEnabled(false); } if (mMech) { mMech->setEnabled(false); } if (mQueryMech) { mQueryMech->setEnabled(false); } } void LdapConfigWidget::Private::setSimple(bool on) { if (!on) { return; } if (mUser) { mUser->setEnabled(false); } if (mPassword) { mPassword->setEnabled(true); } if (mBindDn) { mBindDn->setEnabled(true); } if (mRealm) { mRealm->setEnabled(false); } if (mMech) { mMech->setEnabled(false); } if (mQueryMech) { mQueryMech->setEnabled(false); } } void LdapConfigWidget::Private::setSASL(bool on) { if (!on) { return; } if (mUser) { mUser->setEnabled(true); } if (mPassword) { mPassword->setEnabled(true); } if (mBindDn) { mBindDn->setEnabled(true); } if (mRealm) { mRealm->setEnabled(true); } if (mMech) { mMech->setEnabled(true); } if (mQueryMech) { mQueryMech->setEnabled(true); } } void LdapConfigWidget::Private::setLDAPPort() { if (mPort) { mPort->setValue(389); } } void LdapConfigWidget::Private::setLDAPSPort() { if (mPort) { mPort->setValue(636); } } LdapConfigWidget::LdapConfigWidget(QWidget *parent, Qt::WindowFlags fl) : QWidget(parent, fl) , d(new Private(this)) { } LdapConfigWidget::LdapConfigWidget(LdapConfigWidget::WinFlags flags, QWidget *parent, Qt::WindowFlags fl) : QWidget(parent, fl) , d(new Private(this)) { d->mFeatures = flags; d->initWidget(); } LdapConfigWidget::~LdapConfigWidget() { delete d; } LdapUrl LdapConfigWidget::url() const { return server().url(); } void LdapConfigWidget::setUrl(const LdapUrl &url) { LdapServer _server; _server.setUrl(url); setServer(_server); } LdapServer LdapConfigWidget::server() const { LdapServer _server; if (d->mSecSSL && d->mSecSSL->isChecked()) { _server.setSecurity(LdapServer::SSL); } else if (d->mSecTLS && d->mSecTLS->isChecked()) { _server.setSecurity(LdapServer::TLS); } else { _server.setSecurity(LdapServer::None); } if (d->mUser) { _server.setUser(d->mUser->text()); } if (d->mBindDn) { _server.setBindDn(d->mBindDn->text()); } if (d->mPassword) { _server.setPassword(d->mPassword->password()); } if (d->mRealm) { _server.setRealm(d->mRealm->text()); } if (d->mHost) { _server.setHost(d->mHost->text()); } if (d->mPort) { _server.setPort(d->mPort->value()); } if (d->mDn) { _server.setBaseDn(LdapDN(d->mDn->text())); } if (d->mFilter) { _server.setFilter(d->mFilter->text()); } if (d->mVersion) { _server.setVersion(d->mVersion->value()); } if (d->mSizeLimit && d->mSizeLimit->value() != 0) { _server.setSizeLimit(d->mSizeLimit->value()); } if (d->mTimeLimit && d->mTimeLimit->value() != 0) { _server.setTimeLimit(d->mTimeLimit->value()); } if (d->mPageSize && d->mPageSize->value() != 0) { _server.setPageSize(d->mPageSize->value()); } if (d->mAnonymous && d->mAnonymous->isChecked()) { _server.setAuth(LdapServer::Anonymous); } else if (d->mSimple && d->mSimple->isChecked()) { _server.setAuth(LdapServer::Simple); } else if (d->mSASL && d->mSASL->isChecked()) { _server.setAuth(LdapServer::SASL); _server.setMech(d->mMech->currentText()); } return _server; } void LdapConfigWidget::setServer(const LdapServer &server) { switch (server.security()) { case LdapServer::SSL: if (d->mSecSSL) { d->mSecSSL->setChecked(true); } break; case LdapServer::TLS: if (d->mSecTLS) { d->mSecTLS->setChecked(true); } break; case LdapServer::None: if (d->mSecNo) { d->mSecNo->setChecked(true); } break; } switch (server.auth()) { case LdapServer::Anonymous: if (d->mAnonymous) { d->mAnonymous->setChecked(true); } break; case LdapServer::Simple: if (d->mSimple) { d->mSimple->setChecked(true); } break; case LdapServer::SASL: if (d->mSASL) { d->mSASL->setChecked(true); } break; } setUser(server.user()); setBindDn(server.bindDn()); setPassword(server.password()); setRealm(server.realm()); setHost(server.host()); setPort(server.port()); setFilter(server.filter()); setDn(server.baseDn()); setVersion(server.version()); setSizeLimit(server.sizeLimit()); setTimeLimit(server.timeLimit()); setPageSize(server.pageSize()); setMech(server.mech()); } void LdapConfigWidget::setUser(const QString &user) { if (d->mUser) { d->mUser->setText(user); } } QString LdapConfigWidget::user() const { return d->mUser ? d->mUser->text() : QString(); } void LdapConfigWidget::setPassword(const QString &password) { if (d->mPassword) { d->mPassword->setPassword(password); } } QString LdapConfigWidget::password() const { return d->mPassword ? d->mPassword->password() : QString(); } void LdapConfigWidget::setBindDn(const QString &binddn) { if (d->mBindDn) { d->mBindDn->setText(binddn); } } QString LdapConfigWidget::bindDn() const { return d->mBindDn ? d->mBindDn->text() : QString(); } void LdapConfigWidget::setRealm(const QString &realm) { if (d->mRealm) { d->mRealm->setText(realm); } } QString LdapConfigWidget::realm() const { return d->mRealm ? d->mRealm->text() : QString(); } void LdapConfigWidget::setHost(const QString &host) { if (d->mHost) { d->mHost->setText(host); } } QString LdapConfigWidget::host() const { return d->mHost ? d->mHost->text() : QString(); } void LdapConfigWidget::setPort(int port) { if (d->mPort) { d->mPort->setValue(port); } } int LdapConfigWidget::port() const { return d->mPort ? d->mPort->value() : 389; } void LdapConfigWidget::setVersion(int version) { if (d->mVersion) { d->mVersion->setValue(version); } } int LdapConfigWidget::version() const { return d->mVersion ? d->mVersion->value() : 3; } void LdapConfigWidget::setDn(const LdapDN &dn) { if (d->mDn) { d->mDn->setText(dn.toString()); } } LdapDN LdapConfigWidget::dn() const { return d->mDn ? LdapDN(d->mDn->text()) : LdapDN(); } void LdapConfigWidget::setFilter(const QString &filter) { if (d->mFilter) { d->mFilter->setText(filter); } } QString LdapConfigWidget::filter() const { return d->mFilter ? d->mFilter->text() : QString(); } void LdapConfigWidget::setMech(const QString &mech) { if (d->mMech == nullptr) { return; } if (!mech.isEmpty()) { int i = 0; while (i < d->mMech->count()) { if (d->mMech->itemText(i) == mech) { break; } i++; } if (i == d->mMech->count()) { d->mMech->addItem(mech); } d->mMech->setCurrentIndex(i); } } QString LdapConfigWidget::mech() const { return d->mMech ? d->mMech->currentText() : QString(); } void LdapConfigWidget::setSecurity(Security security) { switch (security) { case None: d->mSecNo->setChecked(true); break; case SSL: d->mSecSSL->setChecked(true); break; case TLS: d->mSecTLS->setChecked(true); break; } } LdapConfigWidget::Security LdapConfigWidget::security() const { if (d->mSecTLS->isChecked()) { return TLS; } if (d->mSecSSL->isChecked()) { return SSL; } return None; } void LdapConfigWidget::setAuth(Auth auth) { switch (auth) { case Anonymous: d->mAnonymous->setChecked(true); break; case Simple: d->mSimple->setChecked(true); break; case SASL: d->mSASL->setChecked(true); break; } } LdapConfigWidget::Auth LdapConfigWidget::auth() const { if (d->mSimple->isChecked()) { return Simple; } if (d->mSASL->isChecked()) { return SASL; } return Anonymous; } void LdapConfigWidget::setSizeLimit(int sizelimit) { if (d->mSizeLimit) { d->mSizeLimit->setValue(sizelimit); } } int LdapConfigWidget::sizeLimit() const { return d->mSizeLimit ? d->mSizeLimit->value() : 0; } void LdapConfigWidget::setTimeLimit(int timelimit) { if (d->mTimeLimit) { d->mTimeLimit->setValue(timelimit); } } int LdapConfigWidget::timeLimit() const { return d->mTimeLimit ? d->mTimeLimit->value() : 0; } void LdapConfigWidget::setPageSize(int pagesize) { if (d->mPageSize) { d->mPageSize->setValue(pagesize); } } int LdapConfigWidget::pageSize() const { return d->mPageSize ? d->mPageSize->value() : 0; } LdapConfigWidget::WinFlags LdapConfigWidget::features() const { return d->mFeatures; } void LdapConfigWidget::setFeatures(LdapConfigWidget::WinFlags features) { d->mFeatures = features; // First delete all the child widgets. // FIXME: I hope it's correct QList ch = children(); const int numberOfChild(ch.count()); for (int i = 0; i < numberOfChild; ++i) { QWidget *widget = dynamic_cast(ch[ i ]); if (widget && widget->parent() == this) { delete(widget); } } // Re-create child widgets according to the new flags d->initWidget(); } #include "moc_ldapconfigwidget.cpp" diff --git a/src/ldapconnection.cpp b/src/ldapconnection.cpp index c9b6bab..246eead 100644 --- a/src/ldapconnection.cpp +++ b/src/ldapconnection.cpp @@ -1,460 +1,460 @@ /* This file is part of libkldap. Copyright (c) 2004-2006 Szombathelyi György This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ldapconnection.h" #include "ldapdefs.h" #include "kldap_config.h" // LDAP_FOUND #include -#include +#include #include "ldap_debug.h" #include static const sasl_callback_t callbacks[] = { { SASL_CB_ECHOPROMPT, nullptr, nullptr }, { SASL_CB_NOECHOPROMPT, nullptr, nullptr }, { SASL_CB_GETREALM, nullptr, nullptr }, { SASL_CB_USER, nullptr, nullptr }, { SASL_CB_AUTHNAME, nullptr, nullptr }, { SASL_CB_PASS, nullptr, nullptr }, { SASL_CB_CANON_USER, nullptr, nullptr }, { SASL_CB_LIST_END, nullptr, nullptr } }; static bool ldapoperation_sasl_initialized = false; #ifdef LDAP_FOUND # ifndef HAVE_WINLDAP_H # include # include #else # include #endif // HAVE_WINLDAP_H #ifndef LDAP_OPT_SUCCESS #define LDAP_OPT_SUCCESS 0 #endif #endif using namespace KLDAP; class Q_DECL_HIDDEN LdapConnection::LdapConnectionPrivate { public: LdapConnectionPrivate(); LdapServer mServer; QString mConnectionError; #ifdef LDAP_FOUND LDAP *mLDAP; #else void *mLDAP; #endif sasl_conn_t *mSASLconn; }; LdapConnection::LdapConnectionPrivate::LdapConnectionPrivate() { mSASLconn = nullptr; if (!ldapoperation_sasl_initialized) { sasl_client_init(nullptr); ldapoperation_sasl_initialized = true; } } LdapConnection::LdapConnection() : d(new LdapConnectionPrivate) { d->mLDAP = nullptr; } LdapConnection::LdapConnection(const LdapUrl &url) : d(new LdapConnectionPrivate) { d->mLDAP = nullptr; setUrl(url); } LdapConnection::LdapConnection(const LdapServer &server) : d(new LdapConnectionPrivate) { d->mLDAP = nullptr; setServer(server); } LdapConnection::~LdapConnection() { close(); delete d; } void LdapConnection::setUrl(const LdapUrl &url) { d->mServer.setUrl(url); } void LdapConnection::setServer(const LdapServer &server) { d->mServer = server; } const LdapServer &LdapConnection::server() const { return d->mServer; } void *LdapConnection::handle() const { return (void *)d->mLDAP; } void *LdapConnection::saslHandle() const { return (void *)d->mSASLconn; } QString LdapConnection::errorString(int code) { //No translated error messages yet #ifdef LDAP_FOUND return QString::fromUtf8(ldap_err2string(code)); #else return i18n("No LDAP Support..."); #endif } QString LdapConnection::saslErrorString() const { const char *str; str = sasl_errdetail(d->mSASLconn); return QString::fromLocal8Bit(str); } QString LdapConnection::connectionError() const { return d->mConnectionError; } #ifdef LDAP_FOUND int LdapConnection::getOption(int option, void *value) const { Q_ASSERT(d->mLDAP); return ldap_get_option(d->mLDAP, option, value); } int LdapConnection::setOption(int option, void *value) { Q_ASSERT(d->mLDAP); return ldap_set_option(d->mLDAP, option, value); } int LdapConnection::ldapErrorCode() const { Q_ASSERT(d->mLDAP); int err; ldap_get_option(d->mLDAP, LDAP_OPT_ERROR_NUMBER, &err); return err; } QString LdapConnection::ldapErrorString() const { Q_ASSERT(d->mLDAP); char *errmsg; ldap_get_option(d->mLDAP, LDAP_OPT_ERROR_STRING, &errmsg); QString msg = QString::fromLocal8Bit(errmsg); free(errmsg); return msg; } bool LdapConnection::setSizeLimit(int sizelimit) { Q_ASSERT(d->mLDAP); qCDebug(LDAP_LOG) << "sizelimit:" << sizelimit; if (setOption(LDAP_OPT_SIZELIMIT, &sizelimit) != LDAP_OPT_SUCCESS) { return false; } return true; } int LdapConnection::sizeLimit() const { Q_ASSERT(d->mLDAP); int sizelimit; if (getOption(LDAP_OPT_SIZELIMIT, &sizelimit) != LDAP_OPT_SUCCESS) { return -1; } return sizelimit; } bool LdapConnection::setTimeLimit(int timelimit) { Q_ASSERT(d->mLDAP); qCDebug(LDAP_LOG) << "timelimit:" << timelimit; if (setOption(LDAP_OPT_TIMELIMIT, &timelimit) != LDAP_OPT_SUCCESS) { return false; } return true; } int LdapConnection::timeLimit() const { Q_ASSERT(d->mLDAP); int timelimit; if (getOption(LDAP_OPT_TIMELIMIT, &timelimit) != LDAP_OPT_SUCCESS) { return -1; } return timelimit; } int LdapConnection::connect() { int ret; QString url; if (d->mLDAP) { close(); } int version = d->mServer.version(); int timeout = d->mServer.timeout(); url = d->mServer.security() == LdapServer::SSL ? QStringLiteral("ldaps") : QStringLiteral("ldap"); url += QLatin1String("://"); url += d->mServer.host(); url += QLatin1Char(':'); url += QString::number(d->mServer.port()); qCDebug(LDAP_LOG) << "ldap url:" << url; #ifdef HAVE_LDAP_INITIALIZE ret = ldap_initialize(&d->mLDAP, url.toLatin1().constData()); #else d->mLDAP = ldap_init(d->mServer.host().toLatin1().data(), d->mServer.port()); if (d->mLDAP == 0) { ret = -1; } else { ret = LDAP_SUCCESS; } #endif if (ret != LDAP_SUCCESS) { d->mConnectionError = i18n("An error occurred during the connection initialization phase."); return ret; } qCDebug(LDAP_LOG) << "setting version to:" << version; if (setOption(LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) { ret = ldapErrorCode(); d->mConnectionError = i18n("Cannot set protocol version to %1.", version); close(); return ret; } #if defined(LDAP_OPT_TIMEOUT) qCDebug(LDAP_LOG) << "setting timeout to:" << timeout; if (timeout) { if (setOption(LDAP_OPT_TIMEOUT, &timeout) != LDAP_OPT_SUCCESS) { ret = ldapErrorCode(); d->mConnectionError = i18np("Cannot set timeout to %1 second.", "Cannot set timeout to %1 seconds.", timeout); close(); return ret; } } #endif //FIXME: accessing to certificate handling would be good qCDebug(LDAP_LOG) << "setting security to:" << d->mServer.security(); if (d->mServer.security() == LdapServer::TLS) { bool initContext = false; if (d->mServer.tlsCACertFile().isEmpty() == false) { if (setOption(LDAP_OPT_X_TLS_CACERTFILE, d->mServer.tlsCACertFile().toUtf8().data()) != LDAP_OPT_SUCCESS) { d->mConnectionError = i18n("Could not set CA certificate file."); return -1; } initContext = true; } if (d->mServer.tlsRequireCertificate() != LdapServer::TLSReqCertDefault) { int reqcert; switch (d->mServer.tlsRequireCertificate()) { case LdapServer::TLSReqCertAllow: reqcert = LDAP_OPT_X_TLS_ALLOW; break; case LdapServer::TLSReqCertDemand: reqcert = LDAP_OPT_X_TLS_DEMAND; break; case LdapServer::TLSReqCertHard: reqcert = LDAP_OPT_X_TLS_HARD; break; case LdapServer::TLSReqCertNever: reqcert = LDAP_OPT_X_TLS_NEVER; break; case LdapServer::TLSReqCertTry: reqcert = LDAP_OPT_X_TLS_TRY; break; default: d->mConnectionError = i18n("Invalid TLS require certificate mode."); return -1; } if (setOption(LDAP_OPT_X_TLS_REQUIRE_CERT, &reqcert) != LDAP_OPT_SUCCESS) { d->mConnectionError = i18n("Could not set TLS require certificate mode."); return -1; } initContext = true; } if (initContext) { int isServer = 0; if (setOption(LDAP_OPT_X_TLS_NEWCTX, &isServer) != LDAP_OPT_SUCCESS) { d->mConnectionError = i18n("Could not initialize new TLS context."); return -1; } } qCDebug(LDAP_LOG) << "start TLS"; #ifdef HAVE_LDAP_START_TLS_S if ((ret = ldap_start_tls_s(d->mLDAP, nullptr, nullptr)) != LDAP_SUCCESS) { d->mConnectionError = ldapErrorString(); close(); return ret; } #else close(); d->mConnectionError = i18n("TLS support not available in the LDAP client libraries."); return -1; #endif } qCDebug(LDAP_LOG) << "setting sizelimit to:" << d->mServer.sizeLimit(); if (d->mServer.sizeLimit()) { if (!setSizeLimit(d->mServer.sizeLimit())) { ret = ldapErrorCode(); close(); d->mConnectionError = i18n("Cannot set size limit."); return ret; } } qCDebug(LDAP_LOG) << "setting timelimit to:" << d->mServer.timeLimit(); if (d->mServer.timeLimit()) { if (!setTimeLimit(d->mServer.timeLimit())) { ret = ldapErrorCode(); close(); d->mConnectionError = i18n("Cannot set time limit."); return ret; } } qCDebug(LDAP_LOG) << "initializing SASL client"; int saslresult = sasl_client_new("ldap", d->mServer.host().toLatin1().constData(), nullptr, nullptr, callbacks, 0, &d->mSASLconn); if (saslresult != SASL_OK) { d->mConnectionError = i18n("Cannot initialize the SASL client."); return KLDAP_SASL_ERROR; } return 0; } void LdapConnection::close() { if (d->mLDAP) { #ifdef HAVE_LDAP_UNBIND_EXT ldap_unbind_ext(d->mLDAP, nullptr, nullptr); #else ldap_unbind(d->mLDAP); #endif } d->mLDAP = nullptr; if (d->mSASLconn) { sasl_dispose(&d->mSASLconn); d->mSASLconn = nullptr; } qCDebug(LDAP_LOG) << "connection closed!"; } #else //LDAP_FOUND int LdapConnection::getOption(int option, void *value) const { qCritical() << "No LDAP support..."; return -1; } int LdapConnection::setOption(int option, void *value) { qCritical() << "No LDAP support..."; return -1; } int LdapConnection::ldapErrorCode() const { qCritical() << "No LDAP support..."; return -1; } QString LdapConnection::ldapErrorString() const { qCritical() << "No LDAP support..."; return QString(); } bool LdapConnection::setSizeLimit(int sizelimit) { qCritical() << "No LDAP support..."; return false; } int LdapConnection::sizeLimit() const { qCritical() << "No LDAP support..."; return -1; } bool LdapConnection::setTimeLimit(int timelimit) { qCritical() << "No LDAP support..."; return false; } int LdapConnection::timeLimit() const { qCritical() << "No LDAP support..."; return -1; } int LdapConnection::connect() { d->mConnectionError = i18n("LDAP support not compiled in. Please recompile libkldap with the " "OpenLDAP (or compatible) client libraries, or complain to your " "distribution packagers."); qCritical() << "No LDAP support..."; return -1; } void LdapConnection::close() { qCritical() << "No LDAP support..."; } #endif diff --git a/src/ldapmodel.cpp b/src/ldapmodel.cpp index 6489c75..59051e6 100644 --- a/src/ldapmodel.cpp +++ b/src/ldapmodel.cpp @@ -1,313 +1,313 @@ /* This file is part of libkldap. Copyright (c) 2006 Sean Harmer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ldapmodel.h" #include "ldapmodel_p.h" #include "ldapmodelnode_p.h" #include "ldapsearch.h" #include "ldap_debug.h" -#include +#include using namespace KLDAP; LdapModel::LdapModel(QObject *parent) : QAbstractItemModel(parent) , m_d(new LdapModelPrivate(this)) { m_d->createConnections(); } LdapModel::LdapModel(LdapConnection &connection, QObject *parent) : QAbstractItemModel(parent) , m_d(new LdapModelPrivate(this, connection)) { m_d->createConnections(); // Populate items from the root object to that representing the baseDN m_d->populateRootToBaseDN(); } LdapModel::~LdapModel() { delete m_d; } void LdapModel::setConnection(LdapConnection &connection) { m_d->setConnection(connection); // Refresh the model m_d->recreateRootItem(); // Populate the root object by searching the baseDN m_d->populateRootToBaseDN(); } QModelIndex LdapModel::parent(const QModelIndex &child) const { if (!child.isValid()) { return QModelIndex(); } LdapModelNode *childItem = static_cast(child.internalPointer()); LdapModelDNNode *parentItem = childItem->parent(); if (parentItem == m_d->rootNode()) { return QModelIndex(); } return createIndex(parentItem->row(), 0, parentItem); } QModelIndex LdapModel::index(int row, int col, const QModelIndex &parent) const { // Retrieve a pointer to the parent item LdapModelDNNode *parentItem = nullptr; if (!parent.isValid()) { parentItem = m_d->rootNode(); } else { parentItem = static_cast(parent.internalPointer()); } LdapModelNode *childItem = parentItem->child(row); if (childItem) { return createIndex(row, col, childItem); } qCDebug(LDAP_LOG) << "Could not create valid index for row =" << row << ", col =" << col; return QModelIndex(); } QVariant LdapModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } if (role == Qt::DisplayRole) { // This is what gets displayed by the view delegates. LdapModelNode *node = static_cast(index.internalPointer()); if (node->nodeType() == LdapModelNode::DN) { LdapModelDNNode *dn = static_cast(node); if (index.column() == 0) { return dn->dn().rdnString(); } else { return QVariant(); } } else { LdapModelAttrNode *attr = static_cast(node); if (index.column() == 0) { return QVariant(attr->attributeName()); } else { return QVariant(QLatin1String(attr->attributeData().constData())); } } } else if (role == NodeTypeRole) { LdapModelNode *node = static_cast(index.internalPointer()); return QVariant(int(node->nodeType())); } /** \todo Include support for nice decorative icons dependent upon the objectClass + other role data. */ /** \todo Include support for other roles as needed */ return QVariant(); } bool LdapModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(index); Q_UNUSED(value); Q_UNUSED(role); return false; } QVariant LdapModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return i18n("Attribute"); } else { return i18n("Value"); } } return QVariant(); } Qt::ItemFlags LdapModel::flags(const QModelIndex &index) const { /** \TODO Read-only for now, make read-write upon request */ if (!index.isValid()) { return Qt::ItemIsEnabled; } return Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); } int LdapModel::columnCount(const QModelIndex &parent) const { LdapModelDNNode *parentNode = parent.isValid() ? static_cast(parent.internalPointer()) : m_d->rootNode(); return parentNode->columnCount(); } int LdapModel::rowCount(const QModelIndex &parent) const { if (parent.column() > 0) { return 0; } const LdapModelDNNode *parentNode = parent.isValid() ? static_cast(parent.internalPointer()) : m_d->rootNode(); return parentNode->childCount(); } bool LdapModel::hasChildren(const QModelIndex &parent) const { // We return true unless the item has been populated and we are able to do a definitive test const LdapModelNode *node = parent.isValid() ? static_cast(parent.internalPointer()) : m_d->rootNode(); if (node->nodeType() != LdapModelNode::DN) { return false; } const LdapModelDNNode *parentNode = static_cast(node); if (!parent.isValid() || parentNode->isPopulated()) { return parentNode->childCount() > 0; } return true; } bool LdapModel::canFetchMore(const QModelIndex &parent) const { const LdapModelDNNode *parentNode = parent.isValid() ? static_cast(parent.internalPointer()) : m_d->rootNode(); return !parentNode->isPopulated(); } void LdapModel::fetchMore(const QModelIndex &parent) { LdapModelDNNode *parentNode = parent.isValid() ? static_cast(parent.internalPointer()) : m_d->rootNode(); // Search for the immediate children of parentItem. m_d->searchResults().clear(); m_d->setSearchType(LdapModelPrivate::ChildObjects, parentNode); m_d->search(parentNode->dn(), // DN to search from LdapUrl::One, // What to search QString()); // Attributes to retrieve parentNode->setPopulated(true); } bool LdapModel::insertRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(count); Q_UNUSED(parent); return false; } bool LdapModel::removeRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(count); Q_UNUSED(parent); return false; } void LdapModel::sort(int column, Qt::SortOrder order) { Q_UNUSED(column); Q_UNUSED(order); } Qt::DropActions LdapModel::supportedDropActions() const { return Qt::MoveAction; } QMimeData *LdapModel::mimeData(const QModelIndexList &indexes) const { Q_UNUSED(indexes); return nullptr; } bool LdapModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { /** \todo Implement drag and drop for LdapModel */ Q_UNUSED(data); Q_UNUSED(action); Q_UNUSED(row); Q_UNUSED(column); Q_UNUSED(parent); return false; } bool LdapModel::hasChildrenOfType(const QModelIndex &parent, LdapDataType type) const { // Map from LdapDataType to our internal NodeType LdapModelNode::NodeType nodeType; switch (type) { case Attribute: nodeType = LdapModelNode::Attr; break; case DistinguishedName: default: nodeType = LdapModelNode::DN; break; } const LdapModelNode *node = parent.isValid() ? static_cast(parent.internalPointer()) : m_d->rootNode(); const LdapModelDNNode *parentNode = static_cast(node); if (!parent.isValid() || parentNode->isPopulated()) { // Check to see if the parent has any children of the specified type const QList &children = parentNode->children(); for (LdapModelNode *child : children) { if (child->nodeType() == nodeType) { return true; } } // Either there are no children or only children of a different type return false; } // If the node is not populated or is the root node (invalid), then return // true to be on the safe side. return true; } void LdapModel::revert() { } bool LdapModel::submit() { return false; } #include "moc_ldapmodel.cpp" diff --git a/src/ldapstructureproxymodel.cpp b/src/ldapstructureproxymodel.cpp index 154a246..f43f0a0 100644 --- a/src/ldapstructureproxymodel.cpp +++ b/src/ldapstructureproxymodel.cpp @@ -1,145 +1,145 @@ /* This file is part of libkldap. Copyright (c) 2006 Sean Harmer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ldapstructureproxymodel.h" #include "ldapmodel.h" #include "ldapmodelnode_p.h" #include "ldap_debug.h" -#include +#include using namespace KLDAP; LdapStructureProxyModel::LdapStructureProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { } LdapStructureProxyModel::~LdapStructureProxyModel() { } QVariant LdapStructureProxyModel::data(const QModelIndex &index, int role) const { // Included just in case we decide to do any special presentation of the data // at some other point throughout the 4.x series. return sourceModel()->data(mapToSource(index), role); } bool LdapStructureProxyModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(index); Q_UNUSED(value); Q_UNUSED(role); return false; } bool LdapStructureProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent); LdapModelNode::NodeType nodeType = static_cast( sourceModel()->data(idx, LdapModel::NodeTypeRole).toUInt()); return nodeType == LdapModelNode::DN; } QVariant LdapStructureProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_UNUSED(section); if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { return i18n("Distinguished Name"); } return QVariant(); } int LdapStructureProxyModel::columnCount(const QModelIndex & /*parent*/) const { // No need for more than one column just to show the structure return 1; } Qt::ItemFlags LdapStructureProxyModel::flags(const QModelIndex &index) const { // Included so as not to break BC in case we wish to use this later in 4.x return sourceModel()->flags(mapToSource(index)); } bool LdapStructureProxyModel::hasChildren(const QModelIndex &parent) const { // We need to handle this carefully bacause of the filtering out of attributes // and the lazy population approach. LdapModel *model = static_cast(sourceModel()); return model->hasChildrenOfType(mapToSource(parent), LdapModel::DistinguishedName); } QModelIndex LdapStructureProxyModel::mapFromSource(const QModelIndex &sourceIndex) const { return QSortFilterProxyModel::mapFromSource(sourceIndex); } QModelIndex LdapStructureProxyModel::mapToSource(const QModelIndex &proxyIndex) const { return QSortFilterProxyModel::mapToSource(proxyIndex); } bool LdapStructureProxyModel::insertRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(count); Q_UNUSED(parent); return false; } bool LdapStructureProxyModel::removeRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(count); Q_UNUSED(parent); return false; } void LdapStructureProxyModel::sort(int column, Qt::SortOrder order) { Q_UNUSED(column); Q_UNUSED(order); } Qt::DropActions LdapStructureProxyModel::supportedDropActions() const { return Qt::MoveAction; } QMimeData *LdapStructureProxyModel::mimeData(const QModelIndexList &indexes) const { Q_UNUSED(indexes); return nullptr; } bool LdapStructureProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { /** \todo Implement drag and drop for LdapModel */ Q_UNUSED(data); Q_UNUSED(action); Q_UNUSED(row); Q_UNUSED(column); Q_UNUSED(parent); return false; }