File: gwcontactlist.cpp

package info (click to toggle)
kopete 4%3A17.08.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 38,864 kB
  • sloc: cpp: 348,298; ansic: 13,983; xml: 1,775; lex: 1,735; python: 421; sh: 271; perl: 126; ruby: 28; makefile: 18
file content (176 lines) | stat: -rw-r--r-- 4,661 bytes parent folder | download | duplicates (5)
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
/*
    gwcontactlist.cpp - Kopete GroupWise Protocol

    Copyright (c) 2006,2007 Novell, Inc	 	 	 http://www.opensuse.org
    Copyright (c) 2005      SUSE Linux Products GmbH	 	 http://www.suse.com

    Kopete    (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * 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 "gwcontactlist.h"
#include <qobject.h>

#include <kdebug.h>

#include "gwerror.h" //debug area

GWContactList::GWContactList( QObject * parent )
 : QObject( parent ), rootFolder( new GWFolder( this, 0, 0, QString() ) )
{  }

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 )
{
	GWContactInstance * contact = 0;
	foreach ( GWFolder *folder, findChildren<GWFolder *>() )
	{
		if ( folder && folder->id == parent )
		{
			contact = new GWContactInstance( folder, id, sequence, displayName, dn );
			break;
		}
	}
	return contact;
}

GWFolder * GWContactList::findFolderById( unsigned int id )
{
	GWFolder * folder = 0;
	foreach ( GWFolder *candidate, findChildren<GWFolder *>() )
	{
		if ( candidate->id == id )
		{
			folder = candidate;
			break;
		}
	}
	return folder;
}

GWFolder * GWContactList::findFolderByName( const QString & displayName )
{
	GWFolder * folder = 0;
	foreach ( GWFolder *candidate, findChildren<GWFolder *>() )
	{
		if ( candidate->displayName == displayName )
		{
			folder = candidate;
			break;
		}
	}
	return folder;
}

int GWContactList::maxSequenceNumber()
{
	unsigned int sequence = 0;
	foreach ( GWFolder *current, findChildren<GWFolder *>() )
	{
		sequence = qMax( sequence, current->sequence );
	}
	return sequence;
}

GWContactInstanceList GWContactList::instancesWithDn( const QString & dn )
{
	GWContactInstanceList matches;
	foreach ( GWContactInstance * current, findChildren<GWContactInstance *>() )
	{
		if ( current->dn == dn )
			matches.append( current );
	}
	return matches;
}

void GWContactList::removeInstance( GWContactListItem * instance )
{
	delete instance;
}

void GWContactList::removeInstanceById( unsigned int id )
{
	GWContactInstanceList matches;
	foreach ( GWContactInstance * current, findChildren<GWContactInstance *>() )
	{
		if ( current->id == id )
		{
			delete current;
			break;
		}
	}
}

void GWContactList::dump()
{
	kDebug() ;
	foreach ( GWFolder * folder, findChildren<GWFolder *>() )
	{
		if ( folder )
			folder->dump( 1 );
	}
}

void GWContactList::clear()
{
	kDebug() ;
	foreach ( QObject *obj, children() )
	{
		delete obj;
	}
}

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 );
	kDebug() << s <<"Folder " << displayName << " id: " << id << " contains: ";
	foreach ( QObject *obj, children() )
	{
		GWContactInstance * instance = qobject_cast< GWContactInstance * >( obj );
		if (instance)
			instance->dump( depth );
		else
		{
			GWFolder * folder = qobject_cast< GWFolder * >( obj );
			if ( folder )
				folder->dump( depth );
		}
	}
}

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 );
	kDebug() << s << "Contact " << displayName << " id: " << id << " dn: " << dn;
}
#include "gwcontactlist.moc"