2 gwcontactlist.cpp - Kopete GroupWise Protocol
4 Copyright (c) 2006,2007 Novell, Inc http://www.opensuse.org
5 Copyright (c) 2005 SUSE Linux Products GmbH http://www.suse.com
7 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2 of the License, or (at your option) any later version. *
16 *************************************************************************
23 #include "gwcontactlist.h"
24 #include "gwerror.h" //debug area
26 GWContactList::GWContactList( QObject
* parent
)
27 : QObject( parent
), rootFolder( new GWFolder( this, 0, 0, QString() ) )
30 GWFolder
* GWContactList::addFolder( unsigned int id
, unsigned int sequence
, const QString
& displayName
)
33 return new GWFolder( rootFolder
, id
, sequence
, displayName
);
38 GWContactInstance
* GWContactList::addContactInstance( unsigned int id
, unsigned int parent
, unsigned int sequence
, const QString
& displayName
, const QString
& dn
)
40 GWContactInstance
* contact
= 0;
41 foreach ( GWFolder
*folder
, findChildren
<GWFolder
*>() )
43 if ( folder
&& folder
->id
== parent
)
45 contact
= new GWContactInstance( folder
, id
, sequence
, displayName
, dn
);
52 GWFolder
* GWContactList::findFolderById( unsigned int id
)
54 GWFolder
* folder
= 0;
55 foreach ( GWFolder
*candidate
, findChildren
<GWFolder
*>() )
57 if ( candidate
->id
== id
)
66 GWFolder
* GWContactList::findFolderByName( const QString
& displayName
)
68 GWFolder
* folder
= 0;
69 foreach ( GWFolder
*candidate
, findChildren
<GWFolder
*>() )
71 if ( candidate
->displayName
== displayName
)
80 int GWContactList::maxSequenceNumber()
82 unsigned int sequence
= 0;
83 foreach ( GWFolder
*current
, findChildren
<GWFolder
*>() )
85 sequence
= qMax( sequence
, current
->sequence
);
90 GWContactInstanceList
GWContactList::instancesWithDn( const QString
& dn
)
92 GWContactInstanceList matches
;
93 foreach ( GWContactInstance
* current
, findChildren
<GWContactInstance
*>() )
95 if ( current
->dn
== dn
)
96 matches
.append( current
);
101 void GWContactList::removeInstance( GWContactListItem
* instance
)
106 void GWContactList::removeInstanceById( unsigned int id
)
108 GWContactInstanceList matches
;
109 foreach ( GWContactInstance
* current
, findChildren
<GWContactInstance
*>() )
111 if ( current
->id
== id
)
119 void GWContactList::dump()
122 foreach ( GWFolder
* folder
, findChildren
<GWFolder
*>() )
129 void GWContactList::clear()
132 foreach ( QObject
*obj
, children() )
138 GWContactListItem::GWContactListItem( QObject
* parent
, unsigned int theId
, unsigned int theSequence
, const QString
& theDisplayName
) :
139 QObject( parent
), id( theId
), sequence( theSequence
), displayName( theDisplayName
)
142 GWFolder::GWFolder( QObject
* parent
, unsigned int theId
, unsigned int theSequence
, const QString
& theDisplayName
) :
143 GWContactListItem( parent
, theId
, theSequence
, theDisplayName
)
146 void GWFolder::dump( unsigned int depth
)
149 s
.fill( ' ', ++depth
* 2 );
150 kDebug() << s
<<"Folder " << displayName
<< " id: " << id
<< " contains: ";
151 foreach ( QObject
*obj
, children() )
153 GWContactInstance
* instance
= qobject_cast
< GWContactInstance
* >( obj
);
155 instance
->dump( depth
);
158 GWFolder
* folder
= qobject_cast
< GWFolder
* >( obj
);
160 folder
->dump( depth
);
165 GWContactInstance::GWContactInstance( QObject
* parent
, unsigned int theId
, unsigned int theSequence
, const QString
& theDisplayName
, const QString
& theDn
) :
166 GWContactListItem( parent
, theId
, theSequence
, theDisplayName
), dn( theDn
)
169 void GWContactInstance::dump( unsigned int depth
)
172 s
.fill( ' ', ++depth
* 2 );
173 kDebug() << s
<< "Contact " << displayName
<< " id: " << id
<< " dn: " << dn
;
175 #include "gwcontactlist.moc"