summaryrefslogtreecommitdiff
path: root/plugins/FTPFileYM/job_generic.h
blob: 618d891a826038c6095f5a8eaa0b267274b4c8b8 (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
/*
FTP File YM plugin
Copyright (C) 2007-2010 Jan Holub

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 version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "common.h"
#include "dialog.h"
#include "serverlist.h"

class Event
{
private:
	HANDLE handle;

public:
	Event() { handle = CreateEvent (0, FALSE, FALSE, 0); }
	~Event() { CloseHandle (handle); }

	operator HANDLE () { return handle; }

	void release() { SetEvent(handle); }
	void wait() { WaitForSingleObject(handle, INFINITE); }
};

class GenericJob
{
private:
	int openFileDialog();
	int openFolderDialog();
	void getFilesFromOpenDialog();
	int getFilesFromFolder(TCHAR *stzFolder);
	void addFile(TCHAR *fileName);

public:
	enum EMode
	{
		FTP_RAWFILE = 8,
		FTP_ZIPFILE	= 16,
		FTP_ZIPFOLDER = 32
	};

	enum EStatus
	{
		STATUS_CREATED = 0,
		STATUS_WAITING,
		STATUS_CONNECTING,
		STATUS_UPLOADING,
		STATUS_PACKING,
		STATUS_PAUSED,
		STATUS_CANCELED,
		STATUS_COMPLETED
	};

	HANDLE hContact;
	int iFtpNum, fileID;
	ServerList::FTP *ftp;
	TCHAR stzFilePath[1024];
	TCHAR stzFileName[64];
	char szSafeFileName[64];
	EMode mode;
	EStatus status;

	UploadDialog::Tab *tab;
	vector<TCHAR *> files;
	TCHAR * operator[] (int i) const { return files[i];}

	GenericJob(HANDLE hContact, int iFtpNum, EMode mode);
	GenericJob(GenericJob *job);
	virtual ~GenericJob();

	int getFiles();	
	int getFiles(void **objects, int objCount, DWORD flags);
	void setStatus(EStatus status);

	bool isCompleted();
	bool isPaused();
	bool isWaitting();
	bool isConnecting();
	bool isCanceled();

	TCHAR *getStatusString();

	virtual void start() = 0;
	virtual void pause() = 0;
	virtual void resume() = 0;
	virtual void cancel() = 0;
	virtual void addToUploadDlg() = 0;	
	virtual void pauseHandler() = 0;
	
	virtual void refreshTab(bool bTabChanged);
	virtual void closeTab() = 0;
	virtual void closeAllTabs() = 0;
	virtual void createToolTip() = 0;
};