Subversion Repositories Kolibri OS

Rev

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