3 * Configuration file editor
5 * Nicolas Boichat, May 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 three of the GNU Affero 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 Affero 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 Kern Sibbald.
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 "wxbconfigfileeditor.h"
47 #include <wx/filename.h>
56 BEGIN_EVENT_TABLE(wxbConfigFileEditor, wxDialog)
57 EVT_BUTTON(Save, wxbConfigFileEditor::OnSave)
58 EVT_BUTTON(Quit, wxbConfigFileEditor::OnQuit)
60 EVT_PAINT ( wxbConfigFileEditor::OnPaint)
64 wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
65 wxDialog(parent, -1, _("Config file editor"), wxDefaultPosition, wxSize(500, 300),
66 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
67 this->filename = filename;
71 wxFileName filen(filename);
73 if (!filen.FileExists()) {
75 strbuf << _("# Bacula bwx-console Configuration File\n");
78 strbuf << wxT("Director {\n");
79 strbuf << wxT(" Name = <hostname>-dir\n");
80 strbuf << wxT(" DIRport = 9101\n");
81 strbuf << wxT(" address = <hostname>\n");
82 strbuf << wxT(" Password = \"<dir_password>\"\n");
86 wxFile file(filename);
89 while ((len = file.Read(buffer, 2048)) > -1) {
91 strbuf << wxString(buffer,wxConvUTF8);
98 textCtrl = new wxTextCtrl(this,-1,strbuf,wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH2 | wxTE_DONTWRAP);
99 wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
100 #if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2
101 font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1);
103 textCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
104 textCtrl->SetStyle(0, textCtrl->GetLastPosition(), wxTextAttr(*wxBLACK, wxNullColour, font));
106 wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2, 1, 0, 0);
107 mainSizer->AddGrowableCol(0);
108 mainSizer->AddGrowableRow(0);
110 wxBoxSizer *bottomsizer = new wxBoxSizer(wxHORIZONTAL);
111 bottomsizer->Add(new wxButton(this, Save, _("Save and close")), 0, wxALL, 10);
112 bottomsizer->Add(new wxButton(this, Quit, _("Close without saving")), 0, wxALL, 10);
114 mainSizer->Add(textCtrl, 1, wxEXPAND);
115 mainSizer->Add(bottomsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
117 this->SetSizer(mainSizer);
122 wxbConfigFileEditor::~wxbConfigFileEditor() {
126 /* Kludge for Win32, so the text control is not completely selected. */
127 void wxbConfigFileEditor::OnPaint(wxPaintEvent& event) {
132 textCtrl->SetSelection(0, 0);
136 void wxbConfigFileEditor::OnSave(wxCommandEvent& event) {
137 wxFile file(filename, wxFile::write);
138 if (!file.IsOpened()) {
139 wxMessageBox(wxString::Format(_("Unable to write to %s\n"), filename.c_str()),
140 _("Error while saving"),
141 wxOK | wxICON_ERROR, this);
146 file.Write(textCtrl->GetValue(),wxConvLocal);
154 void wxbConfigFileEditor::OnQuit(wxCommandEvent& event) {