Subversion Repositories Kolibri OS

Rev

Rev 6796 | 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:
4164 leency 162
				IF (!CheckActiveProcess(Form.ID)) break;
5640 pavelyakov 163
				mouse.get();
3368 leency 164
 
5640 pavelyakov 165
				if (!mouse.lkm) panels_drag=0;
166
				if (mouse.lkm) && (mouse.y>mail_list.y+mail_list.h-1) && (mouse.y
4509 leency 167
				&& (!scroll1.delta2) && (!scroll_wv.delta2) panels_drag = 1;
3368 leency 168
				if (panels_drag)
169
				{
5709 leency 170
					if (mouse.yForm.cheight-60-status_bar_h-LIST_INFO_H) break;
5640 pavelyakov 171
					mail_list.h = mouse.y - mail_list.y-2;
3368 leency 172
					DrawMailBox();
173
					break;
174
				}
175
 
6796 leency 176
				PageLinks.HoverAndProceed(mouse.x, mouse.y);
4509 leency 177
 
3368 leency 178
				if (!mail_list.count) break;
4509 leency 179
				if (!panels_drag) { scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll_wv); }
3368 leency 180
 
181
				if (mail_list.first <> scroll1.position)
182
				{
183
					mail_list.first = scroll1.position;
184
					DrawMailList();
185
					break;
186
				};
4509 leency 187
				if (WB1.list.first <> scroll_wv.position)
3368 leency 188
				{
4509 leency 189
					WB1.list.first = scroll_wv.position;
3368 leency 190
					DrawLetter();
191
					break;
192
				};
193
 
5640 pavelyakov 194
				if (mail_list.y+mail_list.h + 10 > mouse.y)
3368 leency 195
				{
5640 pavelyakov 196
					if (mail_list.MouseScroll(mouse.vert)) DrawMailList();
3368 leency 197
				}
198
				else
199
				{
5640 pavelyakov 200
					if (WB1.list.MouseScroll(mouse.vert)) DrawLetter();
3368 leency 201
				}
5640 pavelyakov 202
				if (mouse.lkm) && (mail_list.MouseOver(mouse.x, mouse.y)) && (!clicked_list) clicked_list=1;
203
				if (!mouse.lkm) && (clicked_list) if (mail_list.ProcessMouse(mouse.x, mouse.y))
4186 leency 204
				{
205
					clicked_list = 0;
206
					if (aim) break;
207
					DrawMailList();
208
					aim = SEND_RETR;
209
				}
3368 leency 210
 
211
				break;
212
			case evButton:
213
				id = GetButtonID();
214
				if (id==1) SaveAndExit();
215
				if (id==GET_MAIL) aim = SEND_NSTAT;
216
				if (id==SAVE_LETTER)
217
				{
4166 leency 218
					if (!mailstart) break;
7227 leency 219
					CreateFile(strlen(mailstart), mailstart, "mail.txt");
3368 leency 220
					pause(10);
221
					RunProgram("tinypad", "mail.txt");
222
				}
223
				if (id==STOP_LOADING)
224
				{
225
					StopLoading();
226
					DrawStatusBar();
227
					DrawMailList();
228
				}
229
				if (id==EXIT_MAIL)
230
				{
231
					StopLoading();
4139 hidnplayr 232
					Close(socketnum);
3368 leency 233
					LoginBoxLoop();
234
				}
235
				if (id==CHANGE_CHARSET)
236
				{
237
					DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME);
5674 pavelyakov 238
					DrawRectangle(Form.cwidth-100, Form.cheight-status_bar_h- 70, 70, 82, system.color.work_graph);
239
					DrawRectangle3D(Form.cwidth-99, Form.cheight-status_bar_h- 69, 68, 80, 0xFFFfff, system.color.work);
3368 leency 240
					for (id=0; id<5; id++)
241
					{
5674 pavelyakov 242
						if (cur_charset==id+1) { line_col=system.color.work_button; text_col=system.color.work_button_text; }
243
						else { line_col=system.color.work; text_col=system.color.work_text; }
3368 leency 244
						DrawBar(Form.cwidth-98, id*16+Form.cheight-status_bar_h- 68, 67, 16, line_col);
245
						DrawCaptButton(Form.cwidth-100, id*16+Form.cheight-status_bar_h- 68, 70,16, 10+id+BT_HIDE,
246
						0, text_col, charsets[id+1]);
247
					}
248
				}
