Subversion Repositories Kolibri OS

Rev

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