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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
This class represents a DCC transfer.
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
/*
Copyright (C) 2002-2004 Dario Abatianni <eisfuchs@tigress.com>
Copyright (C) 2004-2007 Shintaro Matsuoka <shin@shoegazed.org>
Copyright (C) 2004,2005 John Tapsell <john@geola.co.uk>
*/
#ifndef DCCTRANSFER_H
#define DCCTRANSFER_H
#include <tqdatetime.h>
#include <tqobject.h>
#include <tqtimer.h>
#include <kurl.h>
#include <kio/global.h>
typedef double transferspeed_t;
class DccTransfer : public TQObject
{
Q_OBJECT
public:
enum DccType
{
Receive,
Send
};
enum DccStatus
{
Configuring = 0, // Not queud yet (this means that user can't see the item at this time)
Queued, // Newly added DCC, waiting user's response
Preparing, // Opening KIO to write received data
WaitingRemote, // Waiting for remote host's response
Connecting, // RECV: trying to connect to the server
Transferring,
Done,
Failed,
Aborted
};
enum UnavailableStatus
{
Calculating = -1,
NotInTransfer = -2,
InfiniteValue = -3
};
DccTransfer( DccType dccType, TQObject* parent );
virtual ~DccTransfer();
// info of DccTransfer can be copied with this constructor.
DccTransfer( const DccTransfer& obj );
DccType getType() const;
DccStatus getStatus() const;
const TQString& getStatusDetail() const;
TQDateTime getTimeOffer() const;
int getConnectionId() const;
TQString getOwnIp() const;
TQString getOwnPort() const;
TQString getPartnerNick() const;
TQString getPartnerIp() const;
TQString getPartnerPort() const;
TQString getFileName() const;
KIO::filesize_t getFileSize() const;
KIO::fileoffset_t getTransferringPosition() const;
KIO::fileoffset_t getTransferStartPosition() const;
KURL getFileURL() const;
bool isResumed() const;
bool isReverse() const;
TQString getReverseToken() const;
transferspeed_t getAverageSpeed() const;
transferspeed_t getCurrentSpeed() const;
int getTimeLeft() const;
int getProgress() const;
TQDateTime getTimeTransferStarted() const;
TQDateTime getTimeTransferFinished() const;
// common settings for DccTransferRecv / DccTransferSend
// REQUIRED
void setConnectionId( int connectionId );
// REQUIRED
void setPartnerNick( const TQString& nick );
signals:
void transferStarted( DccTransfer* item );
void done( DccTransfer* item );
void statusChanged( DccTransfer* item, int newStatus, int oldStatus );
public slots:
virtual bool queue();
virtual void start() {};
virtual void abort() {};
protected:
void setStatus( DccStatus status, const TQString& statusDetail = TQString() );
void startTransferLogger();
void finishTransferLogger();
static TQString sanitizeFileName( const TQString& fileName );
static TQString getNumericalIpText( const TQString& ipString );
static unsigned long intel( unsigned long value );
protected slots:
void logTransfer();
protected:
// transfer information
DccType m_type;
DccStatus m_status;
TQString m_statusDetail;
bool m_resumed;
bool m_reverse;
TQString m_reverseToken;
KIO::fileoffset_t m_transferringPosition;
KIO::fileoffset_t m_transferStartPosition;
/*
TQValueList<TQDateTime> m_transferTimeLog; // write per packet to calc CPS
TQValueList<KIO::fileoffset_t> m_transferPositionLog; // write per packet to calc CPS
*/
// we'll communicate with the partner via this server
int m_connectionId;
TQString m_partnerNick;
TQString m_partnerIp; // null when unknown
TQString m_partnerPort;
TQString m_ownIp;
TQString m_ownPort;
unsigned long m_bufferSize;
char* m_buffer;
/**
* The filename.
* For receiving, it holds the filename as the sender said.
* So be careful, it can contain "../" and so on.
*/
TQString m_fileName;
/** The file size of the complete file sending/recieving. */
KIO::filesize_t m_fileSize;
/**
* If we are sending a file, this is the url of the file we are sending.
* If we are recieving a file, this is the url of the file we are saving
* to in the end (Temporararily it will be filename+".part" ).
*/
KURL m_fileURL;
private:
DccTransfer& operator = ( const DccTransfer& obj );
void updateTransferMeters();
private:
TQDateTime m_timeOffer;
TQDateTime m_timeTransferStarted;
//TQDateTime m_timeLastActive;
TQDateTime m_timeTransferFinished;
TQTimer m_loggerTimer;
TQTime m_loggerBaseTime; // for calculating CPS
TQValueList<int> m_transferLogTime;
TQValueList<KIO::fileoffset_t> m_transferLogPosition;
transferspeed_t m_averageSpeed;
transferspeed_t m_currentSpeed;
int m_timeLeft;
};
#endif // DCCTRANSFER_H
|