+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
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.
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;
}
csprint(UA_sock->msg);
return NULL;
}
-
+
+ csprint(NULL, CS_CONNECTED);
+
Write("messages\n");
int stat;
break; /* error or term */
}
}
+
+ csprint(NULL, CS_DISCONNECTED);
csprint("Connection terminated\n");
#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);
*/
wxbMainFrame::~wxbMainFrame()
{
- ct->Delete();
+ if ((ct != NULL) && (!ct->IsRunning())) {
+ ct->Delete();
+ }
}
/*
SetAutoLayout(true);
SetSizer( sizer );
//sizer->SetSizeHints( this );
+ EnableConsole(false);
}
/*
*/
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);
(*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.
*
}
}
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();
}
}
- if (status == CS_END) {
+ if (status != CS_DATA) {
if (csBuffer.Length() != 0) {
firePrintEvent(csBuffer, CS_DATA);
}
csBuffer = "";
- firePrintEvent("", CS_END);
+ firePrintEvent("", status);
}
}
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
SetSizer(sizer);
sizer->SetSizeHints(this);
- setStatus(disabled);
+ SetStatus(disabled);
tableParser = NULL;
}
}
+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();
clientChoice->Append((*tableParser)[i][1], (void*)j);
}
- setStatus(entered);
+ SetStatus(entered);
}
else if (status == entered) {
if (jobChoice->GetStringSelection().Length() < 1) {
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);
tree->Expand(root);
}
else if (status == choosing) {
- setStatus(restoring);
+ SetStatus(restoring);
wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
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;
}
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);
}
}
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. */
----------------------------------------------------------------------------*/
/* 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);
gauge->Enable(false);
break;
case entered:
+ wxbMainFrame::GetInstance()->DisablePanels(this);
gauge->SetValue(0);
start->SetLabel("Choose files to restore");
clientChoice->Enable(true);
list->Enable(false);
break;
case listing:
-
+
break;
case choosing:
start->SetLabel("Restore");
}
//working = true;
//CmdList(event.GetItem());
- tree->SelectItem(event.GetItem());
+ if (tree->GetSelection() != event.GetItem()) {
+ tree->SelectItem(event.GetItem());
+ }
//working = false;
}
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;
void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
if (working) {
- event.Skip();
+ //event.Skip();
return;
}
working = true;
void wxbRestorePanel::OnListActivated(wxListEvent& event) {
if (working) {
- event.Skip();
+ //event.Skip();
return;
}
working = true;
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();
/* wxbPanel overloadings */
virtual wxString GetTitle();
virtual void Print(wxString str, int status);
+ virtual void EnablePanel(bool enable = true);
private:
/* Commands called by events handler */
/* 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