Subversion Repositories Kolibri OS

Rev

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