]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/wx-console/wxbmainframe.cpp
Fix some trivial errors and implemented the restore of IRIX xattrs.
[bacula/bacula] / bacula / src / wx-console / wxbmainframe.cpp
index e7b984dc0cc42982e5c9f0fcdb1d0aa857a4a9fa..a25b2a90d20554e0dfd4a6959d7b1fb1fa3a23ef 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2004-2007 Free Software Foundation Europe e.V.
+
+   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.
+*/
 /*
  *
  *   Main frame
  *
  *    Version $Id$
  */
-/*
-   Copyright (C) 2004-2005 Kern Sibbald
 
-   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.
+/*  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.
+ */
 
-   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.
+#undef _DEBUG
 
- */
+#include "bacula.h"
 
 #include "wxbmainframe.h" // class's header file
 
@@ -72,9 +94,6 @@ enum
 /*
  *   wxbTHREAD_EVENT declaration, used by csprint
  */
-BEGIN_DECLARE_EVENT_TYPES()
-   DECLARE_EVENT_TYPE(wxbTHREAD_EVENT,       1)
-END_DECLARE_EVENT_TYPES()
 
 DEFINE_EVENT_TYPE(wxbTHREAD_EVENT)
 
@@ -245,7 +264,7 @@ wxbMainFrame::wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSi
 
    CreateStatusBar(1);
    
-   SetStatusText(wxString::Format(_("Welcome to bacula wx-console %s (%s)!\n"), wxT(VERSION), wxT(BDATE)));
+   SetStatusText(wxString::Format(_("Welcome to bacula bwx-console %s (%s)!\n"), wxT(VERSION), wxT(BDATE)));
 
    wxPanel* global = new wxPanel(this, -1);
 
@@ -265,7 +284,7 @@ wxbMainFrame::wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSi
 #else 
    consoleCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
 #if (wxUSE_UNICODE == 0) && __WXGTK20__
-   Print(_("Warning : There is a problem with wxWidgets for GTK+ 2.0 without Unicode support when handling non-ASCII filenames: Every non-ASCII character in such filenames will be replaced by an interrogation mark.\nIf this behaviour disturbs you, please build wx-console against a Unicode version of wxWidgets for GTK+ 2.0.\n---\n"), CS_DEBUG);   
+   Print(_("Warning : There is a problem with wxWidgets for GTK+ 2.0 without Unicode support when handling non-ASCII filenames: Every non-ASCII character in such filenames will be replaced by an interrogation mark.\nIf this behaviour disturbs you, please build bwx-console against a Unicode version of wxWidgets for GTK+ 2.0.\n---\n"), CS_DEBUG);   
 #endif
 #endif
 
@@ -354,7 +373,7 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) {
       
       if (((wxTheApp->argc % 2) != 1)) {
          Print(_("Error while parsing command line arguments, using defaults.\n"), CS_DEBUG);
-         Print(_("Usage: wx-console [-c configfile] [-w tmp]\n"), CS_DEBUG);
+         Print(_("Usage: bwx-console [-c configfile] [-w tmp]\n"), CS_DEBUG);
       }
       else {
          for (int c = 1; c < wxTheApp->argc; c += 2) {
@@ -366,24 +385,25 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) {
             }
             if (wxTheApp->argv[c][0] != '-') {
                Print(_("Error while parsing command line arguments, using defaults.\n"), CS_DEBUG);
-               Print(_("Usage: wx-console [-c configfile] [-w tmp]\n"), CS_DEBUG);
+               Print(_("Usage: bwx-console [-c configfile] [-w tmp]\n"), CS_DEBUG);
                break;
             }
          }
       }
       
       if (configfile == wxT("")) {
-         wxConfig::Set(new wxConfig(wxT("wx-console"), wxT("bacula")));
+         wxConfig::Set(new wxConfig(wxT("bwx-console"), wxT("bacula")));
          if (!wxConfig::Get()->Read(wxT("/ConfigFile"), &configfile)) {
 #ifdef HAVE_MACOSX
             wxFileName filename(::wxGetHomeDir());
             filename.MakeAbsolute();
             configfile = filename.GetLongPath();
-            if (configfile.Last() != '/')
+            if (!IsPathSeparator(configfile.Last())) {
                configfile += '/';
-            configfile += "Library/Preferences/org.bacula.wxconsole.conf";
+            }
+            configfile += L"Library/Preferences/org.bacula.wxconsole.conf";
 #else
-            wxFileName filename(::wxGetCwd(), wxT("wx-console.conf"));
+            wxFileName filename(::wxGetCwd(), wxT("bwx-console.conf"));
             filename.MakeAbsolute();
             configfile = filename.GetLongPath();
 #ifdef HAVE_WIN32
@@ -394,7 +414,7 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) {
    
             int answer = wxMessageBox(
                               wxString::Format(_(
-                              "It seems that it is the first time you run wx-console.\nThis file (%s) has been choosen as default configuration file.\nDo you want to edit it? (if you click No you will have to select another file)"),
+                              "It seems that it is the first time you run bwx-console.\nThis file (%s) has been choosen as default configuration file.\nDo you want to edit it? (if you click No you will have to select another file)"),
                               configfile.c_str()),
                               _("First run"),
                               wxYES_NO | wxICON_QUESTION, this);
@@ -494,9 +514,11 @@ void wxbMainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 void wxbMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
    wxString msg;
-   msg.Printf(_("Welcome to Bacula wx-console.\nWritten by Nicolas Boichat <nicolas@boichat.ch>\n(C) 2005 Kern Sibbald\n"));
+   msg.Printf(_("Welcome to Bacula bwx-console.\n"
+     "Written by Nicolas Boichat <nicolas@boichat.ch>\n"
+     "Copyright (C), 2005-2007 Free Software Foundation Europe, e.V.\n"));
 
-   wxMessageBox(msg, _("About Bacula wx-console"), wxOK | wxICON_INFORMATION, this);
+   wxMessageBox(msg, _("About Bacula bwx-console"), wxOK | wxICON_INFORMATION, this);
 }
 
 void wxbMainFrame::OnChangeConfig(wxCommandEvent& event) {
@@ -568,11 +590,18 @@ void wxbMainFrame::Print(wxString str, int status)
       EnableConsole(false);
    }
    
