Subversion Repositories Kolibri OS

Rev

Rev 7227 | 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:
5674 pavelyakov 65
				WriteText(5, Form.cheight-11, 0x80, system.color.work_text, "Send LIST, awaiting answer...");
4169 leency 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();
5825 leency 94
				request_len = GetRequest("RETR", itoa(mail_list.cur_y+1));
4169 leency 95
				if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
96
				{
97
					StopConnect("Error while trying to get letter from server");
98
					break;
99
				}
5825 leency 100
				mailsize = atr.GetSize(mail_list.cur_y+1) + 1024;
4169 leency 101
				free(mailstart);
4186 leency 102
				mailstart = malloc(mailsize);
4870 leency 103
				mailend = mailstart;
4186 leency 104
				if (!mailstart)
4169 leency 105
				{
4645 leency 106
					debugln("alloc error!");
4169 leency 107
					aim=NULL;
108
					break;
109
				}
4870 leency 110
				debug("mailsize: "); debugi(mailsize);
4169 leency 111
				aim = GET_ANSWER_RETR;
4645 leency 112
				debugln("goto GET_ANSWER_RETR");
4186 leency 113
				break;
4169 leency 114
 
115
		case GET_ANSWER_RETR:
4870 leency 116
				debug("mailsize: "); debugi(mailsize);
117
				debug("mailstart: "); debugi(mailstart);
118
				debug("mailend: "); debugi(mailend);
4169 leency 119
				ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
120
				if (ticks == 0xffffffff) break;
4870 leency 121
				mailend = mailend + ticks;
4169 leency 122
				if (mailsize + mailstart - mailend - 2 < 0)
123
				{
4645 leency 124
					debugln("Resizing buffer");
4169 leency 125
					mailsize += 4096;
126
					mailstart = realloc(mailstart, mailsize);
127
					if (!mailstart) { StopConnect("Realloc error!"); break;}
128
				}
4870 leency 129
				/*
4180 leency 130
				if (mailsize>9000)
4169 leency 131
				{
132
					load_persent = mailend - mailstart * 100 ;
133
					load_persent /= mailsize - 1024;
134
					if (load_persent != cur_st_percent) SetMailBoxStatus( load_persent , NULL);
135
				}
4870 leency 136
				*/
137
				//ParseMail();
4169 leency 138
	}
139
}
140
 
141
 
4509 leency 142
void MailBoxLoop() {
5714 punk_joker 143
	int id;
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();
5779 leency 149
	WB1.list.no_selection = true;
3368 leency 150
	SetMailBoxStatus( NULL , NULL);
151
	cur_charset = 0;
4166 leency 152
	aim = SEND_NSTAT;
3368 leency 153
 
154
	goto _MB_DRAW;
155
 
156
	loop()
157
	{
158
		WaitEventTimeout(2);
159
		switch(EAX & 0xFF)
160
		{
161
			case evMouse:
5640 pavelyakov 162
				mouse.get();
3368 leency 163
 
5640 pavelyakov 164
				if (!mouse.lkm) panels_drag=0;
165
				if (mouse.lkm) && (mouse.y>mail_list.y+mail_list.h-1) && (mouse.y
4509 leency 166
				&& (!scroll1.delta2) && (!scroll_wv.delta2) panels_drag = 1;
3368 leency 167
				if (panels_drag)
168
				{
5709 leency 169
					if (mouse.yForm.cheight-60-status_bar_h-LIST_INFO_H) break;
5640 pavelyakov 170
					mail_list.h = mouse.y - mail_list.y-2;
3368 leency 171
					DrawMailBox();
172
					break;
173
				}
174
 
6796 leency 175
				PageLinks.HoverAndProceed(mouse.x, mouse.y);
4509 leency 176
 
3368 leency 177
				if (!mail_list.count) break;
4509 leency 178
				if (!panels_drag) { scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll_wv); }
3368 leency 179
 
180
				if (mail_list.first <> scroll1.position)
181
				{
182
					mail_list.first = scroll1.position;
183
					DrawMailList();
184
					break;
185
				};
4509 leency 186
				if (WB1.list.first <> scroll_wv.position)
3368 leency 187
				{
4509 leency 188
					WB1.list.first = scroll_wv.position;
3368 leency 189
					DrawLetter();
190
					break;
191
				};
192
 
5640 pavelyakov 193
				if (mail_list.y+mail_list.h + 10 > mouse.y)
3368 leency 194
				{
5640 pavelyakov 195
					if (mail_list.MouseScroll(mouse.vert)) DrawMailList();
3368 leency 196
				}
197
				else
198
				{
5640 pavelyakov 199
					if (WB1.list.MouseScroll(mouse.vert)) DrawLetter();
3368 leency 200
				}
5640 pavelyakov 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))
4186 leency 203
				{
204
					clicked_list = 0;
205
					if (aim) break;
206
					DrawMailList();
207
					aim = SEND_RETR;
208
				}
3368 leency 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
				{
4166 leency 217
					if (!mailstart) break;
7227 leency 218
					CreateFile(strlen(mailstart), mailstart, "mail.txt");
3368 leency 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();
4139 hidnplayr 231
					Close(socketnum);
3368 leency 232
					LoginBoxLoop();
233
				}
234
				if (id==CHANGE_CHARSET)
235
				{
236
					DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME);
5674 pavelyakov 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);
3368 leency 239
					for (id=0; id<5; id++)
