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
|
/*
Kopete Groupwise Protocol
joinconferencetask.cpp - Join a conference on the server, after having been invited.
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 "gwerror.h"
#include "client.h"
#include "response.h"
#include "userdetailsmanager.h"
#include "joinconferencetask.h"
JoinConferenceTask::JoinConferenceTask(Task* tqparent): RequestTask(tqparent)
{
}
JoinConferenceTask::~JoinConferenceTask()
{
}
void JoinConferenceTask::join( const GroupWise::ConferenceGuid & guid )
{
m_guid = guid;
Field::FieldList lst, tmp;
tmp.append( new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, guid ) );
lst.append( new Field::MultiField( NM_A_FA_CONVERSATION, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, tmp ) );
createTransfer( "joinconf", lst );
}
bool JoinConferenceTask::take( Transfer * transfer )
{
if ( forMe( transfer ) )
{
client()->debug( "JoinConferenceTask::take()" );
Response * response = dynamic_cast<Response *>( transfer );
Field::FieldList responseFields = response->fields();
// if the request was successful
if ( response->resultCode() == GroupWise::None )
{
// extract the list of participants and store them
Field::MultiField * participants = responseFields.findMultiField( NM_A_FA_CONTACT_LIST );
if ( participants )
{
Field::SingleField * contact = 0;
Field::FieldList contactList = participants->fields();
const Field::FieldListIterator end = contactList.end();
for ( Field::FieldListIterator it = contactList.find( NM_A_SZ_DN );
it != end;
it = contactList.find( ++it, NM_A_SZ_DN ) )
{
contact = static_cast<Field::SingleField *>( *it );
if ( contact )
{
// HACK: lowercased DN
TQString dn = contact->value().toString().lower();
m_participants.append( dn );
// need to ask for details for these contacts
if ( !client()->userDetailsManager()->known( dn ) )
m_unknowns.append( dn );
}
}
}
else
setError( GroupWise::Protocol );
// now, extract the list of pending invites and store them
Field::MultiField * invitees = responseFields.findMultiField( NM_A_FA_RESULTS );
if ( invitees )
{
Field::SingleField * contact = 0;
Field::FieldList contactList = invitees->fields();
const Field::FieldListIterator end = contactList.end();
for ( Field::FieldListIterator it = contactList.find( NM_A_SZ_DN );
it != end;
it = contactList.find( ++it, NM_A_SZ_DN ) )
{
contact = static_cast<Field::SingleField *>( *it );
if ( contact )
{
// HACK: lowercased DN
TQString dn = contact->value().toString().lower();
m_invitees.append( dn );
// need to ask for details for these contacts
if ( !client()->userDetailsManager()->known( dn ) )
m_unknowns.append( dn );
}
}
}
else
setError( GroupWise::Protocol );
if ( m_unknowns.empty() ) // ready to chat
{
client()->debug( "JoinConferenceTask::finished()" );
finished();
}
else // need to get some more details first
{
client()->debug( "JoinConferenceTask::slotReceiveUserDetails(), requesting details" );
connect( client()->userDetailsManager(),
TQT_SIGNAL( gotContactDetails( const GroupWise::ContactDetails & ) ),
TQT_SLOT( slotReceiveUserDetails( const GroupWise::ContactDetails & ) ) );
client()->userDetailsManager()->requestDetails( m_unknowns );
}
}
else
setError( response->resultCode() );
return true;
}
else
return false;
}
void JoinConferenceTask::slotReceiveUserDetails( const ContactDetails & details )
{
client()->debug( TQString( "JoinConferenceTask::slotReceiveUserDetails() - got %1" ).tqarg( details.dn ) );
TQStringList::Iterator it = m_unknowns.begin();
TQStringList::Iterator end = m_unknowns.end();
while( it != end )
{
TQString current = *it;
++it;
client()->debug( TQString( " - can we remove %1?" ).tqarg(current ) );
if ( current == details.dn )
{
client()->debug( " - it's gone!" );
m_unknowns.remove( current );
break;
}
}
client()->debug( TQString( " - now %1 unknowns").tqarg( m_unknowns.count() ) );
if ( m_unknowns.empty() )
{
client()->debug( " - finished()" );
finished();
}
// would be better to count the number of received details and listen to the getdetails task's error signal.
// else
// {
// client()->debug( " - ERROR - we requested details for the list of chat participants/invitees, but the server did not send us all the details! - setting finished() anyway, so the chat can take place." );
// finished();
// }
}
TQStringList JoinConferenceTask::participants() const
{
return m_participants;
}
TQStringList JoinConferenceTask::invitees() const
{
return m_invitees;
}
GroupWise::ConferenceGuid JoinConferenceTask::guid() const
{
return m_guid;
}
#include "joinconferencetask.moc"
|