+   if (status == CS_REMOVEPROMPT) {
+      if (consoleCtrl->GetLastPosition() > 0) {
+         consoleCtrl->Remove(consoleCtrl->GetLastPosition()-1, consoleCtrl->GetLastPosition()+1);
+      }
+      return;
+   }
+   
    if (status == CS_TERMINATED) {
       consoleCtrl->AppendText(consoleBuffer);
       consoleBuffer = wxT("");
       SetStatusText(_("Console thread terminated."));
-#ifndef HAVE_WIN32
+#ifdef HAVE_WIN32
       consoleCtrl->PageDown();
 #else
       consoleCtrl->ScrollLines(1);
@@ -598,15 +627,24 @@ void wxbMainFrame::Print(wxString str, int status)
    if (status == CS_CONNECTED) {
       SetStatusText(_("Connected to the director."));
       typeCtrl->ClearCommandList();
+      bool parsed = false;
+      int retries = 3;
       wxbDataTokenizer* dt = wxbUtils::WaitForEnd(wxT(".help"), true);
-      int i, j;
-      wxString str;
-      for (i = 0; i < (int)dt->GetCount(); i++) {
-         str = (*dt)[i];
-         str.RemoveLast();
-         if ((j = str.Find(' ')) > -1) {
-            typeCtrl->AddCommand(str.Mid(0, j), str.Mid(j+1));
+      while (true) {
+         int i, j;
+         wxString str;
+         for (i = 0; i < (int)dt->GetCount(); i++) {
+            str = (*dt)[i];
+            str.RemoveLast();
+            if ((j = str.Find(' ')) > -1) {
+               typeCtrl->AddCommand(str.Mid(0, j), str.Mid(j+1));
+               parsed = true;
+            }
          }
+         retries--;
+         if ((parsed) || (!retries))
+            break;
+         dt = wxbUtils::WaitForEnd(wxT(""), true);
       }
       EnablePanels();
       menuFile->Enable(MenuConnect, true);
@@ -620,7 +658,7 @@ void wxbMainFrame::Print(wxString str, int status)
    if (status == CS_DISCONNECTED) {
       consoleCtrl->AppendText(consoleBuffer);
       consoleBuffer = wxT("");
-#ifndef HAVE_WIN32
+#ifdef HAVE_WIN32
       consoleCtrl->PageDown();
 #else
       consoleCtrl->ScrollLines(1);
@@ -667,7 +705,7 @@ void wxbMainFrame::Print(wxString str, int status)
             }
             
             int res = ::wxGetSingleChoiceIndex(message,
-               _("wx-console: unexpected director's question."), n, choices, this);
+               _("bwx-console: unexpected director's question."), n, choices, this);
             if (res == -1) { //Cancel pressed
                Send(wxT(".\n"));
             }
@@ -679,10 +717,12 @@ void wxbMainFrame::Print(wxString str, int status)
                   Send(wxString() << choices[res] << wxT("\n"));
                }
             }
+            delete[] choices;
+            delete[] numbers;
          }
          else {
             Send(::wxGetTextFromUser(message,
-               _("wx-console: unexpected director's question."),
+               _("bwx-console: unexpected director's question."),
                wxT(""), this) + wxT("\n"));
          }
       }
@@ -699,7 +739,7 @@ void wxbMainFrame::Print(wxString str, int status)
    if (status == CS_DEBUG) {
       consoleCtrl->AppendText(consoleBuffer);
       consoleBuffer = wxT("");
-#ifndef HAVE_WIN32
+#ifdef HAVE_WIN32
       consoleCtrl->PageDown();
 #else
       consoleCtrl->ScrollLines(1);
@@ -714,14 +754,14 @@ void wxbMainFrame::Print(wxString str, int status)
       if (lockedbyconsole) {
          EnableConsole(true);
       }
-      //consoleBuffer << "<P>";
+      //consoleBuffer << wxT("<P>");
    }
    
    if ((status == CS_END) || (status == CS_PROMPT) || (str.Find(wxT("\n")) > -1)) {
       consoleCtrl->AppendText(consoleBuffer);
       consoleBuffer = wxT("");
 
-#ifndef HAVE_WIN32
+#ifdef HAVE_WIN32
       consoleCtrl->PageDown();
 #else
       consoleCtrl->ScrollLines(1);
@@ -742,7 +782,10 @@ void wxbMainFrame::Print(wxString str, int status)
 void wxbMainFrame::Send(wxString str)
 {
    if (ct != NULL) {
-      ct->Write(str.mb_str(wxConvUTF8));
+      /* wxString may contain everything in UNICODE
+       * -> convert to UTF-8 and send to director
+       */
+      ct->Write (str.mb_str(wxConvUTF8));
       typeCtrl->SetValue(wxT(""));
       consoleCtrl->SetDefaultStyle(wxTextAttr(*wxRED));
       consoleCtrl->AppendText(wxbUtils::ConvertToPrintable(str));