240
					{
5674 pavelyakov 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; }
3368 leency 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:
5714 punk_joker 252
				GetKeys();
3368 leency 253
 
5714 punk_joker 254
				if (!aim) && (mail_list.ProcessKey(key_scancode))
4152 leency 255
				{
3368 leency 256
					DrawMailList();
257
					aim = SEND_RETR;
258
				}
259
 
260
				break;
261
			case evReDraw: _MB_DRAW:
262
				if !(DefineWindow(MAILBOX_HEADER)) break;
4509 leency 263
				scroll1.bckg_col = scroll_wv.bckg_col = 0xBBBbbb;
5674 pavelyakov 264
				scroll1.frnt_col = scroll_wv.frnt_col = system.color.work;
265
				scroll1.line_col = scroll_wv.line_col = system.color.work_graph;
3368 leency 266
				DrawToolbar();
267
				DrawMailBox();
268
 
269
				break;
270
			default:
4169 leency 271
				MailBoxNetworkProcess();
3368 leency 272
		}
273
	}
274
}
275
 
276
 
277
void DrawMailBox()
278
{
279
	DrawMailList();
280
	DrawLetterInfo();
4509 leency 281
	InitTWB();
3368 leency 282
	DrawLetter();
283
	DrawStatusBar();
284
}
285
 
286
 
4509 leency 287
void DrawToolbar() {
3368 leency 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;
5709 leency 292
	mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 18);
3368 leency 293
 
5674 pavelyakov 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");
3368 leency 298
 
5674 pavelyakov 299
	DrawBar(0, mail_list.y-3, mail_list.w,1, system.color.work_graph);
3368 leency 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
 