249
				if (id==CLOSE_CHANGE_CHARSET) goto _MB_DRAW;
250
 
251
				break;
252
			case evKey:
5714 punk_joker 253
				GetKeys();
3368 leency 254
 
5714 punk_joker 255
				if (!aim) && (mail_list.ProcessKey(key_scancode))
4152 leency 256
				{
3368 leency 257
					DrawMailList();
258
					aim = SEND_RETR;
259
				}
260
 
261
				break;
262
			case evReDraw: _MB_DRAW:
263
				if !(DefineWindow(MAILBOX_HEADER)) break;
4509 leency 264
				scroll1.bckg_col = scroll_wv.bckg_col = 0xBBBbbb;
5674 pavelyakov 265
				scroll1.frnt_col = scroll_wv.frnt_col = system.color.work;
266
				scroll1.line_col = scroll_wv.line_col = system.color.work_graph;
3368 leency 267
				DrawToolbar();
268
				DrawMailBox();
269
 
270
				break;
271
			default:
4169 leency 272
				MailBoxNetworkProcess();
3368 leency 273
		}
274
	}
275
}
276
 
277
 
278
void DrawMailBox()
279
{
280
	DrawMailList();
281
	DrawLetterInfo();
4509 leency 282
	InitTWB();
3368 leency 283
	DrawLetter();
284
	DrawStatusBar();
285
}
286
 
287
 
4509 leency 288
void DrawToolbar() {
3368 leency 289
	#define BUT_Y 7
290
	#define BUT_H 22
291
	#define BUT_W 74
292
	int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
5709 leency 293
	mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 18);
3368 leency 294
 
5674 pavelyakov 295
	DrawBar(0,0, Form.cwidth,toolbar_w-3, system.color.work);
296
	DrawCaptButton(10                    , BUT_Y, BUT_W, BUT_H, GET_MAIL,    system.color.work_button, system.color.work_button_text,"Get mail");
297
	DrawCaptButton(BUT_W+ 20, BUT_Y, BUT_W+10, BUT_H, SAVE_LETTER, system.color.work_button, system.color.work_button_text,"Save letter");
298
	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 299
 
5674 pavelyakov 300
	DrawBar(0, mail_list.y-3, mail_list.w,1, system.color.work_graph);
3368 leency 301
	DrawBar(0, mail_list.y-2, mail_list.w,1, 0xdfdfdf);
302
	DrawBar(0, mail_list.y-1, mail_list.w,1, 0xf0f0f0);
303
}
304
 
