5
Copyright (c) 2005 AndrƩ Duffeck <duffeck@kde.org>
7
*************************************************************************
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. *
14
*************************************************************************
17
#include "conferencetask.h"
19
#include "ymsgtransfer.h"
20
#include "yahootypes.h"
23
#include <qstringlist.h>
26
ConferenceTask::ConferenceTask(Task* parent) : Task(parent)
28
kDebug(YAHOO_RAW_DEBUG) ;
31
ConferenceTask::~ConferenceTask()
35
bool ConferenceTask::take( Transfer* transfer )
37
if ( !forMe( transfer ) )
41
t = static_cast<YMSGTransfer*>(transfer);
43
if( t->service() == Yahoo::ServiceConfInvite ||
44
t->service() == Yahoo::ServiceConfAddInvite)
46
else if( t->service() == Yahoo::ServiceConfMsg )
48
else if( t->service() == Yahoo::ServiceConfLogon )
50
else if( t->service() == Yahoo::ServiceConfLogoff )
52
else if( t->service() == Yahoo::ServiceConfDecline )
53
parseUserDeclined( t );
58
bool ConferenceTask::forMe( const Transfer* transfer ) const
60
const YMSGTransfer *t = 0L;
61
t = dynamic_cast<const YMSGTransfer*>(transfer);
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 )
76
void ConferenceTask::parseInvitation( YMSGTransfer *t )
78
kDebug(YAHOO_RAW_DEBUG) ;
81
QString who = t->firstParam( 50 );
82
QString room = t->firstParam( 57 );
83
bool utf = QString( t->firstParam( 97 ) ).toInt() == 1;
86
msg = QString::fromUtf8( t->firstParam( 58 ) );
88
msg = t->firstParam( 58 );
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() )
98
if( !who.isEmpty() && !room.isEmpty() )
99
emit gotInvite( who, room, msg, members );
102
void ConferenceTask::parseMessage( YMSGTransfer *t )
104
kDebug(YAHOO_RAW_DEBUG) ;
106
QString room = t->firstParam( 57 );
107
QString from = t->firstParam( 3 );
108
bool utf = QString( t->firstParam( 97 ) ).toInt() == 1;
111
msg = QString::fromUtf8( t->firstParam( 14 ) );
113
msg = t->firstParam( 14 );
116
emit gotMessage( from, room, msg );
119
void ConferenceTask::parseUserJoined( YMSGTransfer *t )
121
kDebug(YAHOO_RAW_DEBUG) ;
123
QString room = t->firstParam( 57 );
124
QString who = t->firstParam( 53 );
126
if( !who.isEmpty() && !room.isEmpty() )
127
emit userJoined( who, room );
130
void ConferenceTask::parseUserLeft( YMSGTransfer *t )
132
kDebug(YAHOO_RAW_DEBUG) ;
134
QString room = t->firstParam( 57 );
135
QString who = t->firstParam( 56 );
137
if( !who.isEmpty() && !room.isEmpty() )
138
emit userLeft( who, room );
141
void ConferenceTask::parseUserDeclined( YMSGTransfer *t )
143
kDebug(YAHOO_RAW_DEBUG) ;
145
QString room = t->firstParam( 57 );
146
QString who = t->firstParam( 54 );
147
QString msg = t->firstParam( 14 );
149
if( !who.isEmpty() && !room.isEmpty() )
150
emit userDeclined( who, room, msg );
153
void ConferenceTask::inviteConference( const QString &room, const QStringList &members, const QString &msg )
155
kDebug(YAHOO_RAW_DEBUG) ;
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" );
171
void ConferenceTask::addInvite( const QString &room, const QStringList &who, const QStringList &members, const QString &msg )
173
kDebug(YAHOO_RAW_DEBUG) ;
175
YMSGTransfer *t = new YMSGTransfer(Yahoo::ServiceConfAddInvite);
176
t->setId( client()->sessionID() );
177
t->setParam( 1, client()->userId().toLocal8Bit() );
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() );
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 )
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
192
t->setParam( 13, "0" );
197
void ConferenceTask::joinConference( const QString &room, const QStringList &members )
199
kDebug(YAHOO_RAW_DEBUG) ;
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() );
211
void ConferenceTask::declineConference( const QString &room, const QStringList &members, const QString &msg )
213
kDebug(YAHOO_RAW_DEBUG) ;
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 );
226
void ConferenceTask::leaveConference( const QString &room, const QStringList &members )
228
kDebug(YAHOO_RAW_DEBUG) ;
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() );
240
void ConferenceTask::sendMessage( const QString &room, const QStringList &members, const QString &msg )
242
kDebug(YAHOO_RAW_DEBUG) ;
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 );
255
#include "conferencetask.moc"