summaryrefslogtreecommitdiffstats
path: root/src/ftpsession.h
blob: 37abcd8476f59a3b9f4ccfcec4fdb9230b8899ea (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 <qstring.h>
#include <qdir.h>
#include <qpixmap.h>
#include <qobject.h>
#include <qcolor.h>
#include <list>

#include "kbfileinfo.h"

using namespace std;

class FtpThread;
class EventHandler;
class QMutex;
class QTextEdit;
class QToolButton;
class QListView;
class KbSiteInfo;
class QPopupMenu;
class KLineEdit;
class QLabel;
class QPoint;
class KbDirInfo;
class QHeader;
class KbTransferItem;

typedef pair<QString, bool> logentries;

/**
@author Magnus Kulke
*/
class FtpSession : public QObject
{
Q_OBJECT
public:
	enum filecheck
	{
		off = 0,
		skip,
		clear,
		resume
	};
public:
	FtpSession(QObject *parent = 0, const char *name = 0);
	~FtpSession();
	void SetLogWindow(QTextEdit* logwindow) { mp_logwindow = logwindow; };
	void SetRefreshButton(QToolButton* refreshbutton) { mp_refreshbutton = refreshbutton; };
	void SetConnectButton(QToolButton* connectbutton) { mp_connectbutton = connectbutton; };
	void SetTransferButton(QToolButton* transferbutton) { mp_transferbutton = transferbutton; }
	void SetBrowser(QListView* browser) { mp_browser = browser; };
	void SetStatusLine(QLabel* statusline) { mp_statusline = statusline; };
	void SetEncryptionIcon(QLabel* encryptionicon) { mp_encryptionicon = encryptionicon; };
	void SetBookmarksMenu(QPopupMenu *bookmarksmenu) { mp_bookmarksmenu = bookmarksmenu; };
	void SetRclickMenu(QPopupMenu *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();
	QString WorkingDir();
 	void Transfer(KbTransferItem *item);
	int CheckFile(KbTransferItem *item);
	void Abort();
	FtpThread* Ftp() { return mp_ftpthread; };
	KbSiteInfo* SiteInfo() { return mp_siteinfo; };
	void SetColors(QColor local, QColor success, QColor failure, QColor background);
	void SetFont(QFont 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;
	QTextEdit *mp_logwindow;
	QToolButton *mp_connectbutton, *mp_refreshbutton, *mp_transferbutton;
	KLineEdit *mp_cwdline, *mp_cmdline;
	QPopupMenu* mp_bookmarksmenu, *mp_rclickmenu;
	QListView *mp_browser;
	QLabel *mp_statusline, *mp_encryptionicon;
	QString m_remoteworkingdir; 
	QDir m_localworkingdir;
	QColor m_colorsuccess, m_colorfailure, m_colorlocal;
	QFont m_logwindowfont;
	int m_sortpref;
	bool m_connected, m_occupied, m_sortascending, m_startqueue;
	list<logentries> m_loglist;
	QPixmap m_iconencrypted, m_iconunencrypted;
	QHeader *mp_header;
	list<FtpSession*> *mp_sessionlist;
	KbTransferItem *mp_currenttransfer;
	filecheck m_onfileexistsdefault;
	bool m_encrypted;
	
public slots:
	void SLOT_Log(QString 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(KProcess* proc) { delete proc; };
	void SLOT_ItemClicked(QListViewItem*);
	void SLOT_ItemRClicked(QListViewItem * item, const QPoint & point, int col);
	void SLOT_Connect(bool success);
	void SLOT_Login(bool success);
	void SLOT_Pwd(bool success, QString 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(QString cwd = "");
	//bool RmdirLocal(QString dir);
	void GetFile(KbTransferItem *item, filecheck fc);
	void PutFile(KbTransferItem *item, filecheck fc);
	void FxpFile(KbTransferItem *item, filecheck fc);
	void ChangeDirectory(QString path);
	bool CheckLocalDirectory(QString path);
	bool MakeLocalDirectory(QString path);
	bool CopyLocalFile(KbTransferItem* item);
	bool ScandirLocal(KbDirInfo *dir, QString path);
	void SortItems();
	void MakeDirectory(QString dir);
	void timerEvent(QTimerEvent*);
signals:
	void gui_update();
	void gui_queueitems(KbDirInfo* dir, FtpSession* src, FtpSession* dst, bool startqueue);
	void gui_succeedtransfer(QListViewItem* item);
	void gui_clearqueue(FtpSession* session);
};

#endif