Subversion Repositories Kolibri OS

Rev

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