1 #include "includes.hpp"
15 BEGIN_EVENT_TABLE(RoomView, wxMDIChildFrame)
16 EVT_BUTTON( BUTTON_GOTO, RoomView::OnButtonPressed)
17 EVT_BUTTON( BUTTON_SKIP, RoomView::OnButtonPressed)
18 EVT_BUTTON( BUTTON_CLOSE, RoomView::OnButtonPressed)
19 /* EVT_BUTTON( BUTTON_READNEW, RoomView::OnButtonPressed)*/
20 EVT_BUTTON( BUTTON_READALL, RoomView::OnButtonPressed)
21 EVT_BUTTON( BUTTON_ENTER, RoomView::OnButtonPressed)
22 EVT_BUTTON( BUTTON_ZAP, RoomView::OnButtonPressed)
28 CitClient *sock, wxMDIParentFrame *MyMDI, wxString roomname)
29 : wxMDIChildFrame(MyMDI, //parent
34 wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
38 wxString sendcmd, recvcmd, xferbuf, buf;
42 message_window = NULL;
44 if (citsock->GotoRoom(roomname, "", recvcmd) != TRUE) {
49 // Learn more about this room by sending away for a free brochure,
50 // or by simply parsing the returned parameters from GotoRoom().
52 extract(ThisRoom, recvcmd.Mid(4), 0); // actual name of room
53 new_messages = extract_int(recvcmd.Mid(4), 1);
54 total_messages = extract_int(recvcmd.Mid(4), 2);
55 RoomFlags = extract_int(recvcmd.Mid(4), 4);
56 is_roomaide = (extract_int(recvcmd.Mid(4), 8) ? TRUE : FALSE);
58 SetTitle(ThisRoom); // FIX why doesn't this work?
63 // Set up a top panel for the room banner...
64 banner = new wxPanel(this, -1);
65 banner->SetBackgroundColour(wxColour(0x00, 0x00, 0x77));
66 banner->SetForegroundColour(wxColour(0xFF, 0xFF, 0x00));
68 wxLayoutConstraints *b1 = new wxLayoutConstraints;
69 b1->top.SameAs(this, wxTop, 2);
70 b1->left.SameAs(this, wxLeft, 2);
71 b1->right.SameAs(this, wxRight, 2);
72 b1->height.PercentOf(this, wxHeight, 25);
73 banner->SetConstraints(b1);
75 // Room name in the banner
76 wxStaticText *rname = new wxStaticText(banner, -1, ThisRoom);
77 rname->SetFont(wxFont(18, wxDEFAULT, wxNORMAL, wxNORMAL));
78 rname->SetForegroundColour(wxColour(0xFF, 0xFF, 0x00));
80 wxLayoutConstraints *b2 = new wxLayoutConstraints;
81 b2->top.SameAs(banner, wxTop, 1);
82 b2->left.SameAs(banner, wxLeft, 1);
83 b2->width.PercentOf(banner, wxWidth, 50);
84 b2->height.PercentOf(banner, wxHeight, 50);
85 rname->SetConstraints(b2);
87 // Message counts in the banner
88 wxString *mcount_text = new wxString;
89 mcount_text->Printf("%d messages\n%d new",
90 total_messages, new_messages);
91 wxStaticText *mcount = new wxStaticText(banner, -1, *mcount_text);
93 wxLayoutConstraints *c0 = new wxLayoutConstraints;
94 c0->top.Below(rname, 5);
95 c0->left.SameAs(rname, wxLeft);
98 mcount->SetConstraints(c0);
100 // HTML window containing room info blurb
101 wxHtmlWindow *roominfo = new wxHtmlWindow(banner);
103 wxLayoutConstraints *b3 = new wxLayoutConstraints;
104 b3->top.SameAs(banner, wxTop);
105 b3->bottom.SameAs(banner, wxBottom);
106 b3->right.SameAs(banner, wxRight);
107 b3->left.PercentOf(banner, wxWidth, 67);
108 roominfo->SetConstraints(b3);
111 close_button = new wxButton(
117 wxLayoutConstraints *c1 = new wxLayoutConstraints;
118 c1->bottom.SameAs(this, wxBottom, 2);
121 c1->right.SameAs(this, wxRight, 2);
122 close_button->SetConstraints(c1);
124 wxButton *goto_button = new wxButton(
130 wxLayoutConstraints *g2 = new wxLayoutConstraints;
131 g2->top.SameAs(close_button, wxTop);
132 g2->bottom.SameAs(close_button, wxBottom);
134 g2->right.LeftOf(close_button, 3);
135 goto_button->SetConstraints(g2);
137 wxButton *skip_button = new wxButton(
143 wxLayoutConstraints *g3 = new wxLayoutConstraints;
144 g3->top.SameAs(goto_button, wxTop);
145 g3->bottom.SameAs(goto_button, wxBottom);
147 g3->right.LeftOf(goto_button, 3);
148 skip_button->SetConstraints(g3);
150 /* wxButton *readnew_button = new wxButton(
156 wxLayoutConstraints *c2 = new wxLayoutConstraints;
157 c2->top.SameAs(skip_button, wxTop);
158 c2->bottom.SameAs(skip_button, wxBottom);
160 c2->right.LeftOf(skip_button, 3);
161 readnew_button->SetConstraints(c2); */
163 wxButton *readall_button = new wxButton(
169 wxLayoutConstraints *c2 = new wxLayoutConstraints;
170 c2->top.SameAs(skip_button, wxTop);
171 c2->bottom.SameAs(skip_button, wxBottom);
173 c2->right.LeftOf(skip_button, 3);
174 readall_button->SetConstraints(c2);
176 wxButton *enter_button = new wxButton(
182 wxLayoutConstraints *c4 = new wxLayoutConstraints;
183 c4->top.SameAs(readall_button, wxTop);
184 c4->bottom.SameAs(readall_button, wxBottom);
186 c4->right.LeftOf(readall_button, 3);
187 enter_button->SetConstraints(c4);
189 wxButton *zap_button = new wxButton(
194 wxLayoutConstraints *c5 = new wxLayoutConstraints;
195 c5->top.SameAs(enter_button, wxTop);
196 c5->bottom.SameAs(enter_button, wxBottom);
198 c5->right.LeftOf(enter_button, 3);
199 zap_button->SetConstraints(c5);
205 if (citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom) == 1) {
206 variformat_to_html(buf, xferbuf, FALSE);
212 hbuf = "<HTML><BODY TEXT=#FFFF00 BGCOLOR=#000077>";
213 hbuf += "<FONT SIZE=-1>";
215 hbuf += "</FONT></BODY></HTML>";
216 roominfo->SetPage(hbuf);
218 do_readloop("MSGS NEW"); // FIX make this configurable
223 void RoomView::OnButtonPressed(wxCommandEvent& whichbutton) {
224 wxString sendcmd, recvcmd, xferbuf;
226 if (whichbutton.GetId() == BUTTON_CLOSE) {
228 /* } else if (whichbutton.GetId() == BUTTON_READNEW) {
229 if (citadel->IsConnected()==FALSE) {
230 wxMessageBox("You are not connected to a BBS.");
231 do_readloop("MSGS NEW"); */
232 } else if (whichbutton.GetId() == BUTTON_READALL) {
233 if (citadel->IsConnected()==FALSE) {
234 wxMessageBox("You are not connected to a BBS.");
237 do_readloop("MSGS ALL");
238 } else if (whichbutton.GetId() == BUTTON_ENTER) {
239 if (citadel->IsConnected()==FALSE) {
240 wxMessageBox("You are not connected to a BBS.");
243 new EnterMessage(citsock, citMyMDI, ThisRoom, RoomFlags);
244 } else if (whichbutton.GetId() == BUTTON_SKIP) {
245 if (citadel->IsConnected()==FALSE) {
246 wxMessageBox("You are not connected to a BBS.");
249 new RoomView(citsock, citMyMDI, RoomList->GetNextRoom());
251 } else if (whichbutton.GetId() == BUTTON_GOTO) {
252 if (citadel->IsConnected()==FALSE) {
253 wxMessageBox("You are not connected to a BBS.");
257 sendcmd = "SLRP HIGHEST"; // mark messages as read
258 citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom);
259 new RoomView(citsock, citMyMDI, RoomList->GetNextRoom());
262 } else if (whichbutton.GetId() == BUTTON_ZAP) {
263 if (citadel->IsConnected()==FALSE) {
264 wxMessageBox("You are not connected to a BBS.");
267 sendcmd = "FORG"; //Zap (forget) room
268 citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom);
269 new RoomView(citsock, citMyMDI, "_BASEROOM_");
270 RoomList->LoadRoomList();
276 void RoomView::do_readloop(wxString readcmd) {
278 wxString sendcmd, recvcmd, buf, allmsgs;
283 if (citadel->IsConnected()==FALSE) {
284 wxMessageBox("You have lost your connection.");
287 // Transmit the "read messages" command
289 if (citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom) != 1) {
290 wxMessageDialog cantread(this,
293 wxOK | wxCENTRE | wxICON_INFORMATION,
295 cantread.ShowModal();
300 // Read the messages into the window, one at a time
301 allmsgs = "<HTML><BODY>";
303 while (pos = xferbuf.Find('\n', FALSE), (pos >= 0)) {
305 buf.Printf("Reading message %d", ++i);
306 citMyMDI->SetStatusText(buf, 0);
309 buf = xferbuf.Left(pos);
310 xferbuf = xferbuf.Mid(pos+1);
312 sendcmd = "MSG0 " + buf;
313 message = new CitMessage(citsock, sendcmd, ThisRoom);
315 allmsgs += generate_html_header(message, ThisRoom,
317 allmsgs += message->msgtext;
323 citMyMDI->SetStatusText("Done", 0);
324 allmsgs += "</BODY></HTML>";
326 message_window = new wxHtmlWindow(this);
329 wxLayoutConstraints *m1 = new wxLayoutConstraints;
330 m1->top.Below(banner, 2);
331 m1->bottom.Above(close_button, -2);
332 m1->left.SameAs(this, wxLeft, 2);
333 m1->right.SameAs(this, wxRight, 2);
334 message_window->SetConstraints(m1);
336 message_window->SetPage(allmsgs);