Subversion Repositories Kolibri OS

Rev

Rev 7755 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //Leency & SoUrcerer, LGPL
  2. //Hidnplayer
  3.  
  4. TWebBrowser WB1;
  5.  
  6. #define LIST_INFO_H 59
  7. int status_bar_h = 15;
  8.  
  9. scroll_bar scroll1 = { 17,200,210, LIST_INFO_H-3,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  10.  
  11. char *listbuffer;
  12. char *listpointer;
  13.  
  14. char *mailstart;
  15. char *mailend;
  16. int mailsize;
  17.  
  18. int cur_charset;
  19.  
  20.  
  21. enum {
  22.         GET_MAIL = 20,
  23.         SEND_MAIL,
  24.         DELETE_LETTER,
  25.         SAVE_LETTER,
  26.         STOP_LOADING,
  27.         EXIT_MAIL,
  28.         CHANGE_CHARSET,
  29.         CLOSE_CHANGE_CHARSET
  30. };
  31.  
  32. void MailBoxNetworkProcess() {
  33.         int load_persent;
  34.         if (aim) switch(aim)
  35.         {
  36.                 case SEND_NSTAT:
  37.                                 SetMailBoxStatus(NULL, "Counting mail, awaiting answer...");                   
  38.                                 request_len = GetRequest("STAT", NULL);
  39.                                 Send(socketnum, #request, request_len, 0);
  40.                                 if (EAX == 0xffffffff) { debugln("Error sending STAT. Retry..."w); break;}
  41.                                 aim = GET_ANSWER_NSTAT;
  42.                                 break;
  43.  
  44.                 case GET_ANSWER_NSTAT:
  45.                                 ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  46.                                 if ((ticks == 0xffffff) || (ticks < 2)) break;
  47.                                                                        
  48.                                 if (immbuffer[ticks-2]=='\n')
  49.                                 {
  50.                                         debugln(#immbuffer);
  51.                                         if (strstr(#immbuffer,"+OK"))
  52.                                         {
  53.                                                 strcpyb(#immbuffer, #param, "+OK ", " ");
  54.                                                 mail_list.count = atoi(#param);
  55.                                                 free(listbuffer);
  56.                                                 listbuffer = mem_Alloc(30*mail_list.count); //24* original
  57.                                                 listpointer = listbuffer;      
  58.                                                 aim = SEND_NLIST;
  59.                                                 debugln("Receiving mail list...");
  60.                                         }
  61.                                         else
  62.                                         {
  63.                                                 StopConnect("Sorry, can't recieve your mail");
  64.                                         }
  65.                                 }
  66.                                 break;
  67.  
  68.                 case SEND_NLIST:
  69.                                 WriteText(5, Form.cheight-11, 0x80, system.color.work_text, "Send LIST, awaiting answer...");
  70.                                 request_len = GetRequest("LIST", NULL);
  71.                                 Send(socketnum, #request, request_len, 0);
  72.                                 if (EAX == 0xffffffff) {debugln("Error while sending LIST. Retry..."); break;}
  73.                                 else aim = GET_ANSWER_NLIST;
  74.                                 break;
  75.  
  76.                 case GET_ANSWER_NLIST:
  77.                                 ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT);
  78.                                 if (ticks == 0xffffffff) break;
  79.                                 listpointer = listpointer + ticks;     
  80.                                
  81.                                 if (listpointer - listbuffer < 5) break;
  82.                                 if (strncmp(listpointer-5,"\n.\n",5)==0)  // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a   
  83.                                 {
  84.                                         aim = SEND_RETR;
  85.                                         debugln("goto SEND_RETR");
  86.                                         DrawMailBox();
  87.                                        
  88.                                         *listpointer='\0';
  89.                                         atr.CreateArray();
  90.                                         atr.SetSizes();
  91.                                 }
  92.                                 break;
  93.  
  94.                 case SEND_RETR:
  95.                                 from = to = date = subj = cur_charset = NULL;
  96.                                 WB1.list.ClearList();
  97.                                 DrawMailBox();
  98.                                 request_len = GetRequest("RETR", itoa(mail_list.cur_y+1));
  99.                                 if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
  100.                                 {
  101.                                         StopConnect("Error while trying to get letter from server");
  102.                                         break;
  103.                                 }
  104.                                 mailsize = atr.GetSize(mail_list.cur_y+1) + 1024;
  105.                                 free(mailstart);
  106.                                 mailstart = malloc(mailsize);
  107.                                 mailend = mailstart;
  108.                                 if (!mailstart)
  109.                                 {
  110.                                         debugln("alloc error!");
  111.                                         aim=NULL;
  112.                                         break;
  113.                                 }
  114.                                 debugval("mailsize", mailsize);
  115.                                 aim = GET_ANSWER_RETR;
  116.                                 debugln("goto GET_ANSWER_RETR");
  117.                                 break;
  118.                        
  119.                 case GET_ANSWER_RETR:
  120.                                 debugval("mailsize", mailsize);
  121.                                 debugval("mailstart", mailstart);
  122.                                 debugval("mailend", mailend);
  123.                                 ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
  124.                                 if (ticks == 0xffffffff) break;
  125.                                 mailend = mailend + ticks;
  126.                                 if (mailsize + mailstart - mailend - 2 < 0)
  127.                                 {
  128.                                         debugln("Resizing buffer");
  129.                                         mailsize += 4096;
  130.                                         mailstart = realloc(mailstart, mailsize);
  131.                                         if (!mailstart) { StopConnect("Realloc error!"); break;}
  132.                                 }
  133.                                 /*
  134.                                 if (mailsize>9000)
  135.                                 {
  136.                                         load_persent = mailend - mailstart * 100 ;
  137.                                         load_persent /= mailsize - 1024;
  138.                                         if (load_persent != cur_st_percent) SetMailBoxStatus( load_persent , NULL);
  139.                                 }
  140.                                 */
  141.                                 //ParseMail();
  142.         }
  143. }
  144.  
  145.  
  146. void MailBoxLoop() {
  147.         int id;
  148.         int panels_drag=0, clicked_list=0;
  149.         dword line_col, text_col;
  150.  
  151.         mail_list.h = Form.cheight/4;
  152.         mail_list.ClearList();
  153.         WB1.list.no_selection = true;
  154.         SetMailBoxStatus( NULL , NULL);
  155.         cur_charset = 0;
  156.         aim = SEND_NSTAT;
  157.        
  158.         goto _MB_DRAW;
  159.  
  160.         loop() 
  161.         {
  162.                 WaitEventTimeout(2);
  163.                 switch(EAX & 0xFF)
  164.                 {
  165.                         case evMouse:
  166.                                 mouse.get();
  167.                                
  168.                                 if (!mouse.lkm) panels_drag=0;
  169.                                 if (mouse.lkm) && (mouse.y>mail_list.y+mail_list.h-1) && (mouse.y<mail_list.y+mail_list.h+6)
  170.                                 && (!scroll1.delta2) && (!scroll_wv.delta2) panels_drag = 1;
  171.                                 if (panels_drag)
  172.                                 {
  173.                                         if (mouse.y<mail_list.y+60) || (mouse.y>Form.cheight-60-status_bar_h-LIST_INFO_H) break;
  174.                                         mail_list.h = mouse.y - mail_list.y-2;
  175.                                         DrawMailBox();
  176.                                         break;
  177.                                 }
  178.  
  179.                                 PageLinks.HoverAndProceed(mouse.x, mouse.y);
  180.  
  181.                                 if (!mail_list.count) break;
  182.                                 if (!panels_drag) { scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll_wv); }
  183.                                
  184.                                 if (mail_list.first <> scroll1.position)
  185.                                 {
  186.                                         mail_list.first = scroll1.position;
  187.                                         DrawMailList();
  188.                                         break;
  189.                                 };
  190.                                 if (WB1.list.first <> scroll_wv.position)
  191.                                 {
  192.                                         WB1.list.first = scroll_wv.position;
  193.                                         DrawLetter();
  194.                                         break;
  195.                                 };
  196.                                
  197.                                 if (mail_list.y+mail_list.h + 10 > mouse.y)
  198.                                 {
  199.                                         if (mail_list.MouseScroll(mouse.vert)) DrawMailList();
  200.                                 }
  201.                                 else
  202.                                 {
  203.                                         if (WB1.list.MouseScroll(mouse.vert)) DrawLetter();
  204.                                 }
  205.                                 if (mouse.lkm) && (mail_list.MouseOver(mouse.x, mouse.y)) && (!clicked_list) clicked_list=1;
  206.                                 if (!mouse.lkm) && (clicked_list) if (mail_list.ProcessMouse(mouse.x, mouse.y))
  207.                                 {
  208.                                         clicked_list = 0;
  209.                                         if (aim) break;
  210.                                         DrawMailList();
  211.                                         aim = SEND_RETR;
  212.                                 }
  213.  
  214.                                 break;                         
  215.                         case evButton:
  216.                                 id = GetButtonID();
  217.                                 if (id==1) SaveAndExit();
  218.                                 if (id==GET_MAIL) aim = SEND_NSTAT;
  219.                                 if (id==SAVE_LETTER)
  220.                                 {
  221.                                         if (!mailstart) break;
  222.                                         CreateFile(strlen(mailstart), mailstart, "mail.txt");
  223.                                         pause(10);
  224.                                         RunProgram("/sys/tinypad", "mail.txt");
  225.                                 }
  226.                                 if (id==STOP_LOADING)
  227.                                 {
  228.                                         StopLoading();
  229.                                         DrawStatusBar();
  230.                                         DrawMailList();
  231.                                 }
  232.                                 if (id==EXIT_MAIL)
  233.                                 {
  234.                                         StopLoading();
  235.                                         Close(socketnum);
  236.                                         LoginBoxLoop();
  237.                                 }
  238.                                 if (id==CHANGE_CHARSET)
  239.                                 {
  240.                                         DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME);
  241.                                         DrawRectangle(Form.cwidth-100, Form.cheight-status_bar_h- 70, 70, 82, system.color.work_graph);
  242.                                         DrawRectangle3D(Form.cwidth-99, Form.cheight-status_bar_h- 69, 68, 80, 0xFFFfff, system.color.work);
  243.                                         for (id=0; id<5; id++)
  244.                                         {
  245.                                                 if (cur_charset==id+1) { line_col=system.color.work_button; text_col=system.color.work_button_text; }
  246.                                                 else { line_col=system.color.work; text_col=system.color.work_text; }
  247.                                                 DrawBar(Form.cwidth-98, id*16+Form.cheight-status_bar_h- 68, 67, 16, line_col);
  248.                                                 DrawCaptButton(Form.cwidth-100, id*16+Form.cheight-status_bar_h- 68, 70,16, 10+id+BT_HIDE,
  249.                                                 0, text_col, charsets[id+1]);
  250.                                         }
  251.                                 }
  252.                                 if (id==CLOSE_CHANGE_CHARSET) goto _MB_DRAW;
  253.  
  254.                                 break;                         
  255.                         case evKey:
  256.                                 GetKeys();
  257.  
  258.                                 if (!aim) && (mail_list.ProcessKey(key_scancode))
  259.                                 {
  260.                                         DrawMailList();
  261.                                         aim = SEND_RETR;
  262.                                 }
  263.  
  264.                                 break;
  265.                         case evReDraw: _MB_DRAW:
  266.                                 if !(DefineWindow(MAILBOX_HEADER)) break;
  267.                                 scroll1.bckg_col = scroll_wv.bckg_col = 0xBBBbbb;
  268.                                 scroll1.frnt_col = scroll_wv.frnt_col = system.color.work;
  269.                                 scroll1.line_col = scroll_wv.line_col = system.color.work_graph;
  270.                                 DrawToolbar();
  271.                                 DrawMailBox();
  272.  
  273.                                 break;
  274.                         default:
  275.                                 MailBoxNetworkProcess();
  276.                 }
  277.         }
  278. }
  279.  
  280.  
  281. void DrawMailBox()
  282. {
  283.         DrawMailList();
  284.         DrawLetterInfo();
  285.         InitTWB();
  286.         DrawLetter();
  287.         DrawStatusBar();
  288. }
  289.  
  290.  
  291. void DrawToolbar() {
  292.         #define BUT_Y 7
  293.         #define BUT_H 22
  294.         #define BUT_W 74
  295.         int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
  296.         mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 18);
  297.  
  298.         DrawBar(0,0, Form.cwidth,toolbar_w-3, system.color.work);
  299.         DrawCaptButton(10                    , BUT_Y, BUT_W, BUT_H, GET_MAIL,    system.color.work_button, system.color.work_button_text,"Get mail");
  300.         DrawCaptButton(BUT_W+ 20, BUT_Y, BUT_W+10, BUT_H, SAVE_LETTER, system.color.work_button, system.color.work_button_text,"Save letter");
  301.         DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL,   system.color.work_button, system.color.work_button_text,"< Exit");
  302.  
  303.         DrawBar(0, mail_list.y-3, mail_list.w,1, system.color.work_graph);
  304.         DrawBar(0, mail_list.y-2, mail_list.w,1, 0xdfdfdf);
  305.         DrawBar(0, mail_list.y-1, mail_list.w,1, 0xf0f0f0);
  306. }
  307.  
  308. void DrawMailList() {
  309.         int i, on_y, on_x, direction;
  310.         dword sel_col;
  311.         mail_list.visible = mail_list.h / mail_list.item_h;
  312.  
  313.         for (i=30; i<150; i++) DeleteButton(i);
  314.         for (i=0; (i<mail_list.visible) && (i+mail_list.first<mail_list.count); i++)
  315.         {
  316.                 on_y = i*mail_list.item_h + mail_list.y;
  317.                 if (mail_list.cur_y==mail_list.first+i) sel_col=0xEEEeee; else sel_col=0xFFFfff;
  318.                 DrawBar(0, on_y, mail_list.w, mail_list.item_h-1, sel_col);
  319.                 direction = atr.GetDirection(i+mail_list.first+1);
  320.                 on_x = strlen(itoa(i+mail_list.first+1))*6;
  321.                 letter_icons_pal[0]=sel_col;
  322.                 PutPaletteImage(sizeof(letter_icons)/3*direction + #letter_icons, 18,12, on_x+18,
  323.                         mail_list.item_h-12/2+ on_y, 8, #letter_icons_pal);
  324.                 WriteText(on_x + 42, on_y+5, 0x80, 0, atr.GetSubject(i+mail_list.first+1));
  325.                 DrawBar(0, on_y + mail_list.item_h-1, mail_list.w, 1, 0xCCCccc);
  326.                 WriteText(10, on_y+5, 0x80, 0, itoa(i+mail_list.first+1));
  327.                 WriteText(mail_list.w - 40, on_y+5, 0x80, 0, ConvertSize(atr.GetSize(i+mail_list.first+1)));
  328.         }
  329.         DrawBar(0, i*mail_list.item_h + mail_list.y, mail_list.w, -i*mail_list.item_h+mail_list.h, 0xFFFfff);
  330.         DrawScroller1();
  331. }
  332.  
  333. void DrawLetterInfo() {
  334.         int lt_y = mail_list.y+mail_list.h;
  335.         DrawBar(0, lt_y, mail_list.w, 1, system.color.work_graph);
  336.         DrawBar(0, lt_y+1, Form.cwidth, 1, LBUMP);
  337.         DrawBar(0, lt_y+2, Form.cwidth, LIST_INFO_H-4, system.color.work);
  338.         WriteText(mail_list.w-30/2, lt_y, 0x80, 0x888888, "= = =");
  339.         WriteText(mail_list.w-30/2, lt_y+1, 0x80, 0xEeeeee, "= = =");
  340.         DrawBar(0, lt_y+LIST_INFO_H-2, Form.cwidth, 1, system.color.work_graph); //bottom
  341.         DrawBar(0, lt_y+LIST_INFO_H-1, Form.cwidth, 1, 0xdfdfdf);
  342.         DrawBar(0, lt_y+LIST_INFO_H  , Form.cwidth, 1, 0xf0f0f0);
  343.         WriteTextB(10, lt_y+8 , 0x80, system.color.work_text, "From:");
  344.         WriteText (45, lt_y+8 , 0x80, system.color.work_text, #from);
  345.         WriteTextB(10, lt_y+20, 0x80, system.color.work_text, "To:");
  346.         WriteText (45, lt_y+20, 0x80, system.color.work_text, #to);
  347.         WriteTextB(10, lt_y+32, 0x80, system.color.work_text, "Date:");
  348.         WriteText (45, lt_y+32, 0x80, system.color.work_text, #date);
  349.         WriteTextB(10, lt_y+44, 0x80, system.color.work_text, "Subj:");
  350.         WriteText (45, lt_y+44, 0x80, system.color.work_text, #subj);
  351. }
  352.  
  353.  
  354. void InitTWB() {
  355.         WB1.list.SetSizes(0, mail_list.y+mail_list.h+LIST_INFO_H+1, Form.cwidth - scroll_wv.size_x - 1,
  356.                 Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 12);
  357.         WB1.list.column_max = WB1.list.w - 30 / 6;
  358.         WB1.list.visible = WB1.list.h / WB1.list.item_h;
  359.         WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h);
  360.         WB1.list.first = WB1.list.count = 0;
  361. }
  362.  
  363.  
  364. void DrawLetter() {
  365.         WB1.ParseHtml(mdata, strlen(mdata));
  366.         WB1.DrawPage();
  367.         DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff);
  368. }
  369.  
  370. void DrawScroller1() {
  371.         scroll1.max_area = mail_list.count;
  372.         scroll1.cur_area = mail_list.visible;
  373.         scroll1.position = mail_list.first;
  374.         scroll1.all_redraw=1;
  375.         scroll1.start_x = mail_list.x + mail_list.w;
  376.         scroll1.start_y = mail_list.y - 3;
  377.         scroll1.size_y = mail_list.h + 4;
  378.         scrollbar_v_draw(#scroll1);
  379. }
  380.  
  381.  
  382.  
  383. void DrawStatusBar() {
  384.         int st_y = Form.cheight -status_bar_h;
  385.         DrawBar(0, st_y, Form.cwidth, status_bar_h, system.color.work);
  386.         if (aim) {
  387.                 SetMailBoxStatus(cur_st_percent, cur_st_text);
  388.                 DrawCaptButton(240, st_y+1, 36, status_bar_h-3, STOP_LOADING, system.color.work_button, system.color.work_button_text,"Stop");
  389.         }
  390.         DrawCaptButton(Form.cwidth - 100, st_y+1, 70, status_bar_h-2, CHANGE_CHARSET+BT_HIDE,
  391.                 system.color.work, system.color.work_text,cur_charset*10+#charsets);
  392. }
  393.  
  394.  
  395.  
  396. void SetMailBoxStatus(dword percent1, text1) {
  397.         DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, system.color.work, 0xC3C3C3, 0x54B1D6, system.color.work_text, percent1);
  398.         WriteText(3, Form.cheight -status_bar_h + 1, 0x80, system.color.work_text, text1);
  399.         cur_st_percent = percent1;
  400.         cur_st_text = text1;
  401. }
  402.  
  403.  
  404. void StopLoading() {
  405.         aim = NULL;
  406.         mailstart = free(mailstart);
  407.         to = from = date = subj = cur_charset = NULL;
  408. }
  409.  
  410. int GetLetterSize_(int number) {
  411.    char search_num[24];
  412.    char mailsize1[24];
  413.    strcpy(#search_num, "\x0a");       // 0x0d, 0x0a
  414.    itoa_(#search_num+1, number);
  415.    chrcat(#search_num, ' ');
  416.    strcpyb(listbuffer, #mailsize1, #search_num, "\x0d");
  417.    return atoi(#mailsize1);
  418. }
  419.  
  420.  
  421. void EventClickLink() {
  422.         RunProgram("/sys/network/WebView", PageLinks.GetURL(PageLinks.active));
  423. }