1 // ============================================================================
3 // ============================================================================
5 #include "includes.hpp"
7 // ----------------------------------------------------------------------------
9 // ----------------------------------------------------------------------------
11 // userlogin is the frame for logging in.
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
17 // IDs for the controls and the menu commands
25 // ----------------------------------------------------------------------------
26 // event tables and other macros for wxWindows
27 // ----------------------------------------------------------------------------
29 // the event tables connect the wxWindows events with the functions (event
30 // handlers) which process them. It can be also done at run-time, but for the
31 // simple menu events like this the static method is much simpler.
32 BEGIN_EVENT_TABLE( UserLogin, wxMDIChildFrame)
33 EVT_BUTTON( BUTTON_LOGIN, UserLogin::OnButtonPressed)
34 EVT_BUTTON( BUTTON_NEWUSER, UserLogin::OnButtonPressed)
35 EVT_BUTTON( BUTTON_EXIT, UserLogin::OnButtonPressed)
38 // ============================================================================
40 // ============================================================================
43 // ----------------------------------------------------------------------------
44 // the application class
45 // ----------------------------------------------------------------------------
48 UserLogin::UserLogin(CitClient *sock, wxMDIParentFrame *MyMDI)
49 : wxMDIChildFrame(MyMDI, //parent
54 wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
58 wxString sendcmd, recvcmd, xferbuf, buf;
65 /* SetIcon(wxICON(mondrian)); */
67 wxStaticText *username_label = new wxStaticText(
68 this, -1, "User name:",
69 wxDefaultPosition, wxDefaultSize, 0, ""
72 username = new wxTextCtrl(
83 wxStaticText *password_label = new wxStaticText(
84 this, -1, "Password:",
85 wxDefaultPosition, wxDefaultSize, 0, ""
88 password = new wxTextCtrl(
99 login_button = new wxButton(
109 login_button->SetDefault();
111 newuser_button = new wxButton(
122 exit_button = new wxButton(
133 wxHtmlWindow *hello = new wxHtmlWindow(this);
135 // Set up a panel for the title...
136 banner = new wxPanel(this, -1);
137 banner->SetBackgroundColour(wxColour(0x00, 0x00, 0x77));
138 banner->SetForegroundColour(wxColour(0xFF, 0xFF, 0x00));
140 wxLayoutConstraints *b1 = new wxLayoutConstraints;
141 b1->top.SameAs(this, wxTop, 2);
142 b1->left.SameAs(this, wxLeft, 2);
143 b1->right.SameAs(this, wxRight, 2);
144 b1->height.PercentOf(this, wxHeight, 10);
145 banner->SetConstraints(b1);
147 wxStaticText *rname = new wxStaticText(banner, -1, citsock->HumanNode);
148 rname->SetFont(wxFont(18, wxDEFAULT, wxNORMAL, wxNORMAL));
149 rname->SetForegroundColour(wxColour(0xFF, 0xFF, 0x00));
150 wxLayoutConstraints *t2 = new wxLayoutConstraints;
151 t2->top.SameAs(banner, wxTop, 1);
152 t2->centreX.SameAs(banner, wxCentreX);
153 t2->width.SameAs(banner, wxWidth);
155 rname->SetConstraints(t2);
157 wxLayoutConstraints *h0 = new wxLayoutConstraints;
158 h0->top.Below(banner, 10);
159 h0->bottom.Above(username, -10);
160 h0->left.SameAs(this, wxLeft, 10);
161 h0->right.SameAs(this, wxRight, 10);
162 hello->SetConstraints(h0);
164 wxLayoutConstraints *c1 = new wxLayoutConstraints;
165 c1->bottom.SameAs(this, wxBottom, 10); // 10 from the bottom
166 c1->centreX.SameAs(this, wxCentreX); // in the middle
167 c1->height.AsIs(); c1->width.AsIs();
168 newuser_button->SetConstraints(c1);
170 wxLayoutConstraints *c2 = new wxLayoutConstraints;
171 c2->bottom.SameAs(newuser_button, wxBottom);
172 c2->right.LeftOf(newuser_button, 10); // 10 from middle btn
173 c2->height.AsIs(); c2->width.AsIs();
174 login_button->SetConstraints(c2);
176 wxLayoutConstraints *c3 = new wxLayoutConstraints;
177 c3->bottom.SameAs(newuser_button, wxBottom);
178 c3->left.RightOf(newuser_button, 10); // 10 from middle btn
179 c3->height.AsIs(); c3->width.AsIs();
180 exit_button->SetConstraints(c3);
182 wxLayoutConstraints *c6 = new wxLayoutConstraints;
183 c6->left.SameAs(this, wxLeft, 10);
184 c6->bottom.SameAs(password, wxBottom);
185 c6->width.AsIs(); c6->height.AsIs();
186 password_label->SetConstraints(c6);
188 wxLayoutConstraints *c7 = new wxLayoutConstraints;
189 c7->left.SameAs(this, wxLeft, 10);
190 c7->bottom.SameAs(username, wxBottom);
191 c7->width.AsIs(); c7->height.AsIs();
192 username_label->SetConstraints(c7);
194 wxLayoutConstraints *c4 = new wxLayoutConstraints;
195 c4->bottom.Above(newuser_button, -10);
196 c4->left.RightOf(username_label, 10);
198 c4->right.SameAs(this, wxRight, 10);
199 password->SetConstraints(c4);
201 wxLayoutConstraints *c5 = new wxLayoutConstraints;
202 c5->bottom.Above(password, -10);
203 c5->left.SameAs(password, wxLeft);
205 c5->width.SameAs(password, wxWidth);
206 username->SetConstraints(c5);
212 sendcmd = "MESG hello";
213 if (citsock->serv_trans(sendcmd, recvcmd, xferbuf)==1) {
214 variformat_to_html(buf, xferbuf, FALSE);
215 buf = "<HTML><BODY><CENTER>"
216 + buf + "</CENTER></BODY></HTML>\n";
220 username->SetFocus();
225 void UserLogin::OnButtonPressed(wxCommandEvent& whichbutton) {
230 if (whichbutton.GetId() == BUTTON_EXIT) {
232 citsock->serv_trans(sendbuf);
236 if (whichbutton.GetId() == BUTTON_LOGIN) {
237 sendbuf = "USER " + username->GetValue();
238 r = citsock->serv_trans(sendbuf, recvbuf);
240 wxMessageDialog nouser(this,
243 wxOK | wxCENTRE | wxICON_INFORMATION,
248 sendbuf += password->GetValue();
249 r = citsock->serv_trans(sendbuf, recvbuf);
251 wxMessageDialog nopass(this,
254 wxOK | wxCENTRE | wxICON_INFORMATION,
258 BeginSession(recvbuf);
259 citsock->curr_pass = password->GetValue();
260 delete this; // dismiss the login box
265 if (whichbutton.GetId() == BUTTON_NEWUSER) {
266 sendbuf = "NEWU " + username->GetValue();
267 r = citsock->serv_trans(sendbuf, recvbuf);
269 wxMessageDialog nouser(this,
272 wxOK | wxCENTRE | wxICON_INFORMATION,
276 sendbuf = "SETP " + password->GetValue();
277 citsock->serv_trans(sendbuf);
278 BeginSession(recvbuf);
279 citsock->curr_pass = password->GetValue();
280 delete this; // dismiss the login box
287 void UserLogin::BeginSession(wxString serv_response) {
290 extract(citsock->curr_user, serv_response.Mid(4), 0);
291 BigMDI->SetStatusText(citsock->curr_user, 1);
292 citsock->GotoRoom("_BASEROOM_", "", junk);
293 citsock->axlevel = extract_int(serv_response.Mid(4), 1);
295 // FIX ... add code here to perform registration if necessary
297 RoomList->LoadRoomList();