Subversion Repositories Kolibri OS

Rev

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