]> code.citadel.org Git - citadel.git/blob - daphne/prefs.cpp
- port to Cygwin (DLL support, etc.)
[citadel.git] / daphne / prefs.cpp
1 // $Id$
2
3 // =========================================================================
4 // declarations
5 // =========================================================================
6
7 #include "includes.hpp"
8
9 // ----------------------------------------------------------------------------
10 // constants
11 // ----------------------------------------------------------------------------
12
13 // IDs for the controls and the menu commands
14 enum
15 {
16         BUTTON_SAVE,
17         BUTTON_CANCEL,
18 };
19
20 // ----------------------------------------------------------------------------
21 // event tables and other macros for wxWindows
22 // ----------------------------------------------------------------------------
23
24 // the event tables connect the wxWindows events with the functions (event
25 // handlers) which process them. It can be also done at run-time, but for the
26 // simple menu events like this the static method is much simpler.
27 BEGIN_EVENT_TABLE(      Preferences, wxMDIChildFrame)
28         EVT_BUTTON(     BUTTON_SAVE,            Preferences::OnButtonPressed)
29         EVT_BUTTON(     BUTTON_CANCEL,          Preferences::OnButtonPressed)
30 END_EVENT_TABLE()
31
32 // ============================================================================
33 // implementation
34 // ============================================================================
35
36
37 // ----------------------------------------------------------------------------
38 // the application class
39 // ----------------------------------------------------------------------------
40
41 // frame constructor
42 Preferences::Preferences(       CitClient *sock,
43                                 wxMDIParentFrame *MyMDI)
44        : wxMDIChildFrame(MyMDI, //parent
45                         -1,     //window id
46                         " Preferences ",
47                         wxDefaultPosition,
48                         wxDefaultSize,
49                         wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL,
50                         "Preferences"
51                         ) {
52         
53         wxString buf;
54
55         citsock = sock;
56         citMyMDI = MyMDI;
57
58         // set the frame icon
59         /* SetIcon(wxICON(mondrian)); */
60
61         wxButton *save_button = new wxButton(
62                 this,
63                 BUTTON_SAVE,
64                 "Save",
65                 wxPoint(200,200),
66                 wxSize(100,30),
67                 0L,
68                 wxDefaultValidator,
69                 "save_button"
70                 );
71
72         wxButton *cancel_button = new wxButton(
73                 this,
74                 BUTTON_CANCEL,
75                 "Cancel",
76                 wxPoint(300,300),
77                 wxSize(100,30),
78                 0L,
79                 wxDefaultValidator,
80                 "cancel_button"
81                 );
82
83         wxLayoutConstraints *c1 = new wxLayoutConstraints;
84         c1->bottom.SameAs(this, wxBottom, 5);
85         c1->left.SameAs(this, wxLeft, 10);
86         c1->height.AsIs(); c1->width.AsIs();
87         save_button->SetConstraints(c1);
88
89         wxLayoutConstraints *c3 = new wxLayoutConstraints;
90         c3->bottom.SameAs(save_button, wxBottom);
91         c3->right.SameAs(this, wxRight, 10);
92         c3->height.AsIs(); c3->width.AsIs();
93         cancel_button->SetConstraints(c3);
94
95         wxStaticText *server_host_label = new wxStaticText(
96                 this, -1, "Server host");
97
98         server_host = new wxTextCtrl(this, -1);
99         
100         wxStaticText *server_port_label = new wxStaticText(
101                 this, -1, "Server port");
102         
103         server_port = new wxTextCtrl(this, -1);
104
105         wxLayoutConstraints *c4 = new wxLayoutConstraints;
106         c4->top.SameAs(this, wxTop, 10);
107         c4->left.SameAs(this, wxLeft, 10);
108         c4->height.AsIs(); c4->width.AsIs();
109         server_host_label->SetConstraints(c4);
110
111         wxLayoutConstraints *c5 = new wxLayoutConstraints;
112         c5->centreY.SameAs(server_host_label, wxCentreY);
113         c5->left.RightOf(server_host_label, 10);
114         c5->right.SameAs(this, wxRight, 10);
115         c5->height.AsIs();
116         server_host->SetConstraints(c5);
117
118         wxLayoutConstraints *c6 = new wxLayoutConstraints;
119         c6->top.Below(server_host_label, 15);
120         c6->left.SameAs(this, wxLeft, 10);
121         c6->height.AsIs(); c6->width.AsIs();
122         server_port_label->SetConstraints(c6);
123
124         wxLayoutConstraints *c7 = new wxLayoutConstraints;
125         c7->centreY.SameAs(server_port_label, wxCentreY);
126         c7->left.SameAs(server_host, wxLeft);
127         c7->right.PercentOf(this, wxWidth, 50);
128         c7->height.AsIs();
129         server_port->SetConstraints(c7);
130
131         server_autoconnect = new wxCheckBox(this, -1,
132                 "Automatically connect at startup");
133
134         wxLayoutConstraints *c8 = new wxLayoutConstraints;
135         c8->centreY.SameAs(server_port, wxCentreY);
136         c8->left.RightOf(server_port, 5);
137         c8->width.AsIs(); c8->height.AsIs();
138         server_autoconnect->SetConstraints(c8);
139
140
141
142
143
144         ini->Read("/Citadel Server/Host", &buf, DEFAULT_HOST);
145         server_host->SetValue(buf);
146
147         ini->Read("/Citadel Server/Port", &buf, DEFAULT_PORT);
148         server_port->SetValue(buf);
149
150         ini->Read("/Citadel Server/ConnectOnStartup", &buf, "no");
151         server_autoconnect->SetValue(
152                 ((!buf.CmpNoCase("yes")) ? TRUE : FALSE));
153
154         SetAutoLayout(TRUE);
155         Show(TRUE);
156         Layout();
157 }
158
159
160
161 void Preferences::OnButtonPressed(wxCommandEvent& whichbutton) {
162         if (whichbutton.GetId() == BUTTON_CANCEL) {
163                 delete this;
164         } else if (whichbutton.GetId() == BUTTON_SAVE) {
165                 ini->Write("/Citadel Server/Host", server_host->GetValue());
166                 ini->Write("/Citadel Server/Port", server_port->GetValue());
167                 ini->Write("/Citadel Server/ConnectOnStartup",
168                         ((server_autoconnect->GetValue()==TRUE)
169                         ? wxString("yes") : wxString("no")));
170                 ini->Flush(FALSE);
171                 delete this;
172         }
173 }