Fix filetransfer cancel.
[kdenetwork.git] / kopete / protocols / oscar / liboscar / oftmetatransfer.h
bloba9c841daffdb2de52996f0399694468120381c7b
1 // oftmetatransfer.h
3 // Copyright (C) 2006
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without fdeven the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
20 #ifndef OFTMETATRANSFER_H
21 #define OFTMETATRANSFER_H
23 #include <QtCore/QFile>
24 #include <QtCore/QTimer>
25 #include <QtNetwork/QAbstractSocket>
27 #include "oscartypes.h"
29 class QTcpSocket;
31 class OftMetaTransfer : public QObject
33 Q_OBJECT
34 public:
35 /** Receive constructor */
36 OftMetaTransfer( const QByteArray& cookie, const QString& dir, QTcpSocket *socket );
38 /** Send constructor */
39 OftMetaTransfer( const QByteArray& cookie, const QStringList& files, QTcpSocket *socket );
41 ~OftMetaTransfer();
43 void start(); //start sending file
45 public slots:
46 void doCancel(); //one of the users is cancelling us
48 signals:
49 void fileIncoming( const QString& fileName, unsigned int fileSize );
50 void fileReceived( const QString& fileName, unsigned int bytesSent );
52 void fileOutgoing( const QString& fileName, unsigned int fileSize );
53 void fileSent( const QString& fileName, unsigned int fileSize );
55 void fileProcessed( unsigned int bytesSent, unsigned int fileSize );
57 void transferCompleted();
58 void transferError( int errorCode, const QString &error );
60 private slots:
61 //bool validFile();
62 void socketError( QAbstractSocket::SocketError );
63 void socketRead();
64 void write();
65 void timeout();
67 private:
68 void initOft();
69 void handelReceiveSetup( const Oscar::OFT &oft );
70 void handelReceiveResumeSetup( const Oscar::OFT &oft );
72 void handelSendSetup( const Oscar::OFT &oft );
73 void handelSendResumeSetup( const Oscar::OFT &oft );
74 void handleSendResumeRequest( const Oscar::OFT &oft );
75 void handelSendDone( const Oscar::OFT &oft );
77 void sendOft();
78 void prompt();
79 void ack();
80 void done();
81 void resume(); //receiver wants to resume partial file
82 void rAgree(); //sender agrees to resume
83 void rAck(); //resume ack
84 void saveData(); //save incoming data to disk
85 void readOft(); //handle incoming oft packet
86 Oscar::DWORD checksum( int max = -1 ); //return checksum of our file, up to max bytes
87 //XXX this does put an arbitrary limit on file size
89 Oscar::OFT m_oft;
91 QFile m_file;
93 QString m_dir; //directory where we save files
94 QStringList m_files; //list of files that we want to send
96 QTcpSocket *m_socket; //where we actually send file data
97 QTimer m_timer; //if we're idle too long, then give up
98 enum State { SetupReceive, SetupSend, Receiving, Sending, Done };
99 State m_state;
102 #endif