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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
/*
gwcontactlist.cpp - Kopete GroupWise Protocol
Copyright (c) 2005 SUSE Linux Products GmbH http://www.suse.com
Kopete (c) 2002-2005 by the Kopete developers <[email protected]>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include <qobjectlist.h>
#include <kdebug.h>
#include "gwcontactlist.h"
#include "gwerror.h" //debug area
GWContactList::GWContactList( QObject * parent )
: QObject( parent ), rootFolder( new GWFolder( this, 0, 0, QString::null ) )
{ }
GWFolder * GWContactList::addFolder( unsigned int id, unsigned int sequence, const QString & displayName )
{
if ( rootFolder )
return new GWFolder( rootFolder, id, sequence, displayName );
else
return 0;
}
GWContactInstance * GWContactList::addContactInstance( unsigned int id, unsigned int parent, unsigned int sequence, const QString & displayName, const QString & dn )
{
QObjectList * l = queryList( "GWFolder", 0, false, true );
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
GWContactInstance * contact = 0;
while ( (obj = it.current()) != 0 )
{
GWFolder * folder = ::qt_cast< GWFolder * >( obj );
if ( folder && folder->id == parent )
{
contact = new GWContactInstance( folder, id, sequence, displayName, dn );
break;
}
++it;
}
delete l;
return contact;
}
GWFolder * GWContactList::findFolderById( unsigned int id )
{
QObjectList * l = queryList( "GWFolder", 0, false, true );
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
GWFolder * candidate, * folder = 0;
while ( (obj = it.current()) != 0 )
{
candidate = ::qt_cast< GWFolder * >( obj );
if ( candidate->id == id )
{
folder = candidate;
break;
}
++it;
}
delete l;
return folder;
}
GWFolder * GWContactList::findFolderByName( const QString & displayName )
{
QObjectList * l = queryList( "GWFolder", 0, false, true );
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
GWFolder * folder = 0;
while ( (obj = it.current()) != 0 )
{
GWFolder * candidate = ::qt_cast< GWFolder * >( obj );
if ( candidate->displayName == displayName )
{
folder = candidate;
break;
}
++it;
}
delete l;
return folder;
}
int GWContactList::maxSequenceNumber()
{
QObjectList * l = queryList( "GWFolder", 0, false, true );
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
unsigned int sequence = 0;
while ( (obj = it.current()) != 0 )
{
GWFolder * current = ::qt_cast< GWFolder * >( obj );
sequence = QMAX( sequence, current->sequence );
++it;
}
delete l;
return sequence;
}
GWContactInstanceList GWContactList::instancesWithDn( const QString & dn )
{
QObjectList * l = queryList( "GWContactInstance", 0, false, true );
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
GWContactInstanceList matches;
while ( (obj = it.current()) != 0 )
{
++it;
GWContactInstance * current = ::qt_cast<GWContactInstance *>( obj );
if ( current->dn == dn )
matches.append( current );
}
delete l;
return matches;
}
void GWContactList::removeInstance( GWContactListItem * instance )
{
delete instance;
}
void GWContactList::removeInstanceById( unsigned int id )
{
QObjectList * l = queryList( "GWContactInstance", 0, false, true );
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
GWContactInstanceList matches;
while ( (obj = it.current()) != 0 )
{
++it;
GWContactInstance * current = ::qt_cast<GWContactInstance *>( obj );
if ( current->id == id )
{
delete current;
break;
}
}
delete l;
}
void GWContactList::dump()
{
kdDebug(GROUPWISE_DEBUG_GLOBAL) << k_funcinfo << endl;
const QObjectList * l = children();
if ( l && !l->isEmpty() )
{
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
while ( (obj = it.current()) != 0 )
{
GWFolder * folder = ::qt_cast< GWFolder * >( obj );
if ( folder )
folder->dump( 1 );
++it;
}
}
else
kdDebug ( GROUPWISE_DEBUG_GLOBAL ) << " contact list is empty." << endl;
}
void GWContactList::clear()
{
kdDebug(GROUPWISE_DEBUG_GLOBAL) << k_funcinfo << endl;
const QObjectList * l = children();
if ( l && !l->isEmpty() )
{
QObjectListIt it( *l );
QObject *obj;
while ( (obj = it.current()) != 0 )
{
delete obj;
++it;
}
}
}
GWContactListItem::GWContactListItem( QObject * parent, unsigned int theId, unsigned int theSequence, const QString & theDisplayName ) :
QObject( parent), id( theId ), sequence( theSequence ), displayName( theDisplayName )
{ }
GWFolder::GWFolder( QObject * parent, unsigned int theId, unsigned int theSequence, const QString & theDisplayName ) :
GWContactListItem( parent, theId, theSequence, theDisplayName )
{ }
void GWFolder::dump( unsigned int depth )
{
QString s;
s.fill( ' ', ++depth * 2 );
kdDebug( GROUPWISE_DEBUG_GLOBAL ) << s <<"Folder " << displayName << " id: " << id << " contains: " << endl;
const QObjectList * l = children();
if ( l )
{
QObjectListIt it( *l ); // iterate over the buttons
QObject *obj;
while ( (obj = it.current()) != 0 )
{
++it;
GWContactInstance * instance = ::qt_cast< GWContactInstance * >( obj );
if (instance)
instance->dump( depth );
else
{
GWFolder * folder = ::qt_cast< GWFolder * >( obj );
if ( folder )
folder->dump( depth );
}
}
}
else
kdDebug( GROUPWISE_DEBUG_GLOBAL ) << s << " no contacts." << endl;
}
GWContactInstance::GWContactInstance( QObject * parent, unsigned int theId, unsigned int theSequence, const QString & theDisplayName, const QString & theDn ) :
GWContactListItem( parent, theId, theSequence, theDisplayName ), dn( theDn )
{ }
void GWContactInstance::dump( unsigned int depth )
{
QString s;
s.fill( ' ', ++depth * 2 );
kdDebug( GROUPWISE_DEBUG_GLOBAL ) << s << "Contact " << displayName << " id: " << id << " dn: " << dn << endl;
}
#include "gwcontactlist.moc"
|