3 * Configuration file editor
5 * Nicolas Boichat, May 2004
10 Copyright (C) 2004-2005 Kern Sibbald
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 version 2 as amended with additional clauses defined in the
15 file LICENSE in the main source directory.
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 the file LICENSE for additional details.
24 #include "wxbconfigfileeditor.h"
27 #include <wx/filename.h>
35 BEGIN_EVENT_TABLE(wxbConfigFileEditor, wxDialog)
36 EVT_BUTTON(Save, wxbConfigFileEditor::OnSave)
37 EVT_BUTTON(Quit, wxbConfigFileEditor::OnQuit)
40 wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
41 wxDialog(parent, -1, _("Config file editor"), wxDefaultPosition, wxSize(500, 300),
42 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
43 this->filename = filename;
45 textCtrl = new wxTextCtrl(this,-1,wxT(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH | wxTE_DONTWRAP);
46 wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
47 #if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2
48 font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1);
50 textCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
52 wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2, 1, 0, 0);
53 mainSizer->AddGrowableCol(0);
54 mainSizer->AddGrowableRow(0);
56 wxBoxSizer *bottomsizer = new wxBoxSizer(wxHORIZONTAL);
57 bottomsizer->Add(new wxButton(this, Save, _("Save and close")), 0, wxALL, 10);
58 bottomsizer->Add(new wxButton(this, Quit, _("Close without saving")), 0, wxALL, 10);
60 mainSizer->Add(textCtrl, 1, wxEXPAND);
61 mainSizer->Add(bottomsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
63 this->SetSizer(mainSizer);
65 wxFileName filen(filename);
67 if (!filen.FileExists()) {
68 (*textCtrl) << wxT("#\n");
69 (*textCtrl) << _("# Bacula wx-console Configuration File\n");
70 (*textCtrl) << wxT("#\n");
71 (*textCtrl) << wxT("\n");
72 (*textCtrl) << wxT("Director {\n");
73 (*textCtrl) << wxT(" Name = <hostname>-dir\n");
74 (*textCtrl) << wxT(" DIRport = 9101\n");
75 (*textCtrl) << wxT(" address = <hostname>\n");
76 (*textCtrl) << wxT(" Password = \"<dir_password>\"\n");
77 (*textCtrl) << wxT("}\n");
80 wxFile file(filename);
83 while ((len = file.Read(buffer, 2048)) > -1) {
85 (*textCtrl) << wxString(buffer,wxConvLocal);
93 wxbConfigFileEditor::~wxbConfigFileEditor() {
97 void wxbConfigFileEditor::OnSave(wxCommandEvent& event) {
98 wxFile file(filename, wxFile::write);
99 if (!file.IsOpened()) {
100 wxMessageBox(wxString::Format(_("Unable to write to %s\n"), filename.c_str()),
101 _("Error while saving"),
102 wxOK | wxICON_ERROR, this);
107 file.Write(textCtrl->GetValue(),wxConvLocal);
115 void wxbConfigFileEditor::OnQuit(wxCommandEvent& event) {