Subversion Repositories Kolibri OS

Rev

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

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