Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

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