Subversion Repositories Kolibri OS

Rev

Rev 6217 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5493 leency 1
#ifdef LANG_RUS
5519 leency 2
	#define DL_WINDOW_HEADER "Менеджер загрузок"
3
	#define START_DOWNLOADING "Начать закачку"
6217 leency 4
	#define STOP_DOWNLOADING "Остановить"
5519 leency 5
	#define SHOW_IN_FOLDER "Показать в папке"
6
	#define OPEN_FILE "Открыть файл"
7
	#define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как "
8
	#define KB_RECEIVED " получено"
5493 leency 9
#else
10
	#define DL_WINDOW_HEADER "Download Manager"
11
	#define START_DOWNLOADING "Start downloading"
12
	#define STOP_DOWNLOADING "Stop downloading"
5519 leency 13
	#define SHOW_IN_FOLDER "Show in folder"
14
	#define OPEN_FILE "Open file"
5493 leency 15
	#define FILE_SAVED_AS "'Download manager\nFile saved as "
5519 leency 16
	#define KB_RECEIVED " received"
5493 leency 17
#endif
6001 leency 18
char save_to[4096] = "/tmp0/1/Downloads/";
5493 leency 19
 
20
proc_info DL_Form;
6001 leency 21
char downloader_edit[10000];
5493 leency 22
char filepath[4096];
23
int	mouse_twbi;
6001 leency 24
edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(downloader_edit),#downloader_edit,#mouse_twbi,2,19,19};
25
progress_bar pb = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
5493 leency 26
 
5519 leency 27
byte downloader_opened;
5493 leency 28
 
5519 leency 29
 
5493 leency 30
void Downloader()
31
{
5685 leency 32
	int key;
5493 leency 33
	char notify_message[4296];
5685 leency 34
	downloader_opened = 1;
35
	SetEventMask(0x27);
5493 leency 36
 
6001 leency 37
	downloader.Stop();
38
	if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://");
39
	ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit);
5493 leency 40
 
41
	loop()
42
	{
43
		WaitEventTimeout(40);
44
		switch(EAX & 0xFF)
45
		{
46
			CASE evMouse:
47
				if (!CheckActiveProcess(DL_Form.ID)) break;
6001 leency 48
				edit_box_mouse stdcall (#ed);
5493 leency 49
				break;
50
 
51
			case evButton:
6001 leency 52
				Key_Scan(GetButtonID());
5493 leency 53
				break;
54
 
55
			case evKey:
6001 leency 56
				GetKeys();
57
				EAX = key_ascii << 8;
58
				edit_box_key stdcall(#ed);
59
				if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
5493 leency 60
				break;
61
 
62
			case evReDraw:
5674 pavelyakov 63
				system.color.get();
64
				DefineAndDrawWindow(215, 100, 420, 120, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
5493 leency 65
				GetProcessInfo(#DL_Form, SelfInfo);
66
				if (DL_Form.status_window>2) break;
67
				if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120);
68
				if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD);
69
				DL_Draw_Window();
70
				break;
71
 
72
			default:
6001 leency 73
				if (!downloader.MonitorProgress()) break;
74
				pb.max = downloader.data_full_size;
75
				if (pb.value != downloader.data_downloaded_size)
5519 leency 76
				{
6001 leency 77
					pb.value = downloader.data_downloaded_size;
78
					progressbar_draw stdcall(#pb);
79
					DrawDownloading();
5519 leency 80
				}
6001 leency 81
				if (downloader.state == STATE_COMPLETED)
82
				{
5493 leency 83
					strcpy(#filepath, #save_to);
6005 leency 84
					strcat(#filepath, #save_to+strrchr(#save_to, '/'));
6001 leency 85
					if (WriteFile(downloader.bufsize, downloader.bufpointer, #filepath)==0)
5685 leency 86
						sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
5493 leency 87
					else
5685 leency 88
						sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
5493 leency 89
					notify(#notify_message);
6001 leency 90
					StopDownloading();
5493 leency 91
					DL_Draw_Window();
5519 leency 92
					break;
6001 leency 93
				}
5493 leency 94
		}
95
	}
96
}
97
 
6001 leency 98
void Key_Scan(int id)
99
{
100
	if (id==001) { downloader_opened=0; StopDownloading(); ExitProcess(); }
101
	if (id==301) && (downloader.http_transfer <= 0) StartDownloading();
102
	if (id==302) StopDownloading();
103
	if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
104
	if (id==306) RunProgram("@open", #filepath);
105
}
5493 leency 106
 
107
void DL_Draw_Window()
108
{
6001 leency 109
	byte cleft = 15;
5674 pavelyakov 110
	DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
5519 leency 111
	DeleteButton(305);
112
	DeleteButton(306);
6001 leency 113
	if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
5493 leency 114
	{
6217 leency 115
		DrawCaptButton(cleft, 50, 140, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING);
5493 leency 116
	}
6001 leency 117
	if (downloader.state == STATE_IN_PROGRESS)
5493 leency 118
	{
5674 pavelyakov 119
		DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING);
5519 leency 120
		DrawDownloading();
5493 leency 121
	}
6001 leency 122
	if (downloader.state == STATE_COMPLETED)
5493 leency 123
	{
5674 pavelyakov 124
		DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER);
125
		DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE);
5493 leency 126
	}
6001 leency 127
	WriteText(cleft, ed.top + 4, 0x80, system.color.work_text, "URL:");
128
	ed.left = strlen("URL:")*6 + 10 + cleft;
129
	ed.width = DL_Form.cwidth - ed.left - cleft - 3;
130
	ed.offset=0;
6278 leency 131
	//edit_box_draw stdcall(#ed);
132
	DrawEditBox(#ed);
133
	//DrawRectangle(ed.left-1, ed.top-1, ed.width+2, 16, ed.blur_border_color);
134
	//DrawRectangle(ed.left-2, ed.top-2, ed.width+4, 18, border_color);
5519 leency 135
}
5493 leency 136
 
6001 leency 137
void StartDownloading()
138
{
139
	StopDownloading();
140
	if (strncmp(#downloader_edit,"http://",7)!=0) {
141
		notify("'File address should start from http://' -E");
142
		return;
143
	}
144
	if (!downloader.Start(#downloader_edit)) {
145
		notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E");
146
		StopDownloading();
147
		return;
148
	}
149
	ed.blur_border_color = 0xCACACA;
150
	ed.flags = 100000000000b;
151
	pb.value = 0;
152
	DL_Draw_Window();
153
}
5519 leency 154
 
155
void DrawDownloading()
156
{
157
	char bytes_received[70];
6001 leency 158
	dword tmp = ConvertSizeToKb(downloader.data_downloaded_size);
159
	sprintf(#bytes_received, "%s%s", tmp, KB_RECEIVED);
160
	DrawBar(pb.left, pb.top + 17, DL_Form.cwidth - pb.left, 9, system.color.work);
161
	WriteText(pb.left, pb.top + 17, 0x80, system.color.work_text, #bytes_received);
162
	progressbar_draw stdcall(#pb);
5493 leency 163
}
164
 
165
void StopDownloading()
166
{
6001 leency 167
	downloader.Stop();
168
	ed.blur_border_color = 0xFFFfff;
169
	ed.flags = 10b;
5493 leency 170
	DL_Draw_Window();
171
}
172