4509 leency 304
void DrawMailList() {
3413 leency 305
	int i, on_y, on_x, direction;
4152 leency 306
	dword sel_col;
5825 leency 307
	mail_list.visible = mail_list.h / mail_list.item_h;
3368 leency 308
 
309
	for (i=30; i<150; i++) DeleteButton(i);
310
	for (i=0; (i
311
	{
5825 leency 312
		on_y = i*mail_list.item_h + mail_list.y;
313
		if (mail_list.cur_y==mail_list.first+i) sel_col=0xEEEeee; else sel_col=0xFFFfff;
314
		DrawBar(0, on_y, mail_list.w, mail_list.item_h-1, sel_col);
3413 leency 315
		direction = atr.GetDirection(i+mail_list.first+1);
316
		on_x = strlen(itoa(i+mail_list.first+1))*6;
4152 leency 317
		letter_icons_pal[0]=sel_col;
318
		PutPaletteImage(sizeof(letter_icons)/3*direction + #letter_icons, 18,12, on_x+18,
5825 leency 319
			mail_list.item_h-12/2+ on_y, 8, #letter_icons_pal);
3413 leency 320
		WriteText(on_x + 42, on_y+5, 0x80, 0, atr.GetSubject(i+mail_list.first+1));
5825 leency 321
		DrawBar(0, on_y + mail_list.item_h-1, mail_list.w, 1, 0xCCCccc);
3368 leency 322
		WriteText(10, on_y+5, 0x80, 0, itoa(i+mail_list.first+1));
4870 leency 323
		WriteText(mail_list.w - 40, on_y+5, 0x80, 0, ConvertSize(atr.GetSize(i+mail_list.first+1)));
3368 leency 324
	}
5825 leency 325
	DrawBar(0, i*mail_list.item_h + mail_list.y, mail_list.w, -i*mail_list.item_h+mail_list.h, 0xFFFfff);
3368 leency 326
	DrawScroller1();
327
}
328
 
4509 leency 329
void DrawLetterInfo() {
3368 leency 330
	int lt_y = mail_list.y+mail_list.h;
5674 pavelyakov 331
	DrawBar(0, lt_y, mail_list.w, 1, system.color.work_graph);
3368 leency 332
	DrawBar(0, lt_y+1, Form.cwidth, 1, LBUMP);
5674 pavelyakov 333
	DrawBar(0, lt_y+2, Form.cwidth, LIST_INFO_H-4, system.color.work);
3368 leency 334
	WriteText(mail_list.w-30/2, lt_y, 0x80, 0x888888, "= = =");
335
	WriteText(mail_list.w-30/2, lt_y+1, 0x80, 0xEeeeee, "= = =");
5674 pavelyakov 336
	DrawBar(0, lt_y+LIST_INFO_H-2, Form.cwidth, 1, system.color.work_graph); //bottom
4870 leency 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);
5674 pavelyakov 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);
3368 leency 347
}
348
 
349
 
4509 leency 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,
5709 leency 352
		Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 12);
4509 leency 353
	WB1.list.column_max = WB1.list.w - 30 / 6;
5825 leency 354
	WB1.list.visible = WB1.list.h / WB1.list.item_h;
4870 leency 355
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h);
3368 leency 356
 
4509 leency 357
	strcpy(#header, #version);
358
	WB1.list.first = WB1.list.count = 0;
359
}
3368 leency 360
 
4509 leency 361
void DrawLetter() {
4540 leency 362
	bufsize = strlen(mdata);
5747 leency 363
	WB1.LoadInternalPage(bufsize, mdata);
5766 leency 364
	if (bufsize) WB1.Prepare();
4870 leency 365
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff);
3368 leency 366
}
367
 
4509 leency 368
 
369
void DrawScroller1() {
3368 leency 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
 
4509 leency 382
void DrawStatusBar() {
3368 leency 383
	int st_y = Form.cheight -status_bar_h;
5674 pavelyakov 384
	DrawBar(0, st_y, Form.cwidth, status_bar_h, system.color.work);
3368 leency 385
	if (aim) {
386
		SetMailBoxStatus(cur_st_percent, cur_st_text);
5674 pavelyakov 387
		DrawCaptButton(240, st_y+1, 36, status_bar_h-3, STOP_LOADING, system.color.work_button, system.color.work_button_text,"Stop");
3368 leency 388
	}
5674 pavelyakov 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]);
3368 leency 390
}
391
 
392
 
393
 
4509 leency 394
void SetMailBoxStatus(dword percent1, text1) {
5674 pavelyakov 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);
4169 leency 397
	cur_st_percent = percent1;
3368 leency 398
	cur_st_text = text1;
399
}
400
 
401
 
4509 leency 402
void StopLoading() {
3368 leency 403
	aim = NULL;
4166 leency 404
	mailstart = free(mailstart);
3368 leency 405
	to = from = date = subj = cur_charset = NULL;
406
}
407
 
4509 leency 408
int GetLetterSize_(int number) {
4166 leency 409
   char search_num[24];
410
   char mailsize1[24];
4185 leency 411
   strcpy(#search_num, "\x0a");       // 0x0d, 0x0a
4166 leency 412
   itoa_(#search_num+1, number);
413
   chrcat(#search_num, ' ');
414
   strcpyb(listbuffer, #mailsize1, #search_num, "\x0d");
415
   return atoi(#mailsize1);
3368 leency 416
}
417
 
418
 
5774 leency 419
void ClickLink() {
420
	RunProgram("/sys/network/WebView", PageLinks.GetURL(PageLinks.active));
421
}