Subversion Repositories Kolibri OS

Rev

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