summaryrefslogtreecommitdiffstats
path: root/konversation/src/dcctransfermanager.h
blob: 6d275296394fed49de961783b24958daa6acb764 (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
/*
  DccTransferManager controls DccTransfer instances.
  All DccTransferRecv/DccTransferSend instances are created and deleted by this class.
  Each DccTransfer instance is deleted immediately after its transfer done.
*/

/*
  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) 2007 Shintaro Matsuoka <shin@shoegazed.org>
*/

#ifndef DCCTRANSFERMANAGER_H
#define DCCTRANSFERMANAGER_H

#include "dcctransfer.h"

#include <tqobject.h>
#include <tqvaluelist.h>


class KURL;

class DccTransferRecv;
class DccTransferSend;

class DccTransferManager : public TQObject
{
    TQ_OBJECT
  

    public:
        DccTransferManager( TQObject* parent = 0 );
        ~DccTransferManager();

    signals:
        /*
         * The status of the item is DccTransfer::Configuring when this signal is emitted.
         */
        void newTransferAdded( DccTransfer* transfer );
        /*
         * The status of the item is DccTransfer::Queued when this signal is emitted.
         */
        void newTransferQueued( DccTransfer* transfer );

        void fileURLChanged( DccTransferRecv* transfer );

    public:
        DccTransferRecv* newDownload();
        DccTransferSend* newUpload();

        /**
         * @return a DccTransferRecv item if applicable one found, otherwise 0.
         */
        DccTransferRecv* resumeDownload(int connectionId, const TQString& partnerNick, const TQString& fileName, const TQString& ownPort, unsigned long position );

        /**
         * @return a DccTransferSend item if applicable one found, otherwise 0.
         */
        DccTransferSend* resumeUpload(int connectionId, const TQString& partnerNick, const TQString& fileName, const TQString& ownPort, unsigned long position );

        DccTransferSend* startReverseSending(int connectionId, const TQString& partnerNick, const TQString& fileName, const TQString& partnerHost, const TQString& partnerPort, unsigned long fileSize, const TQString& token );

        bool isLocalFileInWritingProcess( const KURL& localUrl ) const;

        int generateReverseTokenNumber();

        bool hasActiveTransfers();

    private:
        /*
         * initTransfer() does the common jobs for newDownload() and newUpload()
         */
        void initTransfer( DccTransfer* transfer );

    private slots:
        void slotTransferStatusChanged( DccTransfer* item, int newStatus, int oldStatus );
        void removeSendItem( DccTransfer* item );
        void removeRecvItem( DccTransfer* item );

        void slotSettingsChanged();

    private:
        TQValueList< DccTransferSend* > m_sendItems;
        TQValueList< DccTransferRecv* > m_recvItems;

        int m_nextReverseTokenNumber;
        TQString m_defaultIncomingFolder;  // store here to know if this settings is changed
};

#endif  // DCCTRANSFERMANAGER_H