2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * Config panel, used to specify parameters (for example clients, filesets... in restore)
32 * Nicolas Boichat, April 2004
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 int wxbConfigParam::GetCount() {
164 return choicectrl->GetCount();
170 void wxbConfigParam::SetIndex(int ind) {
172 choicectrl->SetSelection(ind);
176 void wxbConfigParam::Clear() {
182 void wxbConfigParam::Add(wxString value) {
184 choicectrl->Append(value);
188 /* Creates a new config panel, config must be allocated with new */
189 wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config, wxString title,
190 wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
192 this->config = config;
194 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
197 new wxStaticText(this, -1, title, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER),
198 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
200 wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
202 for (i = 0; i < config->GetCount(); i++) {
203 (*config)[i].AddControl(this, cfgSizer);
205 mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
207 wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
209 cfgOk = new wxButton(this, ok, _("OK"), wxDefaultPosition, wxSize(70, 25));
210 restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
213 cfgApply = new wxButton(this, apply, _("Apply"), wxDefaultPosition, wxSize(70, 25));
214 restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
220 cfgCancel = new wxButton(this, cancel, _("Cancel"), wxDefaultPosition, wxSize(70, 25));
221 restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
223 mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
226 mainSizer->SetSizeHints(this);
231 wxbConfigPanel::~wxbConfigPanel() {
235 void wxbConfigPanel::SetRowString(const wxChar* title, wxString value) {
237 if ((i = FindRow(title)) > -1) {
238 (*config)[i].SetValue(value);
242 wxString wxbConfigPanel::GetRowString(const wxChar* title) {
244 if ((i = FindRow(title)) > -1) {
245 return (*config)[i].GetValue();
250 void wxbConfigPanel::SetRowSelection(const wxChar* title, int ind) {
252 if ((i = FindRow(title)) > -1) {
253 (*config)[i].SetIndex(ind);
257 int wxbConfigPanel::GetRowSelection(const wxChar* title) {
259 if ((i = FindRow(title)) > -1) {
260 return (*config)[i].GetIndex();
265 void wxbConfigPanel::ClearRowChoices(const wxChar* title) {
267 if ((i = FindRow(title)) > -1) {
268 (*config)[i].Clear();
272 void wxbConfigPanel::AddRowChoice(const wxChar* title, wxString value) {
274 if ((i = FindRow(title)) > -1) {
275 (*config)[i].Add(value);
279 int wxbConfigPanel::FindRow(const wxChar* title) {
282 for (i = last; i < config->GetCount(); i++) {
283 if ((*config)[i].GetTitle() == title) {
289 for (i = 0; i < last; i++) {
290 if ((*config)[i].GetTitle() == title) {
300 int wxbConfigPanel::GetRowCount(const wxChar* title)
303 if ((i = FindRow(title)) > -1) {
304 return (*config)[i].GetCount();
310 void wxbConfigPanel::EnableApply(bool enable) {
311 cfgOk->Enable(!enable);
312 if (cfgApply) cfgApply->Enable(enable);