]> code.citadel.org Git - citadel.git/blob - daphne/who.cpp
further format string cleanups (for i686-linux type sizes)
[citadel.git] / daphne / who.cpp
1 // ============================================================================
2 // declarations
3 // ============================================================================
4
5 #include "includes.hpp"
6
7 // ----------------------------------------------------------------------------
8 // private classes
9 // ----------------------------------------------------------------------------
10
11 // ----------------------------------------------------------------------------
12 // constants
13 // ----------------------------------------------------------------------------
14
15 // IDs for the controls and the menu commands
16 enum
17 {
18         BUTTON_REFRESH,
19         BUTTON_CLOSE,
20 };
21
22 // ----------------------------------------------------------------------------
23 // event tables and other macros for wxWindows
24 // ----------------------------------------------------------------------------
25
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)
32 END_EVENT_TABLE()
33
34 // ============================================================================
35 // implementation
36 // ============================================================================
37
38
39 // ----------------------------------------------------------------------------
40 // the application class
41 // ----------------------------------------------------------------------------
42
43 // frame constructor
44 who::who(CitClient *sock, wxMDIParentFrame *MyMDI)
45        : wxMDIChildFrame(MyMDI, //parent
46                         -1,     //window id
47                         "Who is online?",
48                         wxDefaultPosition,
49                         wxDefaultSize,
50                         wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
51                         "who"
52                         ) {
53
54
55         citsock = sock;
56
57
58 /*      who_refresh *ref = new who_refresh(this); 
59         if(!this) { delete this; }  */
60
61         // set the frame icon
62         /* SetIcon(wxICON(mondrian)); */
63
64         wholist = new wxListCtrl(
65                 this,
66                 -1,     // replace this eventually with something active
67                 wxDefaultPosition,
68                 wxDefaultSize,
69                 wxLC_REPORT,            // multicolumn
70                 wxDefaultValidator,
71                 "wholist");
72
73
74         wxButton *refresh_button = new wxButton(
75                 this,
76                 BUTTON_REFRESH,
77                 "Refresh",
78                 wxPoint(100,100),
79                 wxSize(100,30),
80                 0L,
81                 wxDefaultValidator,
82                 "refresh_button"
83                 );
84
85         wxButton *close_button = new wxButton(
86                 this,
87                 BUTTON_CLOSE,
88                 "Close",
89                 wxPoint(200,200),
90                 wxSize(100,30),
91                 0L,
92                 wxDefaultValidator,
93                 "close_button"
94                 );
95
96         
97         wxLayoutConstraints *c1 = new wxLayoutConstraints;
98         c1->top.SameAs(this, wxTop, 10);                // 10 from the top
99 #ifdef __WXMSW__
100         c1->bottom.SameAs(this, wxBottom, 40);
101 #endif
102 #ifdef __WXGTK__
103         c1->bottom.SameAs(this, wxBottom, 10);
104 #endif
105         c1->left.SameAs(this, wxLeft, 10);
106         c1->right.SameAs(this, wxRight, 10);
107         wholist->SetConstraints(c1);
108
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);
113
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();
118
119         wxLayoutConstraints *b1 = new wxLayoutConstraints;
120         b1->bottom.SameAs(this, wxBottom, 2);
121         b1->height.AsIs(); 
122         b1->width.AsIs();
123         b1->right.SameAs(this, wxRight, 10);
124         close_button->SetConstraints(b1);
125
126         wxLayoutConstraints *b2 = new wxLayoutConstraints;
127         b2->bottom.SameAs(close_button, wxBottom);
128         b2->left.SameAs(this, wxLeft, 10);
129         b2->height.AsIs(); 
130         b2->width.AsIs();
131         refresh_button->SetConstraints(b2);
132
133         SetAutoLayout(TRUE);
134         Maximize(TRUE);
135         Show(TRUE);
136         LoadWholist();
137         Layout();
138 }
139
140
141 void who::OnButtonPressed(wxCommandEvent& whichbutton) {
142
143
144         if (whichbutton.GetId() == BUTTON_CLOSE) {
145         wholist->DeleteAllItems();      
146         delete this;
147 }
148         if (whichbutton.GetId() == BUTTON_REFRESH) {
149         LoadWholist(); 
150 }
151 }
152 // Load up the control
153 void who::LoadWholist(void) {
154
155
156         wxString sendcmd, recvcmd, buf;
157         wxString rwho;
158         int i = 0;
159         wxString sess, user, room, host;
160         wxStringTokenizer *wl;
161
162                 if (wholist==NULL) {
163                 return; }
164                 if (citadel->IsConnected()==FALSE) { 
165                 wxMessageBox("You are not connected to a BBS."); 
166                 wholist->DeleteAllItems();
167                 return; 
168         } else 
169
170
171         sendcmd = "RWHO";
172         if (citsock->serv_trans(sendcmd, recvcmd, rwho) != 1) return;
173         wholist->DeleteAllItems();
174
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);
186                 ++i;
187         }
188    }
189
190
191
192
193 /*who_refresh::who_refresh(who *parent_who)
194         : wxTimer() {
195
196                 if(!this) {
197                 if (citadel->IsConnected()==FALSE) {
198                 Stop(); 
199                 delete this;
200         } else 
201
202         which_who = parent_who;         // Know which instance to refresh
203
204         Start(15000, FALSE);            // Call every 30 seconds
205
206
207
208 void who_refresh::Notify(void)  {
209
210         which_who->LoadWholist();
211
212
213 */