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#ifndef KLDAP_LDAPMODELNODE_P_H
22#define KLDAP_LDAPMODELNODE_P_H
23
24#include <QByteArray>
25#include <QString>
26#include <QtCore/QList>
27#include <QtCore/QVariant>
28
29#include "ldapdn.h"
30#include "ldapobject.h"
31#include "kldap_export.h"
32
33namespace KLDAP {
34
35class LdapModelDNNode;
36
37/**
38 * @internal
39 */
40class LdapModelNode
41{
42 public:
43 explicit LdapModelNode( LdapModelDNNode *parent = 0 );
44 virtual ~LdapModelNode();
45
46 enum NodeType {
47 DN,
48 Attr
49 };
50
51 virtual NodeType nodeType() const = 0;
52
53 LdapModelDNNode *parent();
54 int columnCount() const { return 2; }
55 int row() const;
56
57 void setPopulated( bool b ) { m_isPopulated = b; }
58 bool isPopulated() const { return m_isPopulated; }
59
60 private:
61 LdapModelDNNode *m_parent;
62 bool m_isPopulated;
63};
64
65/**
66 * @internal
67 */
68class LdapModelDNNode : public LdapModelNode
69{
70 public:
71 explicit LdapModelDNNode( LdapModelDNNode *parent = 0,
72 const LdapDN &dn = LdapDN() );
73 ~LdapModelDNNode();
74
75 LdapModelNode::NodeType nodeType() const
76 { return LdapModelNode::DN; }
77
78 void appendChild( LdapModelNode *pItem );
79 LdapModelNode *child( int row );
80 int childCount() const { return m_childItems.size(); }
81 const QList<LdapModelNode*>& children() const
82 { return m_childItems; }
83
84 const LdapDN &dn() const { return m_dn; }
85
86 /**
87 * Creates child LdapModelAttrNode object to store \p object's attributes
88 * and adds them as children of this node.
89 *
90 * \param The LdapObject to store in this node.
91 */
92 void setLdapObject( const LdapObject &object );
93
94 private:
95 QList<LdapModelNode*> m_childItems;
96 LdapDN m_dn;
97};
98
99/**
100 * @internal
101 */
102class LdapModelAttrNode : public LdapModelNode
103{
104 public:
105 explicit LdapModelAttrNode( LdapModelDNNode *parent = 0,
106 const QString &attrName = QString(),
107 const QByteArray &attrData = QByteArray() );
108 ~LdapModelAttrNode();
109
110 LdapModelNode::NodeType nodeType() const
111 { return LdapModelNode::Attr; }
112
113 const QString &attributeName() { return m_attrName; }
114 const QByteArray &attributeData() { return m_attrData; }
115
116 private:
117 QString m_attrName;
118 QByteArray m_attrData;
119};
120
121}
122
123#endif
124