--- /dev/null
+/*
+ *
+ * Config panel, used to specify parameters (for example clients, filesets... in restore)
+ *
+ * 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 "wxbconfigpanel.h"
+
+#include <wx/arrimpl.cpp>
+
+WX_DEFINE_OBJARRAY(wxbConfig);
+
+/* Create a new config parameter */
+wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, wxString value) {
+ this->title = title;
+ this->id = id;
+ this->type = type;
+ this->value = value;
+ this->values = NULL;
+ this->nvalues = 0;
+ this->choicectrl = NULL;
+ this->textctrl = NULL;
+ this->statictext = NULL;
+}
+
+wxbConfigParam::wxbConfigParam(wxString title, wxWindowID id, wxbConfigType type, int n, wxString* values) {
+ this->title = title;
+ this->id = id;
+ this->type = type;
+ this->values = new wxString[n];
+ for (int i = 0; i < n; i++) {
+ this->values[i] = values[i];
+ }
+ this->nvalues = n;
+ this->choicectrl = NULL;
+ this->textctrl = NULL;
+ this->statictext = NULL;
+}
+
+wxbConfigParam::~wxbConfigParam() {
+ if (values) delete[] values;
+ if (choicectrl) delete choicectrl;
+ if (textctrl) delete textctrl;
+ if (statictext) delete statictext;
+}
+
+void wxbConfigParam::AddControl(wxWindow* parent, wxSizer* sizer) {
+ sizer->Add(new wxStaticText(parent, -1, title + ": ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
+ switch (type) {
+ case text:
+ statictext = new wxStaticText(parent, -1, value, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
+ sizer->Add(statictext, 1, wxEXPAND | wxADJUST_MINSIZE);
+ break;
+ case modifiableText:
+ textctrl = new wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize);
+ sizer->Add(textctrl, 1, wxEXPAND | wxADJUST_MINSIZE);
+ break;
+ case choice:
+ choicectrl = new wxChoice(parent, id, wxDefaultPosition, wxDefaultSize, nvalues, values);
+ sizer->Add(choicectrl, 1, wxEXPAND);
+ break;
+ }
+}
+
+wxString wxbConfigParam::GetTitle() {
+ return title;
+}
+
+wxString wxbConfigParam::GetValue() {
+ switch (type) {
+ case text:
+ return (statictext) ? statictext->GetLabel() : "";
+ break;
+ case modifiableText:
+ return (textctrl) ? textctrl->GetValue() : "";
+ break;
+ case choice:
+ return (choicectrl) ? choicectrl->GetStringSelection() : "";
+ break;
+ }
+ return "";
+}
+
+void wxbConfigParam::SetValue(wxString str) {
+ switch (type) {
+ case text:
+ if (statictext)
+ statictext->SetLabel(str);
+ break;
+ case modifiableText:
+ if (textctrl)
+ textctrl->SetValue(str);
+ break;
+ case choice:
+ if (choicectrl) {
+ int k;
+ for (k = 0; k < choicectrl->GetCount(); k++) {
+ if (str == choicectrl->GetString(k)) {
+ choicectrl->SetSelection(k);
+ break;
+ }
+ }
+ if (k == choicectrl->GetCount()) { // Should never happen
+ choicectrl->Append(str);
+ choicectrl->SetSelection(k);
+ }
+ }
+ break;
+ }
+}
+
+int wxbConfigParam::GetIndex() {
+ if (choicectrl) {
+ return choicectrl->GetSelection();
+ }
+ return -1;
+}
+
+void wxbConfigParam::SetIndex(int ind) {
+ if (choicectrl) {
+ choicectrl->SetSelection(ind);
+ }
+}
+
+void wxbConfigParam::Clear() {
+ if (choicectrl) {
+ choicectrl->Clear();
+ }
+}
+
+void wxbConfigParam::Add(wxString value) {
+ if (choicectrl) {
+ choicectrl->Append(value);
+ }
+}
+
+/* Creates a new config panel, config must be allocated with new */
+wxbConfigPanel::wxbConfigPanel(wxWindow* parent, wxbConfig* config,
+ wxWindowID ok, wxWindowID cancel, wxWindowID apply): wxPanel(parent) {
+
+ this->config = config;
+
+ wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
+ wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(config->GetCount()+1, 2, 8, 5);
+ unsigned int i;
+ for (i = 0; i < config->GetCount(); i++) {
+ (*config)[i].AddControl(this, cfgSizer);
+ }
+ mainSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
+
+ wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
+
+ cfgOk = new wxButton(this, ok, "OK", wxDefaultPosition, wxSize(70, 25));
+ restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
+
+ if (apply != -1) {
+ cfgApply = new wxButton(this, apply, "Apply", wxDefaultPosition, wxSize(70, 25));
+ restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
+ }
+ else {
+ cfgApply = NULL;
+ }
+
+ cfgCancel = new wxButton(this, cancel, "Cancel", wxDefaultPosition, wxSize(70, 25));
+ restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
+
+ mainSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
+
+ SetSizer(mainSizer);
+ mainSizer->SetSizeHints(this);
+
+ last = 0;
+}
+
+wxbConfigPanel::~wxbConfigPanel() {
+ delete config;
+}
+
+void wxbConfigPanel::SetRowString(const char* title, wxString value) {
+ int i;
+ if ((i = FindRow(title)) > -1) {
+ (*config)[i].SetValue(value);
+ }
+}
+
+wxString wxbConfigPanel::GetRowString(const char* title) {
+ int i;
+ if ((i = FindRow(title)) > -1) {
+ return (*config)[i].GetValue();
+ }
+ return "";
+}
+
+void wxbConfigPanel::SetRowSelection(const char* title, int ind) {
+ int i;
+ if ((i = FindRow(title)) > -1) {
+ (*config)[i].SetIndex(ind);
+ }
+}
+
+int wxbConfigPanel::GetRowSelection(const char* title) {
+ int i;
+ if ((i = FindRow(title)) > -1) {
+ return (*config)[i].GetIndex();
+ }
+ return -1;
+}
+
+void wxbConfigPanel::ClearRowChoices(const char* title) {
+ int i;
+ if ((i = FindRow(title)) > -1) {
+ return (*config)[i].Clear();
+ }
+}
+
+void wxbConfigPanel::AddRowChoice(const char* title, wxString value) {
+ int i;
+ if ((i = FindRow(title)) > -1) {
+ return (*config)[i].Add(value);
+ }
+}
+
+int wxbConfigPanel::FindRow(const char* title) {
+ unsigned int i;
+
+ for (i = last; i < config->GetCount(); i++) {
+ if ((*config)[i].GetTitle() == title) {
+ last = i;
+ return i;
+ }
+ }
+
+ for (i = 0; i < last; i++) {
+ if ((*config)[i].GetTitle() == title) {
+ last = i;
+ return i;
+ }
+ }
+
+ last = 0;
+ return -1;
+}
+
+void wxbConfigPanel::EnableApply(bool enable) {
+ cfgOk->Enable(!enable);
+ if (cfgApply) cfgApply->Enable(enable);
+}
RestoreStart = 1,
TreeCtrl = 2,
ListCtrl = 3,
- ClientChoice = 4,
- ConfigOk = 5,
- ConfigApply = 6,
- ConfigCancel = 7,
- ConfigWhere = 8,
- ConfigReplace = 9,
- ConfigWhen = 10,
- ConfigPriority = 11,
- ConfigClient = 12,
- ConfigFileset = 13
+ ConfigOk = 4,
+ ConfigApply = 5,
+ ConfigCancel = 6,
+ ConfigWhere = 7,
+ ConfigReplace = 8,
+ ConfigWhen = 9,
+ ConfigPriority = 10,
+ ConfigClient = 11,
+ ConfigFileset = 12,
+ ConfigStorage = 13,
+ ConfigJobName = 14,
+ ConfigPool = 15
};
BEGIN_EVENT_TABLE(wxbRestorePanel, wxPanel)
EVT_BUTTON(RestoreStart, wxbRestorePanel::OnStart)
- EVT_CHOICE(ClientChoice, wxbRestorePanel::OnClientChoiceChanged)
EVT_TREE_SEL_CHANGING(TreeCtrl, wxbRestorePanel::OnTreeChanging)
EVT_TREE_SEL_CHANGED(TreeCtrl, wxbRestorePanel::OnTreeChanged)
EVT_TEXT(ConfigWhere, wxbRestorePanel::OnConfigUpdated)
EVT_TEXT(ConfigWhen, wxbRestorePanel::OnConfigUpdated)
EVT_TEXT(ConfigPriority, wxbRestorePanel::OnConfigUpdated)
+ EVT_CHOICE(ConfigWhen, wxbRestorePanel::OnConfigUpdated)
EVT_CHOICE(ConfigReplace, wxbRestorePanel::OnConfigUpdated)
EVT_CHOICE(ConfigClient, wxbRestorePanel::OnConfigUpdated)
EVT_CHOICE(ConfigFileset, wxbRestorePanel::OnConfigUpdated)
+ EVT_CHOICE(ConfigStorage, wxbRestorePanel::OnConfigUpdated)
+ EVT_CHOICE(ConfigJobName, wxbRestorePanel::OnConfigUpdated)
+ EVT_CHOICE(ConfigPool, wxbRestorePanel::OnConfigUpdated)
EVT_BUTTON(ConfigOk, wxbRestorePanel::OnConfigOk)
EVT_BUTTON(ConfigApply, wxbRestorePanel::OnConfigApply)
wxString elist[1];
- clientChoice = new wxChoice(this, ClientChoice, wxDefaultPosition, wxSize(150, 30), 0, elist);
+/* clientChoice = new wxChoice(this, ClientChoice, wxDefaultPosition, wxSize(150, 30), 0, elist);
firstSizer->Add(clientChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
jobChoice = new wxChoice(this, -1, wxDefaultPosition, wxSize(150, 30), 0, elist);
- firstSizer->Add(jobChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
+ firstSizer->Add(jobChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);*/
mainSizer->Add(firstSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
wxFlexGridSizer* treelistSizer = new wxFlexGridSizer(1, 2, 10, 10);
tree = new wxbTreeCtrl(treelistPanel, TreeCtrl, wxDefaultPosition, wxSize(200,50));
- treelistSizer->Add(tree, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 10);
+ treelistSizer->Add(tree, 1, wxEXPAND, 10);
tree->SetImageList(imagelist);
- list = new wxbListCtrl(treelistPanel, ListCtrl, wxDefaultPosition, wxDefaultSize);
- treelistSizer->Add(list, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 10);
+ list = new wxbListCtrl(treelistPanel, ListCtrl, wxDefaultPosition, wxSize(200,50));
+ treelistSizer->Add(list, 1, wxEXPAND, 10);
list->SetImageList(imagelist, wxIMAGE_LIST_SMALL);
treelistPanel->SetSizer(treelistSizer);
treelistSizer->SetSizeHints(treelistPanel);
- restorePanel = new wxPanel(this, -1);
+ treelistPanel->Show(false);
- wxBoxSizer* restoreSizer = new wxBoxSizer(wxVERTICAL);
+ wxbConfig* config = new wxbConfig();
+ config->Add(new wxbConfigParam("Job Name", ConfigJobName, choice, 0, elist));
+ config->Add(new wxbConfigParam("Client", ConfigClient, choice, 0, elist));
+ config->Add(new wxbConfigParam("Fileset", ConfigFileset, choice, 0, elist));
+ config->Add(new wxbConfigParam("Pool", ConfigPool, choice, 0, elist));
+ config->Add(new wxbConfigParam("Storage", ConfigStorage, choice, 0, elist));
+ config->Add(new wxbConfigParam("Before", ConfigWhen, choice, 0, elist));
- wxFlexGridSizer* cfgSizer = new wxFlexGridSizer(9, 2, 8, 5);
+ configPanel = new wxbConfigPanel(this, config, RestoreStart, ConfigCancel, -1);
- cfgJobname = new wxStaticText(restorePanel, -1, " ", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
- cfgBootstrap = new wxStaticText(restorePanel, -1, " ", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
- cfgWhere = new wxTextCtrl(restorePanel, ConfigWhere, "", wxDefaultPosition, wxDefaultSize);
- wxString erlist[] = {"always", "if newer", "if older", "never"};
- cfgReplace = new wxChoice(restorePanel, ConfigReplace, wxDefaultPosition, wxDefaultSize, 4, erlist);
- cfgFileset = new wxChoice(restorePanel, ConfigFileset, wxDefaultPosition, wxDefaultSize, 0, elist);
- cfgClient = new wxChoice(restorePanel, ConfigClient, wxDefaultPosition, wxDefaultSize, 0, elist);
- cfgStorage = new wxStaticText(restorePanel, -1, " ", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
- cfgWhen = new wxTextCtrl(restorePanel, ConfigWhen, "0000-00-00 00:00:00", wxDefaultPosition, wxDefaultSize);
- cfgPriority = new wxTextCtrl(restorePanel, ConfigPriority, "", wxDefaultPosition, wxDefaultSize);
-
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Job Name: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgJobname, 1, wxEXPAND | wxADJUST_MINSIZE);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Bootstrap: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgBootstrap, 1, wxEXPAND | wxADJUST_MINSIZE);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Where: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgWhere, 1, wxEXPAND | wxADJUST_MINSIZE);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Replace: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgReplace, 1, wxEXPAND);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Fileset: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgFileset, 1, wxEXPAND);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Client: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgClient, 1, wxEXPAND);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Storage: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgStorage, 1, wxEXPAND | wxADJUST_MINSIZE);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "When: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgWhen, 1, wxEXPAND | wxADJUST_MINSIZE);
- cfgSizer->Add(new wxStaticText(restorePanel, -1, "Priority: ", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxEXPAND | wxALIGN_CENTER_HORIZONTAL);
- cfgSizer->Add(cfgPriority, 1, wxEXPAND | wxADJUST_MINSIZE);
-
- //cfgSizer->SetMinSize(400, 400);
-
- restoreSizer->Add(cfgSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
-
- wxBoxSizer* restoreBottomSizer = new wxBoxSizer(wxHORIZONTAL);
-
- cfgOk = new wxButton(restorePanel, ConfigOk, "OK", wxDefaultPosition, wxSize(70, 25));
- restoreBottomSizer->Add(cfgOk, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
-
- cfgApply = new wxButton(restorePanel, ConfigApply, "Apply", wxDefaultPosition, wxSize(70, 25));
- restoreBottomSizer->Add(cfgApply, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 10);
-
- cfgCancel = new wxButton(restorePanel, ConfigCancel, "Cancel", wxDefaultPosition, wxSize(70, 25));
- restoreBottomSizer->Add(cfgCancel, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 10);
+ configPanel->Show(true);
+ configPanel->Enable(false);
- restoreSizer->Add(restoreBottomSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5);
-
- restorePanel->SetSizer(restoreSizer);
- restoreSizer->SetSizeHints(restorePanel);
+ config = new wxbConfig();
+ config->Add(new wxbConfigParam("Job Name", -1, text, ""));
+ config->Add(new wxbConfigParam("Bootstrap", -1, text, ""));
+ config->Add(new wxbConfigParam("Where", ConfigWhere, modifiableText, ""));
+ wxString erlist[] = {"always", "if newer", "if older", "never"};
+ config->Add(new wxbConfigParam("Replace", ConfigReplace, choice, 4, erlist));
+ config->Add(new wxbConfigParam("Fileset", ConfigFileset, choice, 0, erlist));
+ config->Add(new wxbConfigParam("Client", ConfigClient, choice, 0, erlist));
+ config->Add(new wxbConfigParam("Storage", ConfigStorage, choice, 0, erlist));
+ config->Add(new wxbConfigParam("When", ConfigWhen, modifiableText, ""));
+ config->Add(new wxbConfigParam("Priority", ConfigPriority, modifiableText, ""));
+ restorePanel = new wxbConfigPanel(this, config, ConfigOk, ConfigCancel, ConfigApply);
+
restorePanel->Show(false);
centerSizer = new wxBoxSizer(wxHORIZONTAL);
- centerSizer->Add(treelistPanel, 1, wxEXPAND | wxADJUST_MINSIZE);
+ //centerSizer->Add(treelistPanel, 1, wxEXPAND | wxADJUST_MINSIZE);
mainSizer->Add(centerSizer, 1, wxEXPAND, 10);
SetStatus(disabled);
- jobChoice->Enable(false);
-
for (int i = 0; i < 7; i++) {
list->SetColumnWidth(i, 70);
}
wxbDataTokenizer* dt = WaitForEnd(".clients\n", true, false);
wxString str;
- clientChoice->Clear();
- cfgClient->Clear();
+ configPanel->ClearRowChoices("Client");
+ restorePanel->ClearRowChoices("Client");
if (dt->GetCount() == 0) {
wxbMainFrame::GetInstance()->SetStatusText("Error : no clients returned by the director.");
for (i = 0; i < dt->GetCount(); i++) {
str = (*dt)[i];
str.RemoveLast();
- clientChoice->Append(str);
- cfgClient->Append(str);
+ configPanel->AddRowChoice("Client", str);
+ restorePanel->AddRowChoice("Client", str);
}
-
+
delete dt;
dt = WaitForEnd(".filesets\n", true, false);
-
- cfgFileset->Clear();
+ configPanel->ClearRowChoices("Fileset");
+ restorePanel->ClearRowChoices("Fileset");
+
if (dt->GetCount() == 0) {
wxbMainFrame::GetInstance()->SetStatusText("Error : no filesets returned by the director.");
return;
for (i = 0; i < dt->GetCount(); i++) {
str = (*dt)[i];
str.RemoveLast();
- cfgFileset->Append(str);
+ configPanel->AddRowChoice("Fileset", str);
+ restorePanel->AddRowChoice("Fileset", str);
}
delete dt;
+
+ dt = WaitForEnd(".storage\n", true, false);
+
+ configPanel->ClearRowChoices("Storage");
+ restorePanel->ClearRowChoices("Storage");
+
+ if (dt->GetCount() == 0) {
+ wxbMainFrame::GetInstance()->SetStatusText("Error : no storage returned by the director.");
+ return;
+ }
+
+ for (i = 0; i < dt->GetCount(); i++) {
+ str = (*dt)[i];
+ str.RemoveLast();
+ configPanel->AddRowChoice("Storage", str);
+ restorePanel->AddRowChoice("Storage", str);
+ }
+
+ delete dt;
+
+ dt = WaitForEnd(".jobs\n", true, false);
+
+ configPanel->ClearRowChoices("Job Name");
+
+ if (dt->GetCount() == 0) {
+ wxbMainFrame::GetInstance()->SetStatusText("Error : no jobs returned by the director.");
+ return;
+ }
+
+ for (i = 0; i < dt->GetCount(); i++) {
+ str = (*dt)[i];
+ str.RemoveLast();
+ configPanel->AddRowChoice("Job Name", str);
+ }
+
+ configPanel->SetRowString("Job Name", "RestoreFiles");
+
+ delete dt;
+
+ dt = WaitForEnd(".pools\n", true, false);
+
+ configPanel->ClearRowChoices("Pool");
+
+ if (dt->GetCount() == 0) {
+ wxbMainFrame::GetInstance()->SetStatusText("Error : no jobs returned by the director.");
+ return;
+ }
+
+ for (i = 0; i < dt->GetCount(); i++) {
+ str = (*dt)[i];
+ str.RemoveLast();
+ configPanel->AddRowChoice("Pool", str);
+ }
+
+ delete dt;
+
+ dt = WaitForEnd(wxString(".defaults job=") + configPanel->GetRowString("Job Name") + "\n", true, false);
+ /* job=RestoreFiles
+ * pool=Default
+ * messages=Standard
+ * client=***
+ * storage=File
+ * where=/tmp/bacula-restores
+ * level=0
+ * type=Restore
+ * fileset=Full Set */
+
+ wxString name;
+ int j;
+
+ for (i = 0; i < dt->GetCount(); i++) {
+ str = (*dt)[i];
+ if ((j = str.Find('=')) > -1) {
+ name = str.Mid(0, j);
+ if (name == "pool") {
+ configPanel->SetRowString("Pool", str.Mid(j+1));
+ }
+ else if (name == "client") {
+ configPanel->SetRowString("Client", str.Mid(j+1));
+ }
+ else if (name == "storage") {
+ configPanel->SetRowString("Storage", str.Mid(j+1));
+ }
+ else if (name == "fileset") {
+ configPanel->SetRowString("Fileset", str.Mid(j+1));
+ }
+ }
+ }
+
+ delete dt;
SetStatus(entered);
- clientChoice->Enable(false);
- jobChoice->Enable(false);
- clientChoice->SetSelection(0);
+ configPanel->Enable(false);
+ configPanel->SetRowSelection("Client", 0);
CmdListJobs();
- jobChoice->Enable(true);
- clientChoice->Enable(true);
+ configPanel->Enable(true);
wxbMainFrame::GetInstance()->SetStatusText("Please select a client and a date at which the files you'll select were backed up.");
}
else if (status == entered) {
- if (clientChoice->GetStringSelection().Length() < 1) {
+/* 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;
- }
+ }*/
wxbMainFrame::GetInstance()->SetStatusText("Building restore tree...");
WaitForPrompt("restore\n");
WaitForPrompt("6\n");
- wxbPromptParser *pp = WaitForPrompt(wxString() << jobChoice->GetStringSelection() << "\n", true);
- int client = pp->getChoices()->Index(clientChoice->GetStringSelection());
+ wxbPromptParser *pp = WaitForPrompt(wxString() << configPanel->GetRowString("Before") << "\n", true);
+ int client = pp->getChoices()->Index(configPanel->GetRowString("Client"));
if (client == wxNOT_FOUND) {
wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected client.");
return;
WaitForEnd("unmark *\n");
SetStatus(choosing);
- wxTreeItemId root = tree->AddRoot(clientChoice->GetStringSelection(), -1, -1, new wxbTreeItemData("/", clientChoice->GetStringSelection(), 0));
+ wxTreeItemId root = tree->AddRoot(configPanel->GetRowString("Client"), -1, -1, new wxbTreeItemData("/", configPanel->GetRowString("Client"), 0));
tree->Refresh();
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.");
delete dt;
EnableConfig(true);
+ restorePanel->EnableApply(false);
if (totfilemessages == 0) {
wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
}
else if (status == configuring) {
EnableConfig(false);
- cfgOk->Enable(false);
- cfgApply->Enable(false);
- cfgCancel->Enable(false);
wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
wxbMainFrame::GetInstance()->SetStatusText(wxString("Restoring, please wait (") << filemessages << " of " << totfilemessages << " files done)...");
time_t start = wxDateTime::Now().GetTicks();
- while (((wxDateTime::Now().GetTicks())-start) < 3) {
+ while (((wxDateTime::Now().GetTicks())-start) < 10) {
wxTheApp->Yield();
}
}
/* Apply configuration changes */
/* 1: Level (not appropriate)
- * 2: Storage (automatic ?)
+ * 2: Storage (yes)
* 3: Job (no)
* 4: FileSet (yes)
* 5: Client (yes)
wxbDataTokenizer* dt = NULL;
+ bool failed = false;
+
while (cfgUpdated > 0) {
wxString def; //String to send if can't use our data
if ((cfgUpdated >> ConfigWhere) & 1) {
WaitForPrompt("mod\n"); /* TODO: check results */
WaitForPrompt("9\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(cfgWhere->GetValue() + "\n");
+ WaitForPrompt(restorePanel->GetRowString("Where") + "\n");
def = "/tmp";
cfgUpdated = cfgUpdated & (~(1 << ConfigWhere));
}
WaitForPrompt("mod\n"); /* TODO: check results */
WaitForPrompt("10\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(wxString() << (cfgReplace->GetSelection()+1) << "\n");
+ WaitForPrompt(wxString() << (restorePanel->GetRowSelection("Replace")+1) << "\n");
def = "1";
cfgUpdated = cfgUpdated & (~(1 << ConfigReplace));
}
WaitForPrompt("mod\n"); /* TODO: check results */
WaitForPrompt("6\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(cfgWhen->GetValue() + "\n");
+ WaitForPrompt(restorePanel->GetRowString("When") + "\n");
def = "";
cfgUpdated = cfgUpdated & (~(1 << ConfigWhen));
}
WaitForPrompt("mod\n"); /* TODO: check results */
WaitForPrompt("7\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(cfgPriority->GetValue() + "\n");
+ WaitForPrompt(restorePanel->GetRowString("Priority") + "\n");
def = "10";
cfgUpdated = cfgUpdated & (~(1 << ConfigPriority));
}
else if ((cfgUpdated >> ConfigClient) & 1) {
WaitForPrompt("mod\n"); /* TODO: check results */
wxbPromptParser *pp = WaitForPrompt("5\n", true);
- int client = pp->getChoices()->Index(cfgClient->GetStringSelection());
+ 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;
else if ((cfgUpdated >> ConfigFileset) & 1) {
WaitForPrompt("mod\n"); /* TODO: check results */
wxbPromptParser *pp = WaitForPrompt("4\n", true);
- int fileset = pp->getChoices()->Index(cfgFileset->GetStringSelection());
+ 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);
+ WaitForPrompt(wxString() << fileset << "\n");
+ def = "1";
+ cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
+ }
+ else if ((cfgUpdated >> ConfigStorage) & 1) {
+ WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbPromptParser *pp = WaitForPrompt("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;
}
delete pp;
if (i == dt->GetCount()) {
delete dt;
dt = WaitForEnd(def + "\n", true);
+ failed = true;
}
}
UpdateConfig(dt); /* TODO: Check result */
EnableConfig(true);
- wxbMainFrame::GetInstance()->SetStatusText("Restore configuration changes were applied.");
+ if (!failed) {
+ wxbMainFrame::GetInstance()->SetStatusText("Restore configuration changes were applied.");
+ }
delete dt;
}
/* List jobs for a specified client */
void wxbRestorePanel::CmdListJobs() {
if (status == entered) {
- jobChoice->Clear();
+ configPanel->ClearRowChoices("Before");
WaitForPrompt("query\n");
WaitForPrompt("6\n");
- wxbTableParser* tableparser = CreateAndWaitForParser(clientChoice->GetString(clientChoice->GetSelection()) + "\n");
+ wxbTableParser* tableparser = CreateAndWaitForParser(configPanel->GetRowString("Client") + "\n");
for (int i = tableparser->size()-1; i > -1; i--) {
wxString str = (*tableparser)[i][3];
if ( ( (chr = datetime.ParseDate(str.GetData()) ) != NULL ) && ( datetime.ParseTime(++chr) != NULL ) ) {
datetime = datetime.GetTicks() + 1;
//wxbMainFrame::GetInstance()->Print(wxString("-") << datetime.Format("%Y-%m-%d %H:%M:%S"), CS_DEBUG);
- jobChoice->Append(datetime.Format("%Y-%m-%d %H:%M:%S"));
+ configPanel->AddRowChoice("Before", datetime.Format("%Y-%m-%d %H:%M:%S"));
}
/*else {
jobChoice->Append("Invalid");
delete tableparser;
- jobChoice->SetSelection(0);
+ configPanel->SetRowSelection("Before", 0);
}
}
//delete dt;
- SetStatus(listing);
+ status = listing;
if (updatelist)
list->DeleteAllItems();
delete dt;
tree->Refresh();
- SetStatus(choosing);
+ status = choosing;
}
/* Parse dir command results. */
int k;
if ((k = (*dt)[++i].Find("JobName:")) != 0) return false;
- cfgJobname->SetLabel((*dt)[i].Mid(10).Trim(false).RemoveLast());
+ restorePanel->SetRowString("Job Name", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("Bootstrap:")) != 0) return false;
- cfgBootstrap->SetLabel((*dt)[i].Mid(10).Trim(false).RemoveLast());
+ restorePanel->SetRowString("Bootstrap", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("Where:")) != 0) return false;
- cfgWhere->SetValue((*dt)[i].Mid(10).Trim(false).RemoveLast());
+ restorePanel->SetRowString("Where", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("Replace:")) != 0) return false;
wxString str = (*dt)[i].Mid(10).Trim(false).RemoveLast();
- if (str == "always") cfgReplace->SetSelection(0);
- else if (str == "ifnewer") cfgReplace->SetSelection(1);
- else if (str == "ifolder") cfgReplace->SetSelection(2);
- else if (str == "never") cfgReplace->SetSelection(3);
- else cfgReplace->SetSelection(0);
-
+ if (str == "always") restorePanel->SetRowSelection("Replace", 0);
+ else if (str == "ifnewer") restorePanel->SetRowSelection("Replace", 1);
+ else if (str == "ifolder") restorePanel->SetRowSelection("Replace", 2);
+ else if (str == "never") restorePanel->SetRowSelection("Replace", 3);
+ else restorePanel->SetRowSelection("Replace", 0);
+
if ((k = (*dt)[++i].Find("FileSet:")) != 0) return false;
- str = (*dt)[i].Mid(10).Trim(false).RemoveLast();
- for (k = 0; k < cfgFileset->GetCount(); k++) {
- if (str == cfgFileset->GetString(k)) {
- cfgFileset->SetSelection(k);
- break;
- }
- }
- if (k == cfgFileset->GetCount()) { // Should never happen
- cfgFileset->Append(str);
- cfgFileset->SetSelection(k+1);
- }
-
+ restorePanel->SetRowString("Fileset", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("Client:")) != 0) return false;
- str = (*dt)[i].Mid(10).Trim(false).RemoveLast();
- for (k = 0; k < cfgClient->GetCount(); k++) {
- if (str == cfgClient->GetString(k)) {
- cfgClient->SetSelection(k);
- break;
- }
- }
- if (k == cfgClient->GetCount()) { // Should never happen
- cfgClient->Append(str);
- cfgClient->SetSelection(k+1);
- }
-
+ restorePanel->SetRowString("Client", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("Storage:")) != 0) return false;
- cfgStorage->SetLabel((*dt)[i].Mid(10).Trim(false).RemoveLast());
+ restorePanel->SetRowString("Storage", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("When:")) != 0) return false;
- cfgWhen->SetValue((*dt)[i].Mid(10).Trim(false).RemoveLast());
+ restorePanel->SetRowString("When", (*dt)[i].Mid(10).Trim(false).RemoveLast());
if ((k = (*dt)[++i].Find("Priority:")) != 0) return false;
- cfgPriority->SetValue((*dt)[i].Mid(10).Trim(false).RemoveLast());
+ restorePanel->SetRowString("Priority", (*dt)[i].Mid(10).Trim(false).RemoveLast());
cfgUpdated = 0;
restorePanel->Layout();
void wxbRestorePanel::SetStatus(status_enum newstatus) {
switch (newstatus) {
case disabled:
+ centerSizer->Remove(configPanel);
centerSizer->Remove(restorePanel);
centerSizer->Remove(treelistPanel);
+ treelistPanel->Show(false);
restorePanel->Show(false);
- centerSizer->Add(treelistPanel, 1, wxEXPAND);
- treelistPanel->Show(true);
+ centerSizer->Add(configPanel, 1, wxEXPAND);
+ configPanel->Show(true);
+ configPanel->Layout();
+ centerSizer->Layout();
this->Layout();
start->SetLabel("Enter restore mode");
start->Enable(false);
- clientChoice->Enable(false);
- jobChoice->Enable(false);
+ configPanel->Enable(false);
tree->Enable(false);
list->Enable(false);
gauge->Enable(false);
+ cfgUpdated = 0;
break;
case finished:
+ centerSizer->Remove(configPanel);
centerSizer->Remove(restorePanel);
+ centerSizer->Remove(treelistPanel);
+ treelistPanel->Show(false);
restorePanel->Show(false);
- centerSizer->Add(treelistPanel, 1, wxEXPAND);
- treelistPanel->Show(true);
+ centerSizer->Add(configPanel, 1, wxEXPAND);
+ configPanel->Show(true);
+ configPanel->Layout();
centerSizer->Layout();
this->Layout();
tree->DeleteAllItems();
list->DeleteAllItems();
- clientChoice->Clear();
- jobChoice->Clear();
+ configPanel->ClearRowChoices("Client");
+ configPanel->ClearRowChoices("Before");
wxbMainFrame::GetInstance()->EnablePanels();
newstatus = activable;
case activable:
start->SetLabel("Enter restore mode");
start->Enable(true);
- clientChoice->Enable(false);
- jobChoice->Enable(false);
+ configPanel->Enable(false);
tree->Enable(false);
list->Enable(false);
gauge->Enable(false);
+ cfgUpdated = 0;
break;
case entered:
wxbMainFrame::GetInstance()->DisablePanels(this);
gauge->SetValue(0);
- start->SetLabel("Choose files to restore");
- clientChoice->Enable(true);
- jobChoice->Enable(true);
+ start->Enable(false);
+ //start->SetLabel("Choose files to restore");
+ configPanel->Enable(true);
tree->Enable(false);
list->Enable(false);
+ cfgUpdated = 0;
break;
case listing:
break;
case choosing:
+ start->Enable(true);
start->SetLabel("Restore");
- clientChoice->Enable(false);
- jobChoice->Enable(false);
+ centerSizer->Remove(configPanel);
+ configPanel->Show(false);
+ centerSizer->Add(treelistPanel, 1, wxEXPAND);
+ treelistPanel->Show(true);
+ treelistPanel->Layout();
+ centerSizer->Layout();
+ this->Layout();
tree->Enable(true);
list->Enable(true);
working = false;
break;
case configuring:
start->Enable(false);
- clientChoice->Enable(false);
- jobChoice->Enable(false);
+ configPanel->Enable(false);
tree->Enable(false);
list->Enable(false);
centerSizer->Remove(treelistPanel);
restorePanel->Layout();
centerSizer->Layout();
this->Layout();
- cfgApply->Enable(false);
- cfgOk->Enable(true);
+ restorePanel->EnableApply(false);
break;
case restoring:
start->SetLabel("Restoring...");
gauge->Enable(true);
gauge->SetValue(0);
start->Enable(false);
- clientChoice->Enable(false);
- jobChoice->Enable(false);
+ configPanel->Enable(false);
tree->Enable(false);
list->Enable(false);
SetCursor(*wxHOURGLASS_CURSOR);
----------------------------------------------------------------------------*/
void wxbRestorePanel::EnableConfig(bool enable) {
- cfgWhere->Enable(enable);
- cfgReplace->Enable(enable);
- cfgWhen->Enable(enable);
- cfgPriority->Enable(enable);
- cfgClient->Enable(enable);
- cfgFileset->Enable(enable);
+ restorePanel->Enable(enable);
}
/*----------------------------------------------------------------------------
----------------------------------------------------------------------------*/
void wxbRestorePanel::OnClientChoiceChanged(wxCommandEvent& event) {
- if (working) {
- return;
- }
- SetCursor(*wxHOURGLASS_CURSOR);
- working = true;
- clientChoice->Enable(false);
- jobChoice->Enable(false);
- CmdListJobs();
- clientChoice->Enable(true);
- jobChoice->Enable(true);
- jobChoice->Refresh();
- working = false;
- SetCursor(*wxSTANDARD_CURSOR);
+
}
void wxbRestorePanel::OnStart(wxEvent& WXUNUSED(event)) {
SetCursor(*wxSTANDARD_CURSOR);
tree->Expand(currentTreeItem);
tree->SelectItem(currentChild);
- //tree->Refresh();
+ tree->Refresh();
return;
}
currentChild = tree->GetNextChild(currentTreeItem, cookie);
}
void wxbRestorePanel::OnConfigUpdated(wxCommandEvent& event) {
- if (status != configuring) return;
- cfgApply->Enable(true);
- cfgOk->Enable(false);
- cfgUpdated = cfgUpdated | (1 << event.GetId());
+ if (status == entered) {
+ if (event.GetId() == ConfigClient) {
+ if (working) {
+ return;
+ }
+ SetCursor(*wxHOURGLASS_CURSOR);
+ working = true;
+ configPanel->Enable(false);
+ CmdListJobs();
+ configPanel->Enable(true);
+ working = false;
+ SetCursor(*wxSTANDARD_CURSOR);
+ }
+ cfgUpdated = cfgUpdated | (1 << event.GetId());
+ }
+ else if (status == configuring) {
+ restorePanel->EnableApply(true);
+ cfgUpdated = cfgUpdated | (1 << event.GetId());
+ }
}
void wxbRestorePanel::OnConfigOk(wxEvent& WXUNUSED(event)) {
working = true;
CmdConfigApply();
if (cfgUpdated == 0) {
- cfgApply->Enable(false);
- cfgOk->Enable(true);
+ restorePanel->EnableApply(false);
}
working = false;
SetCursor(*wxSTANDARD_CURSOR);