Port things from MSN to WLM plugin:
[kdenetwork.git] / kopete / protocols / groupwise / gwcontactlist.cpp
bloba1914ea510f8e68095612ed0d37fa9ee769ac60c
1 /*
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 *************************************************************************
10 * *
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. *
15 * *
16 *************************************************************************
19 #include <qobject.h>
21 #include <kdebug.h>
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() ) )
28 { }
30 GWFolder * GWContactList::addFolder( unsigned int id, unsigned int sequence, const QString & displayName )
32 if ( rootFolder )
33 return new GWFolder( rootFolder, id, sequence, displayName );
34 else
35 return 0;
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 );
46 break;
49 return contact;
52 GWFolder * GWContactList::findFolderById( unsigned int id )
54 GWFolder * folder = 0;
55 foreach ( GWFolder *candidate, findChildren<GWFolder *>() )
57 if ( candidate->id == id )
59 folder = candidate;
60 break;
63 return folder;
66 GWFolder * GWContactList::findFolderByName( const QString & displayName )
68 GWFolder * folder = 0;
69 foreach ( GWFolder *candidate, findChildren<GWFolder *>() )
71 if ( candidate->displayName == displayName )
73 folder = candidate;
74 break;
77 return folder;
80 int GWContactList::maxSequenceNumber()
82 unsigned int sequence = 0;
83 foreach ( GWFolder *current, findChildren<GWFolder *>() )
85 sequence = qMax( sequence, current->sequence );
87 return 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 );
98 return matches;
101 void GWContactList::removeInstance( GWContactListItem * instance )
103 delete instance;
106 void GWContactList::removeInstanceById( unsigned int id )
108 GWContactInstanceList matches;
109 foreach ( GWContactInstance * current, findChildren<GWContactInstance *>() )
111 if ( current->id == id )
113 delete current;
114 break;
119 void GWContactList::dump()
121 kDebug() ;
122 foreach ( GWFolder * folder, findChildren<GWFolder *>() )
124 if ( folder )
125 folder->dump( 1 );
129 void GWContactList::clear()
131 kDebug() ;
132 foreach ( QObject *obj, children() )
134 delete obj;
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 )
148 QString s;
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 );
154 if (instance)
155 instance->dump( depth );
156 else
158 GWFolder * folder = qobject_cast< GWFolder * >( obj );
159 if ( folder )
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 )
171 QString s;
172 s.fill( ' ', ++depth * 2 );
173 kDebug() << s << "Contact " << displayName << " id: " << id << " dn: " << dn;
175 #include "gwcontactlist.moc"