~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/groupwise/libgroupwise/tasks/joinconferencetask.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Kopete Groupwise Protocol
 
3
    joinconferencetask.cpp - Join a conference on the server, after having been invited.
 
4
 
 
5
    Copyright (c) 2004      SUSE Linux AG                http://www.suse.com
 
6
    
 
7
    Based on Iris, Copyright (C) 2003  Justin Karneges <justin@affinix.com>
 
8
 
 
9
    Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
 
10
 
 
11
    *************************************************************************
 
12
    *                                                                       *
 
13
    * This library is free software; you can redistribute it and/or         *
 
14
    * modify it under the terms of the GNU Lesser General Public            *
 
15
    * License as published by the Free Software Foundation; either          *
 
16
    * version 2 of the License, or (at your option) any later version.      *
 
17
    *                                                                       *
 
18
    *************************************************************************
 
19
*/
 
20
 
 
21
#include "gwerror.h"
 
22
#include "client.h"
 
23
#include "response.h"
 
24
#include "userdetailsmanager.h"
 
25
 
 
26
#include "joinconferencetask.h"
 
27
 
 
28
JoinConferenceTask::JoinConferenceTask(Task* parent): RequestTask(parent)
 
29
{
 
30
}
 
31
 
 
32
JoinConferenceTask::~JoinConferenceTask()
 
33
{
 
34
}
 
35
 
 
36
void JoinConferenceTask::join( const GroupWise::ConferenceGuid & guid )
 
37
{
 
38
        m_guid = guid;
 
39
        Field::FieldList lst, tmp;
 
40
        tmp.append( new Field::SingleField( Field::NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, guid ) );
 
41
        lst.append( new Field::MultiField( Field::NM_A_FA_CONVERSATION, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, tmp ) );
 
42
        createTransfer( "joinconf", lst );
 
43
}
 
44
 
 
45
bool JoinConferenceTask::take( Transfer * transfer )
 
46
{
 
47
        if ( forMe( transfer ) )
 
48
        {
 
49
                client()->debug( "JoinConferenceTask::take()" );
 
50
                Response * response = dynamic_cast<Response *>( transfer );
 
51
                Field::FieldList responseFields = response->fields();
 
52
                // if the request was successful
 
53
                if ( response->resultCode() == GroupWise::None )
 
54
                {
 
55
                        // extract the list of participants and store them
 
56
                        Field::MultiField * participants = responseFields.findMultiField( Field::NM_A_FA_CONTACT_LIST );
 
57
                        if ( participants )
 
58
                        {
 
59
                                Field::SingleField * contact = 0;
 
60
                                Field::FieldList contactList = participants->fields();
 
61
                                const Field::FieldListIterator end = contactList.end();
 
62
                                for ( Field::FieldListIterator it = contactList.find( Field::NM_A_SZ_DN );
 
63
                                         it != end;
 
64
                                         it = contactList.find( ++it, Field::NM_A_SZ_DN ) )
 
65
                                {
 
66
                                        contact = static_cast<Field::SingleField *>( *it );
 
67
                                        if ( contact )
 
68
                                        {
 
69
                                                // HACK: lowercased DN 
 
70
                                                QString dn = contact->value().toString().toLower();
 
71
                                                m_participants.append( dn );
 
72
                                                // need to ask for details for these contacts
 
73
                                                if ( !client()->userDetailsManager()->known( dn )  )
 
74
                                                        m_unknowns.append( dn );
 
75
                                        }
 
76
                                }
 
77
                        }
 
78
                        else 
 
79
                                setError( GroupWise::Protocol );
 
80
                        
 
81
                        // now, extract the list of pending invites and store them
 
82
                        Field::MultiField * invitees = responseFields.findMultiField( Field::NM_A_FA_RESULTS );
 
83
                        if ( invitees )
 
84
                        {
 
85
                                Field::SingleField * contact = 0;
 
86
                                Field::FieldList contactList = invitees->fields();
 
87
                                const Field::FieldListIterator end = contactList.end();
 
88
                                for ( Field::FieldListIterator it = contactList.find( Field::NM_A_SZ_DN );
 
89
                                         it != end;
 
90
                                         it = contactList.find( ++it, Field::NM_A_SZ_DN ) )
 
91
                                {
 
92
                                        contact = static_cast<Field::SingleField *>( *it );
 
93
                                        if ( contact )
 
94
                                        {
 
95
                                                // HACK: lowercased DN 
 
96
                                                QString dn = contact->value().toString().toLower();
 
97
                                                m_invitees.append( dn );
 
98
                                                // need to ask for details for these contacts
 
99
                                                if ( !client()->userDetailsManager()->known( dn )  )
 
100
                                                        m_unknowns.append( dn );
 
101
                                        }
 
102
                                }
 
103
                        }
 
104
                        else 
 
105
                                setError( GroupWise::Protocol );
 
106
 
 
107
                        if ( m_unknowns.empty() )       // ready to chat
 
108
                        {
 
109
                                client()->debug( "JoinConferenceTask::finished()" );
 
110
                                finished();
 
111
                        }
 
112
                        else                                                            // need to get some more details first
 
113
                        {
 
114
                                client()->debug( "JoinConferenceTask::slotReceiveUserDetails(), requesting details" );
 
115
                                connect( client()->userDetailsManager(), 
 
116
                                                SIGNAL(gotContactDetails(GroupWise::ContactDetails)),
 
117
                                                SLOT(slotReceiveUserDetails(GroupWise::ContactDetails)) );
 
118
                                client()->userDetailsManager()->requestDetails( m_unknowns );
 
119
                        }
 
120
                }
 
121
                else
 
122
                        setError( response->resultCode() );
 
123
                return true;
 
124
        }
 
125
        else
 
126
                return false;
 
127
}
 
128
 
 
129
void JoinConferenceTask::slotReceiveUserDetails( const ContactDetails & details )
 
130
{
 
131
        client()->debug( QString( "JoinConferenceTask::slotReceiveUserDetails() - got %1" ).arg( details.dn ) );
 
132
        QStringList::Iterator it = m_unknowns.begin();
 
133
        QStringList::Iterator end = m_unknowns.end();
 
134
        for( ; it != end; ++it )
 
135
        {
 
136
                QString current = *it;
 
137
                client()->debug( QString( " - can we remove %1?" ).arg(current ) );
 
138
                if ( current == details.dn )
 
139
                {
 
140
                        client()->debug( " - it is gone!" );
 
141
                        m_unknowns.erase( it );
 
142
                        break;
 
143
                }
 
144
        }
 
145
        client()->debug( QString( " - now %1 unknowns").arg( m_unknowns.count() ) );
 
146
        if ( m_unknowns.empty() )
 
147
        {
 
148
                client()->debug( " - finished()" );
 
149
                finished();
 
150
        }
 
151
// would be better to count the number of received details and listen to the getdetails task's error signal.
 
152
//      else
 
153
//      {
 
154
//              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." );
 
155
//              finished();
 
156
//      }
 
157
}
 
158
 
 
159
QStringList JoinConferenceTask::participants() const
 
160
{
 
161
        return m_participants;
 
162
}
 
163
 
 
164
QStringList JoinConferenceTask::invitees() const
 
165
{
 
166
        return m_invitees;
 
167
}
 
168
 
 
169
GroupWise::ConferenceGuid JoinConferenceTask::guid() const
 
170
{
 
171
        return m_guid;
 
172
}
 
173
 
 
174
#include "joinconferencetask.moc"