3 * Configuration file editor
5 * Nicolas Boichat, May 2004
9 Copyright (C) 2004 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "wxbconfigfileeditor.h"
29 #include <wx/filename.h>
37 BEGIN_EVENT_TABLE(wxbConfigFileEditor, wxDialog)
38 EVT_BUTTON(Save, wxbConfigFileEditor::OnSave)
39 EVT_BUTTON(Quit, wxbConfigFileEditor::OnQuit)
42 wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
43 wxDialog(parent, -1, "Config file editor", wxDefaultPosition, wxSize(500, 300),
44 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
45 this->filename = filename;
47 textCtrl = new wxTextCtrl(this,-1,"",wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH | wxTE_DONTWRAP);
48 wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
49 #if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2
50 font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1);
52 textCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
54 wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2, 1, 0, 0);
55 mainSizer->AddGrowableCol(0);
56 mainSizer->AddGrowableRow(0);
58 wxBoxSizer *bottomsizer = new wxBoxSizer(wxHORIZONTAL);
59 bottomsizer->Add(new wxButton(this, Save, "Save and close"), 0, wxALL, 10);
60 bottomsizer->Add(new wxButton(this, Quit, "Close without saving"), 0, wxALL, 10);
62 mainSizer->Add(textCtrl, 1, wxEXPAND);
63 mainSizer->Add(bottomsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
65 this->SetSizer(mainSizer);
67 wxFileName filen(filename);
69 if (!filen.FileExists()) {
71 (*textCtrl) << "# Bacula wx-console Configuration File\n";
74 (*textCtrl) << "Director {\n";
75 (*textCtrl) << " Name = <hostname>-dir\n";
76 (*textCtrl) << " DIRport = 9101\n";
77 (*textCtrl) << " address = <hostname>\n";
78 (*textCtrl) << " Password = \"<dir_password>\"\n";
82 wxFile file(filename);
85 while ((len = file.Read(buffer, 2048)) > -1) {
86 buffer[len] = (wxChar)0;
87 (*textCtrl) << buffer;
95 wxbConfigFileEditor::~wxbConfigFileEditor() {
99 void wxbConfigFileEditor::OnSave(wxCommandEvent& event) {
100 wxFile file(filename, wxFile::write);
101 if (!file.IsOpened()) {
102 wxMessageBox(wxString("Unable to write to ") << filename << "\n", "Error while saving",
103 wxOK | wxICON_ERROR, this);
108 file.Write(textCtrl->GetValue());
116 void wxbConfigFileEditor::OnQuit(wxCommandEvent& event) {