4509 leency 305
void DrawMailList() {
3413 leency 306
	int i, on_y, on_x, direction;
4152 leency 307
	dword sel_col;
5825 leency 308
	mail_list.visible = mail_list.h / mail_list.item_h;
3368 leency 309
 
310
	for (i=30; i<150; i++) DeleteButton(i);
311
	for (i=0; (i
312
	{
5825 leency 313
		on_y = i*mail_list.item_h + mail_list.y;
314
		if (mail_list.cur_y==mail_list.first+i) sel_col=0xEEEeee; else sel_col=0xFFFfff;
315
		DrawBar(0, on_y, mail_list.w, mail_list.item_h-1, sel_col);
3413 leency 316
		direction = atr.GetDirection(i+mail_list.first+1);
317
		on_x = strlen(itoa(i+mail_list.first+1))*6;
4152 leency 318
		letter_icons_pal[0]=sel_col;
319
		PutPaletteImage(sizeof(letter_icons)/3*direction + #letter_icons, 18,12, on_x+18,
5825 leency 320
			mail_list.item_h-12/2+ on_y, 8, #letter_icons_pal);
3413 leency 321
		WriteText(on_x + 42, on_y+5, 0x80, 0, atr.GetSubject(i+mail_list.first+1));
5825 leency 322
		DrawBar(0, on_y + mail_list.item_h-1, mail_list.w, 1, 0xCCCccc);
3368 leency 323
		WriteText(10, on_y+5, 0x80, 0, itoa(i+mail_list.first+1));
4870 leency 324
		WriteText(mail_list.w - 40, on_y+5, 0x80, 0, ConvertSize(atr.GetSize(i+mail_list.first+1)));
3368 leency 325
	}
5825 leency 326
	DrawBar(0, i*mail_list.item_h + mail_list.y, mail_list.w, -i*mail_list.item_h+mail_list.h, 0xFFFfff);
3368 leency 327
	DrawScroller1();
328
}
329
 
4509 leency 330
void DrawLetterInfo() {
3368 leency 331
	int lt_y = mail_list.y+mail_list.h;
5674 pavelyakov 332
	DrawBar(0, lt_y, mail_list.w, 1, system.color.work_graph);
3368 leency 333
	DrawBar(0, lt_y+1, Form.cwidth, 1, LBUMP);
5674 pavelyakov 334
	DrawBar(0, lt_y+2, Form.cwidth, LIST_INFO_H-4, system.color.work);
3368 leency 335
	WriteText(mail_list.w-30/2, lt_y, 0x80, 0x888888, "= = =");
336
	WriteText(mail_list.w-30/2, lt_y+1, 0x80, 0xEeeeee, "= = =");
5674 pavelyakov 337
	DrawBar(0, lt_y+LIST_INFO_H-2, Form.cwidth, 1, system.color.work_graph); //bottom
4870 leency 338
	DrawBar(0, lt_y+LIST_INFO_H-1, Form.cwidth, 1, 0xdfdfdf);
339
	DrawBar(0, lt_y+LIST_INFO_H  , Form.cwidth, 1, 0xf0f0f0);
5674 pavelyakov 340
	WriteTextB(10, lt_y+8 , 0x80, system.color.work_text, "From:");
341
	WriteText (45, lt_y+8 , 0x80, system.color.work_text, #from);
342
	WriteTextB(10, lt_y+20, 0x80, system.color.work_text, "To:");
343
	WriteText (45, lt_y+20, 0x80, system.color.work_text, #to);
344
	WriteTextB(10, lt_y+32, 0x80, system.color.work_text, "Date:");
345
	WriteText (45, lt_y+32, 0x80, system.color.work_text, #date);
346
	WriteTextB(10, lt_y+44, 0x80, system.color.work_text, "Subj:");
347
	WriteText (45, lt_y+44, 0x80, system.color.work_text, #subj);
3368 leency 348
}
349
 
350
 
4509 leency 351
void InitTWB() {
352
	WB1.list.SetSizes(0, mail_list.y+mail_list.h+LIST_INFO_H+1, Form.cwidth - scroll_wv.size_x - 1,
5709 leency 353
		Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 12);
4509 leency 354
	WB1.list.column_max = WB1.list.w - 30 / 6;
5825 leency 355
	WB1.list.visible = WB1.list.h / WB1.list.item_h;
4870 leency 356
	WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h);
3368 leency 357
 
4509 leency 358
	strcpy(#header, #version);
359
	WB1.list.first = WB1.list.count = 0;
360
}
3368 leency 361
 
4509 leency 362
void DrawLetter() {
4540 leency 363
	bufsize = strlen(mdata);
5747 leency 364
	WB1.LoadInternalPage(bufsize, mdata);
5766 leency 365
	if (bufsize) WB1.Prepare();
4870 leency 366
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff);
3368 leency 367
}
368
 
4509 leency 369
 
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
	}
5674 pavelyakov 390
	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 391
}
392
 
393
 
394
 
4509 leency 395
void SetMailBoxStatus(dword percent1, text1) {
5674 pavelyakov 396
	DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, system.color.work, 0xC3C3C3, 0x54B1D6, system.color.work_text, percent1);
397
	WriteText(3, Form.cheight -status_bar_h + 1, 0x80, system.color.work_text, text1);
4169 leency 398
	cur_st_percent = percent1;
3368 leency 399
	cur_st_text = text1;
400
}
401
 
402
 
4509 leency 403
void StopLoading() {
3368 leency 404
	aim = NULL;
4166 leency 405
	mailstart = free(mailstart);
3368 leency 406
	to = from = date = subj = cur_charset = NULL;
407
}
408
 
4509 leency 409
int GetLetterSize_(int number) {
4166 leency 410
   char search_num[24];
411
   char mailsize1[24];
4185 leency 412
   strcpy(#search_num, "\x0a");       // 0x0d, 0x0a
4166 leency 413
   itoa_(#search_num+1, number);
414
   chrcat(#search_num, ' ');
415
   strcpyb(listbuffer, #mailsize1, #search_num, "\x0d");
416
   return atoi(#mailsize1);
3368 leency 417
}
418
 
419
 
5774 leency 420
void ClickLink() {
421
	RunProgram("/sys/network/WebView", PageLinks.GetURL(PageLinks.active));
422
}