KVIrc  4.9.2
DeveloperAPIs
DccFileTransfer.h
Go to the documentation of this file.
1 #ifndef _SEND_H_
2 #define _SEND_H_
3 //=============================================================================
4 //
5 // File : DccFileTransfer.h
6 // Creation date : Tue Sep 24 09 2000 15:06:12 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "DccDescriptor.h"
28 #include "DccWindow.h"
29 #include "DccThread.h"
30 
31 #include "KviWindow.h"
32 #include "KviCString.h"
33 #include "kvi_sockettype.h"
34 #include "KviPointerList.h"
35 #include "KviFileTransfer.h"
36 #include "KviTimeUtils.h"
37 #include "KviTalHBox.h"
38 #include "KviTalVBox.h"
39 
40 #include <QLabel>
41 #include <QProgressBar>
42 #include <QFile>
43 #include <QDialog>
44 #include <QCheckBox>
45 #include <QMenu>
46 
47 class QSpinBox;
48 class QTimer;
49 class QPainter;
50 class DccFileTransfer;
51 class DccMarshal;
52 class QMenu;
53 
55 {
57  quint64 uStartPosition;
60  bool bFastSend;
61  bool bNoAcks;
62  bool bIsTdcc;
63  unsigned int uMaxBandwidth;
65 
66 class DccSendThread : public DccThread
67 {
68 public:
69  DccSendThread(QObject * par, kvi_socket_t fd, KviDccSendThreadOptions * opt);
71 
72 private:
73  // stats: SHARED!!!
76  quint64 m_uFilePosition;
77  quint64 m_uAckedBytes;
79  // internal
80  unsigned long m_uStartTime;
81  unsigned long m_uInstantSpeedInterval;
84  KviMSecTimeInterval * m_pTimeInterval; // used for computing the instant bandwidth but not only
85 public:
86  void initGetInfo();
87  uint averageSpeed() { return m_uAverageSpeed; };
88  uint instantSpeed() { return m_uInstantSpeed; };
89  quint64 filePosition() { return m_uFilePosition; };
90  // sent ONLY in this session
91  quint64 sentBytes() { return m_uTotalSentBytes; };
92  quint64 ackedBytes() { return m_uAckedBytes; };
93  unsigned int bandwidthLimit() { return m_pOpt->uMaxBandwidth; };
94  void setBandwidthLimit(unsigned int uMaxBandwidth) { m_pOpt->uMaxBandwidth = uMaxBandwidth; };
95  void doneGetInfo();
96 
97 protected:
98  void updateStats();
99  virtual void run();
100 };
101 
103 {
104  bool bResume;
106  quint64 uTotalFileSize;
110  bool bNoAcks;
111  bool bIsTdcc;
112  unsigned int uMaxBandwidth;
114 
115 class DccRecvThread : public DccThread
116 {
117 public:
118  DccRecvThread(QObject * par, kvi_socket_t fd, KviDccRecvThreadOptions * opt);
119  ~DccRecvThread();
120 
121 protected:
123 
124  // stats: SHARED!
129 
130  // internal
131  unsigned long m_uStartTime;
132  KviMSecTimeInterval * m_pTimeInterval; // used for computing the instant bandwidth
135  QFile * m_pFile;
136 
137 public:
138  void initGetInfo();
139  uint averageSpeed() { return m_uAverageSpeed; };
140  uint instantSpeed() { return m_uInstantSpeed; };
141  quint64 filePosition() { return m_uFilePosition; };
142  // received ONLY in this session
143  quint64 receivedBytes() { return m_uTotalReceivedBytes; };
144  unsigned int bandwidthLimit() { return m_pOpt->uMaxBandwidth; };
145  void setBandwidthLimit(unsigned int uMaxBandwidth) { m_pOpt->uMaxBandwidth = uMaxBandwidth; };
146  void doneGetInfo();
147 
148 protected:
149  void postMessageEvent(const char * msg);
150  void updateStats();
151  bool sendAck(qint64 filePos, bool bUse64BitAck = false);
152  virtual void run();
153 };
154 
155 class DccFileTransferBandwidthDialog : public QDialog
156 {
157  Q_OBJECT
158 public:
159  DccFileTransferBandwidthDialog(QWidget * pParent, DccFileTransfer * t);
161 
162 protected:
164  QCheckBox * m_pEnableLimitCheck;
165  QSpinBox * m_pLimitBox;
166 
167 protected:
168  virtual void closeEvent(QCloseEvent * e);
169 protected slots:
170  void okClicked();
171  void cancelClicked();
172 };
173 
175 {
177  {
182  };
183  Q_OBJECT
184 public:
187 
188 private:
193 
197 
200 
201  QString m_szTransferLog; // html
202 
205  // cached stats
206  quint64 m_uTotalFileSize; // total file size to transfer
207 
208  unsigned int m_uMaxBandwidth;
210 
211  QTimer * m_pResumeTimer; // used to signal resume timeout
212 public:
213  bool resumeAccepted(const char * filename, const char * port, const char * szZeroPortTag);
214  bool doResume(const char * filename, const char * port, quint64 filePos);
215 
216  static void init();
217  static void done();
218  static unsigned int runningTransfersCount();
219  static DccFileTransfer * nonFailedTransferWithLocalFileName(const QString & szLocalFileName);
220  static unsigned int transferCount();
221  static bool handleResumeAccepted(const char * filename, const char * port, const char * szZeroPortTag);
222  static bool handleResumeRequest(const char * filename, const char * port, quint64 filePos);
223 
224  virtual bool event(QEvent * e);
225 
226  virtual KviWindow * dccMarshalOutputWindow();
227  virtual const char * dccMarshalOutputContextString();
228 
229  virtual void displayPaint(QPainter * p, int column, QRect rect);
230  virtual int displayHeight(int iLineSpacing);
231  virtual void fillContextPopup(QMenu * m);
232  virtual void fillStatusString(QString & szBuffer);
233  virtual bool active();
234  virtual QString tipText();
235  virtual QString localFileName();
236 
237  bool isFileUpload() { return m_pDescriptor->isFileUpload(); };
238 
239  unsigned int averageSpeed();
240  unsigned int instantSpeed();
241  unsigned int transferredBytes();
242 
243  int bandwidthLimit();
244  void setBandwidthLimit(int iVal);
245  virtual DccThread * getSlaveThread();
246 
247 protected:
248  void startConnection();
249  void listenOrConnect();
250  void addToTransferLog(const QString & s);
251  void outputAndLog(const QString & s);
252  void outputAndLog(int msgtype, const QString & s);
254 protected slots:
255  void connectionInProgress();
256  void sslError(const char * msg);
257  void startingSSLHandshake();
259  void connected();
261  void configureBandwidth();
262  void resumeTimedOut();
263 public slots:
264  void abort();
265  void retryDCC();
266  void retryTDCC();
267  void retryRevDCC();
268 };
269 
270 #endif //_SEND_H_
void doneGetInfo()
Definition: DccFileTransfer.cpp:1184
Definition: DccFileTransfer.h:115
int kvi_socket_t
Definition: kvi_sockettype.h:40
Definition: DccFileTransfer.h:181
void retryRevDCC()
Definition: DccFileTransfer.cpp:1477
static DccFileTransfer * nonFailedTransferWithLocalFileName(const QString &szLocalFileName)
Definition: DccFileTransfer.cpp:1940
quint64 uStartPosition
Definition: DccFileTransfer.h:57
unsigned long m_uStartTime
Definition: DccFileTransfer.h:80
quint64 ackedBytes()
Definition: DccFileTransfer.h:92
Definition: KviFileTransfer.h:78
virtual bool active()
Definition: DccFileTransfer.cpp:1512
GeneralStatus
Definition: DccFileTransfer.h:176
Definition: KviCString.h:105
Definition: DccFileTransfer.h:180
uint m_uAverageSpeed
Definition: DccFileTransfer.h:74
quint64 m_uInstantSentBytes
Definition: DccFileTransfer.h:82
static void done()
Definition: DccFileTransfer.cpp:1920
Definition: DccFileTransfer.h:54
void resumeTimedOut()
Definition: DccFileTransfer.cpp:1372
Class for horizontal box.
#define m
Definition: detector.cpp:77
void retryTDCC()
Definition: DccFileTransfer.cpp:1464
bool sendAck(qint64 filePos, bool bUse64BitAck=false)
Definition: DccFileTransfer.cpp:116
Class for vertical box.
A class to retrieve the time interval This works for time intervals a bit longer than 24 days...
Definition: KviTimeUtils.h:75
KviDccSendThreadOptions * m_pOpt
Definition: DccFileTransfer.h:83
unsigned long m_uInstantSpeedInterval
Definition: DccFileTransfer.h:81
int bandwidthLimit()
Definition: DccFileTransfer.cpp:1517
kvi_time_t m_tTransferStartTime
Definition: DccFileTransfer.h:203
uint instantSpeed()
Definition: DccFileTransfer.h:140
DccDescriptor * m_pDescriptor
Definition: DccFileTransfer.h:191
quint64 m_uFilePosition
Definition: DccFileTransfer.h:127
~DccSendThread()
Definition: DccFileTransfer.cpp:618
Definition: DccFileTransfer.h:66
static bool handleResumeAccepted(const char *filename, const char *port, const char *szZeroPortTag)
Definition: DccFileTransfer.cpp:1973
void configureBandwidth()
Definition: DccFileTransfer.cpp:1441
void updateStats()
Definition: DccFileTransfer.cpp:222
quint64 filePosition()
Definition: DccFileTransfer.h:89
GeneralStatus m_eGeneralStatus
Definition: DccFileTransfer.h:199
quint64 m_uTotalFileSize
Definition: DccFileTransfer.h:206
bool bResume
Definition: DccFileTransfer.h:104
quint64 m_uInstantSpeedInterval
Definition: DccFileTransfer.h:134
void retryDCC()
Definition: DccFileTransfer.cpp:1451
quint64 sentBytes()
Definition: DccFileTransfer.h:91
unsigned int averageSpeed()
Definition: DccFileTransfer.cpp:1572
uint m_uInstantSpeed
Definition: DccFileTransfer.h:126
int iPacketSize
Definition: DccFileTransfer.h:58
void sslError(const char *msg)
Definition: DccFileTransfer.cpp:2155
Definition: DccFileTransfer.h:155
struct _KviDccSendThreadOptions KviDccSendThreadOptions
virtual int displayHeight(int iLineSpacing)
Definition: DccFileTransfer.cpp:1883
virtual const char * dccMarshalOutputContextString()
Definition: DccFileTransfer.cpp:1387
#define kvi_time_t
Definition: KviTimeUtils.h:43
void abort()
Definition: DccFileTransfer.cpp:1397
int iIdleStepLengthInMSec
Definition: DccFileTransfer.h:59
#define e
Definition: detector.cpp:69
DccFileTransferBandwidthDialog(QWidget *pParent, DccFileTransfer *t)
Definition: DccFileTransfer.cpp:2456
Definition: DccMarshal.h:43
DccFileTransfer * m_pTransfer
Definition: DccFileTransfer.h:163
QFile * m_pFile
Definition: DccFileTransfer.h:135
DccFileTransfer(DccDescriptor *dcc)
Definition: DccFileTransfer.cpp:1189
virtual void fillContextPopup(QMenu *m)
Definition: DccFileTransfer.cpp:1429
Definition: DccMarshal.h:56
static bool handleResumeRequest(const char *filename, const char *port, quint64 filePos)
Definition: DccFileTransfer.cpp:1987
quint64 filePosition()
Definition: DccFileTransfer.h:141
void addToTransferLog(const QString &s)
Definition: DccFileTransfer.cpp:2017
Definition: DccDescriptor.h:33
Definition: DccThread.h:55
KviCString m_szTarget
Definition: DccFileTransfer.h:194
KviCString szFileName
Definition: DccFileTransfer.h:56
quint64 uTotalFileSize
Definition: DccFileTransfer.h:106
void startConnection()
Definition: DccFileTransfer.cpp:1284
struct _KviDccRecvThreadOptions KviDccRecvThreadOptions
Code
Contains all error codes.
Definition: KviError.h:47
bool bFastSend
Definition: DccFileTransfer.h:60
unsigned int uMaxBandwidth
Definition: DccFileTransfer.h:112
char s char s s
Definition: KviIrcNumericCodes.h:391
bool bIsTdcc
Definition: DccFileTransfer.h:111
Definition: DccFileTransfer.h:174
void listenOrConnect()
Definition: DccFileTransfer.cpp:1346
QSpinBox * m_pLimitBox
Definition: DccFileTransfer.h:165
void initGetInfo()
Definition: DccFileTransfer.cpp:1179
virtual void fillStatusString(QString &szBuffer)
Definition: DccFileTransfer.cpp:1490
void okClicked()
Definition: DccFileTransfer.cpp:2505
unsigned int transferredBytes()
Definition: DccFileTransfer.cpp:1620
bool doResume(const char *filename, const char *port, quint64 filePos)
Definition: DccFileTransfer.cpp:2357
static unsigned int runningTransfersCount()
Definition: DccFileTransfer.cpp:1960
uint averageSpeed()
Definition: DccFileTransfer.h:87
unsigned int m_uMaxBandwidth
Definition: DccFileTransfer.h:208
void doneGetInfo()
Definition: DccFileTransfer.cpp:599
virtual void closeEvent(QCloseEvent *e)
Definition: DccFileTransfer.cpp:2525
KviDccRecvThreadOptions * m_pOpt
Definition: DccFileTransfer.h:122
void setBandwidthLimit(int iVal)
Definition: DccFileTransfer.cpp:1545
quint64 m_uFilePosition
Definition: DccFileTransfer.h:76
Time management.
int iIdleStepLengthInMSec
Definition: DccFileTransfer.h:107
bool isFileUpload()
Definition: DccDescriptor.cpp:200
virtual bool event(QEvent *e)
Definition: DccFileTransfer.cpp:2162
DccRecvThread * m_pSlaveRecvThread
Definition: DccFileTransfer.h:190
DccRecvThread(QObject *par, kvi_socket_t fd, KviDccRecvThreadOptions *opt)
Definition: DccFileTransfer.cpp:91
DccMarshal * m_pMarshal
Definition: DccFileTransfer.h:192
QHashIterator< int, QFile * > t(getDict)
DccSendThread * m_pSlaveSendThread
Definition: DccFileTransfer.h:189
void updateStats()
Definition: DccFileTransfer.cpp:625
QCheckBox * m_pEnableLimitCheck
Definition: DccFileTransfer.h:164
kvi_time_t m_tTransferEndTime
Definition: DccFileTransfer.h:204
uint averageSpeed()
Definition: DccFileTransfer.h:139
void bandwidthDialogDestroyed()
Definition: DccFileTransfer.cpp:1271
KviWindow * eventWindow()
Definition: DccFileTransfer.cpp:1276
C++ Template based double linked pointer list class.
~DccFileTransfer()
Definition: DccFileTransfer.cpp:1242
Definition: DccFileTransfer.h:178
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
QString m_szTransferIdString
Definition: DccFileTransfer.h:196
KviMSecTimeInterval * m_pTimeInterval
Definition: DccFileTransfer.h:84
virtual void run()
Definition: DccFileTransfer.cpp:265
KviCString m_szDccType
Definition: DccFileTransfer.h:195
quint64 m_uInstantReceivedBytes
Definition: DccFileTransfer.h:133
void startingSSLHandshake()
Definition: DccFileTransfer.cpp:2147
unsigned int instantSpeed()
Definition: DccFileTransfer.cpp:1596
KviCString szFileName
Definition: DccFileTransfer.h:105
KviMSecTimeInterval * m_pTimeInterval
Definition: DccFileTransfer.h:132
void setBandwidthLimit(unsigned int uMaxBandwidth)
Definition: DccFileTransfer.h:145
unsigned int uMaxBandwidth
Definition: DccFileTransfer.h:63
virtual void displayPaint(QPainter *p, int column, QRect rect)
Definition: DccFileTransfer.cpp:1644
unsigned int bandwidthLimit()
Definition: DccFileTransfer.h:93
quint64 m_uTotalSentBytes
Definition: DccFileTransfer.h:78
void cancelClicked()
Definition: DccFileTransfer.cpp:2520
DccSendThread(QObject *par, kvi_socket_t fd, KviDccSendThreadOptions *opt)
Definition: DccFileTransfer.cpp:604
Contains the KviWindow class.
void outputAndLog(const QString &s)
Definition: DccFileTransfer.cpp:2001
bool bNoAcks
Definition: DccFileTransfer.h:110
Definition: DccFileTransfer.h:179
bool bSendZeroAck
Definition: DccFileTransfer.h:108
uint m_uAverageSpeed
Definition: DccFileTransfer.h:125
Definition: DccFileTransfer.h:102
uint instantSpeed()
Definition: DccFileTransfer.h:88
unsigned int bandwidthLimit()
Definition: DccFileTransfer.h:144
quint64 m_uTotalReceivedBytes
Definition: DccFileTransfer.h:128
char szBuffer[4096]
Definition: winamp.cpp:77
void connected()
Definition: DccFileTransfer.cpp:2257
~DccRecvThread()
Definition: DccFileTransfer.cpp:107
bool isFileUpload()
Definition: DccFileTransfer.h:237
QString m_szTransferLog
Definition: DccFileTransfer.h:201
virtual QString localFileName()
Definition: DccFileTransfer.cpp:1392
static unsigned int transferCount()
Definition: DccFileTransfer.cpp:1933
bool bNoAcks
Definition: DccFileTransfer.h:61
QTimer * m_pResumeTimer
Definition: DccFileTransfer.h:211
virtual KviWindow * dccMarshalOutputWindow()
Definition: DccFileTransfer.cpp:1382
DccFileTransferBandwidthDialog * m_pBandwidthDialog
Definition: DccFileTransfer.h:209
QString m_szStatusString
Definition: DccFileTransfer.h:198
void connectionInProgress()
Definition: DccFileTransfer.cpp:2026
void setBandwidthLimit(unsigned int uMaxBandwidth)
Definition: DccFileTransfer.h:94
#define p
Definition: detector.cpp:80
virtual DccThread * getSlaveThread()
Definition: DccFileTransfer.cpp:2444
unsigned long m_uStartTime
Definition: DccFileTransfer.h:131
void handleMarshalError(KviError::Code)
Definition: DccFileTransfer.cpp:2246
uint m_uInstantSpeed
Definition: DccFileTransfer.h:75
static void init()
Definition: DccFileTransfer.cpp:1906
quint64 m_uAckedBytes
Definition: DccFileTransfer.h:77
bool bIsTdcc
Definition: DccFileTransfer.h:62
void postMessageEvent(const char *msg)
Definition: DccFileTransfer.cpp:252
bool bSend64BitAck
Definition: DccFileTransfer.h:109
void initGetInfo()
Definition: DccFileTransfer.cpp:594
virtual void run()
Definition: DccFileTransfer.cpp:679
virtual QString tipText()
Definition: DccFileTransfer.cpp:1889
bool resumeAccepted(const char *filename, const char *port, const char *szZeroPortTag)
Definition: DccFileTransfer.cpp:2333
quint64 receivedBytes()
Definition: DccFileTransfer.h:143