summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/yahoo/libkyahoo/picturenotifiertask.cpp
blob: cf7a6e34d0bfa12821501b73e239588fb0f84cae (plain)
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
/*
    Kopete Yahoo Protocol
    Notifies about buddy icons

    Copyright (c) 2005 André Duffeck <duffeck@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 "picturenotifiertask.h"
#include "transfer.h"
#include "ymsgtransfer.h"
#include "yahootypes.h"
#include "client.h"

#include <tqstringlist.h>
#include <kdebug.h>
#include <klocale.h>


PictureNotifierTask::PictureNotifierTask(Task* tqparent) : Task(tqparent)
{
	kdDebug(YAHOO_RAW_DEBUG) ;
}

PictureNotifierTask::~PictureNotifierTask()
{

}

bool PictureNotifierTask::take( Transfer* transfer )
{
	if ( !forMe( transfer ) )
		return false;

	YMSGTransfer *t = 0L;
	t = dynamic_cast<YMSGTransfer*>(transfer);
	if (!t)
		return false;

	switch( t->service() )
	{
		case Yahoo::ServicePicturetqStatus:
			parsePicturetqStatus( t );
			parsePicture( t );
		break;
		case Yahoo::ServicePictureChecksum:
			parsePictureChecksum( t );
			parsePicture( t );
		break;
		case Yahoo::ServicePicture:
			parsePicture( t );
		break;
		case Yahoo::ServicePictureUpload:
			parsePictureUploadResponse( t );
		break;
		default:
		break;
	}

	return true;
}

bool PictureNotifierTask::forMe( const Transfer* transfer ) const
{
	const YMSGTransfer *t = 0L;
	t = dynamic_cast<const YMSGTransfer*>(transfer);
	if (!t)
		return false;


	if ( t->service() == Yahoo::ServicePictureChecksum ||
		t->service() == Yahoo::ServicePicture ||
		t->service() == Yahoo::ServicePictureUpdate ||
		t->service() == Yahoo::ServicePictureUpload ||
		t->service() == Yahoo::ServicePicturetqStatus )
		return true;
	else
		return false;
}

void PictureNotifierTask::parsePicturetqStatus( YMSGTransfer *t )
{
	kdDebug(YAHOO_RAW_DEBUG) ;

	TQString	nick;		/* key = 4 */
	int state;		/* key = 213  */

	nick = t->firstParam( 4 );
	state = t->firstParam( 213 ).toInt();

	emit pictureStatusNotify( nick, state );
}

void PictureNotifierTask::parsePictureChecksum( YMSGTransfer *t )
{
	kdDebug(YAHOO_RAW_DEBUG) ;

	TQString	nick;		/* key = 4 */
	int checksum;		/* key = 192  */

	nick = t->firstParam( 4 );
	checksum = t->firstParam( 192 ).toInt();

	if( nick != client()->userId() )
		emit pictureChecksumNotify( nick, checksum );
}

void PictureNotifierTask::parsePicture( YMSGTransfer *t )
{
	kdDebug(YAHOO_RAW_DEBUG) ;

	TQString	nick;		/* key = 4 */
	int type;		/* key = 13: 1 = request, 2 = notification, 0 = Just changed */
	TQString url;		/* key = 20 */
	int checksum;		/* key = 192  */

	nick = t->firstParam( 4 );
	url = t->firstParam( 20 );
	checksum = t->firstParam( 192 ).toInt();
	type = t->firstParam( 13 ).toInt();

	if( type == 1 )
		emit pictureRequest( nick );
	else if( type == 0 )
		emit pictureInfoNotify( nick, KURL( url ), checksum );
	else if( type == 2 )
		emit pictureInfoNotify( nick, KURL( url ), checksum );
}

void PictureNotifierTask::parsePictureUploadResponse( YMSGTransfer *t )
{
	kdDebug(YAHOO_RAW_DEBUG) ;

	TQString url;
	TQString error;
	int expires;

	url = t->firstParam( 20 );
	error = t->firstParam( 16 );
	expires = t->firstParam( 38 ).toInt();

	if( !error.isEmpty() )
		client()->notifyError(i18n("The picture was not successfully uploaded"), error, Client::Error );

	if( !url.isEmpty() )
	{
		kdDebug(YAHOO_RAW_DEBUG) << "Emitting url: " << url << " Picture expires: " << expires << endl;
		emit pictureUploaded( url, expires );
	}
}

#include "picturenotifiertask.moc"