1 // ============================================================================
3 // ============================================================================
5 #include "includes.hpp"
7 // ----------------------------------------------------------------------------
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
15 // IDs for the controls and the menu commands
22 // ----------------------------------------------------------------------------
23 // event tables and other macros for wxWindows
24 // ----------------------------------------------------------------------------
26 // the event tables connect the wxWindows events with the functions (event
27 // handlers) which process them. It can be also done at run-time, but for the
28 // simple menu events like this the static method is much simpler.
29 BEGIN_EVENT_TABLE( who, wxMDIChildFrame)
30 EVT_BUTTON( BUTTON_REFRESH, who::OnButtonPressed)
31 EVT_BUTTON( BUTTON_CLOSE, who::OnButtonPressed)
34 // ============================================================================
36 // ============================================================================
39 // ----------------------------------------------------------------------------
40 // the application class
41 // ----------------------------------------------------------------------------
44 who::who(CitClient *sock, wxMDIParentFrame *MyMDI)
45 : wxMDIChildFrame(MyMDI, //parent
50 wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
58 /* who_refresh *ref = new who_refresh(this);
59 if(!this) { delete this; } */
62 /* SetIcon(wxICON(mondrian)); */
64 wholist = new wxListCtrl(
66 -1, // replace this eventually with something active
69 wxLC_REPORT, // multicolumn
74 wxButton *refresh_button = new wxButton(
85 wxButton *close_button = new wxButton(
97 wxLayoutConstraints *c1 = new wxLayoutConstraints;
98 c1->top.SameAs(this, wxTop, 10); // 10 from the top
100 c1->bottom.SameAs(this, wxBottom, 40);
103 c1->bottom.SameAs(this, wxBottom, 10);
105 c1->left.SameAs(this, wxLeft, 10);
106 c1->right.SameAs(this, wxRight, 10);
107 wholist->SetConstraints(c1);
109 wholist->InsertColumn(0, "Session", wxLIST_FORMAT_CENTER, 60);
110 wholist->InsertColumn(1, "User name", wxLIST_FORMAT_CENTER, 150);
111 wholist->InsertColumn(2, "Room", wxLIST_FORMAT_CENTER, 150);
112 wholist->InsertColumn(3, "From host", wxLIST_FORMAT_CENTER, 150);
114 wxLayoutConstraints *c2 = new wxLayoutConstraints;
115 c2->bottom.SameAs(this, wxBottom, 10);
116 c2->centreX.SameAs(this, wxCentreX);
117 c2->height.AsIs(); c2->width.AsIs();
119 wxLayoutConstraints *b1 = new wxLayoutConstraints;
120 b1->bottom.SameAs(this, wxBottom, 2);
123 b1->right.SameAs(this, wxRight, 10);
124 close_button->SetConstraints(b1);
126 wxLayoutConstraints *b2 = new wxLayoutConstraints;
127 b2->bottom.SameAs(close_button, wxBottom);
128 b2->left.SameAs(this, wxLeft, 10);
131 refresh_button->SetConstraints(b2);
141 void who::OnButtonPressed(wxCommandEvent& whichbutton) {
144 if (whichbutton.GetId() == BUTTON_CLOSE) {
145 wholist->DeleteAllItems();
148 if (whichbutton.GetId() == BUTTON_REFRESH) {
152 // Load up the control
153 void who::LoadWholist(void) {
156 wxString sendcmd, recvcmd, buf;
159 wxString sess, user, room, host;
160 wxStringTokenizer *wl;
164 if (citadel->IsConnected()==FALSE) {
165 wxMessageBox("You are not connected to a BBS.");
166 wholist->DeleteAllItems();
172 if (citsock->serv_trans(sendcmd, recvcmd, rwho) != 1) return;
173 wholist->DeleteAllItems();
175 wl = new wxStringTokenizer(rwho, "\n", FALSE);
176 while (wl->HasMoreTokens()) {
177 buf = wl->NextToken();
178 extract(sess, buf, 0);
179 extract(user, buf, 1);
180 extract(room, buf, 2);
181 extract(host, buf, 3);
182 wholist->InsertItem(i, sess);
183 wholist->SetItem(i, 1, user);
184 wholist->SetItem(i, 2, room);
185 wholist->SetItem(i, 3, host);
193 /*who_refresh::who_refresh(who *parent_who)
197 if (citadel->IsConnected()==FALSE) {
202 which_who = parent_who; // Know which instance to refresh
204 Start(15000, FALSE); // Call every 30 seconds
208 void who_refresh::Notify(void) {
210 which_who->LoadWholist();