Subversion Repositories Kolibri OS

Rev

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