summaryrefslogtreecommitdiffstats
path: root/konversation/src/dcctransfersend.h
blob: 9df25ce7c9ba652f9ed71b2ab79c223ebf29c52b (plain)
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
/*
  send a file on DCC protocol
  begin:     Mit Aug 7 2002
  copyright: (C) 2002 by Dario Abatianni
  email:     eisfuchs@tigress.com
*/
// Copyright (C) 2004-2007 Shintaro Matsuoka <shin@shoegazed.org>
// Copyright (C) 2004,2005 John Tapsell <john@geola.co.uk>

/*
  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.
*/

#ifndef DCCTRANSFERSEND_H
#define DCCTRANSFERSEND_H

#include "dcctransfer.h"

#include <tqfile.h>


class TQTimer;

namespace KNetwork
{
    class TDEServerSocket;
    class KStreamSocket;
}

class DccTransferSend : public DccTransfer
{
    Q_OBJECT
  

        public:
        DccTransferSend(TQObject* parent);
        virtual ~DccTransferSend();

        // REQUIRED
        void setFileURL( const KURL& url );
        // OPTIONAL
        void setFileName( const TQString& fileName );
        // REQUIRED
        // FIXME: this setting should be an optional one or be removed: make DccTransferSend itself read the configuration
        void setOwnIp( const TQString& ownIp );
        // OPTIONAL
        void setFileSize( TDEIO::filesize_t fileSize );
        // OPTIONAL
        void setReverse( bool reverse );

        bool setResume( unsigned long position );

    public slots:
        virtual bool queue();
        virtual void start();
        virtual void abort();

        // invoked when the receiver accepts the offer (Reverse DCC)
        void connectToReceiver( const TQString& partnerHost, const TQString& partnerPort );

    protected slots:
        void acceptClient();
        // it must be invoked when m_sendSocket is ready
        void startSending();
        void writeData();
        void getAck();
        void slotGotSocketError( int errorCode );
        void slotConnectionTimeout();
        void slotConnectionFailed( int errorCode );
        void slotSendSocketClosed();
        void slotServerSocketClosed();

    protected:
        void cleanUp();
        void failed(const TQString& errorMessage = TQString() );

        void startConnectionTimer( int sec );
        void stopConnectionTimer();

        TQString getTQFileErrorString( int code );

        TQFile m_file;

        /*The filename of the temporary file that we downloaded.  So if send a file ftp://somewhere/file.txt
         * Then this will be downloaded to /tmp.
         */
        TQString m_tmpFile;

        KNetwork::TDEServerSocket* m_serverSocket;
        KNetwork::KStreamSocket* m_sendSocket;
        bool m_fastSend;

        TQTimer* m_connectionTimer;
};

#endif  // DCCTRANSFERSEND_H