Reduce file transfer CPU usage from 100% to 2% during send :D
[kdenetwork.git] / kopete / protocols / oscar / liboscar / oftmetatransfer.h
blob2180979e915acbea7d59647923cfa5770e23671f
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 <QtNetwork/QAbstractSocket>
26 #include "oscartypes.h"
28 class QTcpSocket;
30 class OftMetaTransfer : public QObject
32 Q_OBJECT
33 public:
34 /** Receive constructor */
35 OftMetaTransfer( const QByteArray& cookie, const QString& dir, QTcpSocket *socket );
37 /** Send constructor */
38 OftMetaTransfer( const QByteArray& cookie, const QStringList& files, QTcpSocket *socket );
40 ~OftMetaTransfer();
42 void start(); //start sending file
44 public slots:
45 void doCancel(); //one of the users is cancelling us
47 signals:
48 void fileIncoming( const QString& fileName, unsigned int fileSize );
49 void fileReceived( const QString& fileName, unsigned int bytesSent );
51 void fileOutgoing( const QString& fileName, unsigned int fileSize );
52 void fileSent( const QString& fileName, unsigned int fileSize );
54 void fileProcessed( unsigned int bytesSent, unsigned int fileSize );
56 void transferCompleted();
57 void transferError( int errorCode, const QString &error );
59 private slots:
60 //bool validFile();
61 void socketError( QAbstractSocket::SocketError );
62 void socketRead();
63 void write();
64 void emitTransferCompleted();
66 private:
67 void initOft();
68 void handelReceiveSetup( const Oscar::OFT &oft );
69 void handelReceiveResumeSetup( const Oscar::OFT &oft );
71 void handelSendSetup( const Oscar::OFT &oft );
72 void handelSendResumeSetup( const Oscar::OFT &oft );
73 void handleSendResumeRequest( const Oscar::OFT &oft );
74 void handelSendDone( const Oscar::OFT &oft );
76 void sendOft();
77 void prompt();
78 void ack();
79 void done();
80 void resume(); //receiver wants to resume partial file
81 void rAgree(); //sender agrees to resume
82 void rAck(); //resume ack
83 void saveData(); //save incoming data to disk
84 void readOft(); //handle incoming oft packet
85 Oscar::DWORD checksum( int max = -1 ); //return checksum of our file, up to max bytes
86 //XXX this does put an arbitrary limit on file size
88 Oscar::OFT m_oft;
90 QFile m_file;
92 QString m_dir; //directory where we save files
93 QStringList m_files; //list of files that we want to send
95 QTcpSocket *m_socket; //where we actually send file data
96 enum State { SetupReceive, SetupSend, Receiving, Sending, Done };
97 State m_state;
100 #endif