Subversion Repositories Kolibri OS

Rev

Rev 9601 | 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};
9287 leency 8
scroll_bar scroll_wv;
3368 leency 9
 
10
char *listbuffer;
11
char *listpointer;
12
 
4166 leency 13
char *mailstart;
14
char *mailend;
15
int mailsize;
3368 leency 16
 
7759 leency 17
int cur_charset;
3368 leency 18
 
9287 leency 19
llist list;
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:
9287 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;
9287 leency 47
 
4169 leency 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
9287 leency 57
						listpointer = listbuffer;
4169 leency 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:
7806 leency 69
				WriteText(5, Form.cheight-11, 0x80, sc.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);
9287 leency 78
				if (ticks == 0xffffffff) break;
79
				listpointer = listpointer + ticks;
80
 
4169 leency 81
				if (listpointer - listbuffer < 5) break;
9287 leency 82
				if (strncmp(listpointer-5,"\n.\n",5)==0)  // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
4169 leency 83
				{
84
					aim = SEND_RETR;
4645 leency 85
					debugln("goto SEND_RETR");
4169 leency 86
					DrawMailBox();
9287 leency 87
 
4169 leency 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
				DrawMailBox();
5825 leency 97
				request_len = GetRequest("RETR", itoa(mail_list.cur_y+1));
4169 leency 98
				if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
99
				{
100
					StopConnect("Error while trying to get letter from server");
101
					break;
102
				}
5825 leency 103
				mailsize = atr.GetSize(mail_list.cur_y+1) + 1024;
4169 leency 104
				free(mailstart);
4186 leency 105
				mailstart = malloc(mailsize);
4870 leency 106
				mailend = mailstart;
4186 leency 107
				if (!mailstart)
4169 leency 108
				{
4645 leency 109
					debugln("alloc error!");
4169 leency 110
					aim=NULL;
111
					break;
112
				}
7746 leency 113
				debugval("mailsize", mailsize);
4169 leency 114
				aim = GET_ANSWER_RETR;
4645 leency 115
				debugln("goto GET_ANSWER_RETR");
4186 leency 116
				break;
9287 leency 117
 
4169 leency 118
		case GET_ANSWER_RETR:
7746 leency 119
				debugval("mailsize", mailsize);
120
				debugval("mailstart", mailstart);
121
				debugval("mailend", mailend);
4169 leency 122
				ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
123
				if (ticks == 0xffffffff) break;
4870 leency 124
				mailend = mailend + ticks;
4169 leency 125
				if (mailsize + mailstart - mailend - 2 < 0)
126
				{
4645 leency 127
					debugln("Resizing buffer");
4169 leency 128
					mailsize += 4096;
129
					mailstart = realloc(mailstart, mailsize);
130
					if (!mailstart) { StopConnect("Realloc error!"); break;}
131
				}
4870 leency 132
				/*
4180 leency 133
				if (mailsize>9000)
4169 leency 134
				{
135
					load_persent = mailend - mailstart * 100 ;
136
					load_persent /= mailsize - 1024;
137
					if (load_persent != cur_st_percent) SetMailBoxStatus( load_persent , NULL);
138
				}
4870 leency 139
				*/
140
				//ParseMail();
4169 leency 141
	}
142
}
143
 
144
 
