]> code.citadel.org Git - citadel.git/blob - daphne/enter.cpp
Clarify that we are GPLv2
[citadel.git] / daphne / enter.cpp
1 #include "includes.hpp"
2
3 enum {
4         BUTTON_SAVE,
5         BUTTON_CANCEL,
6         BUTTON_FIND
7 };
8
9
10 BEGIN_EVENT_TABLE(EnterMessage, wxMDIChildFrame)
11         EVT_BUTTON(BUTTON_CANCEL,       EnterMessage::OnCancel)
12         EVT_BUTTON(BUTTON_SAVE,         EnterMessage::OnSave)
13         EVT_BUTTON(BUTTON_FIND,         EnterMessage::OnFind)
14 END_EVENT_TABLE()
15
16
17 // frame constructor
18 EnterMessage::EnterMessage(
19         CitClient *sock, 
20         wxMDIParentFrame *MyMDI,
21         wxString roomname, 
22         unsigned int roomflags) 
23
24         : wxMDIChildFrame(MyMDI,        //parent
25                         -1,     //window id
26                         roomname + ": enter message",
27                         wxDefaultPosition,
28                         wxDefaultSize,
29                         wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
30                         roomname
31                         ) {
32
33         wxString sendcmd, recvcmd;
34
35         citsock = sock;
36         citMyMDI = MyMDI;
37         ThisRoom = roomname;
38         finduser_panel = (SelectUser *) NULL;
39
40         wxButton *cancel_button = new wxButton(
41                 this,
42                 BUTTON_CANCEL,
43                 " Cancel ",
44                 wxDefaultPosition);
45
46         wxLayoutConstraints *c1 = new wxLayoutConstraints;
47         c1->bottom.SameAs(this, wxBottom, 2);
48         c1->height.AsIs();
49         c1->width.AsIs();
50         c1->right.SameAs(this, wxRight, 2);
51         cancel_button->SetConstraints(c1);
52
53         wxButton *save_button = new wxButton(
54                 this,
55                 BUTTON_SAVE,
56                 " Save ",
57                 wxDefaultPosition);
58
59
60         wxLayoutConstraints *c2 = new wxLayoutConstraints;
61         c2->bottom.SameAs(cancel_button, wxBottom);
62         c2->right.LeftOf(cancel_button, 5);
63         c2->height.SameAs(cancel_button, wxHeight);
64         c2->width.AsIs();
65         save_button->SetConstraints(c2);
66
67
68
69
70         // If the user has a choice of several posting names, present them.
71
72         wxStaticText *fromlabel = new wxStaticText(this, -1, "From: ");
73
74         wxLayoutConstraints *c6 = new wxLayoutConstraints;
75         c6->top.SameAs(this, wxTop, 10);
76         c6->left.SameAs(this, wxLeft, 2);
77         c6->width.AsIs();
78         c6->height.AsIs();
79         fromlabel->SetConstraints(c6);
80
81         wxString posting_name_choices[2]; 
82         int num_choices;
83
84         if (roomflags & QR_ANONONLY) {
85                 posting_name_choices[0] = "****";
86                 num_choices = 1;
87         } else {
88                 posting_name_choices[0] = citsock->curr_user;
89                 num_choices = 1;
90         }
91         
92         if (roomflags & QR_ANONOPT) {
93                 posting_name_choices[num_choices++] = "Anonymous";
94         }
95
96         fromname = new wxChoice(this, -1,
97                 wxDefaultPosition, wxSize(150,25),
98                         num_choices, posting_name_choices);
99
100         wxLayoutConstraints *c7 = new wxLayoutConstraints;
101         c7->centreY.SameAs(fromlabel, wxCentreY);
102         c7->left.RightOf(fromlabel, 3);
103         c7->width.AsIs();
104         c7->height.AsIs();
105         fromname->SetConstraints(c7);
106
107
108
109         // There may also be the opportunity to present a recipient.
110         // FIX ... disable this if we're not in a mail room 
111
112         wxStaticText *tolabel = new wxStaticText(this, -1, "To: ");
113
114         wxLayoutConstraints *c8 = new wxLayoutConstraints;
115         c8->centreY.SameAs(fromname, wxCentreY);
116         c8->left.RightOf(fromname, 5);
117         c8->width.AsIs();
118         c8->height.AsIs();
119         tolabel->SetConstraints(c8);
120
121         toname = new wxTextCtrl(this, -1, "",
122                 wxDefaultPosition, wxSize(150,25));
123         
124         wxLayoutConstraints *c9 = new wxLayoutConstraints;
125         c9->centreY.SameAs(tolabel, wxCentreY);
126         c9->left.RightOf(tolabel, 3);
127         c9->width.AsIs();
128         c9->height.AsIs();
129         toname->SetConstraints(c9);
130
131         wxButton *findrecp = new wxButton(
132                 this,
133                 BUTTON_FIND,
134                 " Find "
135                 );
136
137         wxLayoutConstraints *d1 = new wxLayoutConstraints;
138         d1->centreY.SameAs(toname, wxCentreY);
139         d1->left.RightOf(toname, 3);
140         d1->width.AsIs();
141         d1->height.AsIs();
142         findrecp->SetConstraints(d1);
143
144
145
146         // The main portion of this screen is a text entry box.
147
148         TheMessage = new wxTextCtrl(this, -1, "",
149                 wxDefaultPosition, wxDefaultSize,
150                 wxTE_MULTILINE);
151
152         wxLayoutConstraints *d9 = new wxLayoutConstraints;
153         d9->top.Below(fromname, 2);
154         d9->bottom.Above(cancel_button, -5);
155         d9->left.SameAs(this, wxLeft, 2);
156         d9->right.SameAs(this, wxRight, 2);
157         TheMessage->SetConstraints(d9);
158
159
160
161         SetAutoLayout(TRUE);
162         Show(TRUE);
163         Layout();
164 }
165
166
167
168 void EnterMessage::OnCancel(wxCommandEvent& whichbutton) {
169         delete this;
170 }
171
172
173 // The user clicked "Find" ... so we have to go looking for a recipient.
174 // Shove a FindUser panel right in front of everything else.
175 //
176 void EnterMessage::OnFind(wxCommandEvent& whichbutton) {
177         finduser_panel = new SelectUser(citsock, this,
178                                 "Please select a recipient",
179                                 "Recipients",
180                                 0,
181                                 toname);
182
183         wxLayoutConstraints *f1 = new wxLayoutConstraints;
184         f1->centreX.SameAs(this, wxCentreX);
185         f1->centreY.SameAs(this, wxCentreY);
186         f1->width.SameAs(this, wxWidth);
187         f1->height.SameAs(this, wxHeight);
188         finduser_panel->SetConstraints(f1);
189         Layout();
190 }
191
192
193 void EnterMessage::OnSave(wxCommandEvent& whichbutton) {
194         wxString sendcmd, recvcmd, xferbuf;
195
196         sendcmd = "ENT0 1|" + toname->GetValue() + "|"
197                 + ((!fromname->GetString(fromname->GetSelection()).CmpNoCase("Anonymous")) ? "1" : "0")
198                 + "|0" ;
199         xferbuf = TheMessage->GetValue();
200         if (citsock->serv_trans(sendcmd, recvcmd,
201                                 xferbuf, ThisRoom) == 4) {
202                 delete this;
203         } else {
204                 // Display the error message
205                 wxMessageDialog save_error(this,
206                         recvcmd.Mid(4),
207                         "Error",
208                         wxOK | wxCENTRE | wxICON_INFORMATION,
209                         wxDefaultPosition);
210                         save_error.ShowModal();
211
212         }
213 }