3 * Config panel, used to specify parameters (for example clients, filesets... in restore)
5 * Nicolas Boichat, April 2004
10 Bacula® - The Network Backup Solution
12 Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
14 The main author of Bacula is Kern Sibbald, with contributions from
15 many others, a complete list can be found in the file AUTHORS.
16 This program is Free Software; you can redistribute it and/or
17 modify it under the terms of version two of the GNU General Public
18 License as published by the Free Software Foundation and included
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 Bacula® is a registered trademark of John Walker.
32 The licensor of Bacula is the Free Software Foundation Europe
33 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34 Switzerland, email:ftf@fsfeurope.org.
37 /* Windows debug builds set _DEBUG which is used by wxWidgets to select their
38 * debug memory allocator. Unfortunately it conflicts with Bacula's SmartAlloc.
39 * So we turn _DEBUG off since we aren't interested in things it enables.
45 #include "wxbconfigpanel.h"
46 #include <wx/arrimpl.cpp>
49 WX_DEFINE_OBJARRAY(wxbConfig);
51 /* Create a new config parameter */
52 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
59 this->choicectrl = NULL;
60 this->textctrl = NULL;
61 this->statictext = NULL;
64 wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
68 this->values = new wxString[n];
69 for (int i = 0; i < n; i++) {
70 this->values[i] = values[i];
73 this->choicectrl = NULL;
74 this->textctrl = NULL;
75 this->statictext = NULL;
78 wxbConfigParam::~wxbConfigParam() {
79 if (values) delete[] values;
80 if (choicectrl) delete choicectrl;
81 if (textctrl) delete textctrl;
82 if (statictext) delete statictext;
85 void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
86 sizer->Add(new wxStaticText(parent, -1, title + wxT(": "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 0, wxALIGN_CENTER_VERTICAL);
89 statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
90 sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
93 textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
94 sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
97 #if defined __WXGTK20__ /* Choices are taller under GTK+-2.0 */
98 wxSize size = wxSize(150, 25);
100 wxSize size = wxSize(150, 20);
102 choicectrl = new wxChoice(parent, id, wxDefaultPosition, size, nvalues, values);
103 sizer->Add(choicectrl, 1, wxEXPAND);
108 wxString wxbConfigParam::GetTitle() {
112 wxString wxbConfigParam::GetValue() {
115 return (statictext != NULL) ? statictext->GetLabel() : wxString(wxT(""));
118 return (textctrl != NULL) ? textctrl->GetValue() : wxString(wxT(""));
121 return (choicectrl != NULL) ? choicectrl->GetStringSelection() : wxString(wxT(""));
127 void wxbConfigParam::SetValue(wxString str) {
131 statictext->SetLabel(str);
135 textctrl->SetValue(str);
140 for (k = 0; k < (int)choicectrl->GetCount(); k++) {
141 if (str == choicectrl->GetString(k)) {
142 choicectrl->SetSelection(k);
146 if (k == (int)choicectrl->GetCount()) { // Should never happen
147 choicectrl->Append(str);
148 choicectrl->SetSelection(k);
155 int wxbConfigParam::GetIndex() {
157 return choicectrl->GetSelection();
162 void wxbConfigParam::SetIndex(int ind) {
164 choicectrl->SetSelection(ind);
168 void wxbConfigParam::Clear() {
174 void wxbConfigParam::Add(wxString value) {
176 choicectrl->Append(value);
180 /* Creates a new config panel, config must be allocated with new */
181 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
182 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
184 this->config = config;
186 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
189 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
190 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
192 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
194 for (i = 0; i < config->GetCount(); i++) {
195 (*config)[i].AddControl(this, cfgSizer);
197 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
199 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
201 cfgOk = new wxButton(this, ok, _("OK"), wxDefaultPosition, wxSize(70, 25));
202 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
205 cfgApply = new wxButton(this, apply, _("Apply"), wxDefaultPosition, wxSize(70, 25));
206 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
212 cfgCancel = new wxButton(this, cancel, _("Cancel"), wxDefaultPosition, wxSize(70, 25));
213 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
215 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
218 mainSizer->SetSizeHints(this);
223 wxbConfigPanel::~wxbConfigPanel() {
227 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
229 if ((i = FindRow(title)) > -1) {
230 (*config)[i].SetValue(value);
234 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
236 if ((i = FindRow(title)) > -1) {
237 return (*config)[i].GetValue();
242 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
244 if ((i = FindRow(title)) > -1) {
245 (*config)[i].SetIndex(ind);
249 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
251 if ((i = FindRow(title)) > -1) {
252 return (*config)[i].GetIndex();
257 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
259 if ((i = FindRow(title)) > -1) {
260 (*config)[i].Clear();
264 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
266 if ((i = FindRow(title)) > -1) {
267 (*config)[i].Add(value);
271 int wxbConfigPanel::FindRow(const wxChar* title) {
274 for (i = last; i < config->GetCount(); i++) {
275 if ((*config)[i].GetTitle() == title) {
281 for (i = 0; i < last; i++) {
282 if ((*config)[i].GetTitle() == title) {
292 void wxbConfigPanel::EnableApply(bool enable) {
293 cfgOk->Enable(!enable);
294 if (cfgApply) cfgApply->Enable(enable);