1 #ifndef _KVI_FILETRANSFER_H_
2 #define _KVI_FILETRANSFER_H_
3 //=============================================================================
4 //
5 //   File : KviFileTransfer.h
6 //   Creation date : Mon Apr 21 22:14:31 2003 GMT by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2003-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 "kvi_settings.h"
28 #include "KviTalTableWidget.h"
29 
30 #include <QObject>
31 #include <vector>
32 
33 class KviFileTransfer;
34 class KviWindow;
35 class QMenu;
36 class QPainter;
37 
38 // This is for the external extension
39 #define KVI_FILE_TRANSFER_WINDOW_EXTENSION_NAME "File transfer extension"
40 
41 class KVIRC_API KviFileTransferManager : public QObject
42 {
43 	friend class KviApplication;
44 	friend class KviFileTransfer;
45 	friend class FileTransferWindow; // FIXME: This is in a module!
46 	Q_OBJECT
47 public:
48 	KviFileTransferManager();
49 	~KviFileTransferManager();
50 
51 protected:
52 	std::vector<KviFileTransfer *> m_pTransferList;
53 	KviWindow * m_pTransferWindow = nullptr;
54 
55 protected:
56 	static void cleanup();
57 	void registerTransfer(KviFileTransfer * t);
58 	void unregisterTransfer(KviFileTransfer * t);
setTransferWindow(KviWindow * wnd)59 	void setTransferWindow(KviWindow * wnd) { m_pTransferWindow = wnd; }
60 public:
61 	// might be zero!
transferWindow()62 	KviWindow * transferWindow() const { return m_pTransferWindow; }
63 	static KviFileTransferManager * instance();
transferList()64 	std::vector<KviFileTransfer *> transferList() const { return m_pTransferList; }
65 	void invokeTransferWindow(bool bCreateMinimized = false, bool bNoRaise = false);
66 	void killAllTransfers();
67 	void killTerminatedTransfers();
68 signals:
69 	void transferRegistered(KviFileTransfer * t);
70 	void transferUnregistering(KviFileTransfer * t);
71 };
72 
73 #define COLUMN_TRANSFERTYPE 0
74 #define COLUMN_FILEINFO 1
75 #define COLUMN_PROGRESS 2
76 
77 class KVIRC_API KviFileTransfer : public QObject
78 {
79 	Q_OBJECT
80 public:
81 	KviFileTransfer();
82 	~KviFileTransfer();
83 
84 protected:
85 	int m_iId;
86 	KviTalTableWidgetItemEx * m_pDisplayItem = nullptr;
87 
88 public:
89 	// This is called by KviFileTransferItem at any time
setDisplayItem(KviTalTableWidgetItemEx * i)90 	void setDisplayItem(KviTalTableWidgetItemEx * i) { m_pDisplayItem = i; }
id()91 	int id() const { return m_iId; }
92 	// this is just a convenience function : it's equivalent to !active()
93 	bool terminated();
94 	// This may be used to invoke the transfer window
95 	void invokeTransferWindow(bool bCreateMinimized = false, bool bNoRaise = false);
manager()96 	KviFileTransferManager * manager() const { return KviFileTransferManager::instance(); }
97 	// this returns the pointer to the transfer window : may be 0!
transferWindow()98 	KviWindow * transferWindow() const { return manager()->transferWindow(); }
99 	// this returns transferWindow() if not 0, otherwise the application's active window
100 	KviWindow * outputWindow();
101 
102 	// this may be called by the transfers to update the display when the state changes
103 	void displayUpdate();
104 
105 	// this must be implemented by the transfer
106 	virtual bool active() = 0;
107 	virtual void displayPaint(QPainter * p, int column, QRect rect) = 0;
108 	virtual QString tipText();
109 	virtual QString localFileName();
110 	virtual QString retryCommand();
111 	virtual int displayHeight(int iLineSpacing);
112 	virtual void fillContextPopup(QMenu * m) = 0;
113 	virtual void die();
114 };
115 
116 #endif //! _KVI_FILETRANSFER_H_
117