Subversion Repositories Kolibri OS

Rev

Rev 6278 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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