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

« back to all changes in this revision

Viewing changes to protocols/yahoo/libkyahoo/conferencetask.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 Yahoo Protocol
 
3
    Handles conferences
 
4
 
 
5
    Copyright (c) 2005 AndrĆ© Duffeck <duffeck@kde.org>
 
6
 
 
7
    *************************************************************************
 
8
    *                                                                       *
 
9
    * This library is free software; you can redistribute it and/or         *
 
10
    * modify it under the terms of the GNU Lesser General Public            *
 
11
    * License as published by the Free Software Foundation; either          *
 
12
    * version 2 of the License, or (at your option) any later version.      *
 
13
    *                                                                       *
 
14
    *************************************************************************
 
15
*/
 
16
 
 
17
#include "conferencetask.h"
 
18
#include "transfer.h"
 
19
#include "ymsgtransfer.h"
 
20
#include "yahootypes.h"
 
21
#include "client.h"
 
22
#include <qstring.h>
 
23
#include <qstringlist.h>
 
24
#include <kdebug.h>
 
25
 
 
26
ConferenceTask::ConferenceTask(Task* parent) : Task(parent)
 
27
{
 
28
        kDebug(YAHOO_RAW_DEBUG) ;
 
29
}
 
30
 
 
31
ConferenceTask::~ConferenceTask()
 
32
{
 
33
}
 
34
 
 
35
bool ConferenceTask::take( Transfer* transfer )
 
36
{
 
37
        if ( !forMe( transfer ) )
 
38
                return false;
 
39
 
 
40
        YMSGTransfer *t = 0L;
 
41
        t = static_cast<YMSGTransfer*>(transfer);
 
42
        
 
43
        if( t->service() == Yahoo::ServiceConfInvite ||
 
44
                t->service() == Yahoo::ServiceConfAddInvite)
 
45
                parseInvitation( t );
 
46
        else if( t->service() == Yahoo::ServiceConfMsg )
 
47
                parseMessage( t );
 
48
        else if( t->service() == Yahoo::ServiceConfLogon )
 
49
                parseUserJoined( t );
 
50
        else if( t->service() == Yahoo::ServiceConfLogoff )
 
51
                parseUserLeft( t );
 
52
        else if( t->service() == Yahoo::ServiceConfDecline )
 
53
                parseUserDeclined( t );
 
54
 
 
55
        return true;
 
56
}
 
57
 
 
58
bool ConferenceTask::forMe( const Transfer* transfer ) const
 
59
{
 
60
        const YMSGTransfer *t = 0L;
 
61
        t = dynamic_cast<const YMSGTransfer*>(transfer);
 
62
        if (!t)
 
63
                return false;
 
64
 
 
65
        if ( t->service() == Yahoo::ServiceConfInvite ||
 
66
                t->service() == Yahoo::ServiceConfLogon ||
 
67
                t->service() == Yahoo::ServiceConfDecline ||
 
68
                t->service() == Yahoo::ServiceConfLogoff ||
 
69
                t->service() == Yahoo::ServiceConfAddInvite ||
 
70
                t->service() == Yahoo::ServiceConfMsg ) 
 
71
                return true;
 
72
        else
 
73
                return false;
 
74
}
 
75
 
 
76
void ConferenceTask::parseInvitation( YMSGTransfer *t )
 
77
{
 
78
        kDebug(YAHOO_RAW_DEBUG) ;
 
79
        
 
80
        int i = 0;
 
81
        QString who = t->firstParam( 50 );
 
82
        QString room = t->firstParam( 57 );
 
83
        bool utf = QString( t->firstParam( 97 ) ).toInt() == 1;
 
84
        QString msg;
 
85
        if( utf )
 
86
                msg = QString::fromUtf8( t->firstParam( 58 ) );
 
87
        else
 
88
                msg = t->firstParam( 58 );
 
89
 
 
90
        QStringList members;
 
91
        for( i = 0; i < t->paramCount( 52 ); ++i )
 
92
                members.append( t->nthParam( 52, i ) );
 
93
        for( i = 0; i < t->paramCount( 53 ); ++i )
 
94
                members.append( t->nthParam( 53, i ) );
 
95
        if( who == client()->userId() )
 
96
                return;
 
97
 
 
98
        if( !who.isEmpty() && !room.isEmpty() )
 
99
                emit gotInvite( who, room, msg, members );
 
100
}
 
