1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
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 "ldapmodelnode_p.h"
#include <kdebug.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<LdapModelNode*>( this ) );
}
return 0;
}
//
// LdapModelDNNode imlpementation
//
LdapModelDNNode::LdapModelDNNode( LdapModelDNNode *parent,
const LdapDN &dn )
: LdapModelNode( parent ),
m_childItems(),
m_dn( dn )
{
kDebug() << "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 );
}
*/
for ( LdapAttrMap::ConstIterator it = attrs.begin(); it != attrs.end(); ++it ) {
QString attr = it.key();
for ( LdapAttrValue::ConstIterator it2 = (*it).begin(); it2 != (*it).end(); ++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 )
{
kDebug() << "Creating Name =" << m_attrName << " Data =" << m_attrData;
}
LdapModelAttrNode::~LdapModelAttrNode()
{
}
|