summaryrefslogtreecommitdiffstats
path: root/src/ftpsession.h
blob: 243bf029dd6ece420b018602d0bff3b85d619d34 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
// C++ Interface: ftpsession
//
// Description: 
//
//
// Author: Magnus Kulke <sikor_sxe@radicalapproach.de>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef FTPSESSION_H
#define FTPSESSION_H

#include <kprocess.h>
#include <tqstring.h>
#include <tqdir.h>
#include <tqpixmap.h>
#include <tqobject.h>
#include <tqcolor.h>
#include <list>

#include "kbfileinfo.h"

using namespace std;

class FtpThread;
class EventHandler;
class TQMutex;
class TQTextEdit;
class TQToolButton;
class TQListView;
class KbSiteInfo;
class TQPopupMenu;
class KLineEdit;
class TQLabel;
class TQPoint;
class KbDirInfo;
class TQHeader;
class KbTransferItem;

typedef pair<TQString, bool> logentries;

/**
@author Magnus Kulke
*/
class FtpSession : public TQObject
{
TQ_OBJECT
public:
	enum filecheck
	{
		off = 0,
		skip,
		clear,
		resume
	};
public:
	FtpSession(TQObject *parent = 0, const char *name = 0);
	~FtpSession();
	void SetLogWindow(TQTextEdit* logwindow) { mp_logwindow = logwindow; };
	void SetRefreshButton(TQToolButton* refreshbutton) { mp_refreshbutton = refreshbutton; };
	void SetConnectButton(TQToolButton* connectbutton) { mp_connectbutton = connectbutton; };
	void SetTransferButton(TQToolButton* transferbutton) { mp_transferbutton = transferbutton; }
	void SetBrowser(TQListView* browser) { mp_browser = browser; };
	void SetStatusLine(TQLabel* statusline) { mp_statusline = statusline; };
	void SetEncryptionIcon(TQLabel* encryptionicon) { mp_encryptionicon = encryptionicon; };
	void SetBookmarksMenu(TQPopupMenu *bookmarksmenu) { mp_bookmarksmenu = bookmarksmenu; };
	void SetRclickMenu(TQPopupMenu *rclickmenu) { mp_rclickmenu = rclickmenu; };
	void SetSessionList(list<FtpSession*> *sessionlist) { mp_sessionlist = sessionlist; };
	void SetCurrentTransfer(KbTransferItem* currenttransfer) { mp_currenttransfer = currenttransfer; };
	bool Connected() { return m_connected; };
	void Disconnect();
	void Connect();
	bool Occupied() { return m_occupied; };
	void Occupy();
	void Free();
	TQString WorkingDir();
 	void Transfer(KbTransferItem *item);
	int CheckFile(KbTransferItem *item);
	void Abort();
	FtpThread* Ftp() { return mp_ftpthread; };
	KbSiteInfo* SiteInfo() { return mp_siteinfo; };
	void SetColors(TQColor local, TQColor success, TQColor failure, TQColor background);
	void SetFont(TQFont font);
	void SetOnFileExistsDefault(filecheck onfileexistsdefault) {m_onfileexistsdefault = onfileexistsdefault; };
	void EnableCmdLine(bool b);
	void FilterHiddenFiles(bool b);
	void SetCmdLine(KLineEdit* cmdline);
	void SetCwdLine(KLineEdit* cwdline);
private:
	FtpThread *mp_ftpthread;
	EventHandler *mp_eventhandler;
	KbSiteInfo *mp_siteinfo;
	TQTextEdit *mp_logwindow;
	TQToolButton *mp_connectbutton, *mp_refreshbutton, *mp_transferbutton;
	KLineEdit *mp_cwdline, *mp_cmdline;
	TQPopupMenu* mp_bookmarksmenu, *mp_rclickmenu;
	TQListView *mp_browser;
	TQLabel *mp_statusline, *mp_encryptionicon;
	TQString m_remoteworkingdir; 
	TQDir m_localworkingdir;
	TQColor m_colorsuccess, m_colorfailure, m_colorlocal;
	TQFont m_logwindowfont;
	int m_sortpref;
	bool m_connected, m_occupied, m_sortascending, m_startqueue;
	list<logentries> m_loglist;
	TQPixmap m_iconencrypted, m_iconunencrypted;
	TQHeader *mp_header;
	list<FtpSession*> *mp_sessionlist;
	KbTransferItem *mp_currenttransfer;
	filecheck m_onfileexistsdefault;
	bool m_encrypted;
	
public slots:
	void SLOT_Log(TQString log, bool out);
	void SLOT_Xfered(off64_t xfered, bool encrypted);
	void SLOT_ActionMenu(int i);
	void SLOT_ConnectMenu(int i);
	void SLOT_HeaderClicked(int section);
	void SLOT_LocalProcessExited(TDEProcess* proc) { delete proc; };
	void SLOT_ItemClicked(TQListViewItem*);
	void SLOT_ItemRClicked(TQListViewItem * item, const TQPoint & point, int col);
	void SLOT_Connect(bool success);
	void SLOT_Login(bool success);
	void SLOT_Pwd(bool success, TQString pwd);
	void SLOT_Misc(bool success);
	void SLOT_AuthTls(bool success);
	void SLOT_EncryptData(bool success);
	void SLOT_Dir(bool success, list<KbFileInfo*> dirlist, list<KbFileInfo*> filelist);
	void SLOT_ConnectButton();
	void SLOT_RefreshButton();
	void SLOT_TransferButton();
	void SLOT_CwdLine();
	void SLOT_CmdLine();
	void SLOT_Finish();
	void SLOT_ConnectionLost();
	void SLOT_Transfer(bool success);
	void SLOT_Scandir(bool success, KbDirInfo* dir);
	
private:
	void PrintLog(bool success);
	void QueueItems();
	void RefreshBrowser();
	void UpdateLocal(TQString cwd = "");
	//bool RmdirLocal(TQString dir);
	void GetFile(KbTransferItem *item, filecheck fc);
	void PutFile(KbTransferItem *item, filecheck fc);
	void FxpFile(KbTransferItem *item, filecheck fc);
	void ChangeDirectory(TQString path);
	bool CheckLocalDirectory(TQString path);
	bool MakeLocalDirectory(TQString path);
	bool CopyLocalFile(KbTransferItem* item);
	bool ScandirLocal(KbDirInfo *dir, TQString path);
	void SortItems();
	void MakeDirectory(TQString dir);
	void timerEvent(TQTimerEvent*);
signals:
	void gui_update();
	void gui_queueitems(KbDirInfo* dir, FtpSession* src, FtpSession* dst, bool startqueue);
	void gui_succeedtransfer(TQListViewItem* item);
	void gui_clearqueue(FtpSession* session);
};

#endif