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