]> code.citadel.org Git - citadel.git/blob - daphne/servprops.cpp
automake build is now a branch
[citadel.git] / daphne / servprops.cpp
1 // =========================================================================
2 // declarations
3 // =========================================================================
4
5 #include "includes.hpp"
6
7 // ----------------------------------------------------------------------------
8 // constants
9 // ----------------------------------------------------------------------------
10
11 // IDs for the controls and the menu commands
12 enum {
13         BUTTON_SAVE,
14         BUTTON_CANCEL,
15 };
16
17 // ----------------------------------------------------------------------------
18 // event tables and other macros for wxWindows
19 // ----------------------------------------------------------------------------
20
21 BEGIN_EVENT_TABLE(ServProps, wxMDIChildFrame)
22         EVT_BUTTON(BUTTON_SAVE,         ServProps::OnButtonPressed)
23         EVT_BUTTON(BUTTON_CANCEL,       ServProps::OnButtonPressed)
24 END_EVENT_TABLE()
25
26 // ============================================================================
27 // implementation
28 // ============================================================================
29
30 // frame constructor
31 ServProps::ServProps(CitClient * sock,
32           wxMDIParentFrame * MyMDI,
33           wxString WhichPanel)
34         :wxMDIChildFrame(MyMDI, //parent
35                  -1,            //window id
36                  " Server properties ",
37                 wxDefaultPosition,
38                 wxDefaultSize,
39                 wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
40                 "ServProps"
41 )
42 {
43
44         wxString buf;
45
46         citsock = sock;
47         citMyMDI = MyMDI;
48
49         // set the frame icon
50         /* SetIcon(wxICON(mondrian)); */
51
52         wxButton *save_button = new wxButton(
53                                 this,
54                                 BUTTON_SAVE,
55                                 "Save",
56                                 wxPoint(200, 200),
57                                 wxSize(100, 30),
58                                 0L,
59                                 wxDefaultValidator,
60                                 "save_button"
61         );
62
63         wxButton *cancel_button = new wxButton(
64                                 this,
65                                 BUTTON_CANCEL,
66                                 "Cancel",
67                                 wxPoint(300, 300),
68                                 wxSize(100, 30),
69                                 0L,
70                                 wxDefaultValidator,
71                                 "cancel_button"
72         );
73
74         wxLayoutConstraints *c1 = new wxLayoutConstraints;
75         c1->bottom.SameAs(this, wxBottom, 5);
76         c1->left.SameAs(this, wxLeft, 10);
77         c1->height.AsIs();
78         c1->width.AsIs();
79         save_button->SetConstraints(c1);
80
81         wxLayoutConstraints *c3 = new wxLayoutConstraints;
82         c3->bottom.SameAs(save_button, wxBottom);
83         c3->right.SameAs(this, wxRight, 10);
84         c3->height.AsIs();
85         c3->width.AsIs();
86         cancel_button->SetConstraints(c3);
87
88         identity_panel = new wxPanel(this, -1);
89         network_panel = new wxPanel(this, -1);
90         security_panel = new wxPanel(this, -1);
91
92         wxLayoutConstraints *c4 = new wxLayoutConstraints;
93         c4->top.SameAs(this, wxTop);
94         c4->left.SameAs(this, wxLeft);
95         c4->right.SameAs(this, wxRight);
96         c4->bottom.Above(cancel_button, -5);
97
98         wxLayoutConstraints *c41 = new wxLayoutConstraints;
99         memcpy(c41, c4, sizeof(wxLayoutConstraints));
100
101         wxLayoutConstraints *c42 = new wxLayoutConstraints;
102         memcpy(c42, c4, sizeof(wxLayoutConstraints));
103
104         identity_panel->SetConstraints(c4);
105         network_panel->SetConstraints(c41);
106         security_panel->SetConstraints(c42);
107
108         wxStaticText *ip_label = new wxStaticText(
109                                   identity_panel, -1, "Server identity");
110         wxStaticText *np_label = new wxStaticText(
111                                   network_panel, -1, "Network presence");
112         wxStaticText *sp_label = new wxStaticText(
113                          security_panel, -1, "Global security settings");
114
115         wxLayoutConstraints *c5 = new wxLayoutConstraints;
116         c5->top.SameAs(network_panel, wxTop, 3);
117         c5->left.SameAs(network_panel, wxLeft, 3);
118         c5->right.SameAs(network_panel, wxRight, 3);
119         c5->height.AsIs();
120
121         ip_label->SetConstraints(c5);
122         //np_label->SetConstraints(c5);
123         //sp_label->SetConstraints(c5);
124
125         SetAutoLayout(TRUE);
126         Show(TRUE);
127         LoadServerConfigStrings();
128         Layout();
129         wxYield();
130         ChangePanel(WhichPanel);
131 }
132
133
134 void ServProps::ChangePanel(wxString WhichPanel)
135 {
136         identity_panel->Show(!WhichPanel.CmpNoCase("Identity") ? TRUE : FALSE);
137         network_panel->Show(!WhichPanel.CmpNoCase("Network") ? TRUE : FALSE);
138         security_panel->Show(!WhichPanel.CmpNoCase("Security") ? TRUE : FALSE);
139         Layout();
140         wxYield();
141 }
142
143
144 void ServProps::OnButtonPressed(wxCommandEvent & whichbutton)
145 {
146         switch (whichbutton.GetId()) {
147         case BUTTON_CANCEL:
148                 delete this;
149                 break;
150         case BUTTON_SAVE:
151                 SaveServerConfigStrings();
152                 delete this;
153                 break;
154         }
155 }
156
157
158 void ServProps::LoadServerConfigStrings()
159 {
160         int i;
161         wxString sendcmd, recvcmd, xferbuf;
162
163         for (i=0; i<20; ++i)
164                 ServerConfigStrings[i].Empty();
165
166         // Make the window go away if this command fails.
167         // Most likely we mistakenly got here without first checking for
168         // the proper access level.
169         sendcmd = "CONF get";
170         if (citsock->serv_trans(sendcmd, recvcmd, xferbuf) != 1)
171                 delete this;
172
173         wxStringTokenizer *cl = new wxStringTokenizer(xferbuf, "\n", FALSE);
174         i = 0;
175         while ((i<20) && (cl->HasMoreTokens())) {
176                 ServerConfigStrings[i++] = cl->NextToken();
177         }
178 }
179
180
181 void ServProps::SaveServerConfigStrings() 
182 {
183         int i;
184         wxString sendcmd, recvcmd, xferbuf;
185
186         xferbuf = "";
187         for (i=0; i<20; ++i) {
188                 xferbuf += ServerConfigStrings[i];
189                 xferbuf += "\n";
190         }
191
192         sendcmd = "CONF set";
193         if (citsock->serv_trans(sendcmd, recvcmd, xferbuf) != 4) {
194                 wxMessageDialog errmsg(this,
195                         recvcmd.Mid(4),
196                         "Error",
197                         wxOK | wxCENTRE | wxICON_INFORMATION,
198                         wxDefaultPosition);
199                 errmsg.ShowModal();
200         }
201 }
202