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
*************************************************************************
19
#include "messagereceivertask.h"
21
#include "ymsgtransfer.h"
22
#include "yahootypes.h"
26
using namespace KYahoo;
28
MessageReceiverTask::MessageReceiverTask(Task* parent) : Task(parent)
30
kDebug(YAHOO_RAW_DEBUG) ;
33
MessageReceiverTask::~MessageReceiverTask()
37
bool MessageReceiverTask::take( Transfer* transfer )
39
if ( !forMe( transfer ) )
43
t = dynamic_cast<YMSGTransfer*>(transfer);
47
if( t->service() == Yahoo::ServiceNotify )
53
if( t->service() == Yahoo::ServiceAnimatedAudibleIcon )
55
parseAnimatedAudibleIcon( t );
66
bool MessageReceiverTask::forMe( const Transfer* transfer ) const
68
const YMSGTransfer *t = 0L;
69
t = dynamic_cast<const YMSGTransfer*>(transfer);
73
if ( t->service() == Yahoo::ServiceMessage ||
74
t->service() == Yahoo::ServiceGameMsg ||
75
t->service() == Yahoo::ServiceSysMessage ||
76
t->service() == Yahoo::ServiceNotify ||
77
t->service() == Yahoo::ServiceAnimatedAudibleIcon )
83
void MessageReceiverTask::parseMessage( YMSGTransfer *t )
85
kDebug(YAHOO_RAW_DEBUG) ;
87
int cnt = t->paramCount( 5 );
88
for( int i = 0; i < cnt; ++i )
90
QString to = t->nthParam( 5, i );
91
QString timestamp = t->nthParamSeparated( 15, i, 4 );
92
QString utf8 = t->nthParamSeparated( 97, i, 4 );
93
QString from = t->nthParamSeparated( 1, i, 4 ).isEmpty() ? t->nthParam( 4, i ) : t->nthParamSeparated( 1, i, 4 );
94
QString msg = t->nthParamSeparated( 14, i, 4 );
95
QString sysmsg = t->nthParamSeparated( 16, i, 4 );
97
// The arrangement of the key->value pairs is different when there is only one message in the packet.
98
// Separating by key "5" (sender) doesn't work in that case, because the "1" and "4" keys are sent before the "5" key
100
from = t->firstParam( 1 ).isEmpty() ? t->firstParam( 4 ) : t->firstParam( 1 );
102
if( !sysmsg.isEmpty() )
104
client()->notifyError( "Server message received: ", sysmsg, Client::Error );
110
kDebug(YAHOO_RAW_DEBUG) << "Got a empty message. Dropped.";
114
if( utf8.startsWith( '1' ) )
115
msg = QString::fromUtf8( msg.toLatin1() );
117
if( t->service() == Yahoo::ServiceSysMessage )
118
emit systemMessage( sysmsg );
121
if( msg.startsWith( "<ding>" ) )
122
emit gotBuzz( from, timestamp.toLong() );
124
emit gotIm( from, msg, timestamp.toLong(), 0);
129
void MessageReceiverTask::parseAnimatedAudibleIcon( YMSGTransfer *t )
131
// added by michaelacole
132
kDebug(YAHOO_RAW_DEBUG) ;
134
int cnt = t->paramCount( 5 );
135
for( int i = 0; i < cnt; ++i )
137
QString to = t->nthParam( 5, i );
138
QString from = t->nthParamSeparated( 1, i, 4 ).isEmpty() ? t->nthParam( 4, i ) : t->nthParamSeparated( 1, i, 4 );
139
QString msg = t->nthParamSeparated( 231, i, 4 );
140
QString msg2 = t->nthParamSeparated( 230, i, 4 );
141
QString utf8 = t->nthParamSeparated( 97, i, 4 );
142
QString timestamp = t->nthParamSeparated( 15, i, 4 );
144
// The arrangement of the key->value pairs is different when there is only one message in the packet.
145
// Separating by key "5" (sender) doesn't work in that case, because the "1" and "4" keys are sent before the "5" key
147
from = t->firstParam( 1 ).isEmpty() ? t->firstParam( 4 ) : t->firstParam( 1 );
151
kDebug(YAHOO_RAW_DEBUG) << "Got a empty message. Dropped.";
155
if( utf8.startsWith( '1' ) )
157
msg = QString::fromUtf8( msg.toLatin1() );
160
msg = "ANIMATED AUDIBLE SENT TO YOU WITH TEXT " + msg;
161
emit gotIm( from, msg, timestamp.toLong(), 0);
162
msg2 = "http://us.dl1.yimg.com//download.yahoo.com/dl/aud/"+msg2.mid(5,2)+"/" + msg2 + ".swf";
163
emit gotIm( from, msg2,timestamp.toLong(), 0);
168
void MessageReceiverTask::parseNotify( YMSGTransfer *t )
170
kDebug(YAHOO_RAW_DEBUG) ;
172
QString from = t->firstParam( 4 );
173
//QString to = t->firstParam( 5 );
174
QString type = t->firstParam( 49 );
175
QString stat = t->firstParam( 13 );
176
QString ind = t->firstParam( 14 );
178
if( type.startsWith( "TYPING" ) )
179
emit gotTypingNotify( from, stat.toInt() );
180
else if( type.startsWith( "GAME" ) )
182
else if( type.startsWith( "WEBCAMINVITE" ) )
184
if( ind.startsWith(' ') )
186
kDebug(YAHOO_RAW_DEBUG) << "Got a WebcamInvitation.";
187
emit gotWebcamInvite( from );
191
kDebug(YAHOO_RAW_DEBUG) << "Got a WebcamRequest-Response: " << ind.toInt();
196
#include "messagereceivertask.moc"