]> git.sur5r.net Git - bacula/bacula/commitdiff
- Added a locking function in wxbPanel.
authorNicolas Boichat <nicolas@boichat.ch>
Sat, 17 Apr 2004 10:12:54 +0000 (10:12 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Sat, 17 Apr 2004 10:12:54 +0000 (10:12 +0000)
 - All panels are locked if we aren't connected
 - Fixed multiple refreshing when double-clicking on a folder in the list.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1221 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/wx-console/CHANGELOG
bacula/src/wx-console/TODO
bacula/src/wx-console/console_thread.cpp
bacula/src/wx-console/csprint.h
bacula/src/wx-console/wxbmainframe.cpp
bacula/src/wx-console/wxbmainframe.h
bacula/src/wx-console/wxbrestorepanel.cpp
bacula/src/wx-console/wxbrestorepanel.h

index 837f7b3b81c4904869758c0f238221a0eefcbcb7..fa6bb903bbd339a7e25f2bc20e9afdde40fb01d1 100644 (file)
@@ -1,5 +1,11 @@
+17-04-2004 :
+ - wxbPanel/wxbMainFrame : Added a locking function (for example, 
+   the user can't type something in the console when a restore
+   is in progress)
+
 16-04-2004 :
- - wxbRestorePanel : Allow the user to change the status by double-clicking on the check mark
+ - wxbRestorePanel : Allow the user to change the status by 
+   double-clicking on the check mark
 
 15-04-2004 :
  - project renamed in wx-console
index a689181706e23835dc75f3351e0851f918a4b8eb..3db46ff0947ab551fc6881b268462d5031082b93 100644 (file)
@@ -4,8 +4,7 @@ wxbRestorePanel : Allow the user to choose where he wants to restore his files
 
 wxbRestorePanel : Add a button to force the refreshing of the whole tree
 
-wxbPanel/wxbMainFrame : Add a locking function (for example, deny the user 
-               to type something in the console when a restore is in progress)
+wxbRestorePanel : Add a timeout when waiting for commands results
 
 wxbRestorePanel : Check more carefully which job we just have run.
 
index 340ca0958dc97cbd6452a9b5a56b7b27009a3a2f..85915d3ed70a77021b91b075ef4e6758f22f6079 100644 (file)
@@ -72,9 +72,9 @@ void* console_thread::Entry() {
 
    memset(&jcr, 0, sizeof(jcr));
 
-   UA_sock = bnet_connect(&jcr, 5, 15, "Director daemon", dir->address, NULL, dir->DIRport, 0);
+   UA_sock = bnet_connect(&jcr, 3, 3, "Director daemon", dir->address, NULL, dir->DIRport, 0);
    if (UA_sock == NULL) {
-      csprint("NULL\n");
+      csprint("Failed to connect to the director\n");
       return NULL;
    }
 
@@ -86,7 +86,9 @@ void* console_thread::Entry() {
       csprint(UA_sock->msg);
       return NULL;
    }
-
+   
+   csprint(NULL, CS_CONNECTED);
+   
    Write("messages\n");
 
    int stat;
@@ -105,6 +107,8 @@ void* console_thread::Entry() {
          break;            /* error or term */
       }
    }
+   
+   csprint(NULL, CS_DISCONNECTED);
 
    csprint("Connection terminated\n");
 
index b84d99a72df58a577aa95dfe1d7d3ebdca549054..eee4a147fbb2dbac719b2b160004bb93c1b01578 100644 (file)
 #ifndef CSPRINT_H
 #define CSPRINT_H
 
-#define CS_DATA   1 /* data has been received */
-#define CS_END    2 /* no data to receive anymore */
-#define CS_DEBUG  3 /* used to print debug messages */
+#define CS_DATA          1 /* data has been received */
+#define CS_END           2 /* no data to receive anymore */
+#define CS_CONNECTED     3 /* the socket is now connected */
+#define CS_DISCONNECTED  4 /* the socket is now disconnected */
+#define CS_DEBUG        10 /* used to print debug messages */
 
 /* function called by console_thread to send events back to the GUI */
 void csprint(char* str, int status=CS_DATA);
index f68e376f97178181d6a875723fea221bac7b20b2..1c95ee8e8d30e5d2238d604110b10de0f4d1341b 100644 (file)
@@ -162,7 +162,9 @@ wxbMainFrame* wxbMainFrame::GetInstance()
  */
 wxbMainFrame::~wxbMainFrame()
 {
-   ct->Delete();
+   if ((ct != NULL) && (!ct->IsRunning())) {
+      ct->Delete();
+   }
 }
 
 /*
@@ -249,6 +251,7 @@ wxbMainFrame::wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSi
    SetAutoLayout(true);
    SetSizer( sizer );
    //sizer->SetSizeHints( this );
+   EnableConsole(false);
 }
 
 /*
@@ -300,7 +303,17 @@ void wxbMainFrame::OnPrint(wxbThreadEvent& event) {
  */
 void wxbMainFrame::Print(wxString str, int status)
 {
-   // CS_DEBUG is often sent by panels, so resend it to them would cause an infinite loop
+   if (status == CS_CONNECTED) {
+      EnablePanels();
+      return;
+   }
+   if (status == CS_DISCONNECTED) {
+      DisablePanels();
+      return;
+   }
+      
+   // 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);
@@ -327,6 +340,34 @@ void wxbMainFrame::Send(wxString str)
    (*consoleCtrl) << str;
 }
 
+/* Enable panels */
+void wxbMainFrame::EnablePanels() {
+   for (int i = 0; panels[i] != NULL; i++) {
+      panels[i]->EnablePanel(true);
+   }
+   EnableConsole(true);
+}
+
+/* Disable panels, except the one passed as parameter */
+void wxbMainFrame::DisablePanels(void* except) {
+   for (int i = 0; panels[i] != NULL; i++) {
+      if (panels[i] != except) {
+         panels[i]->EnablePanel(false);
+      }
+      else {
+         panels[i]->EnablePanel(true);
+      }
+   }
+   if (this != except) {
+      EnableConsole(false);
+   }
+}
+
+/* Enable or disable console typing */
+void wxbMainFrame::EnableConsole(bool enable) {
+   typeCtrl->Enable(enable);
+}
+
 /*
  *  Used by csprint, which is called by console thread.
  *
@@ -369,7 +410,8 @@ void csprint(char* str, int status)
          }
       }
       else {
-         wxStringTokenizer tkz(str, "\n", wxTOKEN_RET_DELIMS | wxTOKEN_RET_EMPTY | wxTOKEN_RET_EMPTY_ALL);
+         wxStringTokenizer tkz(str, "\n", 
+            wxTOKEN_RET_DELIMS | wxTOKEN_RET_EMPTY | wxTOKEN_RET_EMPTY_ALL);
 
          while ( tkz.HasMoreTokens() ) {
             csBuffer << tkz.GetNextToken();
@@ -389,12 +431,12 @@ void csprint(char* str, int status)
       }
    }
 
-   if (status == CS_END) {
+   if (status != CS_DATA) {
       if (csBuffer.Length() != 0) {
          firePrintEvent(csBuffer, CS_DATA);
       }
       csBuffer = "";
-      firePrintEvent("", CS_END);
+      firePrintEvent("", status);
    }
 }
 
index 507b4b2c930eb8eb4d53082442575fe56817f49e..d3ac94994e1f613421903e9c28b4c18a1b631f37 100644 (file)
@@ -90,12 +90,18 @@ public:
    static wxbMainFrame* CreateInstance(const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
    static wxbMainFrame* GetInstance();
 
-    // event handlers (these functions should _not_ be virtual)
+   /* event handlers (these functions should _not_ be virtual) */
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void OnEnter(wxCommandEvent& event);
    void OnPrint(wxbThreadEvent& event);
 
+   /* Enable and disable panels */
+   void EnablePanels();
+   void DisablePanels(void* except = NULL);
+   
+   void EnableConsole(bool enable = true);
+
    /*
     *  Prints data received from director to the console,
     *  and forwards it to the panels
index 29099eb208c97716d57980ffeb19aa45e1598c52..0a1b5abed95a6cdb7cfa8a5c3217d80e2c48dc02 100644 (file)
@@ -237,7 +237,7 @@ wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
    SetSizer(sizer);
    sizer->SetSizeHints(this);
 
-   setStatus(disabled);
+   SetStatus(disabled);
 
    tableParser = NULL;
 
@@ -382,13 +382,24 @@ void wxbRestorePanel::Print(wxString str, int stat) {
    }
 }
 
+void wxbRestorePanel::EnablePanel(bool enable) {
+   if (enable) {
+      if (status == disabled) {
+         SetStatus(activable);
+      }
+   }
+   else {
+      SetStatus(disabled);
+   }
+}
+
 /*----------------------------------------------------------------------------
    Commands called by events handler
   ----------------------------------------------------------------------------*/
 
 /* The main button has been clicked */
 void wxbRestorePanel::CmdStart() {
-   if (status == disabled) {
+   if (status == activable) {
       CreateAndWaitForParser("list clients\n");
 
       clientChoice->Clear();
@@ -402,7 +413,7 @@ void wxbRestorePanel::CmdStart() {
          clientChoice->Append((*tableParser)[i][1], (void*)j);
       }
 
-      setStatus(entered);
+      SetStatus(entered);
    }
    else if (status == entered) {
       if (jobChoice->GetStringSelection().Length() < 1) {
@@ -414,7 +425,7 @@ void wxbRestorePanel::CmdStart() {
       WaitForEnd(wxString() << jobChoice->GetStringSelection() << "\n");
       WaitForEnd(wxString() << *((long*)clientChoice->GetClientData(clientChoice->GetSelection())) << "\n");
       WaitForEnd("unmark *\n");
-      setStatus(choosing);
+      SetStatus(choosing);
       wxTreeItemId root = tree->AddRoot(clientChoice->GetStringSelection(), -1, -1, new wxbTreeItemData("/", clientChoice->GetStringSelection(), 0));
       tree->Refresh();
       WaitForList(root, true);
@@ -422,7 +433,7 @@ void wxbRestorePanel::CmdStart() {
       tree->Expand(root);
    }
    else if (status == choosing) {
-      setStatus(restoring);
+      SetStatus(restoring);
 
       wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
 
@@ -433,7 +444,7 @@ void wxbRestorePanel::CmdStart() {
       if (totfilemessages == 0) {
          wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
          wxbMainFrame::GetInstance()->SetStatusText("Restore failed : no file selected.");
-         setStatus(finished);
+         SetStatus(finished);
          return;
       }
 
@@ -478,7 +489,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.");
       }
-      setStatus(finished);
+      SetStatus(finished);
    }
 }
 
@@ -643,14 +654,14 @@ void wxbRestorePanel::WaitForList(wxTreeItemId item, bool updatelist) {
 
    WaitForEnd(wxString("cd \"") << static_cast<wxbTreeItemData*>(tree->GetItemData(currentTreeItem))->GetPath() << "\"\n");
 
-   status = listing;
+   SetStatus(listing);
 
    if (updatelist)
       list->DeleteAllItems();
    WaitForEnd("dir\n");
 
    tree->Refresh();
-   status = choosing;
+   SetStatus(choosing);
 }
 
 /* Parse dir command results. */
@@ -849,15 +860,25 @@ void wxbRestorePanel::RefreshTree(wxTreeItemId item) {
   ----------------------------------------------------------------------------*/
 
 /* Set current status by enabling/disabling components */
-void wxbRestorePanel::setStatus(status_enum newstatus) {
+void wxbRestorePanel::SetStatus(status_enum newstatus) {
    switch (newstatus) {
+   case disabled:
+      start->SetLabel("Enter restore mode");
+      start->Enable(false);
+      clientChoice->Enable(false);
+      jobChoice->Enable(false);
+      tree->Enable(false);
+      list->Enable(false);
+      gauge->Enable(false);
+      break;
    case finished:
       tree->DeleteAllItems();
       list->DeleteAllItems();
       clientChoice->Clear();
       jobChoice->Clear();
-      newstatus = disabled;
-   case disabled:
+      wxbMainFrame::GetInstance()->EnablePanels();
+      newstatus = activable;
+   case activable:
       start->SetLabel("Enter restore mode");
       start->Enable(true);
       clientChoice->Enable(false);
@@ -867,6 +888,7 @@ void wxbRestorePanel::setStatus(status_enum newstatus) {
       gauge->Enable(false);
       break;
    case entered:
+      wxbMainFrame::GetInstance()->DisablePanels(this);
       gauge->SetValue(0);
       start->SetLabel("Choose files to restore");
       clientChoice->Enable(true);
@@ -875,7 +897,7 @@ void wxbRestorePanel::setStatus(status_enum newstatus) {
       list->Enable(false);
       break;
    case listing:
-
+      
       break;
    case choosing:
       start->SetLabel("Restore");
@@ -938,7 +960,9 @@ void wxbRestorePanel::OnTreeExpanding(wxTreeEvent& event) {
    }
    //working = true;
    //CmdList(event.GetItem());
-   tree->SelectItem(event.GetItem());
+   if (tree->GetSelection() != event.GetItem()) {
+      tree->SelectItem(event.GetItem());
+   }
    //working = false;
 }
 
@@ -946,13 +970,13 @@ void wxbRestorePanel::OnTreeChanged(wxTreeEvent& event) {
    if (working) {
       return;
    }
+
    working = true;
    CmdList(event.GetItem());
    working = false;
 }
 
 void wxbRestorePanel::OnTreeMarked(wxbTreeMarkedEvent& event) {
-   //wxbMainFrame::GetInstance()->Print(wxString("MARKED\n"), CS_DEBUG);
    if (working) {
       //event.Skip();
       return;
@@ -966,7 +990,7 @@ void wxbRestorePanel::OnTreeMarked(wxbTreeMarkedEvent& event) {
 
 void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
    if (working) {
-      event.Skip();
+      //event.Skip();
       return;
    }
    working = true;
@@ -980,7 +1004,7 @@ void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
 
 void wxbRestorePanel::OnListActivated(wxListEvent& event) {
    if (working) {
-      event.Skip();
+      //event.Skip();
       return;
    }
    working = true;
@@ -1000,8 +1024,8 @@ void wxbRestorePanel::OnListActivated(wxListEvent& event) {
          while (currentChild.IsOk()) {
             wxString name2 = tree->GetItemText(currentChild);
             if (name2 == name) {
+               //tree->UnselectAll();
                working = false;
-               tree->UnselectAll();
                tree->Expand(currentTreeItem);
                tree->SelectItem(currentChild);
                //tree->Refresh();
index cc185ac4c67bdbc41ef8ef08ab2ecdb5881a44d8..a97a479ce4a4cd0800fc8cb498ded0d93865069e 100644 (file)
@@ -49,6 +49,7 @@ class wxbRestorePanel : public wxbPanel
       /* wxbPanel overloadings */
       virtual wxString GetTitle();
       virtual void Print(wxString str, int status);
+      virtual void EnablePanel(bool enable = true);
 
    private:
 /* Commands called by events handler */
@@ -105,18 +106,19 @@ class wxbRestorePanel : public wxbPanel
 /* Status related */
       enum status_enum
       {
-         disabled,  // The panel is not activated
+         disabled,  // The panel is not activatable
+         activable, // The panel is activable, but not activated
          entered,   // The panel is activated
          choosing,  // The user is choosing files to restore
          listing,   // Dir listing is in progress
          restoring, // Bacula is restoring files
-         finished   // Retore done
+         finished   // Retore done (state will change in activable)
       };
 
       status_enum status;
 
       /* Set current status by enabling/disabling components */
-      void setStatus(status_enum newstatus);
+      void SetStatus(status_enum newstatus);
 
 /* UI related */
       bool working; // A command is running, discard GUI events