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
|
/*
Kopete Yahoo Protocol
Handles incoming webcam connections
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. *
* *
*************************************************************************
*/
#ifndef WEBCAMTASK_H
#define WEBCAMTASK_H
#include "task.h"
#include <tqmap.h>
#include <tqpixmap.h>
#include <tqstringlist.h>
class TQString;
class YMSGTransfer;
class TQBuffer;
namespace KNetwork {
class KStreamSocket;
}
using namespace KNetwork;
enum ConnectionStatus{ InitialStatus, ConnectedStage1, ConnectedStage2, Receiving, Sending, SendingEmpty };
enum PacketType { Image, ConnectionClosed, UserRequest, NewWatcher, WatcherLeft };
enum Direction { Incoming, Outgoing };
struct YahooWebcamInformation
{
QString sender;
QString server;
QString key;
ConnectionStatus status;
PacketType type;
Direction direction;
uchar reason;
Q_INT32 dataLength;
Q_INT32 timestamp;
bool headerRead;
TQBuffer *buffer;
};
typedef TQMap< KStreamSocket *, YahooWebcamInformation > SocketInfoMap;
/**
@author André Duffeck
*/
class WebcamTask : public Task
{
Q_OBJECT
public:
WebcamTask(Task *parent);
~WebcamTask();
bool take(Transfer *transfer);
bool transmitting() { return transmittingData; }
void requestWebcam( const TQString &who );
void closeWebcam( const TQString &who );
void registerWebcam();
void sendWebcamImage( const TQByteArray &image );
void addPendingInvitation( const TQString &userId );
void grantAccess( const TQString &userId );
void closeOutgoingWebcam();
signals:
void webcamNotAvailable( const TQString & );
void webcamClosed( const TQString &, int );
void webcamPaused( const TQString& );
void webcamImageReceived( const TQString &, const TQPixmap &);
void readyForTransmission();
void stopTransmission();
void viewerJoined( const TQString & );
void viewerLeft( const TQString & );
void viewerRequest( const TQString & );
private slots:
void slotConnectionStage1Established();
void slotConnectionStage2Established();
void slotConnectionFailed(int);
void slotRead();
void sendEmptyWebcamImage();
void transmitWebcamImage();
protected:
virtual bool forMe( const Transfer* transfer ) const;
private:
void parseWebcamInformation( YMSGTransfer *transfer );
void parseData( TQByteArray &data, KStreamSocket *socket );
void connectStage2( KStreamSocket *socket );
void processData( KStreamSocket *socket );
void cleanUpConnection( KStreamSocket *socket );
TQString keyPending; // the buddy we have requested the webcam from
SocketInfoMap socketMap;
bool transmittingData;
TQStringList pendingInvitations;
TQStringList accessGranted;
int timestamp;
TQByteArray pictureBuffer;
bool transmissionPending;
};
#endif
|