101
 
 
102
void ConferenceTask::parseMessage( YMSGTransfer *t )
 
103
{
 
104
        kDebug(YAHOO_RAW_DEBUG) ;
 
105
 
 
106
        QString room = t->firstParam( 57 );
 
107
        QString from = t->firstParam( 3 );
 
108
        bool utf = QString( t->firstParam( 97 ) ).toInt() == 1;
 
109
        QString msg;
 
110
        if( utf )
 
111
                msg = QString::fromUtf8( t->firstParam( 14 ) );
 
112
        else
 
113
                msg = t->firstParam( 14 );
 
114
 
 
115
        if( !msg.isEmpty() )
 
116
                emit gotMessage( from, room, msg ); 
 
117
}
 
118
 
 
119
void ConferenceTask::parseUserJoined( YMSGTransfer *t )
 
120
{
 
121
        kDebug(YAHOO_RAW_DEBUG) ;
 
122
 
 
123
        QString room = t->firstParam( 57 );
 
124
        QString who = t->firstParam( 53 );
 
125
 
 
126
        if( !who.isEmpty() && !room.isEmpty() )
 
127
                emit userJoined( who, room );
 
128
}
 
129
 
 
130
void ConferenceTask::parseUserLeft( YMSGTransfer *t )
 
131
{
 
132
        kDebug(YAHOO_RAW_DEBUG) ;
 
133
 
 
134
        QString room = t->firstParam( 57 );
 
135
        QString who = t->firstParam( 56 );
 
136
 
 
137
        if( !who.isEmpty() && !room.isEmpty() )
 
138
                emit userLeft( who, room );
 
139
}
 
140
 
 
141
void ConferenceTask::parseUserDeclined( YMSGTransfer *t )
 
142
{
 
143
        kDebug(YAHOO_RAW_DEBUG) ;
 
144
 
 
145
        QString room = t->firstParam( 57 );
 
146
        QString who = t->firstParam( 54 );
 
147
        QString msg = t->firstParam( 14 );
 
148
 
 
149
        if( !who.isEmpty() && !room.isEmpty() )
 
150
                emit userDeclined( who, room, msg );
 
151
}
 
152
 
 
153
void ConferenceTask::inviteConference( const QString &room, const QStringList &members, const QString &msg )
 
154
{
 
155
        kDebug(YAHOO_RAW_DEBUG) ;
 
156
 
 
157
        YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfInvite);
 
158
        t->setId( client()->sessionID() );
 
159
        t->setParam( 1, client()->userId().toLocal8Bit() );
 
160
        t->setParam( 50, client()->userId().toLocal8Bit() );
 
161
        t->setParam( 57, room.toLocal8Bit() );
 
162
        t->setParam( 58, msg.toLocal8Bit() );
 
163
        t->setParam( 97, 1 );
 
164
        for( QStringList::const_iterator it = members.begin(); it != members.end(); ++it )
 
165
                t->setParam( 52, (*it).toLocal8Bit() );
 
166
        t->setParam( 13, "0" );
 
167
 
 
168
        send( t );
 
169
}
 
170
 
 
171
void ConferenceTask::addInvite( const QString &room, const QStringList &who, const QStringList &members, const QString &msg )
 
172
{
 
173
        kDebug(YAHOO_RAW_DEBUG) ;
 
174
 
 
175
        YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfAddInvite);
 
176
        t->setId( client()->sessionID() );
 
