Subversion Repositories Kolibri OS

Rev

Rev 7506 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7506 Rev 7806
1
//Leency & SoUrcerer, LGPL
1
//Leency & SoUrcerer, LGPL
2
 
2
 
3
//LoginPanel
3
//LoginPanel
4
#define PANEL_W 220
4
#define PANEL_W 220
5
#define PANEL_H 140
5
#define PANEL_H 140
6
int panel_x, panel_y;
6
int panel_x, panel_y;
7
 
7
 
8
//edit_boxes at LoginPanel 
8
//edit_boxes at LoginPanel 
9
int	mouse_dd;
9
int	mouse_dd;
10
unsigned char email_text[128];
10
unsigned char email_text[128];
11
unsigned char pass_text[32];
11
unsigned char pass_text[32];
12
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
12
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
13
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
13
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
14
 
14
 
15
 
15
 
16
void LoginNetworkProcess()
16
void LoginNetworkProcess()
17
{
17
{
18
	if (aim) switch(aim)
18
	if (aim) switch(aim)
19
	{
19
	{
20
		case RESOLVE:
20
		case RESOLVE:
21
					if (!email_text) StopConnect("Enter email!");
21
					if (!email_text) StopConnect("Enter email!");
22
					if (!pass_text) StopConnect("Enter password!");
22
					if (!pass_text) StopConnect("Enter password!");
23
					if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
23
					if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
24
					if (!aim) return;
24
					if (!aim) return;
25
 
25
 
26
					sockaddr.sin_family = AF_INET4;
26
					sockaddr.sin_family = AF_INET4;
27
					AX = POP_server_port;
27
					AX = POP_server_port;
28
					$xchg	al, ah
28
					$xchg	al, ah
29
					sockaddr.sin_port = AX;
29
					sockaddr.sin_port = AX;
30
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
30
					sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);					
31
					if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
31
					if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
32
					else aim = OPEN_CONNECTION;
32
					else aim = OPEN_CONNECTION;
33
					break;
33
					break;
34
		case OPEN_CONNECTION:
34
		case OPEN_CONNECTION:
35
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
35
					socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
36
					if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
36
					if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
37
					Connect(socketnum, #sockaddr, 16);
37
					Connect(socketnum, #sockaddr, 16);
38
					aim = GET_ANSWER_CONNECT;
38
					aim = GET_ANSWER_CONNECT;
39
					break;
39
					break;
40
		case GET_ANSWER_CONNECT:
40
		case GET_ANSWER_CONNECT:
41
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
41
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
42
					if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
42
					if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
43
					immbuffer[ticks]='\0';					
43
					immbuffer[ticks]='\0';					
44
					if (immbuffer[ticks-2]=='\n')
44
					if (immbuffer[ticks-2]=='\n')
45
					{
45
					{
46
						if (strstr(#immbuffer,"+OK"))
46
						if (strstr(#immbuffer,"+OK"))
47
							aim = SEND_USER;
47
							aim = SEND_USER;
48
						else
48
						else
49
							StopConnect("Failed to connect to server. Retry...");
49
							StopConnect("Failed to connect to server. Retry...");
50
					}
50
					}
51
					break;
51
					break;
52
		case SEND_USER:
52
		case SEND_USER:
53
					request_len = GetRequest("USER", #login);
53
					request_len = GetRequest("USER", #login);
54
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
54
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
55
					{
55
					{
56
						SetLoginStatus("Failed to send USER. Retry...");
56
						SetLoginStatus("Failed to send USER. Retry...");
57
						break;
57
						break;
58
					}
58
					}
59
					else aim = GET_ANSWER_USER;
59
					else aim = GET_ANSWER_USER;
60
					break;
60
					break;
61
		case GET_ANSWER_USER:
61
		case GET_ANSWER_USER:
62
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
62
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
63
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
63
					if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
64
					immbuffer[ticks]='\0';						
64
					immbuffer[ticks]='\0';						
65
					if (immbuffer[ticks-2]=='\n') 
65
					if (immbuffer[ticks-2]=='\n') 
66
					{
66
					{
67
						if (strstr(#immbuffer,"+OK"))
67
						if (strstr(#immbuffer,"+OK"))
68
							aim = SEND_PASS;
68
							aim = SEND_PASS;
69
						else
69
						else
70
						{
70
						{
71
							debug(#immbuffer);
71
							debug(#immbuffer);
72
							StopConnect("Wrong username");
72
							StopConnect("Wrong username");
73
						}
73
						}
74
					}
74
					}
75
					else
75
					else
76
					{
76
					{
77
						StopConnect("Connection failed"); 
77
						StopConnect("Connection failed"); 
78
					}
78
					}
79
					break;
79
					break;
80
		case SEND_PASS:
80
		case SEND_PASS:
81
					request_len = GetRequest("PASS", #pass_text);
81
					request_len = GetRequest("PASS", #pass_text);
82
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
82
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
83
					{
83
					{
84
						SetLoginStatus("Failed to send PASS. Retry...");
84
						SetLoginStatus("Failed to send PASS. Retry...");
85
						break;
85
						break;
86
					}
86
					}
87
					else aim = GET_ANSWER_PASS;
87
					else aim = GET_ANSWER_PASS;
88
					break;
88
					break;
89
		case GET_ANSWER_PASS:
89
		case GET_ANSWER_PASS:
90
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
90
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
91
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
91
					if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
92
					immbuffer[ticks]='\0';						
92
					immbuffer[ticks]='\0';						
93
					
93
					
94
					if (immbuffer[ticks-2]=='\n')
94
					if (immbuffer[ticks-2]=='\n')
95
					{
95
					{
96
						if (strstr(#immbuffer,"+OK")) MailBoxLoop();
96
						if (strstr(#immbuffer,"+OK")) MailBoxLoop();
97
						else
97
						else
98
						{
98
						{
99
							StopConnect("Wrong password or POP3 disabled");
99
							StopConnect("Wrong password or POP3 disabled");
100
							debug(#immbuffer);
100
							debug(#immbuffer);
101
						}
101
						}
102
					}
102
					}
103
					else
103
					else
104
					{
104
					{
105
						StopConnect("Connection failed"); 
105
						StopConnect("Connection failed"); 
106
					}
106
					}
107
	}
107
	}
108
}
108
}
109
 
109
 
110
 
110
 
111
void LoginBoxLoop()
111
void LoginBoxLoop()
112
{
112
{
113
	int id;
113
	int id;
114
 
114
 
115
	SetLoginStatus(NULL);
115
	SetLoginStatus(NULL);
116
	goto _LB_DRAW;
116
	goto _LB_DRAW;
117
	loop()
117
	loop()
118
	{
118
	{
119
		WaitEventTimeout(2);
119
		WaitEventTimeout(2);
120
		switch(EAX & 0xFF)
120
		switch(EAX & 0xFF)
121
		{
121
		{
122
			case evMouse:
122
			case evMouse:
123
				edit_box_mouse stdcall (#login_box);
123
				edit_box_mouse stdcall (#login_box);
124
				edit_box_mouse stdcall (#pass_box);
124
				edit_box_mouse stdcall (#pass_box);
125
				break;
125
				break;
126
				
126
				
127
			case evButton:
127
			case evButton:
128
				id = GetButtonID(); 
128
				id = GetButtonID(); 
129
				if (id==1) SaveAndExit();
129
				if (id==1) SaveAndExit();
130
				if (id==11)	SettingsDialog();
130
				if (id==11)	SettingsDialog();
131
				if (id==12)
131
				if (id==12)
132
				{
132
				{
133
					if (!aim) aim=RESOLVE; else aim=NULL;
133
					if (!aim) aim=RESOLVE; else aim=NULL;
134
					GetSettings();
134
					GetSettings();
135
					DrawLoginScreen();
135
					DrawLoginScreen();
136
				}
136
				}
137
				break;
137
				break;
138
				
138
				
139
			case evKey:
139
			case evKey:
140
				GetKeys();
140
				GetKeys();
141
				if (key_scancode==SCAN_CODE_TAB)
141
				if (key_scancode==SCAN_CODE_TAB)
142
				{
142
				{
143
					if (login_box.flags & 0b10)
143
					if (login_box.flags & 0b10)
144
						{ pass_box.flags = 0b11; login_box.flags = 0; }
144
						{ pass_box.flags = 0b11; login_box.flags = 0; }
145
					else
145
					else
146
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
146
						{ pass_box.flags = 0b1; login_box.flags = 0b10; }
147
					edit_box_draw stdcall(#login_box);
147
					edit_box_draw stdcall(#login_box);
148
					edit_box_draw stdcall(#pass_box);
148
					edit_box_draw stdcall(#pass_box);
149
					break;				
149
					break;				
150
				}
150
				}
151
				if (key_scancode==SCAN_CODE_ENTER) && (!aim)
151
				if (key_scancode==SCAN_CODE_ENTER) && (!aim)
152
				{
152
				{
153
					aim=RESOLVE;
153
					aim=RESOLVE;
154
					GetSettings();
154
					GetSettings();
155
					DrawLoginScreen();
155
					DrawLoginScreen();
156
				}
156
				}
157
				EAX = key_editbox;
157
				EAX = key_editbox;
158
				edit_box_key stdcall(#login_box);
158
				edit_box_key stdcall(#login_box);
159
				edit_box_key stdcall(#pass_box);
159
				edit_box_key stdcall(#pass_box);
160
				break;
160
				break;
161
				
161
				
162
			case evReDraw: _LB_DRAW:
162
			case evReDraw: _LB_DRAW:
163
				if !(DefineWindow(LOGIN_HEADER)) break;
163
				if !(DefineWindow(LOGIN_HEADER)) break;
164
				DrawLoginScreen();
164
				DrawLoginScreen();
165
				break;
165
				break;
166
 
166
 
167
			default:
167
			default:
168
				LoginNetworkProcess();				
168
				LoginNetworkProcess();				
169
		}
169
		}
170
	}
170
	}
171
}
171
}
172
 
172
 
173
 
173
 
174
 
174
 
175
void DrawLoginScreen()
175
void DrawLoginScreen()
176
{				
176
{				
177
	panel_x = Form.cwidth - PANEL_W /2;
177
	panel_x = Form.cwidth - PANEL_W /2;
178
	panel_y = Form.cheight - PANEL_H /2 - 5;
178
	panel_y = Form.cheight - PANEL_H /2 - 5;
179
 
179
 
180
	DrawBar(0,0, Form.cwidth, Form.cheight, system.color.work);
180
	DrawBar(0,0, Form.cwidth, Form.cheight, sc.work);
181
	
181
	
182
	WriteText(panel_x,panel_y-3,0x80,system.color.work_text,"Your Email:");
182
	WriteText(panel_x,panel_y-3,0x80,sc.work_text,"Your Email:");
183
	DrawEditBoxPos(panel_x+3, panel_y+12, #login_box);
183
	DrawEditBoxPos(panel_x+3, panel_y+12, #login_box);
184
	
184
	
185
	WriteText(panel_x,panel_y+45,0x80,system.color.work_text,"Password:");
185
	WriteText(panel_x,panel_y+45,0x80,sc.work_text,"Password:");
186
	DrawEditBoxPos(panel_x+3, panel_y+60, #pass_box);
186
	DrawEditBoxPos(panel_x+3, panel_y+60, #pass_box);
187
	
187
	
188
	if (!aim)
188
	if (!aim)
189
	{
189
	{
190
		DrawCaptButton(panel_x,panel_y+100,100,26,11,system.color.work_button, system.color.work_button_text,"Settings");
190
		DrawCaptButton(panel_x,panel_y+100,100,26,11,sc.button, sc.button_text,"Settings");
191
		DrawCaptButton(panel_x+120,panel_y+100,100,26,12,system.color.work_button, system.color.work_button_text,"Enter >");
191
		DrawCaptButton(panel_x+120,panel_y+100,100,26,12,sc.button, sc.button_text,"Enter >");
192
	} 
192
	} 
193
	else DrawCaptButton(panel_x+120,panel_y+100,100,26,12,system.color.work_button, system.color.work_button_text,"Stop");
193
	else DrawCaptButton(panel_x+120,panel_y+100,100,26,12,sc.button, sc.button_text,"Stop");
194
	
194
	
195
	SetLoginStatus(cur_st_text);
195
	SetLoginStatus(cur_st_text);
196
}
196
}
197
 
197
 
198
 
198
 
199
void GetSettings()
199
void GetSettings()
200
{
200
{
201
	strcpy(#login, #email_text);
201
	strcpy(#login, #email_text);
202
	ESBYTE[strchr(#login,'@')] = NULL;
202
	ESBYTE[strchr(#login,'@')] = NULL;
203
	
203
	
204
	if (automatic.checked)
204
	if (automatic.checked)
205
	{
205
	{
206
		strcpy(#POP_server_path, "pop.");
206
		strcpy(#POP_server_path, "pop.");
207
		strcat(#POP_server_path, strchr(#email_text,'@')+1);
207
		strcat(#POP_server_path, strchr(#email_text,'@')+1);
208
		POP_server_port = DEFAULT_POP_PORT;
208
		POP_server_port = DEFAULT_POP_PORT;
209
	}
209
	}
210
	else
210
	else
211
	{
211
	{
212
		strcpy(#POP_server_path, #POP_server1);
212
		strcpy(#POP_server_path, #POP_server1);
213
		POP_server_port = atoi(#POP_server_port1);
213
		POP_server_port = atoi(#POP_server_port1);
214
	}
214
	}
215
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
215
	if (!strcmp(#POP_server_path, "pop.gmail.com"))	StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
216
}
216
}
217
 
217
 
218
void SetLoginStatus(dword text1)
218
void SetLoginStatus(dword text1)
219
{
219
{
220
	if (text1) WriteText(10, Form.cheight-22, 0x80, system.color.work_text, text1);
220
	if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1);
221
	cur_st_text = text1;
221
	cur_st_text = text1;
222
}
222
}