Subversion Repositories Kolibri OS

Rev

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