blob: 10233a18a4ee6e730d0f6309a713728023682810 (
plain)
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
|
/*
Kopete Groupwise Protocol
modifycontactlisttask.cpp - Ancestor of all tasks that change the server side contact list.
Copyright (c) 2004 SUSE Linux AG http://www.suse.com
Based on Iris, Copyright (C) 2003 Justin Karneges
Kopete (c) 2002-2004 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 Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include "client.h"
#include "response.h"
#include "gwerror.h"
#include "modifycontactlisttask.h"
ModifyContactListTask::ModifyContactListTask(Task* parent): RequestTask(parent)
{
}
ModifyContactListTask::~ModifyContactListTask()
{
}
bool ModifyContactListTask::take( Transfer * transfer )
{
if ( !forMe( transfer ) )
return false;
Response * response = dynamic_cast<Response *>( transfer );
if ( !response )
return false;
client()->debug( "ModifyContactListTask::take()" );
// scan the contact list received
// emit each add and delete as a signal
Field::FieldList fl = response->fields();
fl.dump( true );
Field::FieldListIterator it = fl.begin();
Field::FieldListIterator end = fl.end();
Field::MultiField * current = fl.findMultiField( NM_A_FA_RESULTS );
if ( current )
fl = current->fields();
current = fl.findMultiField( NM_A_FA_CONTACT_LIST );
if ( current )
{
Field::FieldList contactList = current->fields();
Field::FieldListIterator cursor = contactList.begin();
const Field::FieldListIterator end = contactList.end();
while ( cursor != end )
{
Field::MultiField * mf = dynamic_cast< Field::MultiField * >( *cursor );
if ( mf->tag() == NM_A_FA_CONTACT )
{
// contact change
processContactChange( mf );
}
else if ( mf->tag() == NM_A_FA_FOLDER )
{
// folder change
processFolderChange( mf );
}
++cursor;
}
}
// TODO: call virtual here to read any fields after the contact list...
if ( response->resultCode() == GroupWise::None )
setSuccess();
else
setError( response->resultCode() );
return true;
}
void ModifyContactListTask::processContactChange( Field::MultiField * container )
{
if ( !( container->method() == NMFIELD_METHOD_ADD
|| container->method() == NMFIELD_METHOD_DELETE ) )
return;
client()->debug( "ModifyContactListTask::processContactChange()" );
Field::SingleField * current;
Field::FieldList fl = container->fields();
ContactItem contact;
current = fl.findSingleField( NM_A_SZ_OBJECT_ID );
contact.id = current->value().toInt();
current = fl.findSingleField( NM_A_SZ_PARENT_ID );
contact.parentId = current->value().toInt();
current = fl.findSingleField( NM_A_SZ_SEQUENCE_NUMBER );
contact.sequence = current->value().toInt();
current = fl.findSingleField( NM_A_SZ_DISPLAY_NAME );
contact.displayName = current->value().toString();
current = fl.findSingleField( NM_A_SZ_DN );
contact.dn = current->value().toString();
if ( container->method() == NMFIELD_METHOD_ADD )
emit gotContactAdded( contact );
else if ( container->method() == NMFIELD_METHOD_DELETE )
emit gotContactDeleted( contact );
}
void ModifyContactListTask::processFolderChange( Field::MultiField * container )
{
if ( !( container->method() == NMFIELD_METHOD_ADD
|| container->method() == NMFIELD_METHOD_DELETE ) )
return;
client()->debug( "ModifyContactListTask::processFolderChange()" );
FolderItem folder;
Field::SingleField * current;
Field::FieldList fl = container->fields();
// object id
current = fl.findSingleField( NM_A_SZ_OBJECT_ID );
folder.id = current->value().toInt();
// sequence number
current = fl.findSingleField( NM_A_SZ_SEQUENCE_NUMBER );
folder.sequence = current->value().toInt();
// name
current = fl.findSingleField( NM_A_SZ_DISPLAY_NAME );
folder.name = current->value().toString();
// parent
current = fl.findSingleField( NM_A_SZ_PARENT_ID );
folder.parentId = current->value().toInt();
if ( container->method() == NMFIELD_METHOD_ADD )
emit gotFolderAdded( folder );
else if ( container->method() == NMFIELD_METHOD_DELETE )
emit gotFolderDeleted( folder );
}
#include "modifycontactlisttask.moc"
|