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