From 176b54733480d5273d02283ee8a7636ab5b6cb47 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Sat, 17 Apr 2004 10:12:54 +0000 Subject: [PATCH] - Added a locking function in wxbPanel. - 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 | 8 ++- bacula/src/wx-console/TODO | 3 +- bacula/src/wx-console/console_thread.cpp | 10 ++-- bacula/src/wx-console/csprint.h | 8 +-- bacula/src/wx-console/wxbmainframe.cpp | 52 ++++++++++++++++++-- bacula/src/wx-console/wxbmainframe.h | 8 ++- bacula/src/wx-console/wxbrestorepanel.cpp | 60 ++++++++++++++++------- bacula/src/wx-console/wxbrestorepanel.h | 8 +-- 8 files changed, 121 insertions(+), 36 deletions(-) diff --git a/bacula/src/wx-console/CHANGELOG b/bacula/src/wx-console/CHANGELOG index 837f7b3b81..fa6bb903bb 100644 --- a/bacula/src/wx-console/CHANGELOG +++ b/bacula/src/wx-console/CHANGELOG @@ -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 diff --git a/bacula/src/wx-console/TODO b/bacula/src/wx-console/TODO index a689181706..3db46ff094 100644 --- a/bacula/src/wx-console/TODO +++ b/bacula/src/wx-console/TODO @@ -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. diff --git a/bacula/src/wx-console/console_thread.cpp b/bacula/src/wx-console/console_thread.cpp index 340ca0958d..85915d3ed7 100644 --- a/bacula/src/wx-console/console_thread.cpp +++ b/bacula/src/wx-console/console_thread.cpp @@ -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"); diff --git a/bacula/src/wx-console/csprint.h b/bacula/src/wx-console/csprint.h index b84d99a72d..eee4a147fb 100644 --- a/bacula/src/wx-console/csprint.h +++ b/bacula/src/wx-console/csprint.h @@ -26,9 +26,11 @@ #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); diff --git a/bacula/src/wx-console/wxbmainframe.cpp b/bacula/src/wx-console/wxbmainframe.cpp index f68e376f97..1c95ee8e8d 100644 --- a/bacula/src/wx-console/wxbmainframe.cpp +++ b/bacula/src/wx-console/wxbmainframe.cpp @@ -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); } } diff --git a/bacula/src/wx-console/wxbmainframe.h b/bacula/src/wx-console/wxbmainframe.h index 507b4b2c93..d3ac94994e 100644 --- a/bacula/src/wx-console/wxbmainframe.h +++ b/bacula/src/wx-console/wxbmainframe.h @@ -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 diff --git a/bacula/src/wx-console/wxbrestorepanel.cpp b/bacula/src/wx-console/wxbrestorepanel.cpp index 29099eb208..0a1b5abed9 100644 --- a/bacula/src/wx-console/wxbrestorepanel.cpp +++ b/bacula/src/wx-console/wxbrestorepanel.cpp @@ -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(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(); diff --git a/bacula/src/wx-console/wxbrestorepanel.h b/bacula/src/wx-console/wxbrestorepanel.h index cc185ac4c6..a97a479ce4 100644 --- a/bacula/src/wx-console/wxbrestorepanel.h +++ b/bacula/src/wx-console/wxbrestorepanel.h @@ -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 -- 2.39.5