diff --git a/autotests/testkldap.h b/autotests/testkldap.h --- a/autotests/testkldap.h +++ b/autotests/testkldap.h @@ -21,7 +21,6 @@ #define TESTKLDAP_H #include -#include #include #include @@ -53,7 +52,6 @@ QString m_url; LdapSearch *m_search = nullptr; LdapObjects m_objects; - LdapModel *m_model = nullptr; }; #endif diff --git a/autotests/testkldap.cpp b/autotests/testkldap.cpp --- a/autotests/testkldap.cpp +++ b/autotests/testkldap.cpp @@ -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 @@ } 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::cleanupTestCase() { delete m_search; - delete m_model; } void KLdapTest::testLdapUrl() @@ -279,17 +274,7 @@ 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); } /* diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,11 +42,6 @@ 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 @@ 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 diff --git a/src/ldapattributeproxymodel.h b/src/ldapattributeproxymodel.h deleted file mode 100644 --- a/src/ldapattributeproxymodel.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - 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. -*/ - -#ifndef KLDAP_LDAPATTRIBUTEPROXYMODEL_H -#define KLDAP_LDAPATTRIBUTEPROXYMODEL_H - -#include - -#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 diff --git a/src/ldapattributeproxymodel.cpp b/src/ldapattributeproxymodel.cpp deleted file mode 100644 --- a/src/ldapattributeproxymodel.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - 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 - -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/ldapmodel.h b/src/ldapmodel.h deleted file mode 100644 --- a/src/ldapmodel.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - 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. -*/ - -#ifndef KLDAP_LDAPMODEL_H -#define KLDAP_LDAPMODEL_H - -#include - -#include "ldapconnection.h" -#include "ldapobject.h" -#include "kldap_export.h" - -namespace KLDAP { -/** - * A ModelView interface to an LDAP tree. At present the model is read only. Editing is - * planned for a future release. - * - * This class is best used in conjunction with an LdapStructureProxyModel object for - * displaying the structure of an LDAP tree, and with LdapAttributeProxyModel for - * displaying the attributes of particular objects within the tree. - * - * \author Sean Harmer - */ -class KLDAP_EXPORT LdapModel : public QAbstractItemModel -{ - Q_OBJECT -public: - enum Roles { - NodeTypeRole = Qt::UserRole + 1 - }; - - enum LdapDataType { - DistinguishedName = 0, - Attribute - }; - - /** - * Constructs an LdapModel. You should set a connection for the model to use with - * setConnection(). Clients of this class should connect a slot to the ready() signal - * before setting this model onto a view. - * @param parent the parent QObject - * \see setConnection() - * \see ready() - */ - explicit LdapModel(QObject *parent = nullptr); - /** - * Constructs an LdapModel. Clients of this class should connect a slot to the ready() - * signal before setting this model onto a view. - * @param connection the Ldap connection to use in model construction - * @param parent the parent QObject - * \see setConnection() - * \see ready() - */ - explicit LdapModel(LdapConnection &connection, QObject *parent = nullptr); - ~LdapModel() override; - - /** - * Set the connection that the model should use. - * @param connection the model connection to set - * \see LdapConnection - * \see LdapUrl - */ - void setConnection(LdapConnection &connection); - - // - // Implement the usual QAbstractItemModel interface - // - /** - * Reimplemented from QAbstractItemModel::index(). - */ - Q_REQUIRED_RESULT QModelIndex index(int row, int col, const QModelIndex &parent) const override; - /** - * Reimplemented from QAbstractItemModel::parent(). - */ - Q_REQUIRED_RESULT QModelIndex parent(const QModelIndex &child) const override; - /** - * Reimplemented from QAbstractItemModel::data(). - */ - Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override; - /** - * Reimplemented from QAbstractItemModel::setData(). This is a placeholder for when - * LdapModel beomes writeable and always returns false. - */ - Q_REQUIRED_RESULT bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - /** - * Reimplemented from QAbstractItemModel::headerData(). - */ - Q_REQUIRED_RESULT QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - /** - * Reimplemented from QAbstractItemModel::flags(). - */ - Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override; - /** - * Reimplemented from QAbstractItemModel::columnCount(). - */ - Q_REQUIRED_RESULT int columnCount(const QModelIndex &parent) const override; - /** - * Reimplemented from QAbstractItemModel::rowCount(). - */ - Q_REQUIRED_RESULT int rowCount(const QModelIndex &parent) const override; - /** - * Reimplemented from QAbstractItemModel::hasChildren(). - */ - Q_REQUIRED_RESULT bool hasChildren(const QModelIndex &parent) const override; - /** - * Reimplemented from QAbstractItemModel::canFetchMore(). - */ - Q_REQUIRED_RESULT bool canFetchMore(const QModelIndex &parent) const override; - /** - * Reimplemented from QAbstractItemModel::fetchMore(). - */ - void fetchMore(const QModelIndex &parent) override; - /** - * Reimplemented from QAbstractItemModel::insertRows(). This is a placeholder for when - * LdapModel 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 - * LdapModel 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 - * LdapModel beomes writeable and always returns 0. - */ - QMimeData *mimeData(const QModelIndexList &indexes) const override; - /** - * Reimplemented from QAbstractItemModel::dropMimedata(). This is a placeholder for when - * LdapModel 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; - - // - // Other public utility functions - // - /** - * Checks to see if the item referenced by \p parent has any children of - * the type \p type. If the item has not been populated by fetchMore() yet, - * then this function returns true. - * - * \see fetchMore() - * \param parent Index to the item to query. - * \param type The type of child item to search for. - */ - bool hasChildrenOfType(const QModelIndex &parent, LdapDataType type) const; - -public Q_SLOTS: - /** - * Reimplemented from QAbstractItemModel::revert(). This is a placeholder for when - * LdapModel beomes writeable. This implementation does nothing. - */ - void revert() override; - /** - * Reimplemented from QAbstractItemModel::revert(). This is a placeholder for when - * LdapModel beomes writeable. This implementation does nothing and returns false. - */ - bool submit() override; - -Q_SIGNALS: - /** - * The ready() signal is emitted when the model is ready for use by other components. - * When the model is first created and a connection is set, the model queries the - * LDAP server for its base DN and automatically creates items down to that level. - * This requires the event loop to be running. This signal indicates that this process - * has completed and the model can now be set onto views or queried directly from code. - */ - void ready(); - -private: - class LdapModelPrivate; - LdapModelPrivate *const m_d; -}; -} -#endif diff --git a/src/ldapmodel.cpp b/src/ldapmodel.cpp deleted file mode 100644 --- a/src/ldapmodel.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* - 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 - -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/ldapmodel_p.h b/src/ldapmodel_p.h deleted file mode 100644 --- a/src/ldapmodel_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - 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. -*/ - -#ifndef KLDAP_LDAPMODELPRIVATE_H -#define KLDAP_LDAPMODELPRIVATE_H - -#include "ldapconnection.h" -#include "ldapdn.h" -#include "ldapmodel.h" -#include "ldapobject.h" - -namespace KLDAP { -class LdapModelDNNode; -class LdapSearch; - -/** - * @internal - */ -class Q_DECL_HIDDEN LdapModel::LdapModelPrivate -{ -public: - enum SearchType { - NotSearching = 0, - NamingContexts, - BaseDN, - ChildObjects - }; - - explicit LdapModelPrivate(LdapModel *parent); - explicit LdapModelPrivate(LdapModel *parent, LdapConnection &connection); - - ~LdapModelPrivate(); - - void setConnection(LdapConnection &connection); - - bool search(const LdapDN &searchBase, LdapUrl::Scope scope = LdapUrl::Sub, const QString &filter = QString(), const QStringList &attributes = QStringList(), int pagesize = 0); - - LdapModelDNNode *rootNode() - { - return m_root; - } - - LdapSearch *search() - { - return m_search; - } - - LdapObjects &searchResults() - { - return m_searchResultObjects; - } - - const LdapObjects &searchResults() const - { - return m_searchResultObjects; - } - - void recreateRootItem(); - - void setBaseDN(const LdapDN &baseDN) - { - m_baseDN = baseDN; - } - - LdapDN &baseDN() - { - return m_baseDN; - } - - const LdapDN &baseDN() const - { - return m_baseDN; - } - - void setSearchType(SearchType t, LdapModelDNNode *item = nullptr); - - Q_REQUIRED_RESULT SearchType searchType() - { - return m_searchType; - } - - LdapModelDNNode *searchItem() - { - return m_searchItem; - } - - void createConnections(); - void populateRootToBaseDN(); - void gotSearchResult(KLDAP::LdapSearch *search); - void gotSearchData(KLDAP::LdapSearch *search, const KLDAP::LdapObject &obj); - -private: - LdapModel *m_parent = nullptr; - LdapModelDNNode *m_root = nullptr; - LdapSearch *m_search = nullptr; - LdapObjects m_searchResultObjects; - LdapDN m_baseDN; - SearchType m_searchType; - LdapModelDNNode *m_searchItem = nullptr; -}; -} -#endif diff --git a/src/ldapmodel_p.cpp b/src/ldapmodel_p.cpp deleted file mode 100644 --- a/src/ldapmodel_p.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - 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_p.h" -#include "ldapmodelnode_p.h" -#include "ldapsearch.h" - -#include "ldap_debug.h" - -using namespace KLDAP; - -LdapModel::LdapModelPrivate::LdapModelPrivate(LdapModel *parent) - : m_parent(parent) - , m_root(new LdapModelDNNode) - , m_search(new LdapSearch) - , m_searchResultObjects() - , m_baseDN() - , m_searchType(NotSearching) - , m_searchItem(nullptr) -{ -} - -LdapModel::LdapModelPrivate::LdapModelPrivate(LdapModel *parent, LdapConnection &connection) - : m_parent(parent) - , m_root(new LdapModelDNNode) - , m_search(new LdapSearch(connection)) - , m_searchResultObjects() - , m_baseDN() - , m_searchType(NotSearching) - , m_searchItem(nullptr) -{ -} - -LdapModel::LdapModelPrivate::~LdapModelPrivate() -{ - delete m_root; - - delete m_search; -} - -void LdapModel::LdapModelPrivate::setConnection(LdapConnection &connection) -{ - m_search->setConnection(connection); -} - -bool LdapModel::LdapModelPrivate::search(const LdapDN &searchBase, LdapUrl::Scope scope, const QString &filter, const QStringList &attributes, int pagesize) -{ - return m_search->search(searchBase, scope, filter, attributes, pagesize); -} - -void LdapModel::LdapModelPrivate::setSearchType(SearchType t, LdapModelDNNode *item) -{ - //qCDebug(LDAP_LOG) << "item =" << item; - m_searchType = t; - m_searchItem = item; -} - -void LdapModel::LdapModelPrivate::recreateRootItem() -{ - //qCDebug(LDAP_LOG); - delete m_root; - m_root = new LdapModelDNNode; - //qCDebug(LDAP_LOG) << "&m_root =" << &m_root; -} - -void LdapModel::LdapModelPrivate::createConnections() -{ - connect(search(), &LdapSearch::data, m_parent, [this](KLDAP::LdapSearch *s, const KLDAP::LdapObject &obj) { - gotSearchData(s, obj); - }); - connect(search(), &LdapSearch::result, m_parent, [this](KLDAP::LdapSearch *s) { - gotSearchResult(s); - }); -} - -void LdapModel::LdapModelPrivate::populateRootToBaseDN() -{ - //qCDebug(LDAP_LOG); - - if (baseDN().isEmpty()) { - // Query the server for the base DN - //qCDebug(LDAP_LOG) << "Searching for the baseDN"; - setSearchType(LdapModelPrivate::NamingContexts, rootNode()); - search(LdapDN(), LdapUrl::Base, QString(), QStringList() << QStringLiteral("namingContexts")); - return; - } - - // Start a search for the details of the baseDN object - //qCDebug(LDAP_LOG) << "Searching for attributes of the baseDN"; - searchResults().clear(); - setSearchType(LdapModelPrivate::BaseDN, rootNode()); - search(baseDN(), LdapUrl::Base, QString(), QStringList() << QStringLiteral("dn") << QStringLiteral("objectClass")); -} - -void LdapModel::LdapModelPrivate::gotSearchResult(KLDAP::LdapSearch *search) -{ - Q_UNUSED(search); - qCDebug(LDAP_LOG); - - switch (searchType()) { - case LdapModelPrivate::NamingContexts: - { - // Set the baseDN - QString baseDN; - if (!searchResults().isEmpty() - && searchResults().at(0).hasAttribute(QStringLiteral("namingContexts"))) { - baseDN = QString::fromLatin1(searchResults().at(0).value(QStringLiteral("namingContexts"))); - //qCDebug(LDAP_LOG) << "Found baseDN =" << baseDN; - } - setBaseDN(LdapDN(baseDN)); - - // Flag that we are no longer searching for the baseDN - setSearchType(LdapModelPrivate::NotSearching); - - // Populate the root item - populateRootToBaseDN(); - - break; - } - case LdapModelPrivate::BaseDN: - { - //qCDebug(LDAP_LOG) << "Found details of the baseDN object." - // << "Creating objects down to this level."; - - // Get the baseDN LdapObject - LdapObject baseDNObj = searchResults().at(0); - - // How many levels of items do we need to create? - int depth = baseDNObj.dn().depth(); - - // Create items that represent objects down to the baseDN - LdapModelDNNode *parent = rootNode(); - LdapModelDNNode *item = nullptr; - for (int i = 0; i < depth; ++i) { - QString dn = baseDN().toString(i); - qCDebug(LDAP_LOG) << "Creating item for DN :" << dn; - - //LdapObject obj( dn ); - item = new LdapModelDNNode(parent, LdapDN(dn)); - parent = item; - } - - // Store the search result - if (item) { - item->setLdapObject(baseDNObj); - } - - // Flag that we are no longer searching - setSearchType(LdapModelPrivate::NotSearching); - //emit( layoutChanged() ); - - // Let the world know we are ready for action - Q_EMIT m_parent->ready(); - - break; - } - case LdapModelPrivate::ChildObjects: - //qCDebug(LDAP_LOG) << "Found" << searchResults().size() << "child objects"; - - if (searchResults().size() != 0) { - // Create an index for the soon-to-be-a-parent item - LdapModelDNNode *parentNode = searchItem(); - int r = parentNode->row(); - QModelIndex parentIndex = m_parent->createIndex(r, 0, parentNode); - - m_parent->beginInsertRows(parentIndex, 0, searchResults().size()); - for (int i = 0; i < searchResults().size(); i++) { - LdapObject object = searchResults().at(i); - LdapModelDNNode *item = new LdapModelDNNode(parentNode, object.dn()); - item->setLdapObject(object); - } - - m_parent->endInsertRows(); - Q_EMIT m_parent->layoutChanged(); - } - - // Flag that we are no longer searching - setSearchType(LdapModelPrivate::NotSearching); - - break; - default: - break; - } -} - -void LdapModel::LdapModelPrivate::gotSearchData(KLDAP::LdapSearch *search, const KLDAP::LdapObject &obj) -{ - Q_UNUSED(search); - //qCDebug(LDAP_LOG); - //qCDebug(LDAP_LOG) << "Object:"; - //qCDebug(LDAP_LOG) << obj.toString(); - searchResults().append(obj); -} diff --git a/src/ldapmodelnode_p.h b/src/ldapmodelnode_p.h deleted file mode 100644 --- a/src/ldapmodelnode_p.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - 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. -*/ - -#ifndef KLDAP_LDAPMODELNODE_P_H -#define KLDAP_LDAPMODELNODE_P_H - -#include -#include -#include - -#include "ldapdn.h" -#include "ldapobject.h" -#include "kldap_export.h" - -// clazy:excludeall=copyable-polymorphic - -namespace KLDAP { -class LdapModelDNNode; - -/** - * @internal - */ -class LdapModelNode -{ -public: - explicit LdapModelNode(LdapModelDNNode *parent = nullptr); - virtual ~LdapModelNode(); - - enum NodeType { - DN, - Attr - }; - - virtual NodeType nodeType() const = 0; - - LdapModelDNNode *parent(); - int columnCount() const - { - return 2; - } - - int row() const; - - void setPopulated(bool b) - { - m_isPopulated = b; - } - - bool isPopulated() const - { - return m_isPopulated; - } - -private: - LdapModelDNNode *m_parent = nullptr; - bool m_isPopulated = false; -}; - -/** - * @internal - */ -class LdapModelDNNode : public LdapModelNode -{ -public: - explicit LdapModelDNNode(LdapModelDNNode *parent = nullptr, const LdapDN &dn = LdapDN()); - ~LdapModelDNNode() override; - - LdapModelNode::NodeType nodeType() const override - { - return LdapModelNode::DN; - } - - void appendChild(LdapModelNode *pItem); - LdapModelNode *child(int row); - int childCount() const - { - return m_childItems.size(); - } - - const QList &children() const - { - return m_childItems; - } - - const LdapDN &dn() const - { - return m_dn; - } - - /** - * Creates child LdapModelAttrNode object to store \p object's attributes - * and adds them as children of this node. - * - * \param The LdapObject to store in this node. - */ - void setLdapObject(const LdapObject &object); - -private: - QList m_childItems; - LdapDN m_dn; -}; - -/** - * @internal - */ -class LdapModelAttrNode : public LdapModelNode -{ -public: - explicit LdapModelAttrNode(LdapModelDNNode *parent = nullptr, const QString &attrName = QString(), const QByteArray &attrData = QByteArray()); - ~LdapModelAttrNode() override; - - LdapModelNode::NodeType nodeType() const override - { - return LdapModelNode::Attr; - } - - const QString &attributeName() - { - return m_attrName; - } - - const QByteArray &attributeData() - { - return m_attrData; - } - -private: - QString m_attrName; - QByteArray m_attrData; -}; -} - -#endif diff --git a/src/ldapmodelnode_p.cpp b/src/ldapmodelnode_p.cpp deleted file mode 100644 --- a/src/ldapmodelnode_p.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - 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 "ldapmodelnode_p.h" - -#include "ldap_debug.h" - -using namespace KLDAP; - -LdapModelNode::LdapModelNode(LdapModelDNNode *parent) - : m_parent(parent) - , m_isPopulated(false) -{ - if (m_parent) { - m_parent->appendChild(this); - } -} - -LdapModelNode::~LdapModelNode() -{ -} - -LdapModelDNNode *LdapModelNode::parent() -{ - return m_parent; -} - -int LdapModelNode::row() const -{ - if (m_parent) { - return m_parent->children().indexOf(const_cast(this)); - } - return 0; -} - -// -// LdapModelDNNode imlpementation -// - -LdapModelDNNode::LdapModelDNNode(LdapModelDNNode *parent, const LdapDN &dn) - : LdapModelNode(parent) - , m_childItems() - , m_dn(dn) -{ - qCDebug(LDAP_LOG) << "Creating DN =" << m_dn.toString(); -} - -LdapModelDNNode::~LdapModelDNNode() -{ - qDeleteAll(m_childItems); -} - -void LdapModelDNNode::appendChild(LdapModelNode *pItem) -{ - m_childItems.append(pItem); - setPopulated(true); -} - -LdapModelNode *LdapModelDNNode::child(int row) -{ - return m_childItems.value(row); -} - -void LdapModelDNNode::setLdapObject(const LdapObject &object) -{ - // Remember whether this item is populated or not - bool populated = isPopulated(); - - const LdapAttrMap &attrs = object.attributes(); - /* - int attributeCount = 0; - for ( LdapAttrMap::ConstIterator it = attrs.begin(); it != attrs.end(); ++it ) { - attributeCount += (*it).size(); - } - - for ( int i = 0; i < attributeCount; i++ ) - { - LdapModelNode* node = new LdapModelAttrNode( this, QString::number( i ) ); - Q_UNUSED( node ); - } - */ - LdapAttrMap::ConstIterator end(attrs.constEnd()); - for (LdapAttrMap::ConstIterator it = attrs.constBegin(); it != end; ++it) { - const QString attr = it.key(); - LdapAttrValue::ConstIterator end2((*it).constEnd()); - for (LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2) { - LdapModelNode *node = new LdapModelAttrNode(this, attr, *it2); - Q_UNUSED(node); - } - } - - // Reset the populated flag so that we don't stop the model querying for children - setPopulated(populated); -} - -// -// LdapModelAttrNode imlpementation -// - -LdapModelAttrNode::LdapModelAttrNode(LdapModelDNNode *parent, const QString &attrName, const QByteArray &attrData) - : LdapModelNode(parent) - , m_attrName(attrName) - , m_attrData(attrData) -{ - qCDebug(LDAP_LOG) << "Creating Name =" << m_attrName << " Data =" << m_attrData; -} - -LdapModelAttrNode::~LdapModelAttrNode() -{ -} diff --git a/src/ldapstructureproxymodel.h b/src/ldapstructureproxymodel.h deleted file mode 100644 --- a/src/ldapstructureproxymodel.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - 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. -*/ - -#ifndef KLDAP_LDAPSTRUCTUREPROXYMODEL_H -#define KLDAP_LDAPSTRUCTUREPROXYMODEL_H - -#include - -#include "kldap_export.h" - -namespace KLDAP { -class KLDAP_EXPORT LdapStructureProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT -public: - explicit LdapStructureProxyModel(QObject *parent = nullptr); - ~LdapStructureProxyModel() override; - - Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override; - /** - * Reimplemented from QAbstractItemModel::setData(). This is a placeholder for when - * LdapStructureProxyModel 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 - * LdapStructureProxyModel 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 - * LdapStructureProxyModel 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 - * LdapStructureProxyModel beomes writeable and always returns 0. - */ - Q_REQUIRED_RESULT QMimeData *mimeData(const QModelIndexList &indexes) const override; - /** - * Reimplemented from QAbstractItemModel::dropMimedata(). This is a placeholder for when - * LdapStructureProxyModel 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 diff --git a/src/ldapstructureproxymodel.cpp b/src/ldapstructureproxymodel.cpp deleted file mode 100644 --- a/src/ldapstructureproxymodel.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - 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 - -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; -}