Subversion Repositories Kolibri OS

Rev

Rev 5683 | Blame | Last modification | View Log | Download | RSS feed

  1. #ifdef LANG_RUS
  2.         #define DL_WINDOW_HEADER "Œ¥­¥¤¦¥à § £à㧮ª"
  3.         #define START_DOWNLOADING " ç âì § ª çªã"
  4.         #define STOP_DOWNLOADING "Žáâ ­®¢¨âì ᪠稢 ­¨¥"
  5.         #define SHOW_IN_FOLDER "®ª § âì ¢ ¯ ¯ª¥"
  6.         #define OPEN_FILE "Žâªàëâì ä ©«"
  7.         #define FILE_SAVED_AS "'Œ¥­¥¤¦¥à § £à㧮ª\n” ©« á®åà ­¥­ ª ª "
  8.         #define KB_RECEIVED " ¯®«ã祭®"
  9. #else
  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 "Open file"
  15.         #define FILE_SAVED_AS "'Download manager\nFile saved as "
  16.         #define KB_RECEIVED " received"
  17. #endif
  18.  
  19. proc_info DL_Form;
  20. char filepath[4096];
  21. int     mouse_twbi;
  22. edit_box dl_edit = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19};
  23. progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
  24.  
  25. char save_to[4096] = "/tmp0/1/Downloads/";
  26. byte cleft = 15;
  27.  
  28. byte downloader_opened;
  29.  
  30.  
  31. void Downloader()
  32. {
  33.         int key;
  34.         char notify_message[4296];
  35.         downloader_opened = 1;
  36.         SetEventMask(0x27);
  37.        
  38.         if (DL_URL[0]) StartDownloading(); else strcpy(#DL_URL, "http://");
  39.         dl_edit.size = dl_edit.pos = dl_edit.shift = dl_edit.shift_old = strlen(#DL_URL);
  40.  
  41.         Downloading_SetDefaults();
  42.  
  43.         loop()
  44.         {
  45.                 WaitEventTimeout(40);
  46.                 switch(EAX & 0xFF)
  47.                 {
  48.                         CASE evMouse:
  49.                                 if (!CheckActiveProcess(DL_Form.ID)) break;
  50.                                 edit_box_mouse stdcall (#dl_edit);
  51.                                 break;
  52.  
  53.                         case evButton:
  54.                                 DL_Scan(GetButtonID());
  55.                                 break;
  56.  
  57.                         case evKey:
  58.                                 key = GetKey();
  59.                                 EAX=key<<8;
  60.                                 edit_box_key stdcall(#dl_edit);
  61.                                 if (key==13) DL_Scan(301);
  62.                                 break;
  63.  
  64.                         case evReDraw:
  65.                                 system.color.get();
  66.                                 DefineAndDrawWindow(215, 100, 420, 120, 0x74, system.color.work, DL_WINDOW_HEADER, 0);
  67.                                 GetProcessInfo(#DL_Form, SelfInfo);
  68.                                 if (DL_Form.status_window>2) break;
  69.                                 if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120);
  70.                                 if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD);
  71.                                 DL_Draw_Window();
  72.                                 break;
  73.                                
  74.                         default:
  75.                                 if (DL_Form.width==0) || (DL_http_transfer <= 0) break;
  76.                                 http_receive stdcall (DL_http_transfer);
  77.                                 $push EAX
  78.                                 ESI = DL_http_transfer;
  79.                                 DL_progress_bar.max = ESI.http_msg.content_length;
  80.                                 if (DL_progress_bar.value != ESI.http_msg.content_received)
  81.                                 {
  82.                                         DL_progress_bar.value = ESI.http_msg.content_received; 
  83.                                         progressbar_draw stdcall(#DL_progress_bar);
  84.                                 }
  85.                                 $pop EAX
  86.                                 if (EAX == 0) {
  87.                                         Downloading_Completed();
  88.                                         strcpy(#filepath, #save_to);
  89.                                         strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/'));
  90.                                         if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0)
  91.                                         {
  92.                                                 sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
  93.                                         }
  94.                                         else
  95.                                         {
  96.                                                 sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
  97.                                         }
  98.                                         notify(#notify_message);
  99.                                         dl_edit.blur_border_color = 0xFFFfff;
  100.                                         dl_edit.flags = 10b;
  101.                                         DL_Draw_Window();
  102.                                         break;
  103.                                 }
  104.                                 ESI = DL_http_transfer;
  105.                                 downloaded_size = ESI.http_msg.content_received;
  106.                                 full_size = ESI.http_msg.content_length;
  107.                                 DrawDownloading();
  108.                 }
  109.         }
  110. }
  111.  
  112.  
  113.  
  114. void DL_Draw_Window()
  115. {      
  116.         DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
  117.         DeleteButton(305);
  118.         DeleteButton(306);
  119.         if (download_state == STATE_NOT_STARTED) ||  (download_state == STATE_COMPLETED)
  120.         {
  121.                 DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING);   
  122.         }
  123.         if (download_state == STATE_IN_PROGRESS)
  124.         {
  125.                 DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING);
  126.                 DrawDownloading();
  127.         }
  128.         if (download_state == STATE_COMPLETED)
  129.         {
  130.                 DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER);
  131.                 DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE);       
  132.         }
  133.         WriteText(cleft, dl_edit.top + 4, 0x80, system.color.work_text, "URL:");
  134.         dl_edit.left = strlen("URL:")*6 + 10 + cleft;
  135.         dl_edit.width = DL_Form.cwidth - dl_edit.left - cleft - 3;
  136.         dl_edit.offset=0;
  137.         edit_box_draw stdcall(#dl_edit);
  138.         DrawRectangle(dl_edit.left-1, dl_edit.top-1, dl_edit.width+2, 16, dl_edit.blur_border_color);
  139.         DrawRectangle(dl_edit.left-2, dl_edit.top-2, dl_edit.width+4, 18, border_color);
  140. }
  141.  
  142.  
  143. void DrawDownloading()
  144. {
  145.         dword tmp;
  146.         char bytes_received[70];
  147.  
  148.         tmp = ConvertSizeToKb(downloaded_size);
  149.         strcpy(#bytes_received, tmp);
  150.         strcat(#bytes_received, KB_RECEIVED);
  151.         DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, system.color.work);
  152.         WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, system.color.work_text, #bytes_received);
  153.         progressbar_draw stdcall(#DL_progress_bar);
  154. }
  155.  
  156.  
  157.  
  158.  
  159. void DL_Scan(int id)
  160. {
  161.         if (id==001) {
  162.                 downloader_opened=0;
  163.                 StopDownloading();
  164.                 ExitProcess();
  165.         }
  166.         if (id==301) && (DL_http_transfer <= 0) StartDownloading();
  167.         if (id==302) StopDownloading();
  168.         if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
  169.         if (id==306) RunProgram("@open", #filepath);
  170. }
  171.  
  172.  
  173. void StopDownloading()
  174. {
  175.         Downloading_Stop();
  176.         dl_edit.blur_border_color = 0xFFFfff;
  177.         dl_edit.flags = 10b;
  178.         DL_Draw_Window();
  179. }
  180.  
  181. void StartDownloading()
  182. {
  183.         StopDownloading();
  184.         if (strncmp(#DL_URL,"http:",5)==0)
  185.         {
  186.                 Downloading_Start();
  187.                 dl_edit.blur_border_color = 0xCACACA;
  188.                 dl_edit.flags = 100000000000b;
  189.                 DL_progress_bar.value = 0;
  190.                 DL_Draw_Window();
  191.                 if (DL_http_transfer == 0)
  192.                 {
  193.                         StopDownloading();
  194.                         DL_bufsize = 0;
  195.                         DL_bufpointer = mem_Free(DL_bufpointer);
  196.                         return;
  197.                 }
  198.         }
  199.         else
  200.         {
  201.                 notify("File adress should starts from http://");
  202.         }
  203. }
  204.