]> git.sur5r.net Git - bacula/bacula/commitdiff
modified the way data is passed to panels (wxbDataParsers instead of Prints)
authorNicolas Boichat <nicolas@boichat.ch>
Sat, 17 Apr 2004 22:14:29 +0000 (22:14 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Sat, 17 Apr 2004 22:14:29 +0000 (22:14 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1226 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/wx-console/CHANGELOG
bacula/src/wx-console/TODO
bacula/src/wx-console/wxbmainframe.cpp
bacula/src/wx-console/wxbmainframe.h
bacula/src/wx-console/wxbrestorepanel.cpp
bacula/src/wx-console/wxbrestorepanel.h
bacula/src/wx-console/wxbtableparser.cpp
bacula/src/wx-console/wxbtableparser.h
bacula/src/wx-console/wxbutils.cpp [new file with mode: 0644]
bacula/src/wx-console/wxbutils.h [new file with mode: 0644]

index fa6bb903bbd339a7e25f2bc20e9afdde40fb01d1..85f446ab90a7bf80653dce1c836f62bf824043c9 100644 (file)
@@ -1,4 +1,10 @@
 17-04-2004 :
+ - wxbRestorePanel modified to use wxbDataParsers
+ - created wxbDataTokenizer, which fetches commands results
+ - modified the way data is passed to panel (no Prints anymore,
+    but wxbDataParsers)
+ - win32 : Makefile.in corrected to use ressource file
+ - win32 : wx-console is now compatible with MinGW.
  - wxbPanel/wxbMainFrame : Added a locking function (for example, 
    the user can't type something in the console when a restore
    is in progress)
index 5b6152e94287aeee9373c4d5ae931cb470a45493..177ff76f6b1e16dfd8784ed8deefa391e6f4d629 100644 (file)
@@ -11,15 +11,13 @@ wxbRestorePanel : Add a timeout when waiting for commands results
 
 wxbRestorePanel : Check more carefully which job we just have run.
 
-console_thread : Allow the user to choose his config file.
-
-general : use dot commands
+wxbRestorePanel : Check if commands run successfully (cd, mark...).
 
-general : create a class like wxbtableparser, which fetches commands results
+wxbTableParser : Replace wxHashMap by wxArray
 
-win32 : do a static build
+console_thread : Allow the user to choose his config file.
 
-win32 : correct Makefile.in to use ressource file
+general : use dot commands
 
 BUGS
 ----
index 1c95ee8e8d30e5d2238d604110b10de0f4d1341b..ab83fc91b05c90d7492e664aeb45a1a52ed42892 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "wxwin16x16.xpm"
 
+#include <wx/arrimpl.cpp>
+
 // ----------------------------------------------------------------------------
 // event tables and other macros for wxWindows
 // ----------------------------------------------------------------------------
@@ -267,6 +269,22 @@ void wxbMainFrame::StartConsoleThread()
    ct->Run();
 }
 
+/* Register a new wxbDataParser */
+void wxbMainFrame::Register(wxbDataParser* dp) {
+   parsers.Add(dp);
+}
+   
+/* Unregister a wxbDataParser */
+void wxbMainFrame::Unregister(wxbDataParser* dp) {
+   int index;
+   if ((index = parsers.Index(dp)) != wxNOT_FOUND) {
+      parsers.RemoveAt(index);
+   }
+   else {
+      Print("Failed to unregister a data parser !", CS_DEBUG);
+   }
+}
+
 // event handlers
 
 void wxbMainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
@@ -315,8 +333,8 @@ void wxbMainFrame::Print(wxString str, int status)
    // CS_DEBUG is often sent by panels, 
    // and resend it to them would sometimes cause an infinite loop
    if (status != CS_DEBUG) {
-      for (int i = 0; panels[i] != NULL; i++) {
-         panels[i]->Print(str, status);
+      for (unsigned int i = 0; i < parsers.GetCount(); i++) {
+         parsers[i]->Print(str, status);
        }
    }
 
index d3ac94994e1f613421903e9c28b4c18a1b631f37..a8777f6488dbd427529197ee140af276774220ee 100644 (file)
 #include <wx/tokenzr.h>
 #include <wx/notebook.h>
 
-//#include "bacula.h"
-//#include "console_conf.h"
+#include <wx/dynarray.h>
 
 #include "console_thread.h"
 
-#include "wxbpanel.h"
+#include "wxbutils.h"
+
+WX_DEFINE_ARRAY(wxbDataParser*, wxbDataParsers);
 
 // ----------------------------------------------------------------------------
 // wxbPrintObject - Used by wxbThreadEvent to contain data sent by director
@@ -115,6 +116,12 @@ public:
     *  Starts the thread interacting with the director
     */
    void StartConsoleThread();
+   
+   /* Register a new wxbDataParser */
+   void Register(wxbDataParser* dp);
+   
+   /* Unregister a wxbDataParser */
+   void Unregister(wxbDataParser* dp);
 
 private:
    /* private constructor, singleton */
@@ -125,7 +132,8 @@ private:
    wxTextCtrl *typeCtrl; /* wxTextCtrl for console user input */
    wxTextCtrl *consoleCtrl; /* wxTextCtrl containing graphical console */
 
-   wxbPanel **panels; /* panels array, contained in the notebook, and which need to receive console communication */
+   wxbPanel **panels; /* panels array, contained in the notebook */
+   wxbDataParsers parsers; /* Data parsers, which need to receive director informations */
 
    console_thread* ct; /* thread interacting with the director */
 
index 0a1b5abed95a6cdb7cfa8a5c3217d80e2c48dc02..5a39e9ba4f449795c73ae0884309abddc79de6a3 100644 (file)
@@ -239,8 +239,6 @@ wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
 
    SetStatus(disabled);
 
-   tableParser = NULL;
-
    jobChoice->Enable(false);
 
    working = false;
@@ -261,127 +259,6 @@ wxString wxbRestorePanel::GetTitle() {
    return "Restore";
 }
 
-void wxbRestorePanel::Print(wxString str, int stat) {
-   if (str == "$ ") {
-      ended = true;
-   }
-   else if (status == listing) {
-      if (str.Find("cwd is:") == 0) { // Sometimes cd command result "infiltrate" into listings.
-         return;
-      }
-
-      str.RemoveLast();
-
-      wxString* file = ParseList(str);
-      
-      if (file == NULL)
-            return;
-
-      wxTreeItemId treeid;
-
-      if (file[8].GetChar(file[8].Length()-1) == '/') {
-         wxString itemStr;
-
-         long cookie;
-         treeid = tree->GetFirstChild(currentTreeItem, cookie);
-
-         bool updated = false;
-
-         while (treeid.IsOk()) {
-            itemStr = tree->GetItemText(treeid);
-            if (file[8] == itemStr) {
-               int stat = wxbTreeItemData::GetMarkedStatus(file[6]);
-               if (static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->GetMarked() != stat) {
-                  tree->SetItemImage(treeid, stat, wxTreeItemIcon_Normal);
-                  tree->SetItemImage(treeid, stat, wxTreeItemIcon_Selected);
-                  static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->SetMarked(file[6]);
-               }
-               updated = true;
-               break;
-            }
-            treeid = tree->GetNextChild(currentTreeItem, cookie);
-         }
-
-         if (!updated) {
-            int img = wxbTreeItemData::GetMarkedStatus(file[6]);
-            treeid = tree->AppendItem(currentTreeItem, file[8], img, img, new wxbTreeItemData(file[7], file[8], file[6]));
-         }
-      }
-
-      if (updatelist) {
-         long ind = list->InsertItem(list->GetItemCount(), wxbTreeItemData::GetMarkedStatus(file[6]));
-         wxbTreeItemData* data = new wxbTreeItemData(file[7], file[8], file[6], ind);
-         data->SetId(treeid);
-         list->SetItemData(ind, (long)data);
-         list->SetItem(ind, 1, file[8]); // filename
-         list->SetItem(ind, 2, file[4]); //Size
-         list->SetItem(ind, 3, file[5]); //date
-         list->SetItem(ind, 4, file[0]); //perm
-         list->SetItem(ind, 5, file[2]); //user
-         list->SetItem(ind, 6, file[3]); //grp
-      }
-
-      delete[] file;
-   }
-   else {
-      if (status == restoring) {
-         int i;
-         //15847 total files; 1 marked to be restored; 1,034 bytes.
-         if ((i = str.Find(" marked to be restored;")) > -1) {
-            int j = str.Find("; ");
-            str.Mid(j+2, i).ToLong(&totfilemessages);
-            //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
-            return;
-         }
-
-         if ((i = str.Find(" files selected to be restored.")) > -1) {
-            str.Mid(0, i).ToLong(&totfilemessages);
-            //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
-            return;
-         }
-
-         if ((i = str.Find(" file selected to be restored.")) > -1) {
-            str.Mid(0, i).ToLong(&totfilemessages);
-            //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
-            return;
-         }
-
-         wxStringTokenizer tkz(str, " ", wxTOKEN_STRTOK);
-
-         wxDateTime datetime;
-
-         //   Date    Time   name:   perm      ?   user   grp      size    date     time
-         //04-Apr-2004 17:19 Tom-fd: -rwx------   1 nicolas  None     514967 2004-03-20 20:03:42  filename
-
-         if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { // Date
-            if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { // Time
-               if (tkz.GetNextToken().Last() == ':') { // name:
-               tkz.GetNextToken(); // perm
-               tkz.GetNextToken(); // ?
-               tkz.GetNextToken(); // user
-               tkz.GetNextToken(); // grp
-               tkz.GetNextToken(); // size
-               if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { //date
-                     if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { //time
-                        filemessages++;
-                        //wxbMainFrame::GetInstance()->Print(wxString("(") << filemessages << ")", CS_DEBUG);
-                        gauge->SetValue(filemessages);
-                     }
-                  }
-               }
-            }
-         }
-      }
-
-      if (tableParser != NULL) {
-         tableParser->Print(str, stat);
-      }
-      if (stat == CS_END) {
-         ended = true;
-      }
-   }
-}
-
 void wxbRestorePanel::EnablePanel(bool enable) {
    if (enable) {
       if (status == disabled) {
@@ -400,18 +277,16 @@ void wxbRestorePanel::EnablePanel(bool enable) {
 /* The main button has been clicked */
 void wxbRestorePanel::CmdStart() {
    if (status == activable) {
-      CreateAndWaitForParser("list clients\n");
+      wxbTableParser* tableparser = CreateAndWaitForParser("list clients\n");
 
       clientChoice->Clear();
-      for (unsigned int i = 0; i < tableParser->size(); i++) {
-         /*for (unsigned int k = 0; k < (*tableParser)[i].size(); k++) {
-            wxbMainFrame::GetInstance()->Print(wxString() << (*tableParser)[i][k] << ":", CS_DEBUG);
-         }
-         wxbMainFrame::GetInstance()->Print(wxString(";\n"), CS_DEBUG);*/
+      for (unsigned int i = 0; i < tableparser->size(); i++) {
          long* j = new long;
-         (*tableParser)[i][0].ToLong(j);
-         clientChoice->Append((*tableParser)[i][1], (void*)j);
+         (*tableparser)[i][0].ToLong(j);
+         clientChoice->Append((*tableparser)[i][1], (void*)j);
       }
+      
+      delete tableparser;
 
       SetStatus(entered);
    }
@@ -428,7 +303,7 @@ void wxbRestorePanel::CmdStart() {
       SetStatus(choosing);
       wxTreeItemId root = tree->AddRoot(clientChoice->GetStringSelection(), -1, -1, new wxbTreeItemData("/", clientChoice->GetStringSelection(), 0));
       tree->Refresh();
-      WaitForList(root, true);
+      UpdateTreeItem(root, true);
       wxbMainFrame::GetInstance()->SetStatusText("Right click on a file or on a directory, or double-click on its mark to add it to the restore list.");
       tree->Expand(root);
    }
@@ -438,8 +313,38 @@ void wxbRestorePanel::CmdStart() {
       wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
 
       totfilemessages = 0;
-      WaitForEnd("estimate\n");
-      WaitForEnd("done\n");
+      wxbDataTokenizer* dt;
+      
+      dt = WaitForEnd("estimate\n");
+      
+      int j, k;
+      
+      for (unsigned int i = 0; i < dt->GetCount(); i++) {
+         /* 15847 total files; 1 marked to be restored; 1,034 bytes. */
+         if ((j = (*dt)[i].Find(" marked to be restored;")) > -1) {
+            k = (*dt)[i].Find("; ");
+            (*dt)[i].Mid(k+2, j).ToLong(&totfilemessages);
+            return;
+         }
+      }
+      
+      delete dt;
+      
+      dt = WaitForEnd("done\n", true);
+
+      for (unsigned int i = 0; i < dt->GetCount(); i++) {
+         if ((j = (*dt)[i].Find(" files selected to be restored.")) > -1) {
+            (*dt)[i].Mid(0, j).ToLong(&totfilemessages);
+            return;
+         }
+
+         if ((j = (*dt)[i].Find(" file selected to be restored.")) > -1) {
+            (*dt)[i].Mid(0, j).ToLong(&totfilemessages);
+            return;
+         }
+      }
+      
+      delete dt;
 
       if (totfilemessages == 0) {
          wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
@@ -455,19 +360,52 @@ void wxbRestorePanel::CmdStart() {
 
       wxString cmd = "list jobid=";
 
-      CreateAndWaitForParser("list jobs\n");
+      wxbTableParser* tableparser = CreateAndWaitForParser("list jobs\n");
         /* TODO (#1#): Check more carefully which job we just have run. */
-      cmd << (*tableParser)[tableParser->size()-1][0] << "\n";
+      cmd << (*tableparser)[tableparser->size()-1][0] << "\n";
+
+      delete tableparser;
 
       filemessages = 0;
 
       while (true) {
-         CreateAndWaitForParser(cmd);
-         if ((*tableParser)[0][7] != "C") {
+         tableparser = CreateAndWaitForParser(cmd);
+         if ((*tableparser)[0][7] != "C") {
             break;
          }
+         delete tableparser;
 
-         WaitForEnd("messages\n");
+         dt = WaitForEnd("messages\n", true);
+         
+         for (unsigned int i = 0; i < dt->GetCount(); i++) {
+            wxStringTokenizer tkz((*dt)[i], " ", wxTOKEN_STRTOK);
+   
+            wxDateTime datetime;
+   
+            //   Date    Time   name:   perm      ?   user   grp      size    date     time
+            //04-Apr-2004 17:19 Tom-fd: -rwx------   1 nicolas  None     514967 2004-03-20 20:03:42  filename
+   
+            if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { // Date
+               if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { // Time
+                  if (tkz.GetNextToken().Last() == ':') { // name:
+                  tkz.GetNextToken(); // perm
+                  tkz.GetNextToken(); // ?
+                  tkz.GetNextToken(); // user
+                  tkz.GetNextToken(); // grp
+                  tkz.GetNextToken(); // size
+                  if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { //date
+                        if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { //time
+                           filemessages++;
+                           //wxbMainFrame::GetInstance()->Print(wxString("(") << filemessages << ")", CS_DEBUG);
+                           gauge->SetValue(filemessages);
+                        }
+                     }
+                  }
+               }
+            }
+         }
+         
+         delete dt;
 
          wxbMainFrame::GetInstance()->SetStatusText(wxString("Restoring, please wait (") << filemessages << " of " << totfilemessages << " files done)...");
 
@@ -481,7 +419,7 @@ void wxbRestorePanel::CmdStart() {
 
       gauge->SetValue(totfilemessages);
 
-      if ((*tableParser)[0][7] == "T") {
+      if ((*tableparser)[0][7] == "T") {
          wxbMainFrame::GetInstance()->Print("Restore done successfully.\n", CS_DEBUG);
          wxbMainFrame::GetInstance()->SetStatusText("Restore done successfully.");
       }
@@ -489,6 +427,7 @@ void wxbRestorePanel::CmdStart() {
          wxbMainFrame::GetInstance()->Print("Restore failed, please look at messages.\n", CS_DEBUG);
          wxbMainFrame::GetInstance()->SetStatusText("Restore failed, please look at messages in console.");
       }
+      delete tableparser;
       SetStatus(finished);
    }
 }
@@ -499,10 +438,10 @@ void wxbRestorePanel::CmdListJobs() {
       jobChoice->Clear();
       WaitForEnd("query\n");
       WaitForEnd("6\n");
-      CreateAndWaitForParser(clientChoice->GetString(clientChoice->GetSelection()) + "\n");
+      wxbTableParser* tableparser = CreateAndWaitForParser(clientChoice->GetString(clientChoice->GetSelection()) + "\n");
 
-      for (int i = tableParser->size()-1; i > -1; i--) {
-         wxString str = (*tableParser)[i][3];
+      for (int i = tableparser->size()-1; i > -1; i--) {
+         wxString str = (*tableparser)[i][3];
          wxDateTime datetime;
          const char* chr;
          if ( ( (chr = datetime.ParseDate(str.GetData()) ) != NULL ) && ( datetime.ParseTime(++chr) != NULL ) ) {
@@ -514,6 +453,8 @@ void wxbRestorePanel::CmdListJobs() {
          jobChoice->Append("Invalid");
          }*/
       }
+      
+      delete tableparser;
 
       jobChoice->SetSelection(0);
    }
@@ -527,7 +468,7 @@ void wxbRestorePanel::CmdList(wxTreeItemId item) {
       if (!item.IsOk()) {
          return;
       }
-      WaitForList(item, (tree->GetSelection() == item));
+      UpdateTreeItem(item, (tree->GetSelection() == item));
     
       if (list->GetItemCount() > 1) {
          int firstwidth = list->GetSize().GetWidth(); 
@@ -589,6 +530,8 @@ void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long listitem) {
       WaitForEnd(wxString("cd ") << dir << "\n");
       WaitForEnd(wxString((itemdata->GetMarked() == 1) ? "unmark " : "mark ") << file << "\n");
 
+      /* TODO: Check commands results */
+
       /*if ((dir == "/") && (file == "*")) {
             itemdata->SetMarked((itemdata->GetMarked() == 1) ? 0 : 1);
       }*/
@@ -617,11 +560,8 @@ void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long listitem) {
   ----------------------------------------------------------------------------*/
 
 /* Parse a table in tableParser */
-void wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
-   if (tableParser != NULL) {
-      delete tableParser;
-   }
-   tableParser = new wxbTableParser();
+wxbTableParser* wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
+   wxbTableParser* tableParser = new wxbTableParser();
 
    wxbMainFrame::GetInstance()->Send(cmd);
 
@@ -631,35 +571,116 @@ void wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
       wxTheApp->Yield();
       //if (base+15 < wxDateTime::Now().GetTicks()) break;
    }
+   return tableParser;
 }
 
 /* Run a command, and waits until result is fully received. */
-void wxbRestorePanel::WaitForEnd(wxString cmd) {
-   wxbMainFrame::GetInstance()->Send(cmd);
+wxbDataTokenizer* wxbRestorePanel::WaitForEnd(wxString cmd, bool keepresults) {
+   wxbDataTokenizer* datatokenizer = new wxbDataTokenizer();
 
-   ended = false;
+   wxbMainFrame::GetInstance()->Send(cmd);
 
    //time_t base = wxDateTime::Now().GetTicks();
-   while (!ended) {
+   while (!datatokenizer->hasFinished()) {
       //innerThread->Yield();
       wxTheApp->Yield();
       //if (base+15 < wxDateTime::Now().GetTicks()) break;
    }
+   if (keepresults) {
+      return datatokenizer;
+   }
+   else {
+      delete datatokenizer;
+      return NULL;
+   }
 }
 
 /* Run a dir command, and waits until result is fully received. */
-void wxbRestorePanel::WaitForList(wxTreeItemId item, bool updatelist) {
-   this->updatelist = updatelist;
+void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist) {
+//   this->updatelist = updatelist;
    currentTreeItem = item;
 
-   WaitForEnd(wxString("cd \"") << static_cast<wxbTreeItemData*>(tree->GetItemData(currentTreeItem))->GetPath() << "\"\n");
+   wxbDataTokenizer* dt;
+
+   dt = WaitForEnd(wxString("cd \"") << 
+      static_cast<wxbTreeItemData*>(tree->GetItemData(currentTreeItem))
+         ->GetPath() << "\"\n", false);
+
+   /* TODO: check command result */
+   
+   //delete dt;
 
    SetStatus(listing);
 
    if (updatelist)
       list->DeleteAllItems();
-   WaitForEnd("dir\n");
+   dt = WaitForEnd("dir\n", true);
+   
+   wxString str;
+   
+   for (unsigned int i = 0; i < dt->GetCount(); i++) {
+      str = (*dt)[i];
+      
+      if (str.Find("cwd is:") == 0) { // Sometimes cd command result "infiltrate" into listings.
+         break;
+      }
+
+      str.RemoveLast();
+
+      wxString* file = ParseList(str);
+      
+      if (file == NULL)
+            break;
+
+      wxTreeItemId treeid;
 
+      if (file[8].GetChar(file[8].Length()-1) == '/') {
+         wxString itemStr;
+
+         long cookie;
+         treeid = tree->GetFirstChild(currentTreeItem, cookie);
+
+         bool updated = false;
+
+         while (treeid.IsOk()) {
+            itemStr = tree->GetItemText(treeid);
+            if (file[8] == itemStr) {
+               int stat = wxbTreeItemData::GetMarkedStatus(file[6]);
+               if (static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->GetMarked() != stat) {
+                  tree->SetItemImage(treeid, stat, wxTreeItemIcon_Normal);
+                  tree->SetItemImage(treeid, stat, wxTreeItemIcon_Selected);
+                  static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->SetMarked(file[6]);
+               }
+               updated = true;
+               break;
+            }
+            treeid = tree->GetNextChild(currentTreeItem, cookie);
+         }
+
+         if (!updated) {
+            int img = wxbTreeItemData::GetMarkedStatus(file[6]);
+            treeid = tree->AppendItem(currentTreeItem, file[8], img, img, new wxbTreeItemData(file[7], file[8], file[6]));
+         }
+      }
+
+      if (updatelist) {
+         long ind = list->InsertItem(list->GetItemCount(), wxbTreeItemData::GetMarkedStatus(file[6]));
+         wxbTreeItemData* data = new wxbTreeItemData(file[7], file[8], file[6], ind);
+         data->SetId(treeid);
+         list->SetItemData(ind, (long)data);
+         list->SetItem(ind, 1, file[8]); // filename
+         list->SetItem(ind, 2, file[4]); //Size
+         list->SetItem(ind, 3, file[5]); //date
+         list->SetItem(ind, 4, file[0]); //perm
+         list->SetItem(ind, 5, file[2]); //user
+         list->SetItem(ind, 6, file[3]); //grp
+      }
+
+      delete[] file;
+   }
+   
+   delete dt;
+   
    tree->Refresh();
    SetStatus(choosing);
 }
@@ -841,7 +862,7 @@ void wxbRestorePanel::UpdateTreeItemState(wxTreeItemId item) {
  * by asking the director for new lists 
  */
 void wxbRestorePanel::RefreshTree(wxTreeItemId item) {
-/*   WaitForList(item, updatelist);
+/*   UpdateTreeItem(item, updatelist);*/
 
    /* Update all child which are not collapsed */
 /*   long cookie;
index a97a479ce4a4cd0800fc8cb498ded0d93865069e..c84fcb3ab85e0645c90aeb6d3f2c2b6bd5e903ed 100644 (file)
@@ -32,7 +32,7 @@
 #include <wx/treectrl.h>
 #include <wx/gauge.h>
 
-#include "wxbpanel.h"
+#include "wxbutils.h"
 
 #include "wxbtreectrl.h"
 #include "wxblistctrl.h"
@@ -48,7 +48,6 @@ class wxbRestorePanel : public wxbPanel
 
       /* wxbPanel overloadings */
       virtual wxString GetTitle();
-      virtual void Print(wxString str, int status);
       virtual void EnablePanel(bool enable = true);
 
    private:
@@ -72,21 +71,16 @@ class wxbRestorePanel : public wxbPanel
       long filemessages; /* When restoring, number of files restored */
       long totfilemessages; /* When restoring, number of files to be restored */
 
-      /* When listing a directory, sets if file list must be updated
-       * (otherwise only the tree structure is updated)
-       */
-      bool updatelist;
-
-      wxbTableParser* tableParser; /* Used to parse tables */
-
       /* Parse a table in tableParser */
-      void CreateAndWaitForParser(wxString cmd);
+      wxbTableParser* CreateAndWaitForParser(wxString cmd);
 
-      /* Run a command, and waits until result is fully received. */
-      void WaitForEnd(wxString cmd);
+      /* Run a command, and waits until result is fully received,
+       * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
+       * containing the data. */
+      wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false);
 
       /* Run a dir command, and waits until result is fully received. */
-      void WaitForList(wxTreeItemId item, bool updatelist);
+      void UpdateTreeItem(wxTreeItemId item, bool updatelist);
 
       /* Parse dir command results. */
       wxString* ParseList(wxString line);
index f5cbf84d3cf6c11f8149c4c45806bda2ae6b75cf..71d354d6401dab8c048587ab7270238bea66d95e 100644 (file)
@@ -41,7 +41,7 @@
 /*
  *   wxbTableParser constructor
  */
-wxbTableParser::wxbTableParser() : wxbTable(5) {
+wxbTableParser::wxbTableParser() : wxbTable(5), wxbDataParser() {
    separatorNum = 0;
    tableHeader = wxbTableRow(5);
 }
index fb249592d38964b40106f898fe24fc7afdf6a78e..0f07aae30cc9d129907dbcefccf96070518c188e 100644 (file)
@@ -45,6 +45,8 @@
    #include "wx/wx.h"
 #endif
 
+#include "wxbutils.h"
+
 #include <wx/hashmap.h>
 
 /* int-indexed array of wxString, used for one line */
@@ -58,17 +60,17 @@ WX_DECLARE_HASH_MAP( int, wxbTableRow, wxIntegerHash, wxIntegerEqual, wxbTable )
  *
  * Example : wxString elem = parser[3][2]; fetches column 2 of element 3.
  */
-class wxbTableParser: public wxbTable
+class wxbTableParser: public wxbTable, public wxbDataParser
 {
    public:
       wxbTableParser();
-      ~wxbTableParser();
+      virtual ~wxbTableParser();
 
       /*
        *   Receives director information, forwarded by the wxbPanel which
        *  uses this parser.
        */
-      void Print(wxString str, int status);
+      virtual void Print(wxString str, int status);
 
       /*
        *   Return true table parsing has finished.
diff --git a/bacula/src/wx-console/wxbutils.cpp b/bacula/src/wx-console/wxbutils.cpp
new file mode 100644 (file)
index 0000000..e639144
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *
+ *   wxbDataParser, class that receives and analyses data
+ *
+ *    Nicolas Boichat, April 2004
+ *
+ */
+/*
+   Copyright (C) 2004 Kern Sibbald and John Walker
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   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 General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+#include "wxbutils.h"
+
+#include "wxbmainframe.h"
+
+#include "csprint.h"
+
+/* Creates a new wxbDataParser, and register it in wxbMainFrame */
+wxbDataParser::wxbDataParser() {
+   wxbMainFrame::GetInstance()->Register(this);
+}
+
+/* Destroy a wxbDataParser, and unregister it in wxbMainFrame */
+wxbDataParser::~wxbDataParser() {
+   wxbMainFrame::GetInstance()->Unregister(this);
+}
+
+/* Creates a new wxbDataTokenizer */
+wxbDataTokenizer::wxbDataTokenizer(): wxbDataParser(), wxArrayString() {
+   finished = false;
+}
+
+/* Destroy a wxbDataTokenizer */
+wxbDataTokenizer::~wxbDataTokenizer() {
+
+}
+
+/*
+ *   Receives director information, forwarded by wxbMainFrame.
+ */
+void wxbDataTokenizer::Print(wxString str, int status) {
+   finished = ((status == CS_END) || (status == CS_DISCONNECTED));
+
+   if (str != "") {
+      Add(str);
+   }
+}
+
+/* Returns true if the last signal received was an end signal, 
+ * indicating that no more data is available */
+bool wxbDataTokenizer::hasFinished() {
+   return finished;
+}
diff --git a/bacula/src/wx-console/wxbutils.h b/bacula/src/wx-console/wxbutils.h
new file mode 100644 (file)
index 0000000..b7726a3
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *
+ *   wxbDataParser, class that receives and analyses data
+ *   wxbPanel, main frame's notebook panels
+ *
+ *    Nicolas Boichat, April 2004
+ *
+ */
+/*
+   Copyright (C) 2004 Kern Sibbald and John Walker
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   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 General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef WXBPANEL_H
+#define WXBPANEL_H
+
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+   #include "wx/wx.h"
+#endif
+
+/*
+ *  abstract class that can receive director information.
+ */
+class wxbDataParser
+{
+   public:
+      /* Creates a new wxbDataParser, and register it in wxbMainFrame */
+      wxbDataParser();
+
+      /* Destroy a wxbDataParser, and unregister it in wxbMainFrame */
+      virtual ~wxbDataParser();
+
+      /*
+       *   Receives director information, forwarded by wxbMainFrame.
+       */
+      virtual void Print(wxString str, int status) = 0;
+};
+
+/*
+ *  abstract panel that can receive director information.
+ */
+class wxbPanel : public wxPanel
+{
+   public:
+      wxbPanel(wxWindow* parent) : wxPanel(parent) {}
+
+      /*
+       *   Tab title in the notebook.
+       */
+      virtual wxString GetTitle() = 0;
+      
+      /*
+       *   Enable or disable this panel
+       */
+      virtual void EnablePanel(bool enable = true) = 0;
+};
+
+/*
+ *  Receives director information, and splits it by line.
+ * 
+ * datatokenizer[0] retrieves first line
+ */
+class wxbDataTokenizer: public wxbDataParser, public wxArrayString
+{
+   public:
+      /* Creates a new wxbDataTokenizer */
+      wxbDataTokenizer();
+
+      /* Destroy a wxbDataTokenizer */
+      virtual ~wxbDataTokenizer();
+
+      /*
+       *   Receives director information, forwarded by wxbMainFrame.
+       */
+      virtual void Print(wxString str, int status);
+      
+      /* Returns true if the last signal received was an end signal, 
+       * indicating that no more data is available */
+      bool hasFinished();
+      
+   private:
+      bool finished;
+      wxString buffer;
+};
+
+#endif // WXBPANEL_H
+