1/*
2 This file is part of libkldap.
3 Copyright (c) 2006 Sean Harmer <sh@theharmers.co.uk>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "ldapmodelnode_p.h"
22
23#include <kdebug.h>
24
25using namespace KLDAP;
26
27LdapModelNode::LdapModelNode( LdapModelDNNode *parent )
28 : m_parent( parent ),
29 m_isPopulated( false )
30{
31 if ( m_parent ) {
32 m_parent->appendChild( this );
33 }
34}
35
36LdapModelNode::~LdapModelNode()
37{
38
39}
40
41LdapModelDNNode *LdapModelNode::parent()
42{
43 return m_parent;
44}
45
46int LdapModelNode::row() const
47{
48 if ( m_parent ) {
49 return m_parent->children().indexOf( const_cast<LdapModelNode*>( this ) );
50 }
51 return 0;
52}
53
54//
55// LdapModelDNNode imlpementation
56//
57
58LdapModelDNNode::LdapModelDNNode( LdapModelDNNode *parent,
59 const LdapDN &dn )
60 : LdapModelNode( parent ),
61 m_childItems(),
62 m_dn( dn )
63{
64 kDebug() << "Creating DN =" << m_dn.toString();
65}
66
67LdapModelDNNode::~LdapModelDNNode()
68{
69 qDeleteAll( m_childItems );
70}
71
72void LdapModelDNNode::appendChild( LdapModelNode *pItem )
73{
74 m_childItems.append( pItem );
75 setPopulated( true );
76}
77
78LdapModelNode *LdapModelDNNode::child( int row )
79{
80 return m_childItems.value( row );
81}
82
83void LdapModelDNNode::setLdapObject( const LdapObject &object )
84{
85 // Remember whether this item is populated or not
86 bool populated = isPopulated();
87
88 const LdapAttrMap &attrs = object.attributes();
89 /*
90 int attributeCount = 0;
91 for ( LdapAttrMap::ConstIterator it = attrs.begin(); it != attrs.end(); ++it ) {
92 attributeCount += (*it).size();
93 }
94
95 for ( int i = 0; i < attributeCount; i++ )
96 {
97 LdapModelNode* node = new LdapModelAttrNode( this, QString::number( i ) );
98 Q_UNUSED( node );
99 }
100 */
101 LdapAttrMap::ConstIterator end( attrs.constEnd() );
102 for ( LdapAttrMap::ConstIterator it = attrs.constBegin(); it != end; ++it ) {
103 const QString attr = it.key();
104 LdapAttrValue::ConstIterator end2( ( *it ).constEnd() );
105 for ( LdapAttrValue::ConstIterator it2 = ( *it ).constBegin(); it2 != end2; ++it2 ) {
106 LdapModelNode *node = new LdapModelAttrNode( this, attr, *it2 );
107 Q_UNUSED( node );
108 }
109 }
110
111 // Reset the populated flag so that we don't stop the model querying for children
112 setPopulated( populated );
113}
114
115//
116// LdapModelAttrNode imlpementation
117//
118
119LdapModelAttrNode::LdapModelAttrNode( LdapModelDNNode *parent,
120 const QString &attrName,
121 const QByteArray &attrData )
122 : LdapModelNode( parent ),
123 m_attrName( attrName ),
124 m_attrData( attrData )
125{
126 kDebug() << "Creating Name =" << m_attrName << " Data =" << m_attrData;
127}
128
129LdapModelAttrNode::~LdapModelAttrNode()
130{
131
132}
133