3 * Configuration file editor
5 * Nicolas Boichat, May 2004
10 Copyright (C) 2004-2006 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.
25 #include "wxbconfigfileeditor.h"
27 #include <wx/filename.h>
36 BEGIN_EVENT_TABLE(wxbConfigFileEditor, wxDialog)
37 EVT_BUTTON(Save, wxbConfigFileEditor::OnSave)
38 EVT_BUTTON(Quit, wxbConfigFileEditor::OnQuit)
40 EVT_PAINT ( wxbConfigFileEditor::OnPaint)
44 wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
45 wxDialog(parent, -1, _("Config file editor"), wxDefaultPosition, wxSize(500, 300),
46 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
47 this->filename = filename;
51 wxFileName filen(filename);
53 if (!filen.FileExists()) {
55 strbuf << _("# Bacula wx-console Configuration File\n");
58 strbuf << wxT("Director {\n");
59 strbuf << wxT(" Name = <hostname>-dir\n");
60 strbuf << wxT(" DIRport = 9101\n");
61 strbuf << wxT(" address = <hostname>\n");
62 strbuf << wxT(" Password = \"<dir_password>\"\n");
66 wxFile file(filename);
69 while ((len = file.Read(buffer, 2048)) > -1) {
71 strbuf << wxString(buffer,wxConvUTF8);
78 textCtrl = new wxTextCtrl(this,-1,strbuf,wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH2 | wxTE_DONTWRAP);
79 wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
80 #if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2
81 font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1);
83 textCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
84 textCtrl->SetStyle(0, textCtrl->GetLastPosition(), wxTextAttr(*wxBLACK, wxNullColour, font));
86 wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2, 1, 0, 0);
87 mainSizer->AddGrowableCol(0);
88 mainSizer->AddGrowableRow(0);
90 wxBoxSizer *bottomsizer = new wxBoxSizer(wxHORIZONTAL);
91 bottomsizer->Add(new wxButton(this, Save, _("Save and close")), 0, wxALL, 10);
92 bottomsizer->Add(new wxButton(this, Quit, _("Close without saving")), 0, wxALL, 10);
94 mainSizer->Add(textCtrl, 1, wxEXPAND);
95 mainSizer->Add(bottomsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
97 this->SetSizer(mainSizer);
102 wxbConfigFileEditor::~wxbConfigFileEditor() {
106 /* Kludge for Win32, so the text control is not completely selected. */
107 void wxbConfigFileEditor::OnPaint(wxPaintEvent& event) {
112 textCtrl->SetSelection(0, 0);
116 void wxbConfigFileEditor::OnSave(wxCommandEvent& event) {
117 wxFile file(filename, wxFile::write);
118 if (!file.IsOpened()) {
119 wxMessageBox(wxString::Format(_("Unable to write to %s\n"), filename.c_str()),
120 _("Error while saving"),
121 wxOK | wxICON_ERROR, this);
126 file.Write(textCtrl->GetValue(),wxConvLocal);
134 void wxbConfigFileEditor::OnQuit(wxCommandEvent& event) {