Subversion Repositories Kolibri OS

Rev

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

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