]> code.citadel.org Git - citadel.git/blob - daphne/roomview.cpp
Fixed a broken tag in siteconfig.c
[citadel.git] / daphne / roomview.cpp
1 #include "includes.hpp"
2
3
4 enum {
5         BUTTON_GOTO,
6         BUTTON_SKIP,
7         BUTTON_CLOSE,
8 /*      BUTTON_READNEW, */
9         BUTTON_READALL,
10         BUTTON_ENTER,
11         BUTTON_ZAP 
12 };
13
14
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)
23 END_EVENT_TABLE()
24
25
26 // frame constructor
27 RoomView::RoomView(
28         CitClient *sock, wxMDIParentFrame *MyMDI, wxString roomname)
29         : wxMDIChildFrame(MyMDI,        //parent
30                         -1,     //window id
31                         roomname,
32                         wxDefaultPosition,
33                         wxDefaultSize,
34                         wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
35                         roomname
36                         ) {
37
38         wxString sendcmd, recvcmd, xferbuf, buf;
39
40         citsock = sock;
41         citMyMDI = MyMDI;
42         message_window = NULL;
43
44         if (citsock->GotoRoom(roomname, "", recvcmd) != TRUE) {
45                 delete this;
46         }
47
48
49         // Learn more about this room by sending away for a free brochure,
50         // or by simply parsing the returned parameters from GotoRoom().
51         //
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);
57
58         SetTitle(ThisRoom);     // FIX why doesn't this work?
59
60         SetAutoLayout(TRUE);
61         Show(TRUE);
62
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));
67
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);
74
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));
79
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);
86
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);
92
93         wxLayoutConstraints *c0 = new wxLayoutConstraints;
94         c0->top.Below(rname, 5);
95         c0->left.SameAs(rname, wxLeft);
96         c0->width.AsIs();
97         c0->height.AsIs();
98         mcount->SetConstraints(c0);
99
100         // HTML window containing room info blurb
101         wxHtmlWindow *roominfo = new wxHtmlWindow(banner);
102
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);
109
110         // Buttons
111         close_button = new wxButton(
112                 this,
113                 BUTTON_CLOSE,
114                 " Close ",
115                 wxDefaultPosition);
116
117         wxLayoutConstraints *c1 = new wxLayoutConstraints;
118         c1->bottom.SameAs(this, wxBottom, 2);
119         c1->height.AsIs();
120         c1->width.AsIs();
121         c1->right.SameAs(this, wxRight, 2);
122         close_button->SetConstraints(c1);
123
124         wxButton *goto_button = new wxButton(
125                 this,
126                 BUTTON_GOTO,
127                 " Goto ",
128                 wxDefaultPosition);
129
130         wxLayoutConstraints *g2 = new wxLayoutConstraints;
131         g2->top.SameAs(close_button, wxTop);
132         g2->bottom.SameAs(close_button, wxBottom);
133         g2->width.AsIs();
134         g2->right.LeftOf(close_button, 3);
135         goto_button->SetConstraints(g2);
136
137         wxButton *skip_button = new wxButton(
138                 this,
139                 BUTTON_SKIP,
140                 " Skip ",
141                 wxDefaultPosition);
142
143         wxLayoutConstraints *g3 = new wxLayoutConstraints;
144         g3->top.SameAs(goto_button, wxTop);
145         g3->bottom.SameAs(goto_button, wxBottom);
146         g3->width.AsIs();
147         g3->right.LeftOf(goto_button, 3);
148         skip_button->SetConstraints(g3);
149
150 /*      wxButton *readnew_button = new wxButton(
151                 this,
152                 BUTTON_READNEW,
153                 " Read new ",
154                 wxDefaultPosition); 
155
156         wxLayoutConstraints *c2 = new wxLayoutConstraints;
157         c2->top.SameAs(skip_button, wxTop);
158         c2->bottom.SameAs(skip_button, wxBottom);
159         c2->width.AsIs();
160         c2->right.LeftOf(skip_button, 3);
161         readnew_button->SetConstraints(c2); */
162
163         wxButton *readall_button = new wxButton(
164                 this,
165                 BUTTON_READALL,
166                 " Read all ",
167                 wxDefaultPosition);
168
169         wxLayoutConstraints *c2 = new wxLayoutConstraints;
170         c2->top.SameAs(skip_button, wxTop);
171         c2->bottom.SameAs(skip_button, wxBottom);
172         c2->width.AsIs();
173         c2->right.LeftOf(skip_button, 3);
174         readall_button->SetConstraints(c2);
175
176         wxButton *enter_button = new wxButton(
177                 this,
178                 BUTTON_ENTER,
179                 " Enter ",
180                 wxDefaultPosition);
181
182         wxLayoutConstraints *c4 = new wxLayoutConstraints;
183         c4->top.SameAs(readall_button, wxTop);
184         c4->bottom.SameAs(readall_button, wxBottom);
185         c4->width.AsIs();
186         c4->right.LeftOf(readall_button, 3);
187         enter_button->SetConstraints(c4);
188
189         wxButton *zap_button = new wxButton(
190                 this,
191                 BUTTON_ZAP,
192                 " Zap ",
193                 wxDefaultPosition);
194         wxLayoutConstraints *c5 = new wxLayoutConstraints;
195         c5->top.SameAs(enter_button, wxTop);
196         c5->bottom.SameAs(enter_button, wxBottom);
197         c5->width.AsIs();
198         c5->right.LeftOf(enter_button, 3);
199         zap_button->SetConstraints(c5);
200
201         Layout();
202         wxYield();
203
204         sendcmd = "RINF";
205         if (citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom) == 1) {
206                 variformat_to_html(buf, xferbuf, FALSE);
207         } else {
208                 buf = " ";
209         }
210
211         wxString hbuf;
212         hbuf = "<HTML><BODY TEXT=#FFFF00 BGCOLOR=#000077>";
213         hbuf += "<FONT SIZE=-1>";
214         hbuf += buf;
215         hbuf += "</FONT></BODY></HTML>";
216         roominfo->SetPage(hbuf);
217
218         do_readloop("MSGS NEW");        // FIX make this configurable
219 }
220
221
222
223 void RoomView::OnButtonPressed(wxCommandEvent& whichbutton) {
224         wxString sendcmd, recvcmd, xferbuf;
225
226         if (whichbutton.GetId() == BUTTON_CLOSE) {
227                 delete this;
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.");
235                 return;
236                 } else
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.");
241                 return;
242                 } else
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.");
247                 return;
248                 } else
249                 new RoomView(citsock, citMyMDI, RoomList->GetNextRoom());
250                 delete this;
251         } else if (whichbutton.GetId() == BUTTON_GOTO) {
252                 if (citadel->IsConnected()==FALSE) {
253                 wxMessageBox("You are not connected to a BBS.");
254                 return;
255                 } else
256                 /*delete this; */
257                 sendcmd = "SLRP HIGHEST";       // mark messages as read
258                 citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom);
259                 new RoomView(citsock, citMyMDI, RoomList->GetNextRoom());
260                 delete this;
261
262         } else if (whichbutton.GetId() == BUTTON_ZAP) {
263                 if (citadel->IsConnected()==FALSE) {
264                 wxMessageBox("You are not connected to a BBS.");
265                 return;
266                 } else
267                 sendcmd = "FORG";               //Zap (forget) room
268                 citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom);
269                 new RoomView(citsock, citMyMDI, "_BASEROOM_"); 
270                 RoomList->LoadRoomList();
271                 delete this; 
272         }
273 }
274
275
276 void RoomView::do_readloop(wxString readcmd) {
277
278         wxString sendcmd, recvcmd, buf, allmsgs;
279         wxString xferbuf;
280         int i, r, pos;
281         CitMessage *message;
282         
283         if (citadel->IsConnected()==FALSE) {
284                 wxMessageBox("You have lost your connection.");
285         } 
286
287         // Transmit the "read messages" command
288         sendcmd = readcmd;
289         if (citsock->serv_trans(sendcmd, recvcmd, xferbuf, ThisRoom) != 1) {
290                 wxMessageDialog cantread(this,
291                         recvcmd.Mid(4),
292                         "Error",
293                         wxOK | wxCENTRE | wxICON_INFORMATION,
294                         wxDefaultPosition);
295                 cantread.ShowModal();
296                 return;
297         }
298
299
300         // Read the messages into the window, one at a time
301         allmsgs = "<HTML><BODY>";
302         i = 0;
303         while (pos = xferbuf.Find('\n', FALSE), (pos >= 0)) {
304         
305                 buf.Printf("Reading message %d", ++i);
306                 citMyMDI->SetStatusText(buf, 0);
307                 wxYield();
308                 
309                 buf = xferbuf.Left(pos);
310                 xferbuf = xferbuf.Mid(pos+1);
311
312                 sendcmd = "MSG0 " + buf;
313                 message = new CitMessage(citsock, sendcmd, ThisRoom);
314
315                 allmsgs += generate_html_header(message, ThisRoom,
316                                                 citsock->NodeName);
317                 allmsgs += message->msgtext;
318
319                 allmsgs += "<HR>";
320                 
321                 }
322
323         citMyMDI->SetStatusText("Done", 0);
324         allmsgs += "</BODY></HTML>";
325
326         message_window = new wxHtmlWindow(this);
327         Maximize(TRUE);
328
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);
335
336         message_window->SetPage(allmsgs);
337         Layout();
338
339 }
340
341