]> code.citadel.org Git - citadel.git/blob - daphne/includes.hpp
* citclient.cpp: different IDEN string depending on __WXMSW__ etc.
[citadel.git] / daphne / includes.hpp
1 // $Id$
2
3 #include <wx/wx.h>              // General-purpose wxWin header
4 #include <wx/listctrl.h>
5 #include <wx/socket.h>          // TCP socket client
6 #include <wx/log.h>
7 #include <wx/imaglist.h>
8 #include <wx/treectrl.h>
9 #include <wx/toolbar.h>
10 #include <wx/tokenzr.h>         // For the string tokenizer
11 #include <wx/thread.h>          // No threads, but we need wxCriticalSection
12 #include <wx/wxhtml.h>          // Vaclav Slavik's HTML display widget
13
14 #define MAXFLOORS       128
15 #define DEFAULT_HOST    "uncnsrd.mt-kisco.ny.us"
16 #define DEFAULT_PORT    "504"
17
18
19 // Room flags (from ipcdef.h in the main Citadel distribution)
20
21 #define QR_PERMANENT    1               /* Room does not purge              */
22 #define QR_INUSE        2               /* Set if in use, clear if avail    */
23 #define QR_PRIVATE      4               /* Set for any type of private room */
24 #define QR_PASSWORDED   8               /* Set if there's a password too    */
25 #define QR_GUESSNAME    16              /* Set if it's a guessname room     */
26 #define QR_DIRECTORY    32              /* Directory room                   */
27 #define QR_UPLOAD       64              /* Allowed to upload                */
28 #define QR_DOWNLOAD     128             /* Allowed to download              */
29 #define QR_VISDIR       256             /* Visible directory                */
30 #define QR_ANONONLY     512             /* Anonymous-Only room              */
31 #define QR_ANONOPT      1024            /* Anonymous-Option room            */
32 #define QR_NETWORK      2048            /* Shared network room              */
33 #define QR_PREFONLY     4096            /* Preferred status needed to enter */
34 #define QR_READONLY     8192            /* Aide status required to post     */
35 #define QR_MAILBOX      16384           /* Set if this is a private mailbox */
36
37
38
39
40 // CitClient represents an application-level connection to a Citadel server.
41 class CitClient {
42 public:
43         CitClient(void);
44         ~CitClient(void);
45
46         // Citadel session-layer commands
47         int attach(wxString host, wxString port);
48         void detach(void);
49         bool IsConnected(void);
50         int CitClient::serv_trans(
51                         wxString& command,
52                         wxString& response,
53                         wxString& xferbuf,
54                         wxString desired_room
55                         );
56         int CitClient::serv_trans(
57                         wxString& command,
58                         wxString& response,
59                         wxString& xferbuf
60                         );
61         int CitClient::serv_trans(wxString& command, wxString& response);
62         int CitClient::serv_trans(wxString& command);
63
64         // Citadel presentation-layer commands
65         bool CitClient::GotoRoom(wxString roomname, wxString password,
66                                 wxString& server_response);
67
68         // Various things we learn about the server ...
69         int SessionID;
70         wxString NodeName;
71         wxString HumanNode;
72         wxString FQDN;
73         wxString ServerSoftware;
74         int ServerRev;
75         wxString GeoLocation;
76         wxString SysAdmin;
77         int ServerType;
78         wxString MorePrompt;
79         bool UseFloors;
80         int PagingLevel;
81
82         // ... and about the user ...
83         wxString curr_user;
84         wxString curr_pass;
85         int axlevel;
86         
87         // Stuff we have to keep track of ...
88         wxString CurrentRoom;
89
90 private:
91         wxSocketClient *sock;                           // transport layer
92         wxCriticalSection Critter;
93         void serv_gets(wxString& buf);                  // session layer
94         void serv_puts(wxString buf);                   // session layer
95         void reconnect_session(void);                   // session layer
96         void download_express_messages(void);           // presentation layer
97         void initialize_session(void);                  // presentation layer
98         wxString curr_host;
99         wxString curr_port;
100 };
101
102
103
104
105 // This is a timer that does keepalives...
106 class keepalive : public wxTimer {
107 public:
108         keepalive(CitClient *sock);
109 private:
110         CitClient *which_sock;
111         void Notify(void);
112 };
113
114
115 // Receive an express message (page)
116 class express_message : public wxFrame {
117 public:
118         express_message(CitClient *sock, wxString sender,
119                 wxString sendsys, wxString msg);
120 private:
121         void OnButtonPressed(wxCommandEvent& whichbutton);
122         CitClient *citsock;
123         wxString reply_to;
124         DECLARE_EVENT_TABLE()
125 };
126
127
128
129
130 // SendExpress is the screen for sending an express message (page).
131
132 class SendExpress : public wxMDIChildFrame {
133 public:
134         SendExpress(    CitClient *sock,
135                         wxMDIParentFrame *MyMDI, 
136                         wxString touser);
137 private:
138         void OnButtonPressed(wxCommandEvent& whichbutton);
139         CitClient *citsock;
140         wxMDIParentFrame *citMyMDI;
141         wxListBox *ToWhom;
142         wxTextCtrl *TheMessage;
143         DECLARE_EVENT_TABLE()
144 };
145
146
147 // Preferences for the application.
148
149 class Preferences : public wxMDIChildFrame {
150 public:
151         Preferences(    CitClient *sock,
152                         wxMDIParentFrame *MyMDI);
153 private:
154         void OnButtonPressed(wxCommandEvent& whichbutton);
155         CitClient *citsock;
156         wxMDIParentFrame *citMyMDI;
157         wxTextCtrl *server_host, *server_port;
158         wxCheckBox *server_autoconnect;
159         DECLARE_EVENT_TABLE()
160 };
161
162
163
164 class Hosts : public wxMDIChildFrame {
165 public:
166         Hosts(    CitClient *sock, 
167                         wxMDIParentFrame *MyMDI);
168 private:
169         void OnButtonPressed(wxCommandEvent& whichbutton);
170         CitClient *citsock;
171         wxMDIParentFrame *citMyMDI;
172         wxTextCtrl *server_host, *server_port;
173         wxCheckBox *server_autoconnect;
174         DECLARE_EVENT_TABLE()
175 };
176
177 // Just testing...
178 class TestWindow : public wxMDIChildFrame {
179 public:
180         TestWindow(CitClient *sock, wxMDIParentFrame *MyMDI);
181 private:
182         wxPanel *panel;
183         wxTextCtrl *sendcmd;
184         wxTextCtrl *recvcmd;
185         wxTextCtrl *xfercmd;
186         wxButton *cmd_button;
187         wxButton *close_button;
188         void OnButtonPressed(wxCommandEvent& whichbutton);
189         CitClient *citsock;
190         DECLARE_EVENT_TABLE()
191 };
192
193 // Just testing...
194 class ChatWindow : public wxMDIChildFrame {
195 public:
196         ChatWindow(CitClient *sock, wxMDIParentFrame *MyMDI);
197 private:
198         wxPanel *panel;
199         wxTextCtrl *sendcmd;
200         wxTextCtrl *recvcmd;
201         wxTextCtrl *xfercmd;
202         wxButton *cmd_button;
203         wxButton *close_button;
204         void OnButtonPressed(wxCommandEvent& whichbutton);
205         CitClient *citsock;
206         DECLARE_EVENT_TABLE()
207 };
208
209
210
211 // userlogin is the frame for logging in.
212 class UserLogin : public wxMDIChildFrame {
213 public:
214         UserLogin(CitClient *sock, wxMDIParentFrame *MyMDI);
215         int do_login();
216 private:
217         wxPanel *panel;
218         wxTextCtrl *username;
219         wxTextCtrl *password;
220         wxButton *login_button;
221         wxButton *newuser_button;
222         wxButton *exit_button;
223         void OnButtonPressed(wxCommandEvent& whichbutton);
224         void UserLogin::BeginSession(wxString serv_response);
225         CitClient *citsock;
226         wxMDIParentFrame *citMyMDI;
227         DECLARE_EVENT_TABLE()
228 };
229
230
231 // Who is online?
232 class who : public wxMDIChildFrame {
233 public:
234         who(CitClient *sock, wxMDIParentFrame *MyMDI);
235         int do_login();
236         void LoadWholist();
237 private:
238         void OnButtonPressed(wxCommandEvent& whichbutton);
239         CitClient *citsock;
240         wxListCtrl *wholist;
241         DECLARE_EVENT_TABLE()
242 };
243
244
245 // This is a timer that periodically refreshes the wholist.
246 class who_refresh : public wxTimer {
247 public:
248         who_refresh(who *parent_who);
249 private:
250         who *which_who;
251         void Notify(void);
252 };
253
254
255 // Global server properties
256
257 class ServProps : public wxMDIChildFrame {
258 public:
259         ServProps(      CitClient *sock,
260                         wxMDIParentFrame *MyMDI,
261                         wxString WhichPanel);
262         void ChangePanel(wxString WhichPanel);
263 private:
264         void OnButtonPressed(wxCommandEvent& whichbutton);
265         CitClient *citsock;
266         wxMDIParentFrame *citMyMDI;
267         wxPanel *identity_panel, *network_panel, *security_panel;
268         wxString ServerConfigStrings[20];
269         void LoadServerConfigStrings(void);
270         void SaveServerConfigStrings(void);
271         DECLARE_EVENT_TABLE()
272 };
273
274
275
276 // The ever-present tree of floors and rooms
277
278 class RoomTree : public wxTreeCtrl {
279 public:
280         RoomTree(wxMDIParentFrame *parent, CitClient *sock);
281         void LoadRoomList(void);
282         wxString GetNextRoom(void);
283 private:
284         wxTreeItemId GetNextRoomId(void);
285         void InitTreeIcons(void);
286         void OnDoubleClick(wxTreeEvent& evt);
287         CitClient *citsock;
288         wxMDIParentFrame *citMyMDI;
289         wxTreeItemId floorboards[MAXFLOORS];
290         wxImageList *TreeIcons;
291         wxTreeItemId march_next;
292         ServProps *CurrServProps;
293         DECLARE_EVENT_TABLE()
294 };
295
296
297
298 // A window representing an open room.
299 class RoomView : public wxMDIChildFrame {
300 public:
301         RoomView(CitClient *sock, wxMDIParentFrame *MyMDI, wxString roomname);
302 private:
303         void OnButtonPressed(wxCommandEvent& whichbutton);
304         CitClient *citsock;
305         void do_readloop(wxString readcmd);
306         wxMDIParentFrame *citMyMDI;
307         wxHtmlWindow *message_window;
308         wxPanel *banner;
309         wxButton *close_button;
310         wxString ThisRoom;
311         unsigned int RoomFlags;
312         unsigned int new_messages;
313         unsigned int total_messages;
314         bool is_roomaide;
315         DECLARE_EVENT_TABLE()
316 };
317
318
319 class SelectUser : public wxPanel {
320 public:
321         SelectUser(CitClient *, wxWindow *, wxString,
322                 wxString, unsigned int, wxTextCtrl *);
323 private:
324         void OnButtonPressed(wxCommandEvent& whichbutton);
325         void AddLocalUsers(wxTreeCtrl *, CitClient *);
326         wxButton select_button;
327         wxButton cancel_button;
328         CitClient *citsock;
329         wxTextCtrl *target_textctrl;
330         wxTreeCtrl *TheTree;
331         DECLARE_EVENT_TABLE()
332 };
333
334
335
336 class EnterMessage : public wxMDIChildFrame {
337 public:
338         EnterMessage(CitClient *sock,  
339         wxMDIParentFrame *MyMDI,
340         wxString roomname, unsigned int roomflags);
341 private:
342         void OnCancel(wxCommandEvent& whichbutton);
343         void OnSave(wxCommandEvent& whichbutton);
344         void OnFind(wxCommandEvent& whichbutton);
345         CitClient *citsock;
346         wxMDIParentFrame *citMyMDI;
347         wxString ThisRoom;
348         wxChoice *fromname;
349         wxTextCtrl *toname;
350         wxTextCtrl *TheMessage;
351         SelectUser *finduser_panel;
352         DECLARE_EVENT_TABLE()
353 };
354
355
356
357
358
359         
360 // A message.  (This is not a GUI class; it's used for internal
361 // representation.)
362 class CitMessage {
363 public:
364         CitMessage(CitClient *sock, wxString getmsg_cmd, wxString inRoom);
365         wxString author;
366         wxString recipient;
367         long timestamp;
368         wxString room;
369         wxString msgtext;
370         wxString nodename;
371 private:
372         int format_type;
373 };
374
375
376
377 // Stuff from utils.cpp
378
379 void extract(wxString& outputbuf, wxString inputbuf, int parmnum);
380 int extract_int(wxString inputbuf, int parmnum);
381 void load_roomlist(RoomTree *tree, CitClient *citsock);
382 void variformat_to_html(wxString& outputbuf,
383                         wxString inputbuf,
384                         bool add_header_and_footer);
385 wxString generate_html_header(CitMessage *, wxString, wxString);
386
387
388
389 void cleanup(int);
390
391
392
393 // Globals
394
395 extern wxMDIParentFrame *BigMDI;
396 extern RoomTree *RoomList;
397 extern CitClient *citadel;
398 extern wxConfig *ini;