]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/wx-console/wxbrestorepanel.cpp
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / wx-console / wxbrestorepanel.cpp
index 962b8e30e8b35b4b81264e14aa565663b845984f..31b459dd25a736974ced7076c1b694839eeb4ae0 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2004-2008 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.
+*/
 /*
  *
  *   wxbPanel for restoring files
@@ -6,20 +33,6 @@
  *
  *    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.
-
-   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.
-
- */
 
 /* Note concerning "done" output (modifiable marked with +)
 Run Restore job
@@ -49,21 +62,25 @@ Parameters to modify:
 Select parameter to modify (1-11):
        */
 
-#include "wxbrestorepanel.h"
+/*  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 "wxbmainframe.h"
+#undef _DEBUG
 
-#include "csprint.h"
+#include "bacula.h"
 
+#include "wxbrestorepanel.h"
+#include "wxbmainframe.h"
+#include "csprint.h"
 #include <wx/choice.h>
 #include <wx/datetime.h>
-
 #include <wx/timer.h>
-
 #include "unmarked.xpm"
 #include "marked.xpm"
 #include "partmarked.xpm"
-
+#include <wx/imaglist.h>
 #include <wx/listimpl.cpp>
 
 /* A macro named Yield is defined under MinGW */
@@ -194,7 +211,8 @@ END_EVENT_TABLE()
 /*
  *  wxbRestorePanel constructor
  */
-wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
+wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) 
+{
    //pendingEvents = new wxbEventList(); //EVTQUEUE
    //processing = false; //EVTQUEUE
    SetWorking(false);
@@ -372,7 +390,8 @@ wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
 /*
  *  wxbRestorePanel destructor
  */
-wxbRestorePanel::~wxbRestorePanel() {
+wxbRestorePanel::~wxbRestorePanel() 
+{
    delete imagelist;
 }
 
@@ -380,17 +399,18 @@ wxbRestorePanel::~wxbRestorePanel() {
    wxbPanel overloadings
   ----------------------------------------------------------------------------*/
 
-wxString wxbRestorePanel::GetTitle() {
+wxString wxbRestorePanel::GetTitle() 
+{
    return _("Restore");
 }
 
-void wxbRestorePanel::EnablePanel(bool enable) {
+void wxbRestorePanel::EnablePanel(bool enable) 
+{
    if (enable) {
       if (status == disabled) {
          SetStatus(activable);
       }
-   }
-   else {
+   } else {
       SetStatus(disabled);
    }
 }
@@ -400,7 +420,8 @@ void wxbRestorePanel::EnablePanel(bool enable) {
   ----------------------------------------------------------------------------*/
 
 /* The main button has been clicked */
-void wxbRestorePanel::CmdStart() {
+void wxbRestorePanel::CmdStart() 
+{
    unsigned int i;
    if (status == activable) {
       wxbMainFrame::GetInstance()->SetStatusText(_("Getting parameters list."));
@@ -530,14 +551,17 @@ void wxbRestorePanel::CmdStart() {
       wxbMainFrame::GetInstance()->SetStatusText(_("Please configure your restore parameters."));
    }
    else if (status == entered) {
-/*      if (clientChoice->GetStringSelection().Length() < 1) {
+#ifdef xxx
+      if (clientChoice->GetStringSelection().Length() < 1) {
          wxbMainFrame::GetInstance()->SetStatusText(_("Please select a client."));
          return;
       }
       if (jobChoice->GetStringSelection().Length() < 1) {
          wxbMainFrame::GetInstance()->SetStatusText(_("Please select a restore date."));
          return;
-      }*/
+      }
+#endif
+
       wxbMainFrame::GetInstance()->SetStatusText(_("Building restore tree..."));
       
       SetStatus(choosing);
@@ -556,17 +580,22 @@ void wxbRestorePanel::CmdStart() {
          wxT("\" storage=\"") << configPanel->GetRowString(wxT("Storage")) <<
          wxT("\" before=\"") << configPanel->GetRowString(wxT("Before")) <<
          wxT("\" select\n"));
-      //wxbUtils::WaitForPrompt("6\n");
-      //WaitForEnd();
-      /*wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxString() << configPanel->GetRowString(wxT("Before")) << "\n", true);
+
+#ifdef xxx
+      wxbUtils::WaitForPrompt("6\n");
+      WaitForEnd();
+
+      wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxString() << configPanel->GetRowString(wxT("Before")) << "\n", true);
+
       int client = pp->getChoices()->Index(configPanel->GetRowString(wxT("Client")));
       if (client == wxNOT_FOUND) {
          wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected client.");
          return;
       }
-      delete pp;*/
+      delete pp;
       
-      //wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString(wxT("Before")) << "\n");
+      wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString(wxT("Before")) << "\n");
+#endif
    
       while (!tableparser->hasFinished() && !dt->hasFinished()) {
          wxTheApp->Yield(true);
@@ -602,8 +631,10 @@ void wxbRestorePanel::CmdStart() {
       gauge->SetValue(0);
       gauge->SetRange(tot);
       
-      /*wxbMainFrame::GetInstance()->Print(
-               wxString("[") << tot << "]", CS_DEBUG);*/
+#ifdef xxx
+      wxbMainFrame::GetInstance()->Print(
+               wxString("[") << tot << "]", CS_DEBUG);
+#endif
       
       wxDateTime base = wxDateTime::Now();
       wxDateTime newdate;
@@ -708,7 +739,7 @@ void wxbRestorePanel::CmdStart() {
             }
             
             int res = ::wxGetSingleChoiceIndex(message,
-               _("wx-console: unexpected restore question."), n, choices, this);
+               _("bwx-console: unexpected restore question."), n, choices, this);
             if (res == -1) {
                delete promptparser;
                promptparser = wxbUtils::WaitForPrompt(wxT(".\n"), true);
@@ -730,7 +761,7 @@ void wxbRestorePanel::CmdStart() {
             delete promptparser;
             
             promptparser = wxbUtils::WaitForPrompt(::wxGetTextFromUser(message,
-               _("wx-console: unexpected restore question."),
+               _("bwx-console: unexpected restore question."),
                wxT(""), this) + wxT("\n"));
          }
       }
@@ -787,9 +818,9 @@ void wxbRestorePanel::CmdStart() {
       int j;
             
       for (i = 0; i < dt->GetCount(); i++) {
-         if ((j = (*dt)[i].Find(_("Job started. JobId="))) > -1) {
+         if ((j = (*dt)[i].Find(_("Job queued. JobId="))) > -1) {
             jobid = (*dt)[i].Mid(j+19);
-            wxbMainFrame::GetInstance()->SetStatusText(_("Restore started, jobid=") + jobid);
+            wxbMainFrame::GetInstance()->SetStatusText(_("Restore queued, jobid=") + jobid);
             break;
          }
 
@@ -828,8 +859,8 @@ void wxbRestorePanel::CmdStart() {
       }
 
       if (scheduledtime.Subtract(currenttime).IsLongerThan(wxTimeSpan::Seconds(150))) {
-         wxbMainFrame::GetInstance()->Print(_("Restore is scheduled in more than two minutes, wx-console will not wait for its completion.\n"), CS_DEBUG);
-         wxbMainFrame::GetInstance()->SetStatusText(_("Restore is scheduled in more than two minutes, wx-console will not wait for its completion."));
+         wxbMainFrame::GetInstance()->Print(_("Restore is scheduled to run. bwx-console will not wait for its completion.\n"), CS_DEBUG);
+         wxbMainFrame::GetInstance()->SetStatusText(_("Restore is scheduled to run. bwx-console will not wait for its completion."));
          SetStatus(finished);
          return;
       }
@@ -848,6 +879,7 @@ void wxbRestorePanel::CmdStart() {
       wxStopWatch sw;
       
       wxbUtils::WaitForEnd(wxT("autodisplay off\n"));
+      wxbUtils::WaitForEnd(wxT("gui on\n"));
       while (true) {
          tableparser = wxbUtils::CreateAndWaitForParser(cmd);
          ended = false;
@@ -924,7 +956,7 @@ void wxbRestorePanel::CmdStart() {
          }
          delete tableparser;
          
-         dt = wxbUtils::WaitForEnd(wxT("messages\n"), true);
+         dt = wxbUtils::WaitForEnd(wxT(".messages\n"), true);
                   
          for (unsigned int i = 0; i < dt->GetCount(); i++) {
             wxStringTokenizer tkz((*dt)[i], wxT(" "), wxTOKEN_STRTOK);
@@ -967,8 +999,8 @@ void wxbRestorePanel::CmdStart() {
          }
          
          if ((!waitforever) && (sw.Time() > 60000)) {
-            wxbMainFrame::GetInstance()->Print(_("The restore job has not been started within one minute, wx-console will not wait for its completion anymore.\n"), CS_DEBUG);
-            wxbMainFrame::GetInstance()->SetStatusText(_("The restore job has not been started within one minute, wx-console will not wait for its completion anymore."));
+            wxbMainFrame::GetInstance()->Print(_("The restore job has not been started within one minute, bwx-console will not wait for its completion anymore.\n"), CS_DEBUG);
+            wxbMainFrame::GetInstance()->SetStatusText(_("The restore job has not been started within one minute, bwx-console will not wait for its completion anymore."));
             break;
          }
       }
@@ -1047,7 +1079,8 @@ void wxbRestorePanel::CmdCancel() {
  *  11: JobId (no)
  */
 
-void wxbRestorePanel::CmdConfigApply() {
+void wxbRestorePanel::CmdConfigApply() 
+{
    if (cfgUpdated == 0) return;
    
    wxbMainFrame::GetInstance()->SetStatusText(_("Applying restore configuration changes..."));
@@ -1074,7 +1107,7 @@ void wxbRestorePanel::CmdConfigApply() {
       }
       else if ((cfgUpdated >> ConfigReplace) & 1) {
          wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
-         wxbUtils::WaitForPrompt(wxT("10\n"));
+         wxbUtils::WaitForPrompt(wxT("11\n"));
          dt = new wxbDataTokenizer(true);
          wxbUtils::WaitForPrompt(wxString() << (restorePanel->GetRowSelection(_("Replace"))+1) << wxT("\n"));
          def = wxT("1");
@@ -1097,49 +1130,64 @@ void wxbRestorePanel::CmdConfigApply() {
          cfgUpdated = cfgUpdated & (~(1 << ConfigPriority));
       }
       else if ((cfgUpdated >> ConfigClient) & 1) {
-         wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
-         wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxT("5\n"), true);
-         int client = pp->getChoices()->Index(restorePanel->GetRowString(_("Client")));
-         if (client == wxNOT_FOUND) {
-            wxbMainFrame::GetInstance()->SetStatusText(_("Failed to find the selected client."));
-            failed = true;
-            client = 1;
+         if (restorePanel->GetRowCount(_("Client")) > 1) {
+            wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
+            wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxT("5\n"), true);
+            int client = pp->getChoices()->Index(restorePanel->GetRowString(_("Client")));
+            if (client == wxNOT_FOUND) {
+               wxbMainFrame::GetInstance()->SetStatusText(_("Failed to find the selected client."));
+               failed = true;
+               client = 1;
+            }
+            delete pp;
+            dt = new wxbDataTokenizer(true);
+            wxbUtils::WaitForPrompt(wxString() << client << wxT("\n"));
+            def = wxT("1");
+            cfgUpdated = cfgUpdated & (~(1 << ConfigClient));
+         } else {
+            cfgUpdated = cfgUpdated & (~(1 << ConfigClient));
+            continue;
          }
-         delete pp;
-         dt = new wxbDataTokenizer(true);
-         wxbUtils::WaitForPrompt(wxString() << client << wxT("\n"));
-         def = wxT("1");
-         cfgUpdated = cfgUpdated & (~(1 << ConfigClient));
       }
       else if ((cfgUpdated >> ConfigFileset) & 1) {
-         wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
-         wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxT("4\n"), true);
-         int fileset = pp->getChoices()->Index(restorePanel->GetRowString(_("Fileset")));
-         if (fileset == wxNOT_FOUND) {
-            wxbMainFrame::GetInstance()->SetStatusText(_("Failed to find the selected fileset."));
-            failed = true;
-            fileset = 1;
+         if (restorePanel->GetRowCount(_("Fileset")) > 1) {
+            wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
+            wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxT("4\n"), true);
+            int fileset = pp->getChoices()->Index(restorePanel->GetRowString(_("Fileset")));
+            if (fileset == wxNOT_FOUND) {
+               wxbMainFrame::GetInstance()->SetStatusText(_("Failed to find the selected fileset."));
+               failed = true;
+               fileset = 1;
+            }
+            delete pp;
+            dt = new wxbDataTokenizer(true);
+            wxbUtils::WaitForPrompt(wxString() << fileset << wxT("\n"));
+            def = wxT("1");
+            cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
+         } else {
+            cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
+            continue;
          }
-         delete pp;
-         dt = new wxbDataTokenizer(true);
-         wxbUtils::WaitForPrompt(wxString() << fileset << wxT("\n"));
-         def = wxT("1");
-         cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
       }
       else if ((cfgUpdated >> ConfigStorage) & 1) {
-         wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
-         wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxT("2\n"), true);
-         int fileset = pp->getChoices()->Index(restorePanel->GetRowString(_("Storage")));
-         if (fileset == wxNOT_FOUND) {
-            wxbMainFrame::GetInstance()->SetStatusText(_("Failed to find the selected storage."));
-            failed = true;
-            fileset = 1;
+         if (restorePanel->GetRowCount(_("Storage")) > 1) {
+            wxbUtils::WaitForPrompt(wxT("mod\n")); /* TODO: check results */
+            wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxT("2\n"), true);
+            int storage = pp->getChoices()->Index(restorePanel->GetRowString(_("Storage")));
+            if (storage == wxNOT_FOUND) {
+               wxbMainFrame::GetInstance()->SetStatusText(_("Failed to find the selected storage."));
+               failed = true;
+               storage = 1;
+            }
+            delete pp;
+            dt = new wxbDataTokenizer(true);
+            wxbUtils::WaitForPrompt(wxString() << storage << wxT("\n"));
+            def = wxT("1");
+            cfgUpdated = cfgUpdated & (~(1 << ConfigStorage));
+         } else {
+            cfgUpdated = cfgUpdated & (~(1 << ConfigStorage));
+            continue;
          }
-         delete pp;
-         dt = new wxbDataTokenizer(true);
-         wxbUtils::WaitForPrompt(wxString() << fileset << wxT("\n"));
-         def = wxT("1");
-         cfgUpdated = cfgUpdated & (~(1 << ConfigStorage));
       }
       else {
          cfgUpdated = 0;
@@ -1153,7 +1201,7 @@ void wxbRestorePanel::CmdConfigApply() {
          }
       }
       
-      if (i == dt->GetCount()) {
+      if (i != 0 && i == dt->GetCount()) {
          delete dt;   
          dt = wxbUtils::WaitForEnd(def + wxT("\n"), true);
          failed = true;
@@ -1162,6 +1210,7 @@ void wxbRestorePanel::CmdConfigApply() {
    UpdateSecondConfig(dt); /* TODO: Check result */
    
    EnableConfig(true);
+   restorePanel->EnableApply(false);
 
    if (!failed) {
       wxbMainFrame::GetInstance()->SetStatusText(_("Restore configuration changes were applied."));
@@ -1303,7 +1352,7 @@ void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long* listitems, int listsi
       wxString file;
 
       if (dir != wxT("/")) {
-         if (dir.GetChar(dir.Length()-1) == '/') {
+         if (IsPathSeparator(dir.GetChar(dir.Length()-1))) {
             dir.RemoveLast();
          }
 
@@ -1396,7 +1445,8 @@ void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long* listitems, int listsi
   ----------------------------------------------------------------------------*/
 
 /* Run a dir command, and waits until result is fully received. */
-void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse) {
+void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse)
+{
 //   this->updatelist = updatelist;
    wxbDataTokenizer* dt;
 
@@ -1432,7 +1482,7 @@ void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist, bool re
 
       wxTreeItemId treeid;
 
-      if (entry.fullname.GetChar(entry.fullname.Length()-1) == '/') {
+      if (IsPathSeparator(entry.fullname.GetChar(entry.fullname.Length()-1))) {
          wxString itemStr;
 
 #if wxCHECK_VERSION(2, 6, 0)
@@ -1488,7 +1538,8 @@ void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist, bool re
 }
 
 /* Parse .dir command results, returns true if the result has been stored in entry, false otherwise. */
-int wxbRestorePanel::ParseList(wxString line, wxbDirEntry* entry) {
+int wxbRestorePanel::ParseList(wxString line, wxbDirEntry* entry) 
+{
    /* See ls_output in dird/ua_tree.c */
    //-rw-r-----,1,root,root,41575,2005-10-18 18:21:36, ,/usr/var/bacula/working/bacula.sql
 
@@ -1533,10 +1584,10 @@ int wxbRestorePanel::ParseList(wxString line, wxbDirEntry* entry) {
    
    if (!tkz.HasMoreTokens())
       return false;
-   entry->fullname = tkz.GetNextToken();
+   entry->fullname = tkz.GetString();
    
    /* Get only the filename (cut path by finding the last '/') */
-   if (entry->fullname.GetChar(entry->fullname.Length()-1) == '/') {
+   if (IsPathSeparator(entry->fullname.GetChar(entry->fullname.Length()-1))) {
       wxString tmp = entry->fullname;
       tmp.RemoveLast();
       entry->filename = entry->fullname.Mid(tmp.Find('/', true)+1);
@@ -1549,7 +1600,8 @@ int wxbRestorePanel::ParseList(wxString line, wxbDirEntry* entry) {
 }
 
 /* Sets a list item state, and update its parents and children if it is a directory */
-void wxbRestorePanel::SetListItemState(long listitem, int newstate) {
+void wxbRestorePanel::SetListItemState(long listitem, int newstate) 
+{
    wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
    
    wxTreeItemId treeitem;
@@ -1864,6 +1916,7 @@ bool wxbRestorePanel::UpdateSecondConfig(wxbDataTokenizer* dt) {
    restorePanel->SetRowString(_("Storage"), (*dt)[i].Mid(10).Trim(false).RemoveLast());
    if ((k = (*dt)[++i].Find(_("When:"))) != 0) return false;
    restorePanel->SetRowString(_("When"), (*dt)[i].Mid(10).Trim(false).RemoveLast());
+   i++;        /* Skip catalog field */
    if ((k = (*dt)[++i].Find(_("Priority:"))) != 0) return false;
    restorePanel->SetRowString(_("Priority"), (*dt)[i].Mid(10).Trim(false).RemoveLast());
    cfgUpdated = 0;
@@ -1941,7 +1994,6 @@ void wxbRestorePanel::SetStatus(status_enum newstatus) {
       cfgUpdated = 0;
       break;
    case listing:
-      
       break;
    case choosing:
       start->Enable(true);
@@ -1970,6 +2022,7 @@ void wxbRestorePanel::SetStatus(status_enum newstatus) {
       centerSizer->Layout();
       this->Layout();
       restorePanel->EnableApply(false);
+      cancel->Enable(true);
       break;
    case restoring:
       start->SetLabel(_("Restoring..."));
@@ -2222,7 +2275,7 @@ void wxbRestorePanel::OnListActivated(wxListEvent& event) {
       long cookie;
 #endif
 
-      if (name.GetChar(name.Length()-1) == '/') {
+      if (IsPathSeparator(name.GetChar(name.Length()-1))) {
          wxTreeItemId currentChild = tree->GetFirstChild(currentTreeItem, cookie);
 
          while (currentChild.IsOk()) {
@@ -2336,7 +2389,8 @@ void wxbRestorePanel::OnListRemove(wxCommandEvent& event) {
    listremove->Enable(false);
 }
 
-void wxbRestorePanel::OnListRefresh(wxCommandEvent& event) {
+void wxbRestorePanel::OnListRefresh(wxCommandEvent& event) 
+{
    if (IsWorking()) {
       return;
    }
@@ -2346,7 +2400,8 @@ void wxbRestorePanel::OnListRefresh(wxCommandEvent& event) {
    SetWorking(false);
 }
 
-void wxbRestorePanel::OnConfigUpdated(wxCommandEvent& event) {
+void wxbRestorePanel::OnConfigUpdated(wxCommandEvent& event) 
+{
    if (status == entered) {
       if (event.GetId() == ConfigJobName) {
          if (IsWorking()) {