Commit 793db841 authored by Volker Krause's avatar Volker Krause
Browse files

Remove unused LDAP model code

Reviewers: mlaurent

Reviewed By: mlaurent

Subscribers: mlaurent, kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D25748
parent 0df5b986
......@@ -26,7 +26,6 @@
#include "ldapurl.h"
#include "ldapserver.h"
#include "ldapconnection.h"
#include "ldapmodel.h"
#include "ldapoperation.h"
#include "ldapsearch.h"
#include "ber.h"
......@@ -58,9 +57,6 @@ void KLdapTest::initTestCase()
}
m_search = new LdapSearch;
/* Let's also create an LdapModel object */
m_model = new LdapModel(this);
}
void KLdapTest::testBer()
......@@ -139,7 +135,6 @@ void KLdapTest::testBer()
void KLdapTest::cleanupTestCase()
{
delete m_search;
delete m_model;
}
void KLdapTest::testLdapUrl()
......@@ -279,17 +274,7 @@ void KLdapTest::testLdapModel()
QEXPECT_FAIL("", "Will fail since no server is available for testing", Abort);
QCOMPARE(ret, 0);
// Let's use this connection with the model
m_model->setConnection(conn);
QCoreApplication::processEvents();
QModelIndex rootIndex = QModelIndex();
QVariant data = m_model->data(rootIndex, Qt::DisplayRole);
qDebug() << "Root Item Distinguished Name =" << data.toString();
QVERIFY(m_model->hasChildren(rootIndex) == true);
QVERIFY(m_model->canFetchMore(rootIndex) == false);
}
/*
......
......@@ -21,7 +21,6 @@
#define TESTKLDAP_H
#include <QObject>
#include <ldapmodel.h>
#include <ldapobject.h>
#include <ldapsearch.h>
......@@ -53,7 +52,6 @@ private:
QString m_url;
LdapSearch *m_search = nullptr;
LdapObjects m_objects;
LdapModel *m_model = nullptr;
};
#endif
......@@ -42,11 +42,6 @@ set(kldap_LIB_SRCS
ldapsearch.cpp
ldapconfigwidget.cpp
ldapdn.cpp
ldapmodelnode_p.cpp
ldapmodel.cpp
ldapmodel_p.cpp
ldapstructureproxymodel.cpp
ldapattributeproxymodel.cpp
)
ecm_qt_declare_logging_category(kldap_LIB_SRCS HEADER ldap_debug.h IDENTIFIER LDAP_LOG CATEGORY_NAME org.kde.pim.ldap)
......@@ -80,18 +75,15 @@ install(TARGETS KF5Ldap EXPORT KF5LdapTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS
ecm_generate_headers(KLdap_CamelCase_HEADERS
HEADER_NAMES
Ber
LdapAttributeProxyModel
LdapConfigWidget
LdapConnection
LdapControl
LdapDN
LdapModel
LdapObject
LdapOperation
LdapSearch
LdapServer
LdapDefs
LdapStructureProxyModel
LdapUrl
Ldif
PREFIX KLDAP
......
/*
This file is part of libkldap.
Copyright (c) 2006 Sean Harmer <sh@theharmers.co.uk>
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 <KLocalizedString>
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<LdapModelNode::NodeType>(
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<LdapModel *>(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;
}
/*
This file is part of libkldap.
Copyright (c) 2006 Sean Harmer <sh@theharmers.co.uk>
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.
*/
#ifndef KLDAP_LDAPATTRIBUTEPROXYMODEL_H
#define KLDAP_LDAPATTRIBUTEPROXYMODEL_H
#include <QSortFilterProxyModel>
#include "kldap_export.h"
namespace KLDAP {
class KLDAP_EXPORT LdapAttributeProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit LdapAttributeProxyModel(QObject *parent = nullptr);
~LdapAttributeProxyModel() override;
Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override;
/**
* Reimplemented from QAbstractItemModel::setData(). This is a placeholder for when
* LdapAttributeProxyModel beomes writeable and always returns false.
*/
Q_REQUIRED_RESULT bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Q_REQUIRED_RESULT bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
Q_REQUIRED_RESULT QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Q_REQUIRED_RESULT int columnCount(const QModelIndex &parent) const override;
Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override;
Q_REQUIRED_RESULT bool hasChildren(const QModelIndex &parent) const override;
Q_REQUIRED_RESULT QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
Q_REQUIRED_RESULT QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
/**
* Reimplemented from QAbstractItemModel::insertRows(). This is a placeholder for when
* LdapAttributeProxyModel beomes writeable and always returns false.
*/
Q_REQUIRED_RESULT bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
/**
* Reimplemented from QAbstractItemModel::removeRows(). This is a placeholder for when
* LdapAttributeProxyModel beomes writeable and always returns false.
*/
Q_REQUIRED_RESULT bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
/**
* Reimplemented from QAbstractItemModel::removeRows(). The default implementation
* does nothing.
*/
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
//
// Drag and drop support
//
/**
* Reimplemented from QAbstractItemModel::supportedDropActions(). The default
* implementation returns Qt::MoveAction.
*/
Q_REQUIRED_RESULT Qt::DropActions supportedDropActions() const override;
/**
* Reimplemented from QAbstractItemModel::mimedata(). This is a placeholder for when
* LdapAttributeProxyModel beomes writeable and always returns 0.
*/
QMimeData *mimeData(const QModelIndexList &indexes) const override;
/**
* Reimplemented from QAbstractItemModel::dropMimedata(). This is a placeholder for when
* LdapAttributeProxyModel beomes writeable and always returns false.
*/
Q_REQUIRED_RESULT bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
};
}
#endif
/*
This file is part of libkldap.
Copyright (c) 2006 Sean Harmer <sh@theharmers.co.uk>
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 <KLocalizedString>
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<LdapModelNode *>(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<LdapModelDNNode *>(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<LdapModelNode *>(index.internalPointer());
if (node->nodeType() == LdapModelNode::DN) {
LdapModelDNNode *dn = static_cast<LdapModelDNNode *>(node);
if (index.column() == 0) {
return dn->dn().rdnString();
} else {
return QVariant();
}
} else {
LdapModelAttrNode *attr = static_cast<LdapModelAttrNode *>(node);
if (index.column() == 0) {
return QVariant(attr->attributeName());
} else {
return QVariant(QLatin1String(attr->attributeData().constData()));
}
}
} else if (role == NodeTypeRole) {
LdapModelNode *node = static_cast<LdapModelNode *>(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<LdapModelDNNode *>(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<LdapModelDNNode *>(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<const LdapModelNode *>(parent.internalPointer())
: m_d->rootNode();
if (node->nodeType() != LdapModelNode::DN) {
return false;
}
const LdapModelDNNode *parentNode = static_cast<const LdapModelDNNode *>(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<LdapModelDNNode *>(parent.internalPointer()) : m_d->rootNode();
return !parentNode->isPopulated();
}
void LdapModel::fetchMore(const QModelIndex &parent)
{
LdapModelDNNode *parentNode
= parent.isValid() ? static_cast<LdapModelDNNode *>(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<const LdapModelNode *>(parent.internalPointer())
: m_d->rootNode();
const LdapModelDNNode *parentNode = static_cast<const LdapModelDNNode *>(node);
if (!parent.isValid() || parentNode->isPopulated()) {
// Check to see if the parent has any children of the specified type
const QList<LdapModelNode *> &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
<