Rev 7281 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7281 | Rev 7282 | ||
---|---|---|---|
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_TEXT "âªàëâì ä ©«" |
6 | #define OPEN_FILE_TEXT "âªàëâì ä ©«" |
7 | #define FILE_SAVED_AS "'¥¥¤¦¥à § £à㧮ª\n ©« á®åà ¥ ª ª " |
7 | #define FILE_SAVED_AS "'¥¥¤¦¥à § £à㧮ª\n ©« á®åà ¥ ª ª " |
8 | #define KB_RECEIVED "¤¥â ᪠稢 ¨¥... %s ¯®«ã祮" |
8 | #define KB_RECEIVED "¤¥â ᪠稢 ¨¥... %s ¯®«ã祮" |
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_TEXT "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 "Downloading... %s received" |
16 | #define KB_RECEIVED "Downloading... %s 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 | edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,0,2,19,19}; |
23 | edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,0,2,19,19}; |
24 | progress_bar pb = {0, 20, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
24 | progress_bar pb = {0, 20, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
25 | //progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
25 | //progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
26 | //progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color; |
26 | //progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color; |
27 | 27 | ||
28 | 28 | ||
29 | bool downloader_opened; |
29 | bool downloader_opened; |
30 | char downloader_stak[4096]; |
30 | char downloader_stak[4096]; |
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | void Downloader() |
34 | void Downloader() |
35 | { |
35 | { |
36 | if (!dir_exists(#save_to)) CreateDir(#save_to); |
36 | if (!dir_exists(#save_to)) CreateDir(#save_to); |
37 | downloader_opened = true; |
37 | downloader_opened = true; |
38 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
38 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
39 | 39 | ||
40 | system.color.get(); |
40 | system.color.get(); |
41 | pb.frame_color = system.color.work_dark; |
41 | pb.frame_color = system.color.work_dark; |
42 | 42 | ||
43 | filepath[0] = NULL; |
43 | filepath[0] = NULL; |
44 | 44 | ||
45 | downloader.Stop(); |
45 | downloader.Stop(); |
46 | if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://"); |
46 | if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://"); |
47 | ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit); |
47 | ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit); |
48 | 48 | ||
49 | loop() switch(WaitEvent()) |
49 | loop() switch(WaitEvent()) |
50 | { |
50 | { |
51 | case evMouse: |
51 | case evMouse: |
52 | edit_box_mouse stdcall (#ed); |
52 | edit_box_mouse stdcall (#ed); |
53 | break; |
53 | break; |
54 | 54 | ||
55 | case evButton: |
55 | case evButton: |
56 | Key_Scan(GetButtonID()); |
56 | Key_Scan(GetButtonID()); |
57 | break; |
57 | break; |
58 | 58 | ||
59 | case evKey: |
59 | case evKey: |
60 | GetKeys(); |
60 | GetKeys(); |
61 | edit_box_key stdcall(#ed); |
61 | edit_box_key stdcall(#ed); |
62 | if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301); |
62 | if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301); |
63 | break; |
63 | break; |
64 | 64 | ||
65 | case evReDraw: |
65 | case evReDraw: |
66 | DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0); |
66 | DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0); |
67 | GetProcessInfo(#DL_Form, SelfInfo); |
67 | GetProcessInfo(#DL_Form, SelfInfo); |
68 | if (DL_Form.status_window>2) break; |
68 | if (DL_Form.status_window>2) break; |
69 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
69 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
70 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
70 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
71 | DL_Draw_Window(); |
71 | DL_Draw_Window(); |
72 | break; |
72 | break; |
73 | 73 | ||
74 | default: |
74 | default: |
75 | if (!downloader.MonitorProgress()) break; |
75 | if (!downloader.MonitorProgress()) break; |
76 | pb.max = downloader.data_full_size; |
76 | pb.max = downloader.httpd.content_length; |
77 | if (pb.value != downloader.data_downloaded_size) |
77 | if (pb.value != downloader.httpd.content_received) |
78 | { |
78 | { |
79 | pb.value = downloader.data_downloaded_size; |
79 | pb.value = downloader.httpd.content_received; |
80 | progressbar_draw stdcall(#pb); |
80 | progressbar_draw stdcall(#pb); |
81 | DrawDownloading(); |
81 | DrawDownloading(); |
82 | } |
82 | } |
83 | if (downloader.state == STATE_COMPLETED) |
83 | if (downloader.state == STATE_COMPLETED) |
84 | { |
84 | { |
85 | SaveDownloadedFile(); |
85 | SaveDownloadedFile(); |
86 | StopDownloading(); |
86 | StopDownloading(); |
87 | DL_Draw_Window(); |
87 | DL_Draw_Window(); |
88 | break; |
88 | break; |
89 | } |
89 | } |
90 | } |
90 | } |
91 | } |
91 | } |
92 | 92 | ||
93 | void Key_Scan(int id) |
93 | void Key_Scan(int id) |
94 | { |
94 | { |
95 | if (id==001) { downloader_opened=false; StopDownloading(); ExitProcess(); } |
95 | if (id==001) { downloader_opened=false; StopDownloading(); ExitProcess(); } |
96 | if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading(); |
96 | if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading(); |
97 | if (id==302) StopDownloading(); |
97 | if (id==302) StopDownloading(); |
98 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
98 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
99 | if (id==306) { |
99 | if (id==306) { |
100 | SetCurDir(#save_to); |
100 | SetCurDir(#save_to); |
101 | RunProgram("/sys/@open", #filepath); |
101 | RunProgram("/sys/@open", #filepath); |
102 | } |
102 | } |
103 | } |
103 | } |
104 | 104 | ||
105 | void DL_Draw_Window() |
105 | void DL_Draw_Window() |
106 | { |
106 | { |
107 | int cleft = 15; |
107 | int cleft = 15; |
108 | int but_x = 0; |
108 | int but_x = 0; |
109 | int but_y = 58; |
109 | int but_y = 58; |
110 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
110 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
111 | DeleteButton(301); |
111 | DeleteButton(301); |
112 | DeleteButton(302); |
112 | DeleteButton(302); |
113 | DeleteButton(305); |
113 | DeleteButton(305); |
114 | DeleteButton(306); |
114 | DeleteButton(306); |
115 | if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) |
115 | if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) |
116 | { |
116 | { |
117 | but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING); |
117 | but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING); |
118 | if (filepath[0]) |
118 | if (filepath[0]) |
119 | { |
119 | { |
120 | but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER); |
120 | but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER); |
121 | DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT); |
121 | DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT); |
122 | } |
122 | } |
123 | } |
123 | } |
124 | if (downloader.state == STATE_IN_PROGRESS) |
124 | if (downloader.state == STATE_IN_PROGRESS) |
125 | { |
125 | { |
126 | DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING); |
126 | DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING); |
127 | DrawDownloading(); |
127 | DrawDownloading(); |
128 | } |
128 | } |
129 | WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:"); |
129 | WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:"); |
130 | ed.width = DL_Form.cwidth - ed.left - cleft - 3; |
130 | ed.width = DL_Form.cwidth - ed.left - cleft - 3; |
131 | ed.offset=0; |
131 | ed.offset=0; |
132 | DrawEditBox(#ed); |
132 | DrawEditBox(#ed); |
133 | } |
133 | } |
134 | 134 | ||
135 | void StartDownloading() |
135 | void StartDownloading() |
136 | { |
136 | { |
137 | StopDownloading(); |
137 | StopDownloading(); |
138 | if (strncmp(#downloader_edit,"http://",7)!=0) { |
138 | if (strncmp(#downloader_edit,"http://",7)!=0) { |
139 | notify("'File address should start from http://' -E"); |
139 | notify("'File address should start from http://' -E"); |
140 | return; |
140 | return; |
141 | } |
141 | } |
142 | if (!downloader.Start(#downloader_edit)) { |
142 | if (!downloader.Start(#downloader_edit)) { |
143 | notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E"); |
143 | notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E"); |
144 | StopDownloading(); |
144 | StopDownloading(); |
145 | return; |
145 | return; |
146 | } |
146 | } |
147 | ed.blur_border_color = 0xCACACA; |
147 | ed.blur_border_color = 0xCACACA; |
148 | ed.flags = 100000000000b; |
148 | ed.flags = 100000000000b; |
149 | pb.value = 0; |
149 | pb.value = 0; |
150 | DL_Draw_Window(); |
150 | DL_Draw_Window(); |
151 | } |
151 | } |
152 | 152 | ||
153 | void DrawDownloading() |
153 | void DrawDownloading() |
154 | { |
154 | { |
155 | char bytes_received[70]; |
155 | char bytes_received[70]; |
156 | sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.data_downloaded_size) ); |
156 | sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) ); |
157 | DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work); |
157 | DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work); |
158 | WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received); |
158 | WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received); |
159 | progressbar_draw stdcall(#pb); |
159 | progressbar_draw stdcall(#pb); |
160 | } |
160 | } |
161 | 161 | ||
162 | void StopDownloading() |
162 | void StopDownloading() |
163 | { |
163 | { |
164 | downloader.Stop(); |
164 | downloader.Stop(); |
165 | ed.blur_border_color = 0xFFFfff; |
165 | ed.blur_border_color = 0xFFFfff; |
166 | ed.flags = 10b; |
166 | ed.flags = 10b; |
167 | DL_Draw_Window(); |
167 | DL_Draw_Window(); |
168 | } |
168 | } |
169 | 169 | ||
170 | void SaveDownloadedFile() |
170 | void SaveDownloadedFile() |
171 | { |
171 | { |
172 | int i; |
172 | int i; |
173 | char aux[2048]; |
173 | char aux[2048]; |
174 | char notify_message[4296]; |
174 | char notify_message[4296]; |
175 | 175 | ||
176 | // Clean all slashes at the end |
176 | // Clean all slashes at the end |
177 | strcpy(#aux, #downloader_edit); |
177 | strcpy(#aux, #downloader_edit); |
178 | while (aux[strlen(#aux)-1] == '/') { |
178 | while (aux[strlen(#aux)-1] == '/') { |
179 | aux[strlen(#aux)-1] = 0; |
179 | aux[strlen(#aux)-1] = 0; |
180 | } |
180 | } |
181 | sprintf(#filepath, "%s/%s", #save_to, #aux+strrchr(#aux, '/')); |
181 | sprintf(#filepath, "%s/%s", #save_to, #aux+strrchr(#aux, '/')); |
182 | 182 | ||
183 | for (i=0; i |
183 | for (i=0; i |
184 | 184 | ||
185 | if (CreateFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0) |
185 | if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0) |
186 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
186 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
187 | else |
187 | else |
188 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
188 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
189 | 189 | ||
190 | notify(#notify_message); |
190 | notify(#notify_message); |
191 | }=>280)>120)> |
191 | }=>280)>120)> |