177
        t->setParam( 1, client()->userId().toLocal8Bit() );
 
178
 
 
179
        QString whoList = who.first();
 
180
        for( int i = 1; i < who.size(); i++ )
 
181
                whoList += QString(",%1").arg( who[i] );
 
182
        t->setParam( 51, whoList.toLocal8Bit() );
 
183
 
 
184
        t->setParam( 57, room.toLocal8Bit() );
 
185
        t->setParam( 58, msg.toLocal8Bit() );
 
186
        t->setParam( 97, 1 );
 
187
        for( QStringList::const_iterator it = members.begin(); it != members.end(); ++it )
 
188
        {
 
189
                t->setParam( 52, (*it).toLocal8Bit() );
 
190
                t->setParam( 53, (*it).toLocal8Bit() ); // Note: this field should only be set if the buddy has already joined the conference, but no harm is done this way
 
191
        }
 
192
        t->setParam( 13, "0" );
 
193
 
 
194
        send( t );
 
195
}
 
196
 
 
197
void ConferenceTask::joinConference( const QString &room, const QStringList &members )
 
198
{
 
199
        kDebug(YAHOO_RAW_DEBUG) ;
 
200
 
 
201
        YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfLogon);
 
202
        t->setId( client()->sessionID() );
 
203
        t->setParam( 1, client()->userId().toLocal8Bit() );
 
204
        for( QStringList::const_iterator it = members.begin(); it != members.end(); ++it )
 
205
                t->setParam( 3, (*it).toLocal8Bit() );
 
206
        t->setParam( 57, room.toLocal8Bit() );
 
207
 
 
208
        send( t );
 
209
}
 
210
 
 
211
void ConferenceTask::declineConference( const QString &room, const QStringList &members, const QString &msg )
 
212
{
 
213
        kDebug(YAHOO_RAW_DEBUG) ;
 
214
 
 
215
        YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfDecline);
 
216
        t->setId( client()->sessionID() );
 
217
        t->setParam( 1, client()->userId().toLocal8Bit() );
 
218
        for( QStringList::const_iterator it = members.begin(); it != members.end(); ++it )
 
219
                t->setParam( 3, (*it).toLocal8Bit() );
 
220
        t->setParam( 57, room.toLocal8Bit() );  
 
221
        t->setParam( 14, msg.toUtf8() );
 
222
        t->setParam( 97, 1 );
 
223
 
 
224
        send( t );
 
225
}
 
226
void ConferenceTask::leaveConference( const QString &room, const QStringList &members )
 
227
{
 
228
        kDebug(YAHOO_RAW_DEBUG) ;
 
229
 
 
230
        YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfLogoff);
 
231
        t->setId( client()->sessionID() );
 
232
        t->setParam( 1, client()->userId().toLocal8Bit() );
 
233
        for( QStringList::const_iterator it = members.begin(); it != members.end(); ++it )
 
234
                t->setParam( 3, (*it).toLocal8Bit() );
 
235
        t->setParam( 57, room.toLocal8Bit() );
 
236
 
 
237
        send( t );
 
238
}
 
239
 
 
240
void ConferenceTask::sendMessage( const QString &room, const QStringList &members, const QString &msg )
 
241
{
 
242
        kDebug(YAHOO_RAW_DEBUG) ;
 
243
 
 
244
        YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfMsg);
 
245
        t->setId( client()->sessionID() );
 
246
        t->setParam( 1, client()->userId().toLocal8Bit() );
 
247
        for( QStringList::const_iterator it = members.begin(); it != members.end(); ++it )
 
248
                t->setParam( 53, (*it).toLocal8Bit() );
 
249
        t->setParam( 57, room.toLocal8Bit() );
 
250
        t->setParam( 14, msg.toUtf8() );
 
251
        t->setParam( 97, 1 );
 
252
 
 
253
        send( t );
 
254
}
 
255
#include "conferencetask.moc"