Subversion Repositories Kolibri OS

Rev

Rev 6978 | 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;
6978 leency 42
    SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
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
 
6978 leency 53
    loop() switch(WaitEvent())
6374 guillem 54
    {
6978 leency 55
        case evMouse:
56
            if (!CheckActiveProcess(DL_Form.ID)) break;
57
            edit_box_mouse stdcall (#ed);
58
            break;
59
 
60
        case evButton:
61
            Key_Scan(GetButtonID());
62
            break;
63
 
64
        case evKey:
65
            GetKeys();
66
            edit_box_key stdcall(#ed);
67
            if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301);
68
            break;
69
 
70
        case evReDraw:
71
            DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
72
            GetProcessInfo(#DL_Form, SelfInfo);
73
            if (DL_Form.status_window>2) break;
74
            if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120);
75
            if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD);
76
            DL_Draw_Window();
77
            break;
78
 
79
        default:
80
            if (!downloader.MonitorProgress()) break;
81
            pb.max = downloader.data_full_size;
82
            if (pb.value != downloader.data_downloaded_size)
83
            {
84
                pb.value = downloader.data_downloaded_size;
85
                progressbar_draw stdcall(#pb);
86
                DrawDownloading();
87
            }
88
            if (downloader.state == STATE_COMPLETED)
89
            {
90
                if (!dir_exists(#save_to)) CreateDir(#save_to);
91
                strcpy(#filepath, #save_to);
92
                chrcat(#filepath, '/');
93
   				// Clean all slashes at the end
94
       			strcpy(#aux,  #downloader_edit);
95
       			while (aux[strlen(#aux)-1] == '/') {
96
                    aux[strlen(#aux)-1] = 0;
97
                }
98
                strcat(#filepath,  #aux+strrchr(#aux, '/'));
99
 
100
				for (i=0; i
6374 guillem 101
 
7227 leency 102
                if (CreateFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
6978 leency 103
                    sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
104
                else
105
                    sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
106
 
107
                notify(#notify_message);
108
                StopDownloading();
6374 guillem 109
                DL_Draw_Window();
110
                break;
6978 leency 111
            }
6374 guillem 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;
6964 leency 127
    int but_x = 0;
6969 leency 128
    int but_y = 58;
6374 guillem 129
    DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
130
    DeleteButton(305);
131
    DeleteButton(306);
132
    if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
133
    {
6969 leency 134
        but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING);
135
        if (filepath[0])
136
        {
137
            but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER);
138
            DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT);
139
        }
6374 guillem 140
    }
141
    if (downloader.state == STATE_IN_PROGRESS)
142
    {
6969 leency 143
        DrawCaptButton(DL_Form.width - 190, but_y, 167, 26, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING);
6374 guillem 144
        DrawDownloading();
145
    }
6678 leency 146
    WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:");
147
    ed.left = strlen("URL:")*8 + 10 + cleft;
6374 guillem 148
    ed.width = DL_Form.cwidth - ed.left - cleft - 3;
149
    ed.offset=0;
150
    DrawEditBox(#ed);
5519 leency 151
}
6374 guillem 152
 
6001 leency 153
void StartDownloading()
154
{
6374 guillem 155
    StopDownloading();
156
    if (strncmp(#downloader_edit,"http://",7)!=0) {
157
        notify("'File address should start from http://' -E");
158
        return;
159
    }
160
    if (!downloader.Start(#downloader_edit)) {
161
        notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E");
162
        StopDownloading();
163
        return;
164
    }
165
    ed.blur_border_color = 0xCACACA;
166
    ed.flags = 100000000000b;
167
    pb.value = 0;
168
    DL_Draw_Window();
6001 leency 169
}
6374 guillem 170
 
5519 leency 171
void DrawDownloading()
172
{
6374 guillem 173
    char bytes_received[70];
6969 leency 174
    sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.data_downloaded_size) );
175
    DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work);
176
    WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received);
6374 guillem 177
    progressbar_draw stdcall(#pb);
5493 leency 178
}
6374 guillem 179
 
5493 leency 180
void StopDownloading()
181
{
6374 guillem 182
    downloader.Stop();
183
    ed.blur_border_color = 0xFFFfff;
184
    ed.flags = 10b;
185
    DL_Draw_Window();
186
}