4509 leency 145
void MailBoxLoop() {
5714 punk_joker 146
	int id;
4186 leency 147
	int panels_drag=0, clicked_list=0;
3368 leency 148
	dword line_col, text_col;
149
 
150
	mail_list.h = Form.cheight/4;
151
	mail_list.ClearList();
152
	SetMailBoxStatus( NULL , NULL);
153
	cur_charset = 0;
4166 leency 154
	aim = SEND_NSTAT;
9287 leency 155
 
3368 leency 156
	goto _MB_DRAW;
157
 
9287 leency 158
	loop()
3368 leency 159
	{
160
		WaitEventTimeout(2);
161
		switch(EAX & 0xFF)
162
		{
163
			case evMouse:
5640 pavelyakov 164
				mouse.get();
9287 leency 165
 
5640 pavelyakov 166
				if (!mouse.lkm) panels_drag=0;
167
				if (mouse.lkm) && (mouse.y>mail_list.y+mail_list.h-1) && (mouse.y
4509 leency 168
				&& (!scroll1.delta2) && (!scroll_wv.delta2) panels_drag = 1;
3368 leency 169
				if (panels_drag)
170
				{
5709 leency 171
					if (mouse.yForm.cheight-60-status_bar_h-LIST_INFO_H) break;
5640 pavelyakov 172
					mail_list.h = mouse.y - mail_list.y-2;
3368 leency 173
					DrawMailBox();
174
					break;
175
				}
176
 
9287 leency 177
				//links.hover(mouse.x, mouse.y);
4509 leency 178
 
3368 leency 179
				if (!mail_list.count) break;
4509 leency 180
				if (!panels_drag) { scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll_wv); }
9287 leency 181
 
3368 leency 182
				if (mail_list.first <> scroll1.position)
183
				{
184
					mail_list.first = scroll1.position;
185
					DrawMailList();
186
					break;
187
				};
9287 leency 188
				if (list.first <> scroll_wv.position)
3368 leency 189
				{
9287 leency 190
					list.first = scroll_wv.position;
3368 leency 191
					DrawLetter();
192
					break;
193
				};
9287 leency 194
 
5640 pavelyakov 195
				if (mail_list.y+mail_list.h + 10 > mouse.y)
3368 leency 196
				{
5640 pavelyakov 197
					if (mail_list.MouseScroll(mouse.vert)) DrawMailList();
3368 leency 198
				}
199
				else
200
				{
9287 leency 201
					if (list.MouseScroll(mouse.vert)) DrawLetter();
3368 leency 202
				}
5640 pavelyakov 203
				if (mouse.lkm) && (mail_list.MouseOver(mouse.x, mouse.y)) && (!clicked_list) clicked_list=1;
9287 leency 204
				if (!mouse.lkm) && (clicked_list) if (mail_list.ProcessMouse(mouse.x, mouse.y))
4186 leency 205
				{
206
					clicked_list = 0;
207
					if (aim) break;
208
					DrawMailList();
209
					aim = SEND_RETR;
210
				}
3368 leency 211
 
9287 leency 212
				break;
3368 leency 213
			case evButton:
9287 leency 214
				id = GetButtonID();
3368 leency 215
				if (id==1) SaveAndExit();
216
				if (id==GET_MAIL) aim = SEND_NSTAT;
217
				if (id==SAVE_LETTER)
218
				{
4166 leency 219
					if (!mailstart) break;
7227 leency 220
					CreateFile(strlen(mailstart), mailstart, "mail.txt");
3368 leency 221
					pause(10);
7614 leency 222
					RunProgram("/sys/tinypad", "mail.txt");
3368 leency 223
				}
9287 leency 224
				if (id==STOP_LOADING)
3368 leency 225
				{
226
					StopLoading();
227
					DrawStatusBar();
228
					DrawMailList();
229
				}
9287 leency 230
				if (id==EXIT_MAIL)
3368 leency 231
				{
232
					StopLoading();
4139 hidnplayr 233
					Close(socketnum);
3368 leency 234
					LoginBoxLoop();
235
				}
9287 leency 236
				if (id==CHANGE_CHARSET)
3368 leency 237
				{
238
					DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME);
9602 leency 239
					DrawRectangle(Form.cwidth-100, Form.cheight-status_bar_h- 70, 70, 82, sc.line);
7806 leency 240
					DrawRectangle3D(Form.cwidth-99, Form.cheight-status_bar_h- 69, 68, 80, 0xFFFfff, sc.work);
3368 leency 241
					for (id=0; id<5; id++)
242
					{
7806 leency 243
						if (cur_charset==id+1) { line_col=sc.button; text_col=sc.button_text; }
244
						else { line_col=sc.work; text_col=sc.work_text; }
3368 leency 245
						DrawBar(Form.cwidth-98, id*16+Form.cheight-status_bar_h- 68, 67, 16, line_col);
246
						DrawCaptButton(Form.cwidth-100, id*16+Form.cheight-status_bar_h- 68, 70,16, 10+id+BT_HIDE,
247
						0, text_col, charsets[id+1]);
248
					}
249
				}
250
				if (id==CLOSE_CHANGE_CHARSET) goto _MB_DRAW;
251
 
9287 leency 252
				break;
3368 leency 253
			case evKey:
5714 punk_joker 254
				GetKeys();
3368 leency 255
 
5714 punk_joker 256
				if (!aim) && (mail_list.ProcessKey(key_scancode))
4152 leency 257
				{
3368 leency 258
					DrawMailList();
259
					aim = SEND_RETR;
260
				}
261
 
262
				break;
263
			case evReDraw: _MB_DRAW:
264
				if !(DefineWindow(MAILBOX_HEADER)) break;
4509 leency 265
				scroll1.bckg_col = scroll_wv.bckg_col = 0xBBBbbb;
7806 leency 266
				scroll1.frnt_col = scroll_wv.frnt_col = sc.work;
9602 leency 267
				scroll1.line_col = scroll_wv.line_col = sc.line;
3368 leency 268
				DrawToolbar();
269
				DrawMailBox();
270
 
271
				break;
272
			default:
4169 leency 273
				MailBoxNetworkProcess();
3368 leency 274
		}
275
	}
276
}
277
 
278
 
