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