]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/wx-console/wxbconfigfileeditor.cpp
Fix some trivial errors and implemented the restore of IRIX xattrs.
[bacula/bacula] / bacula / src / wx-console / wxbconfigfileeditor.cpp
index 8d8481c18b21c85f1de8cbee6534e956af4b37ed..97b570d307abd5378e166504c94550ed8f3030ac 100644 (file)
@@ -7,25 +7,46 @@
  *    Version $Id$
  */
 /*
-   Copyright (C) 2004-2005 Kern Sibbald
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
+   Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
+
+/*  Windows debug builds set _DEBUG which is used by wxWidgets to select their
+ *  debug memory allocator.  Unfortunately it conflicts with Bacula's SmartAlloc.
+ * So we turn _DEBUG off since we aren't interested in things it enables.
  */
 
-#include "wxbconfigfileeditor.h"
+#undef _DEBUG
 
+#include "bacula.h"
+#include "wxbconfigfileeditor.h"
 #include <wx/file.h>
 #include <wx/filename.h>
 
+
 enum
 {
    Save = 1,
@@ -35,6 +56,9 @@ enum
 BEGIN_EVENT_TABLE(wxbConfigFileEditor, wxDialog)
    EVT_BUTTON(Save, wxbConfigFileEditor::OnSave)
    EVT_BUTTON(Quit, wxbConfigFileEditor::OnQuit)
+#ifdef HAVE_WIN32
+   EVT_PAINT (      wxbConfigFileEditor::OnPaint)
+#endif
 END_EVENT_TABLE()
 
 wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
@@ -42,12 +66,42 @@ wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
                    wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
    this->filename = filename;
    
-   textCtrl = new wxTextCtrl(this,-1,wxT(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH | wxTE_DONTWRAP);
+   wxString strbuf;
+
+   wxFileName filen(filename);
+   
+   if (!filen.FileExists()) {
+      strbuf << wxT("#\n");
+      strbuf << _("# Bacula bwx-console Configuration File\n");
+      strbuf << wxT("#\n");
+      strbuf << wxT("\n");
+      strbuf << wxT("Director {\n");
+      strbuf << wxT("  Name = <hostname>-dir\n");
+      strbuf << wxT("  DIRport = 9101\n");
+      strbuf << wxT("  address = <hostname>\n");
+      strbuf << wxT("  Password = \"<dir_password>\"\n");
+      strbuf << wxT("}\n");
+   }
+   else {
+      wxFile file(filename);
+      char buffer[2049];
+      off_t len;
+      while ((len = file.Read(buffer, 2048)) > -1) {
+         buffer[len] = 0;
+         strbuf << wxString(buffer,wxConvUTF8);
+         if (file.Eof())
+            break;
+      }
+      file.Close();
+   }
+
+   textCtrl = new wxTextCtrl(this,-1,strbuf,wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH2 | wxTE_DONTWRAP);
    wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
 #if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2
    font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1);
 #endif
    textCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
+   textCtrl->SetStyle(0, textCtrl->GetLastPosition(), wxTextAttr(*wxBLACK, wxNullColour, font));
 
    wxFlexGridSizer *mainSizer = new wxFlexGridSizer(2, 1, 0, 0);
    mainSizer->AddGrowableCol(0);
@@ -61,39 +115,24 @@ wxbConfigFileEditor::wxbConfigFileEditor(wxWindow* parent, wxString filename):
    mainSizer->Add(bottomsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
    
    this->SetSizer(mainSizer);
-   
-   wxFileName filen(filename);
-   
-   if (!filen.FileExists()) {
-      (*textCtrl) << wxT("#\n");
-      (*textCtrl) << _("# Bacula wx-console Configuration File\n");
-      (*textCtrl) << wxT("#\n");
-      (*textCtrl) << wxT("\n");
-      (*textCtrl) << wxT("Director {\n");
-      (*textCtrl) << wxT("  Name = <hostname>-dir\n");
-      (*textCtrl) << wxT("  DIRport = 9101\n");
-      (*textCtrl) << wxT("  address = <hostname>\n");
-      (*textCtrl) << wxT("  Password = \"<dir_password>\"\n");
-      (*textCtrl) << wxT("}\n");
-   }
-   else {
-      wxFile file(filename);
-      char buffer[2049];
-      off_t len;
-      while ((len = file.Read(buffer, 2048)) > -1) {
-         buffer[len] = 0;
-         (*textCtrl) << wxString(buffer,wxConvLocal);
-         if (file.Eof())
-            break;
-      }
-      file.Close();
-   }
+
+   firstpaint = true;
 }
 
 wxbConfigFileEditor::~wxbConfigFileEditor() {
    
 }
 
+/* Kludge for Win32, so the text control is not completely selected. */
+void wxbConfigFileEditor::OnPaint(wxPaintEvent& event) {
+   wxPaintDC dc(this);
+
+   if (firstpaint) {
+      firstpaint = false;
+      textCtrl->SetSelection(0, 0);
+   }
+}
+
 void wxbConfigFileEditor::OnSave(wxCommandEvent& event) {
    wxFile file(filename, wxFile::write);
    if (!file.IsOpened()) {