279
void DrawMailBox()
280
{
281
	DrawMailList();
282
	DrawLetterInfo();
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
 
7806 leency 295
	DrawBar(0,0, Form.cwidth,toolbar_w-3, sc.work);
296
	DrawCaptButton(10                    , BUT_Y, BUT_W, BUT_H, GET_MAIL,    sc.button, sc.button_text,"Get mail");
297
	DrawCaptButton(BUT_W+ 20, BUT_Y, BUT_W+10, BUT_H, SAVE_LETTER, sc.button, sc.button_text,"Save letter");
298
	DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL,   sc.button, sc.button_text,"< Exit");
3368 leency 299
 
9602 leency 300
	DrawBar(0, mail_list.y-3, mail_list.w,1, sc.line);
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
 
9287 leency 310
	for (i=30; i<150; i++) DeleteButton(i);
3368 leency 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;
9602 leency 332
	DrawBar(0, lt_y, mail_list.w, 1, sc.line);
3368 leency 333
	DrawBar(0, lt_y+1, Form.cwidth, 1, LBUMP);
7806 leency 334
	DrawBar(0, lt_y+2, Form.cwidth, LIST_INFO_H-4, sc.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, "= = =");
9602 leency 337
	DrawBar(0, lt_y+LIST_INFO_H-2, Form.cwidth, 1, sc.line); //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);
7806 leency 340
	WriteTextB(10, lt_y+8 , 0x80, sc.work_text, "From:");
341
	WriteText (45, lt_y+8 , 0x80, sc.work_text, #from);
342
	WriteTextB(10, lt_y+20, 0x80, sc.work_text, "To:");
343
	WriteText (45, lt_y+20, 0x80, sc.work_text, #to);
344
	WriteTextB(10, lt_y+32, 0x80, sc.work_text, "Date:");
345
	WriteText (45, lt_y+32, 0x80, sc.work_text, #date);
346
	WriteTextB(10, lt_y+44, 0x80, sc.work_text, "Subj:");
347
	WriteText (45, lt_y+44, 0x80, sc.work_text, #subj);
3368 leency 348
}
349
 
350
 
4509 leency 351
void DrawLetter() {
9287 leency 352
	//DrawTextLines();
4870 leency 353
	DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff);
3368 leency 354
}
355
 
4509 leency 356
void DrawScroller1() {
3368 leency 357
	scroll1.max_area = mail_list.count;
358
	scroll1.cur_area = mail_list.visible;
359
	scroll1.position = mail_list.first;
360
	scroll1.all_redraw=1;
361
	scroll1.start_x = mail_list.x + mail_list.w;
362
	scroll1.start_y = mail_list.y - 3;
363
	scroll1.size_y = mail_list.h + 4;
364
	scrollbar_v_draw(#scroll1);
365
}
366
 
367
 
368
 
4509 leency 369
void DrawStatusBar() {
3368 leency 370
	int st_y = Form.cheight -status_bar_h;
7806 leency 371
	DrawBar(0, st_y, Form.cwidth, status_bar_h, sc.work);
3368 leency 372
	if (aim) {
373
		SetMailBoxStatus(cur_st_percent, cur_st_text);
7806 leency 374
		DrawCaptButton(240, st_y+1, 36, status_bar_h-3, STOP_LOADING, sc.button, sc.button_text,"Stop");
3368 leency 375
	}
9287 leency 376
	DrawCaptButton(Form.cwidth - 100, st_y+1, 70, status_bar_h-2, CHANGE_CHARSET+BT_HIDE,
7806 leency 377
		sc.work, sc.work_text,cur_charset*10+#charsets);
3368 leency 378
}
379
 
380
 
381
 
4509 leency 382
void SetMailBoxStatus(dword percent1, text1) {
7806 leency 383
	DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, sc.work, 0xC3C3C3, 0x54B1D6, sc.work_text, percent1);
384
	WriteText(3, Form.cheight -status_bar_h + 1, 0x80, sc.work_text, text1);
4169 leency 385
	cur_st_percent = percent1;
3368 leency 386
	cur_st_text = text1;
387
}
388
 
389
 
4509 leency 390
void StopLoading() {
3368 leency 391
	aim = NULL;
4166 leency 392
	mailstart = free(mailstart);
3368 leency 393
	to = from = date = subj = cur_charset = NULL;
394
}
395
 
4509 leency 396
int GetLetterSize_(int number) {
4166 leency 397
   char search_num[24];
398
   char mailsize1[24];
4185 leency 399
   strcpy(#search_num, "\x0a");       // 0x0d, 0x0a
4166 leency 400
   itoa_(#search_num+1, number);
401
   chrcat(#search_num, ' ');
402
   strcpyb(listbuffer, #mailsize1, #search_num, "\x0d");
9287 leency 403
   return atoi(#mailsize1);
3368 leency 404
}
405
 
406
 
9287 leency 407
/*
7742 leency 408
void EventClickLink() {
9287 leency 409
	RunProgram("/sys/network/WebView", links.active_url);
410
}
411
*/