3 * wxbPanel for restoring files
5 * Nicolas Boichat, April-July 2004
9 Copyright (C) 2004 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* Note concerning "done" output (modifiable marked with +)
27 +JobName: RestoreFiles
28 Bootstrap: /var/lib/bacula/restore.bsr
29 +Where: /tmp/bacula-restores
34 +When: 2004-04-18 01:18:56
36 OK to run? (yes/mod/no):mod
38 1: Level (not appropriate)
39 2: Storage (automatic ?)
42 5: Client (yes : "The defined Client resources are:\n\t1: velours-fd\n\t2: tom-fd\nSelect Client (File daemon) resource (1-2):")
43 6: When (yes : "Please enter desired start time as YYYY-MM-DD HH:MM:SS (return for now):")
44 7: Priority (yes : "Enter new Priority: (positive integer)")
46 9: Where (yes : "Please enter path prefix for restore (/ for none):")
47 10: Replace (yes : "Replace:\n 1: always\n 2: ifnewer\n 3: ifolder\n 4: never\n
48 Select replace option (1-4):")
50 Select parameter to modify (1-11):
53 #include "wxbrestorepanel.h"
55 #include "wxbmainframe.h"
59 #include <wx/choice.h>
60 #include <wx/datetime.h>
64 #include "unmarked.xpm"
66 #include "partmarked.xpm"
68 #include <wx/listimpl.cpp>
70 /* A macro named Yield is defined under MinGW */
73 WX_DEFINE_LIST(wxbEventList);
76 * Class which is stored in the tree and in the list to keep informations
79 class wxbTreeItemData : public wxTreeItemData {
81 wxbTreeItemData(wxString path, wxString name, int marked, long listid = -1);
82 wxbTreeItemData(wxString path, wxString name, wxString marked, long listid = -1);
88 void SetMarked(int marked);
89 void SetMarked(wxString marked);
93 static int GetMarkedStatus(wxString file);
95 wxString* path; /* Full path */
96 wxString* name; /* File name */
97 int marked; /* 0 - Not Marked, 1 - Marked, 2 - Some file under is marked */
98 long listid; /* list ID : >-1 if this data is in the list (and/or on the tree) */
101 wxbTreeItemData::wxbTreeItemData(wxString path, wxString name, int marked, long listid): wxTreeItemData() {
102 this->path = new wxString(path);
103 this->name = new wxString(name);
104 this->marked = marked;
105 this->listid = listid;
108 wxbTreeItemData::wxbTreeItemData(wxString path, wxString name, wxString marked, long listid): wxTreeItemData() {
109 this->path = new wxString(path);
110 this->name = new wxString(name);
112 this->listid = listid;
115 wxbTreeItemData::~wxbTreeItemData() {
120 int wxbTreeItemData::GetMarked() {
124 void wxbTreeItemData::SetMarked(wxString marked) {
128 else if (marked == "+") {
136 void wxbTreeItemData::SetMarked(int marked) {
137 this->marked = marked;
140 long wxbTreeItemData::GetListId() {
144 wxString wxbTreeItemData::GetPath() {
148 wxString wxbTreeItemData::GetName() {
152 /*wxbTreeItemData* wxbTreeItemData::GetChild(wxString dirname) {
153 int marked = GetMarkedStatus(dirname);
154 return new wxbTreeItemData(path + (marked ? dirname.Mid(1) : dirname), marked);
157 int wxbTreeItemData::GetMarkedStatus(wxString file) {
158 if (file.Length() == 0)
161 switch (file.GetChar(0)) {
171 // ----------------------------------------------------------------------------
172 // event tables and other macros for wxWindows
173 // ----------------------------------------------------------------------------
201 BEGIN_EVENT_TABLE(wxbRestorePanel, wxPanel)
202 EVT_BUTTON(RestoreStart, wxbRestorePanel::OnStart)
203 EVT_BUTTON(RestoreCancel, wxbRestorePanel::OnCancel)
205 EVT_TREE_SEL_CHANGING(TreeCtrl, wxbRestorePanel::OnTreeChanging)
206 EVT_TREE_SEL_CHANGED(TreeCtrl, wxbRestorePanel::OnTreeChanged)
207 EVT_TREE_ITEM_EXPANDING(TreeCtrl, wxbRestorePanel::OnTreeExpanding)
208 EVT_TREE_MARKED_EVENT(TreeCtrl, wxbRestorePanel::OnTreeMarked)
209 EVT_BUTTON(TreeAdd, wxbRestorePanel::OnTreeAdd)
210 EVT_BUTTON(TreeRemove, wxbRestorePanel::OnTreeRemove)
211 EVT_BUTTON(TreeRefresh, wxbRestorePanel::OnTreeRefresh)
213 EVT_LIST_ITEM_ACTIVATED(ListCtrl, wxbRestorePanel::OnListActivated)
214 EVT_LIST_MARKED_EVENT(ListCtrl, wxbRestorePanel::OnListMarked)
215 EVT_LIST_ITEM_SELECTED(ListCtrl, wxbRestorePanel::OnListChanged)
216 EVT_LIST_ITEM_DESELECTED(ListCtrl, wxbRestorePanel::OnListChanged)
217 EVT_BUTTON(ListAdd, wxbRestorePanel::OnListAdd)
218 EVT_BUTTON(ListRemove, wxbRestorePanel::OnListRemove)
219 EVT_BUTTON(ListRefresh, wxbRestorePanel::OnListRefresh)
221 EVT_TEXT(ConfigWhere, wxbRestorePanel::OnConfigUpdated)
222 EVT_TEXT(ConfigWhen, wxbRestorePanel::OnConfigUpdated)
223 EVT_TEXT(ConfigPriority, wxbRestorePanel::OnConfigUpdated)
224 EVT_CHOICE(ConfigWhen, wxbRestorePanel::OnConfigUpdated)
225 EVT_CHOICE(ConfigReplace, wxbRestorePanel::OnConfigUpdated)
226 EVT_CHOICE(ConfigClient, wxbRestorePanel::OnConfigUpdated)
227 EVT_CHOICE(ConfigFileset, wxbRestorePanel::OnConfigUpdated)
228 EVT_CHOICE(ConfigStorage, wxbRestorePanel::OnConfigUpdated)
229 EVT_CHOICE(ConfigJobName, wxbRestorePanel::OnConfigUpdated)
230 EVT_CHOICE(ConfigPool, wxbRestorePanel::OnConfigUpdated)
232 EVT_BUTTON(ConfigOk, wxbRestorePanel::OnConfigOk)
233 EVT_BUTTON(ConfigApply, wxbRestorePanel::OnConfigApply)
234 EVT_BUTTON(ConfigCancel, wxbRestorePanel::OnConfigCancel)
238 * wxbRestorePanel constructor
240 wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
241 //pendingEvents = new wxbEventList(); //EVTQUEUE
242 //processing = false; //EVTQUEUE
245 imagelist = new wxImageList(16, 16, TRUE, 3);
246 imagelist->Add(wxIcon(unmarked_xpm));
247 imagelist->Add(wxIcon(marked_xpm));
248 imagelist->Add(wxIcon(partmarked_xpm));
250 wxFlexGridSizer* mainSizer = new wxFlexGridSizer(3, 1, 10, 10);
251 mainSizer->AddGrowableCol(0);
252 mainSizer->AddGrowableRow(1);
254 wxFlexGridSizer *firstSizer = new wxFlexGridSizer(1, 2, 10, 10);
256 firstSizer->AddGrowableCol(0);
257 firstSizer->AddGrowableRow(0);
259 start = new wxButton(this, RestoreStart, "Enter restore mode", wxDefaultPosition, wxSize(150, 30));
260 firstSizer->Add(start, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
262 cancel = new wxButton(this, RestoreCancel, "Cancel restore", wxDefaultPosition, wxSize(150, 30));
263 firstSizer->Add(cancel, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_RIGHT, 10);
267 /* clientChoice = new wxChoice(this, ClientChoice, wxDefaultPosition, wxSize(150, 30), 0, elist);
268 firstSizer->Add(clientChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
270 jobChoice = new wxChoice(this, -1, wxDefaultPosition, wxSize(150, 30), 0, elist);
271 firstSizer->Add(jobChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);*/
273 mainSizer->Add(firstSizer, 1, wxEXPAND, 10);
275 treelistPanel = new wxSplitterWindow(this);
277 wxPanel* treePanel = new wxPanel(treelistPanel);
278 wxFlexGridSizer *treeSizer = new wxFlexGridSizer(2, 1, 0, 0);
279 treeSizer->AddGrowableCol(0);
280 treeSizer->AddGrowableRow(0);
282 tree = new wxbTreeCtrl(treePanel, this, TreeCtrl, wxDefaultPosition, wxSize(200,50));
283 tree->SetImageList(imagelist);
285 treeSizer->Add(tree, 1, wxEXPAND, 0);
287 wxBoxSizer *treeCtrlSizer = new wxBoxSizer(wxHORIZONTAL);
288 treeadd = new wxButton(treePanel, TreeAdd, "Add", wxDefaultPosition, wxSize(60, 25));
289 treeCtrlSizer->Add(treeadd, 0, wxLEFT | wxRIGHT, 3);
290 treeremove = new wxButton(treePanel, TreeRemove, "Remove", wxDefaultPosition, wxSize(60, 25));
291 treeCtrlSizer->Add(treeremove, 0, wxLEFT | wxRIGHT, 3);
292 treerefresh = new wxButton(treePanel, TreeRefresh, "Refresh", wxDefaultPosition, wxSize(60, 25));
293 treeCtrlSizer->Add(treerefresh, 0, wxLEFT | wxRIGHT, 3);
295 treeSizer->Add(treeCtrlSizer, 1, wxALIGN_CENTER_HORIZONTAL, 0);
297 treePanel->SetSizer(treeSizer);
299 wxPanel* listPanel = new wxPanel(treelistPanel);
300 wxFlexGridSizer *listSizer = new wxFlexGridSizer(2, 1, 0, 0);
301 listSizer->AddGrowableCol(0);
302 listSizer->AddGrowableRow(0);
304 list = new wxbListCtrl(listPanel, this, ListCtrl, wxDefaultPosition, wxSize(200,50));
305 //treelistSizer->Add(list, 1, wxEXPAND, 10);
307 list->SetImageList(imagelist, wxIMAGE_LIST_SMALL);
310 info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT);
312 info.SetAlign(wxLIST_FORMAT_CENTER);
313 list->InsertColumn(0, info);
315 info.SetText("Filename");
316 info.SetAlign(wxLIST_FORMAT_LEFT);
317 list->InsertColumn(1, info);
319 info.SetText("Size");
320 info.SetAlign(wxLIST_FORMAT_RIGHT);
321 list->InsertColumn(2, info);
323 info.SetText("Date");
324 info.SetAlign(wxLIST_FORMAT_LEFT);
325 list->InsertColumn(3, info);
327 info.SetText("Perm.");
328 info.SetAlign(wxLIST_FORMAT_LEFT);
329 list->InsertColumn(4, info);
331 info.SetText("User");
332 info.SetAlign(wxLIST_FORMAT_RIGHT);
333 list->InsertColumn(5, info);
335 info.SetText("Group");
336 info.SetAlign(wxLIST_FORMAT_RIGHT);
337 list->InsertColumn(6, info);
339 listSizer->Add(list, 1, wxEXPAND, 0);
341 wxBoxSizer *listCtrlSizer = new wxBoxSizer(wxHORIZONTAL);
342 listadd = new wxButton(listPanel, ListAdd, "Add", wxDefaultPosition, wxSize(60, 25));
343 listCtrlSizer->Add(listadd, 0, wxLEFT | wxRIGHT, 5);
344 listremove = new wxButton(listPanel, ListRemove, "Remove", wxDefaultPosition, wxSize(60, 25));
345 listCtrlSizer->Add(listremove, 0, wxLEFT | wxRIGHT, 5);
346 listrefresh = new wxButton(listPanel, ListRefresh, "Refresh", wxDefaultPosition, wxSize(60, 25));
347 listCtrlSizer->Add(listrefresh, 0, wxLEFT | wxRIGHT, 5);
349 listSizer->Add(listCtrlSizer, 1, wxALIGN_CENTER_HORIZONTAL, 0);
351 listPanel->SetSizer(listSizer);
353 treelistPanel->SplitVertically(treePanel, listPanel, 210);
355 treelistPanel->SetMinimumPaneSize(210);
357 treelistPanel->Show(false);
359 wxbConfig* config = new wxbConfig();
360 config->Add(new wxbConfigParam("Job Name", ConfigJobName, choice, 0, elist));
361 config->Add(new wxbConfigParam("Client", ConfigClient, choice, 0, elist));
362 config->Add(new wxbConfigParam("Fileset", ConfigFileset, choice, 0, elist));
363 config->Add(new wxbConfigParam("Pool", ConfigPool, choice, 0, elist));
364 config->Add(new wxbConfigParam("Storage", ConfigStorage, choice, 0, elist));
365 config->Add(new wxbConfigParam("Before", ConfigWhen, choice, 0, elist));
367 configPanel = new wxbConfigPanel(this, config, "Please configure parameters concerning files to restore :", RestoreStart, RestoreCancel, -1);
369 configPanel->Show(true);
370 configPanel->Enable(false);
372 config = new wxbConfig();
373 config->Add(new wxbConfigParam("Job Name", -1, text, ""));
374 config->Add(new wxbConfigParam("Bootstrap", -1, text, ""));
375 config->Add(new wxbConfigParam("Where", ConfigWhere, modifiableText, ""));
376 wxString erlist[] = {"always", "if newer", "if older", "never"};
377 config->Add(new wxbConfigParam("Replace", ConfigReplace, choice, 4, erlist));
378 config->Add(new wxbConfigParam("Fileset", ConfigFileset, choice, 0, erlist));
379 config->Add(new wxbConfigParam("Client", ConfigClient, choice, 0, erlist));
380 config->Add(new wxbConfigParam("Storage", ConfigStorage, choice, 0, erlist));
381 config->Add(new wxbConfigParam("When", ConfigWhen, modifiableText, ""));
382 config->Add(new wxbConfigParam("Priority", ConfigPriority, modifiableText, ""));
384 restorePanel = new wxbConfigPanel(this, config, "Please configure parameters concerning files restoration :", ConfigOk, ConfigCancel, ConfigApply);
386 restorePanel->Show(false);
388 centerSizer = new wxBoxSizer(wxHORIZONTAL);
389 //centerSizer->Add(treelistPanel, 1, wxEXPAND | wxADJUST_MINSIZE);
391 mainSizer->Add(centerSizer, 1, wxEXPAND, 10);
393 gauge = new wxGauge(this, -1, 1, wxDefaultPosition, wxSize(200,20));
395 mainSizer->Add(gauge, 1, wxEXPAND, 5);
397 gauge->Enable(false);
400 mainSizer->SetSizeHints(this);
404 for (int i = 0; i < 7; i++) {
405 list->SetColumnWidth(i, 70);
408 SetCursor(*wxSTANDARD_CURSOR);
410 markWhenListingDone = false;
416 * wxbRestorePanel destructor
418 wxbRestorePanel::~wxbRestorePanel() {
422 /*----------------------------------------------------------------------------
423 wxbPanel overloadings
424 ----------------------------------------------------------------------------*/
426 wxString wxbRestorePanel::GetTitle() {
430 void wxbRestorePanel::EnablePanel(bool enable) {
432 if (status == disabled) {
433 SetStatus(activable);
441 /*----------------------------------------------------------------------------
442 Commands called by events handler
443 ----------------------------------------------------------------------------*/
445 /* The main button has been clicked */
446 void wxbRestorePanel::CmdStart() {
448 if (status == activable) {
449 wxbMainFrame::GetInstance()->SetStatusText("Getting parameters list.");
450 wxbDataTokenizer* dt = wxbUtils::WaitForEnd(".clients\n", true, false);
453 configPanel->ClearRowChoices("Client");
454 restorePanel->ClearRowChoices("Client");
456 if (dt->GetCount() == 0) {
457 wxbMainFrame::GetInstance()->SetStatusText("Error : no clients returned by the director.");
461 for (i = 0; i < dt->GetCount(); i++) {
464 configPanel->AddRowChoice("Client", str);
465 restorePanel->AddRowChoice("Client", str);
475 dt = wxbUtils::WaitForEnd(".filesets\n", true, false);
477 configPanel->ClearRowChoices("Fileset");
478 restorePanel->ClearRowChoices("Fileset");
480 if (dt->GetCount() == 0) {
481 wxbMainFrame::GetInstance()->SetStatusText("Error : no filesets returned by the director.");
485 for (i = 0; i < dt->GetCount(); i++) {
488 configPanel->AddRowChoice("Fileset", str);
489 restorePanel->AddRowChoice("Fileset", str);
499 dt = wxbUtils::WaitForEnd(".storage\n", true, false);
501 configPanel->ClearRowChoices("Storage");
502 restorePanel->ClearRowChoices("Storage");
504 if (dt->GetCount() == 0) {
505 wxbMainFrame::GetInstance()->SetStatusText("Error : no storage returned by the director.");
509 for (i = 0; i < dt->GetCount(); i++) {
512 configPanel->AddRowChoice("Storage", str);
513 restorePanel->AddRowChoice("Storage", str);
523 dt = wxbUtils::WaitForEnd(".jobs\n", true, false);
525 configPanel->ClearRowChoices("Job Name");
527 if (dt->GetCount() == 0) {
528 wxbMainFrame::GetInstance()->SetStatusText("Error : no jobs returned by the director.");
532 for (i = 0; i < dt->GetCount(); i++) {
535 configPanel->AddRowChoice("Job Name", str);
538 configPanel->SetRowString("Job Name", "RestoreFiles");
547 dt = wxbUtils::WaitForEnd(".pools\n", true, false);
549 configPanel->ClearRowChoices("Pool");
551 if (dt->GetCount() == 0) {
552 wxbMainFrame::GetInstance()->SetStatusText("Error : no jobs returned by the director.");
556 for (i = 0; i < dt->GetCount(); i++) {
559 configPanel->AddRowChoice("Pool", str);
573 wxbMainFrame::GetInstance()->SetStatusText("Please configure your restore parameters.");
575 else if (status == entered) {
576 /* if (clientChoice->GetStringSelection().Length() < 1) {
577 wxbMainFrame::GetInstance()->SetStatusText("Please select a client.");
580 if (jobChoice->GetStringSelection().Length() < 1) {
581 wxbMainFrame::GetInstance()->SetStatusText("Please select a restore date.");
584 wxbMainFrame::GetInstance()->SetStatusText("Building restore tree...");
588 wxbUtils::WaitForPrompt(wxString("restore") <<
589 " client=\"" << configPanel->GetRowString("Client") <<
590 "\" fileset=\"" << configPanel->GetRowString("Fileset") <<
591 "\" pool=\"" << configPanel->GetRowString("Pool") <<
592 "\" storage=\"" << configPanel->GetRowString("Storage") << "\"\n");
593 wxbUtils::WaitForPrompt("6\n");
595 /*wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxString() << configPanel->GetRowString("Before") << "\n", true);
596 int client = pp->getChoices()->Index(configPanel->GetRowString("Client"));
597 if (client == wxNOT_FOUND) {
598 wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected client.");
603 wxbTableParser* tableparser = new wxbTableParser();
604 wxbDataTokenizer* dt = new wxbDataTokenizer(true);
606 wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString("Before") << "\n");
608 while (!tableparser->hasFinished() && !dt->hasFinished()) {
609 wxTheApp->Yield(true);
615 if (dt->hasFinished() && !tableparser->hasFinished()) {
617 if (dt->GetCount() > 1) {
618 str = (*dt)[dt->GetCount()-2];
621 wxbMainFrame::GetInstance()->SetStatusText(wxString("Error while starting restore: ") << str);
631 for (i = 0; i < tableparser->GetCount(); i++) {
632 str = (*tableparser)[i][2];
633 str.Replace(",", "");
634 if (str.ToLong(&l)) {
640 gauge->SetRange(tot);
642 /*wxbMainFrame::GetInstance()->Print(
643 wxString("[") << tot << "]", CS_DEBUG);*/
645 wxDateTime base = wxDateTime::Now();
649 unsigned int lastindex = 0;
653 while (!dt->hasFinished()) {
654 newdate = wxDateTime::Now();
655 if (newdate.Subtract(base).GetMilliseconds() > 10 ) {
657 for (; lastindex < dt->GetCount(); lastindex++) {
658 if (((*dt)[lastindex].Find("Building directory tree for JobId ") == 0) &&
659 ((i = (*dt)[lastindex].Find(" ...")) > 0)) {
660 str = (*dt)[lastindex].Mid(34, i-34);
661 for (i = 0; i < tableparser->GetCount(); i++) {
662 if (str == (*tableparser)[i][0]) {
663 str = (*tableparser)[i][2];
664 str.Replace(",", "");
665 if (str.ToLong(&l)) {
668 var = (willdo-done)/3;
676 if (gauge->GetValue() <= done) {
677 gauge->SetValue(done);
681 else if (gauge->GetValue() >= willdo) {
682 gauge->SetValue(willdo);
687 gauge->SetValue(gauge->GetValue()+var);
689 /*wxbMainFrame::GetInstance()->Print(
690 wxString("[") << gauge->GetValue() << "/" << done
691 << "-" << willdo << "]", CS_DEBUG);*/
693 wxTheApp->Yield(true);
697 gauge->SetValue(tot);
698 wxTheApp->Yield(true);
709 wxbUtils::WaitForEnd("unmark *\n");
710 wxTreeItemId root = tree->AddRoot(configPanel->GetRowString("Client"), -1, -1, new wxbTreeItemData("/", configPanel->GetRowString("Client"), 0));
711 currentTreeItem = root;
713 tree->SelectItem(root);
715 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.");
718 else if (status == choosing) {
722 wxbDataTokenizer* dt;
726 dt = new wxbDataTokenizer(true);
727 wxbUtils::WaitForPrompt("done\n");
729 SetStatus(configuring);
731 for (i = 0; i < dt->GetCount(); i++) {
732 if ((j = (*dt)[i].Find(" files selected to be restored.")) > -1) {
733 (*dt)[i].Mid(0, j).ToLong(&totfilemessages);
737 if ((j = (*dt)[i].Find(" file selected to be restored.")) > -1) {
738 (*dt)[i].Mid(0, j).ToLong(&totfilemessages);
743 wxbMainFrame::GetInstance()->SetStatusText(
744 wxString("Please configure your restore (")
745 << totfilemessages << " files selected to be restored)...");
747 UpdateSecondConfig(dt);
752 restorePanel->EnableApply(false);
754 if (totfilemessages == 0) {
755 wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
756 wxbMainFrame::GetInstance()->SetStatusText("Restore failed : no file selected.");
761 else if (status == configuring) {
762 cancel->Enable(false);
766 wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
768 wxbDataTokenizer* dt;
770 SetStatus(restoring);
771 wxbUtils::WaitForEnd("yes\n");
774 gauge->SetRange(totfilemessages);
776 wxDateTime currenttime;
778 dt = wxbUtils::WaitForEnd("time\n", true);
779 wxStringTokenizer ttkz((*dt)[0], " ", wxTOKEN_STRTOK);
780 if ((currenttime.ParseDate(ttkz.GetNextToken()) == NULL) || // Date
781 (currenttime.ParseTime(ttkz.GetNextToken()) == NULL)) { // Time
782 currenttime.SetYear(1990); // If parsing fails, set currenttime to a dummy date
785 currenttime -= wxTimeSpan::Seconds(30); //Adding a 30" tolerance
789 wxDateTime scheduledtime;
790 wxStringTokenizer stkz(restorePanel->GetRowString("When"), " ", wxTOKEN_STRTOK);
792 if ((scheduledtime.ParseDate(stkz.GetNextToken()) == NULL) || // Date
793 (scheduledtime.ParseTime(stkz.GetNextToken()) == NULL)) { // Time
794 scheduledtime.SetYear(2090); // If parsing fails, set scheduledtime to a dummy date
797 if (scheduledtime.Subtract(currenttime).IsLongerThan(wxTimeSpan::Seconds(150))) {
798 wxbMainFrame::GetInstance()->Print("Restore is scheduled in more than two minutes, wx-console will not wait for its completion.\n", CS_DEBUG);
799 wxbMainFrame::GetInstance()->SetStatusText("Restore is scheduled in more than two minutes, wx-console will not wait for its completion.");
804 wxString cmd = "list jobid=";
806 wxString jobname = restorePanel->GetRowString("Job Name");
810 wxbTableParser* tableparser;
813 tableparser = wxbUtils::CreateAndWaitForParser("list jobs\n");
817 for (i = 0; i < tableparser->GetCount(); i++) {
818 if (jobname == (*tableparser)[i][1]) {
819 wxStringTokenizer jtkz((*tableparser)[i][2], " ", wxTOKEN_STRTOK);
820 if ((jobtime.ParseDate(jtkz.GetNextToken()) != NULL) && // Date
821 (jobtime.ParseTime(jtkz.GetNextToken()) != NULL)) { // Time
822 if (jobtime.IsLaterThan(currenttime)) {
823 jobid = (*tableparser)[i][0];
824 cmd << jobid << "\n";
827 cancel->Enable(true);
834 if (tableparser == NULL) { //The job was found
841 while (sw2.Time() < 2000) {
842 wxTheApp->Yield(true);
845 if (sw.Time() > 60000) {
846 wxbMainFrame::GetInstance()->Print("The restore job has not been created within one minute, wx-console will not wait for its completion anymore.\n", CS_DEBUG);
847 wxbMainFrame::GetInstance()->SetStatusText("The restore job has not been created within one minute, wx-console will not wait for its completion anymore.");
849 cancel->Enable(true);
854 long filemessages = 0;
857 tableparser = wxbUtils::CreateAndWaitForParser(cmd);
858 if ((*tableparser)[0][7] != "C") {
863 dt = wxbUtils::WaitForEnd("messages\n", true);
865 for (unsigned int i = 0; i < dt->GetCount(); i++) {
866 wxStringTokenizer tkz((*dt)[i], " ", wxTOKEN_STRTOK);
870 // Date Time name: perm ? user grp size date time
871 //04-Apr-2004 17:19 Tom-fd: -rwx------ 1 nicolas None 514967 2004-03-20 20:03:42 filename
873 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { // Date
874 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { // Time
875 if (tkz.GetNextToken().Last() == ':') { // name:
876 tkz.GetNextToken(); // perm
877 tkz.GetNextToken(); // ?
878 tkz.GetNextToken(); // user
879 tkz.GetNextToken(); // grp
880 tkz.GetNextToken(); // size
881 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { //date
882 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { //time
884 //wxbMainFrame::GetInstance()->Print(wxString("(") << filemessages << ")", CS_DEBUG);
885 gauge->SetValue(filemessages);
895 wxbMainFrame::GetInstance()->SetStatusText(wxString("Restoring, please wait (") << filemessages << " of " << totfilemessages << " files done)...");
898 while (sw2.Time() < 10000) {
899 wxTheApp->Yield(true);
904 wxbUtils::WaitForEnd("messages\n");
906 gauge->SetValue(totfilemessages);
908 if ((*tableparser)[0][7] == "T") {
909 wxbMainFrame::GetInstance()->Print("Restore done successfully.\n", CS_DEBUG);
910 wxbMainFrame::GetInstance()->SetStatusText("Restore done successfully.");
913 wxbMainFrame::GetInstance()->Print("Restore failed, please look at messages.\n", CS_DEBUG);
914 wxbMainFrame::GetInstance()->SetStatusText("Restore failed, please look at messages in console.");
921 /* The cancel button has been clicked */
922 void wxbRestorePanel::CmdCancel() {
925 if (status == restoring) {
927 wxbMainFrame::GetInstance()->Send(wxString("cancel job=") << jobid << "\n");
929 cancel->Enable(true);
934 while ((IsWorking()) && (cancelled != 2)) {
935 wxTheApp->Yield(true);
937 if (sw.Time() > 30000) { /* 30 seconds timeout */
938 if (status == choosing) {
939 wxbMainFrame::GetInstance()->Send("quit\n");
941 else if (status == configuring) {
942 wxbMainFrame::GetInstance()->Send("no\n");
944 else if (status == restoring) {
955 wxbMainFrame::GetInstance()->Send("quit\n");
958 wxbMainFrame::GetInstance()->Send("no\n");
967 /* Apply configuration changes */
969 /* 1: Level (not appropriate)
974 * 6: When (yes : "Please enter desired start time as YYYY-MM-DD HH:MM:SS (return for now):")
975 * 7: Priority (yes : "Enter new Priority: (positive integer)")
977 * 9: Where (yes : "Please enter path prefix for restore (/ for none):")
978 * 10: Replace (yes : "Replace:\n 1: always\n 2: ifnewer\n 3: ifolder\n 4: never\n
979 * Select replace option (1-4):")
983 void wxbRestorePanel::CmdConfigApply() {
984 if (cfgUpdated == 0) return;
986 wxbMainFrame::GetInstance()->SetStatusText("Applying restore configuration changes...");
990 wxbDataTokenizer* dt = NULL;
994 while (cfgUpdated > 0) {
999 wxString def; //String to send if can't use our data
1000 if ((cfgUpdated >> ConfigWhere) & 1) {
1001 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1002 wxbUtils::WaitForPrompt("9\n");
1003 dt = new wxbDataTokenizer(true);
1004 wxbUtils::WaitForPrompt(restorePanel->GetRowString("Where") + "\n");
1006 cfgUpdated = cfgUpdated & (~(1 << ConfigWhere));
1008 else if ((cfgUpdated >> ConfigReplace) & 1) {
1009 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1010 wxbUtils::WaitForPrompt("10\n");
1011 dt = new wxbDataTokenizer(true);
1012 wxbUtils::WaitForPrompt(wxString() << (restorePanel->GetRowSelection("Replace")+1) << "\n");
1014 cfgUpdated = cfgUpdated & (~(1 << ConfigReplace));
1016 else if ((cfgUpdated >> ConfigWhen) & 1) {
1017 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1018 wxbUtils::WaitForPrompt("6\n");
1019 dt = new wxbDataTokenizer(true);
1020 wxbUtils::WaitForPrompt(restorePanel->GetRowString("When") + "\n");
1022 cfgUpdated = cfgUpdated & (~(1 << ConfigWhen));
1024 else if ((cfgUpdated >> ConfigPriority) & 1) {
1025 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1026 wxbUtils::WaitForPrompt("7\n");
1027 dt = new wxbDataTokenizer(true);
1028 wxbUtils::WaitForPrompt(restorePanel->GetRowString("Priority") + "\n");
1030 cfgUpdated = cfgUpdated & (~(1 << ConfigPriority));
1032 else if ((cfgUpdated >> ConfigClient) & 1) {
1033 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1034 wxbPromptParser *pp = wxbUtils::WaitForPrompt("5\n", true);
1035 int client = pp->getChoices()->Index(restorePanel->GetRowString("Client"));
1036 if (client == wxNOT_FOUND) {
1037 wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected client.");
1042 dt = new wxbDataTokenizer(true);
1043 wxbUtils::WaitForPrompt(wxString() << client << "\n");
1045 cfgUpdated = cfgUpdated & (~(1 << ConfigClient));
1047 else if ((cfgUpdated >> ConfigFileset) & 1) {
1048 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1049 wxbPromptParser *pp = wxbUtils::WaitForPrompt("4\n", true);
1050 int fileset = pp->getChoices()->Index(restorePanel->GetRowString("Fileset"));
1051 if (fileset == wxNOT_FOUND) {
1052 wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected fileset.");
1057 dt = new wxbDataTokenizer(true);
1058 wxbUtils::WaitForPrompt(wxString() << fileset << "\n");
1060 cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
1062 else if ((cfgUpdated >> ConfigStorage) & 1) {
1063 wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
1064 wxbPromptParser *pp = wxbUtils::WaitForPrompt("2\n", true);
1065 int fileset = pp->getChoices()->Index(restorePanel->GetRowString("Storage"));
1066 if (fileset == wxNOT_FOUND) {
1067 wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected storage.");
1072 dt = new wxbDataTokenizer(true);
1073 wxbUtils::WaitForPrompt(wxString() << fileset << "\n");
1075 cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
1083 for (i = 0; i < dt->GetCount(); i++) {
1084 if ((*dt)[i].Find("Run Restore job") == 0) {
1089 if (i == dt->GetCount()) {
1091 dt = wxbUtils::WaitForEnd(def + "\n", true);
1095 UpdateSecondConfig(dt); /* TODO: Check result */
1100 wxbMainFrame::GetInstance()->SetStatusText("Restore configuration changes were applied.");
1106 /* Cancel restore */
1107 void wxbRestorePanel::CmdConfigCancel() {
1108 wxbUtils::WaitForEnd("no\n");
1109 wxbMainFrame::GetInstance()->Print("Restore cancelled.\n", CS_DEBUG);
1110 wxbMainFrame::GetInstance()->SetStatusText("Restore cancelled.");
1111 SetStatus(finished);
1114 /* List jobs for a specified client */
1115 void wxbRestorePanel::CmdListJobs() {
1116 if (status == entered) {
1117 configPanel->ClearRowChoices("Before");
1118 wxbUtils::WaitForPrompt("query\n");
1119 wxbUtils::WaitForPrompt("6\n");
1120 wxbTableParser* tableparser = new wxbTableParser();
1121 wxbDataTokenizer* dt = wxbUtils::WaitForEnd(configPanel->GetRowString("Client") + "\n", true);
1123 if (!tableparser->hasFinished()) {
1124 for (unsigned int i = 0; i < dt->Count(); i++) {
1125 if ((*dt)[i].Find("No results to list.") == 0) {
1126 configPanel->AddRowChoice("Before", "No backup found for this client.");
1127 configPanel->SetRowSelection("Before", 0);
1128 configPanel->EnableApply(true); // Enabling the not existing apply button disables the ok button.
1133 else if (((*dt)[i].Find("ERROR") > -1) || ((*dt)[i].Find("Query failed") > -1)) {
1134 configPanel->AddRowChoice("Before", "Cannot get previous backups list, see console.");
1135 configPanel->SetRowSelection("Before", 0);
1136 configPanel->EnableApply(true); // Enabling the not existing apply button disables the ok button.
1144 while (!tableparser->hasFinished()) {
1145 wxTheApp->Yield(true);
1151 for (int i = tableparser->GetCount()-1; i > -1; i--) {
1152 wxString str = (*tableparser)[i][3];
1153 wxDateTime datetime;
1155 if ( ( (chr = datetime.ParseDate(str.GetData()) ) != NULL ) && ( datetime.ParseTime(++chr) != NULL ) ) {
1156 datetime += wxTimeSpan::Seconds(1);
1157 //wxbMainFrame::GetInstance()->Print(wxString("-") << datetime.Format("%Y-%m-%d %H:%M:%S"), CS_DEBUG);
1158 configPanel->AddRowChoice("Before", datetime.Format("%Y-%m-%d %H:%M:%S"));
1161 jobChoice->Append("Invalid");
1167 configPanel->SetRowSelection("Before", 0);
1168 configPanel->EnableApply(false); // Disabling the not existing apply button enables the ok button.
1172 /* List files and directories for a specified tree item */
1173 void wxbRestorePanel::CmdList(wxTreeItemId item) {
1174 if (status == choosing) {
1175 list->DeleteAllItems();
1180 UpdateTreeItem(item, true, false);
1182 if (list->GetItemCount() >= 1) {
1183 int firstwidth = list->GetSize().GetWidth();
1184 for (int i = 2; i < 7; i++) {
1185 list->SetColumnWidth(i, wxLIST_AUTOSIZE);
1186 firstwidth -= list->GetColumnWidth(i);
1189 list->SetColumnWidth(0, 18);
1191 list->SetColumnWidth(1, wxLIST_AUTOSIZE);
1192 if (list->GetColumnWidth(1) < firstwidth) {
1193 list->SetColumnWidth(1, firstwidth-25);
1199 /* Mark a treeitem (directory) or a listitem (file or directory) */
1200 void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long* listitems, int listsize, int state) {
1201 if (status == choosing) {
1202 wxbTreeItemData** itemdata;
1203 int itemdatasize = 0;
1204 if (listsize == 0) {
1205 itemdata = new wxbTreeItemData*[1];
1209 itemdata = new wxbTreeItemData*[listsize];
1210 itemdatasize = listsize;
1213 if (listitems != NULL) {
1214 for (int i = 0; i < listsize; i++) {
1215 itemdata[i] = (wxbTreeItemData*)list->GetItemData(listitems[i]);
1218 else if (treeitem.IsOk()) {
1219 itemdata[0] = (wxbTreeItemData*)tree->GetItemData(treeitem);
1226 if (itemdata[0] == NULL) { //Should never happen
1231 wxString dir = itemdata[0]->GetPath();
1235 if (dir.GetChar(dir.Length()-1) == '/') {
1239 int i = dir.Find('/', TRUE);
1244 else { /* first dir below root */
1245 file = dir.Mid(i+1);
1246 dir = dir.Mid(0, i+1);
1255 bool marked = false;
1256 bool unmarked = false;
1258 for (int i = 0; i < itemdatasize; i++) {
1259 switch(itemdata[i]->GetMarked()) {
1273 if (marked && unmarked)
1289 wxbUtils::WaitForEnd(wxString("cd \"") << dir << "\"\n");
1290 wxbUtils::WaitForEnd(wxString((state==1) ? "mark" : "unmark") << " \"" << file << "\"\n");
1292 /* TODO: Check commands results */
1294 /*if ((dir == "/") && (file == "*")) {
1295 itemdata->SetMarked((itemdata->GetMarked() == 1) ? 0 : 1);
1298 if (listitems == NULL) { /* tree item state changed */
1299 SetTreeItemState(treeitem, state);
1300 /*treeitem = tree->GetSelection();
1301 UpdateTree(treeitem, true);
1302 treeitem = tree->GetItemParent(treeitem);*/
1305 for (int i = 0; i < listsize; i++) {
1306 SetListItemState(listitems[i], state);
1308 /*UpdateTree(treeitem, (tree->GetSelection() == treeitem));
1309 treeitem = tree->GetItemParent(treeitem);*/
1312 /*while (treeitem.IsOk()) {
1313 WaitForList(treeitem, false);
1314 treeitem = tree->GetItemParent(treeitem);
1321 /*----------------------------------------------------------------------------
1323 ----------------------------------------------------------------------------*/
1325 /* Run a dir command, and waits until result is fully received. */
1326 void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse) {
1327 // this->updatelist = updatelist;
1328 wxbDataTokenizer* dt;
1330 dt = wxbUtils::WaitForEnd(wxString("cd \"") <<
1331 static_cast<wxbTreeItemData*>(tree->GetItemData(item))
1332 ->GetPath() << "\"\n", false);
1334 /* TODO: check command result */
1341 list->DeleteAllItems();
1342 dt = wxbUtils::WaitForEnd("dir\n", true);
1346 for (unsigned int i = 0; i < dt->GetCount(); i++) {
1349 if (str.Find("cwd is:") == 0) { // Sometimes cd command result "infiltrate" into listings.
1355 wxString* file = ParseList(str);
1360 wxTreeItemId treeid;
1362 if (file[8].GetChar(file[8].Length()-1) == '/') {
1366 treeid = tree->GetFirstChild(item, cookie);
1368 bool updated = false;
1370 while (treeid.IsOk()) {
1371 itemStr = tree->GetItemText(treeid);
1372 if (file[8] == itemStr) {
1373 int stat = wxbTreeItemData::GetMarkedStatus(file[6]);
1374 if (static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->GetMarked() != stat) {
1375 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Normal);
1376 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Selected);
1377 static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->SetMarked(file[6]);
1379 if ((recurse) && (tree->IsExpanded(treeid))) {
1380 UpdateTreeItem(treeid, false, true);
1385 treeid = tree->GetNextChild(item, cookie);
1389 int img = wxbTreeItemData::GetMarkedStatus(file[6]);
1390 treeid = tree->AppendItem(item, file[8], img, img, new wxbTreeItemData(file[7], file[8], file[6]));
1395 long ind = list->InsertItem(list->GetItemCount(), wxbTreeItemData::GetMarkedStatus(file[6]));
1396 wxbTreeItemData* data = new wxbTreeItemData(file[7], file[8], file[6], ind);
1397 data->SetId(treeid);
1398 list->SetItemData(ind, (long)data);
1399 list->SetItem(ind, 1, file[8]); // filename
1400 list->SetItem(ind, 2, file[4]); //Size
1401 list->SetItem(ind, 3, file[5]); //date
1402 list->SetItem(ind, 4, file[0]); //perm
1403 list->SetItem(ind, 5, file[2]); //user
1404 list->SetItem(ind, 6, file[3]); //grp
1416 /* Parse dir command results. */
1417 wxString* wxbRestorePanel::ParseList(wxString line) {
1418 /* See ls_output in dird/ua_tree.c */
1420 //drwxrwxrwx 1 root root 0 2004-04-03 14:35:21 f:/tocd/NVSU 1.00.00/
1421 //+ 10 + ++ + 8 + + 8 ++ 8 + + 19 + *+ ->
1422 //0 12 15 24 32 42 62
1424 if (line.Length() < 63)
1427 wxString* ret = new wxString[9];
1429 ret[0] = line.Mid(0, 10).Trim();
1430 ret[1] = line.Mid(12, 2).Trim();
1431 ret[2] = line.Mid(15, 8).Trim();
1432 ret[3] = line.Mid(24, 8).Trim();
1433 ret[4] = line.Mid(32, 8).Trim();
1434 ret[5] = line.Mid(42, 19).Trim();
1435 ret[6] = line.Mid(62, 1);
1436 ret[7] = line.Mid(63).Trim();
1438 if (ret[6] == " ") ret[6] = "";
1440 if (ret[7].GetChar(ret[7].Length()-1) == '/') {
1442 ret[8].RemoveLast();
1443 ret[8] = ret[7].Mid(ret[8].Find('/', true)+1);
1446 ret[8] = ret[7].Mid(ret[7].Find('/', true)+1);
1452 /* Sets a list item state, and update its parents and children if it is a directory */
1453 void wxbRestorePanel::SetListItemState(long listitem, int newstate) {
1454 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
1456 wxTreeItemId treeitem;
1458 itemdata->SetMarked(newstate);
1459 list->SetItemImage(listitem, newstate, 0); /* TODO: Find what these ints are for */
1460 list->SetItemImage(listitem, newstate, 1);
1462 if ((treeitem = itemdata->GetId()).IsOk()) {
1463 SetTreeItemState(treeitem, newstate);
1466 UpdateTreeItemState(tree->GetSelection());
1470 /* Sets a tree item state, and update its children, parents and list (if necessary) */
1471 void wxbRestorePanel::SetTreeItemState(wxTreeItemId item, int newstate) {
1473 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
1475 wxbTreeItemData* itemdata;
1477 while (currentChild.IsOk()) {
1478 itemdata = (wxbTreeItemData*)tree->GetItemData(currentChild);
1479 int state = itemdata->GetMarked();
1481 if (state != newstate) {
1482 itemdata->SetMarked(newstate);
1483 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Normal);
1484 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Selected);
1487 currentChild = tree->GetNextChild(item, cookie);
1490 itemdata = (wxbTreeItemData*)tree->GetItemData(item);
1491 itemdata->SetMarked(newstate);
1492 tree->SetItemImage(item, newstate, wxTreeItemIcon_Normal);
1493 tree->SetItemImage(item, newstate, wxTreeItemIcon_Selected);
1496 if (tree->GetSelection() == item) {
1497 for (long i = 0; i < list->GetItemCount(); i++) {
1498 list->SetItemImage(i, newstate, 0); /* TODO: Find what these ints are for */
1499 list->SetItemImage(i, newstate, 1);
1503 UpdateTreeItemState(tree->GetItemParent(item));
1506 /* Update a tree item state, and its parents' state */
1507 void wxbRestorePanel::UpdateTreeItemState(wxTreeItemId item) {
1515 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
1517 bool onechildmarked = false;
1518 bool onechildunmarked = false;
1520 while (currentChild.IsOk()) {
1521 state = ((wxbTreeItemData*)tree->GetItemData(currentChild))->GetMarked();
1524 onechildunmarked = true;
1527 onechildmarked = true;
1530 onechildmarked = true;
1531 onechildunmarked = true;
1535 if (onechildmarked && onechildunmarked) {
1539 currentChild = tree->GetNextChild(item, cookie);
1542 if (tree->GetSelection() == item) {
1543 for (long i = 0; i < list->GetItemCount(); i++) {
1544 state = ((wxbTreeItemData*)list->GetItemData(i))->GetMarked();
1548 onechildunmarked = true;
1551 onechildmarked = true;
1554 onechildmarked = true;
1555 onechildunmarked = true;
1559 if (onechildmarked && onechildunmarked) {
1567 if (onechildmarked && onechildunmarked) {
1570 else if (onechildmarked) {
1573 else if (onechildunmarked) {
1576 else { // no child, don't change anything
1577 UpdateTreeItemState(tree->GetItemParent(item));
1581 wxbTreeItemData* itemdata = (wxbTreeItemData*)tree->GetItemData(item);
1583 itemdata->SetMarked(state);
1584 tree->SetItemImage(item, state, wxTreeItemIcon_Normal);
1585 tree->SetItemImage(item, state, wxTreeItemIcon_Selected);
1587 UpdateTreeItemState(tree->GetItemParent(item));
1590 /* Refresh the whole tree. */
1591 void wxbRestorePanel::RefreshTree() {
1592 /* Save current selection */
1593 wxArrayString current;
1595 wxTreeItemId item = currentTreeItem;
1597 while ((item.IsOk()) && (item != tree->GetRootItem())) {
1598 current.Add(tree->GetItemText(item));
1599 item = tree->GetItemParent(item);
1602 /* Update the tree */
1603 UpdateTreeItem(tree->GetRootItem(), false, true);
1605 /* Reselect the former selected item */
1606 item = tree->GetRootItem();
1608 if (current.Count() == 0) {
1609 tree->SelectItem(item);
1615 for (int i = current.Count()-1; i >= 0; i--) {
1617 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
1621 while (currentChild.IsOk()) {
1622 if (tree->GetItemText(currentChild) == current[i]) {
1623 item = currentChild;
1628 currentChild = tree->GetNextChild(item, cookie);
1634 UpdateTreeItem(item, true, false); /* Update the list */
1636 tree->SelectItem(item);
1639 void wxbRestorePanel::RefreshList() {
1640 if (currentTreeItem.IsOk()) {
1641 UpdateTreeItem(currentTreeItem, true, false); /* Update the list */
1645 /* Update first config, adapting settings to the job name selected */
1646 void wxbRestorePanel::UpdateFirstConfig() {
1647 configPanel->Enable(false);
1648 wxbDataTokenizer* dt = wxbUtils::WaitForEnd(wxString(".defaults job=") + configPanel->GetRowString("Job Name") + "\n", true, false);
1654 * where=/tmp/bacula-restores
1657 * fileset=Full Set */
1663 bool dolistjobs = false;
1665 for (i = 0; i < dt->GetCount(); i++) {
1667 if ((j = str.Find('=')) > -1) {
1668 name = str.Mid(0, j);
1669 if (name == "pool") {
1670 configPanel->SetRowString("Pool", str.Mid(j+1));
1672 else if (name == "client") {
1674 if ((str != configPanel->GetRowString("Client")) || (configPanel->GetRowString("Before") == "")) {
1675 configPanel->SetRowString("Client", str);
1679 else if (name == "storage") {
1680 configPanel->SetRowString("Storage", str.Mid(j+1));
1682 else if (name == "fileset") {
1683 configPanel->SetRowString("Fileset", str.Mid(j+1));
1691 //wxTheApp->Yield(false);
1694 configPanel->Enable(true);
1698 * Update second config.
1701 * JobName: RestoreFiles
1702 * Bootstrap: /var/lib/bacula/restore.bsr
1703 * Where: /tmp/bacula-restores
1708 * When: 2004-04-18 01:18:56
1710 * OK to run? (yes/mod/no):
1713 bool wxbRestorePanel::UpdateSecondConfig(wxbDataTokenizer* dt) {
1715 for (i = 0; i < dt->GetCount(); i++) {
1716 if ((*dt)[i].Find("Run Restore job") == 0)
1720 if ((i + 10) > dt->GetCount()) {
1726 if ((k = (*dt)[++i].Find("JobName:")) != 0) return false;
1727 restorePanel->SetRowString("Job Name", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1728 if ((k = (*dt)[++i].Find("Bootstrap:")) != 0) return false;
1729 restorePanel->SetRowString("Bootstrap", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1730 if ((k = (*dt)[++i].Find("Where:")) != 0) return false;
1731 restorePanel->SetRowString("Where", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1733 if ((k = (*dt)[++i].Find("Replace:")) != 0) return false;
1734 wxString str = (*dt)[i].Mid(10).Trim(false).RemoveLast();
1735 if (str == "always") restorePanel->SetRowSelection("Replace", 0);
1736 else if (str == "ifnewer") restorePanel->SetRowSelection("Replace", 1);
1737 else if (str == "ifolder") restorePanel->SetRowSelection("Replace", 2);
1738 else if (str == "never") restorePanel->SetRowSelection("Replace", 3);
1739 else restorePanel->SetRowSelection("Replace", 0);
1741 if ((k = (*dt)[++i].Find("FileSet:")) != 0) return false;
1742 restorePanel->SetRowString("Fileset", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1743 if ((k = (*dt)[++i].Find("Client:")) != 0) return false;
1744 restorePanel->SetRowString("Client", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1745 if ((k = (*dt)[++i].Find("Storage:")) != 0) return false;
1746 restorePanel->SetRowString("Storage", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1747 if ((k = (*dt)[++i].Find("When:")) != 0) return false;
1748 restorePanel->SetRowString("When", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1749 if ((k = (*dt)[++i].Find("Priority:")) != 0) return false;
1750 restorePanel->SetRowString("Priority", (*dt)[i].Mid(10).Trim(false).RemoveLast());
1753 restorePanel->Layout();
1758 /*----------------------------------------------------------------------------
1760 ----------------------------------------------------------------------------*/
1762 /* Set current status by enabling/disabling components */
1763 void wxbRestorePanel::SetStatus(status_enum newstatus) {
1764 switch (newstatus) {
1766 centerSizer->Remove(configPanel);
1767 centerSizer->Remove(restorePanel);
1768 centerSizer->Remove(treelistPanel);
1769 treelistPanel->Show(false);
1770 restorePanel->Show(false);
1771 centerSizer->Add(configPanel, 1, wxEXPAND);
1772 configPanel->Show(true);
1773 configPanel->Layout();
1774 centerSizer->Layout();
1776 start->SetLabel("Enter restore mode");
1777 start->Enable(false);
1778 configPanel->Enable(false);
1779 tree->Enable(false);
1780 list->Enable(false);
1781 gauge->Enable(false);
1782 cancel->Enable(false);
1787 centerSizer->Remove(configPanel);
1788 centerSizer->Remove(restorePanel);
1789 centerSizer->Remove(treelistPanel);
1790 treelistPanel->Show(false);
1791 restorePanel->Show(false);
1792 centerSizer->Add(configPanel, 1, wxEXPAND);
1793 configPanel->Show(true);
1794 configPanel->Layout();
1795 centerSizer->Layout();
1797 tree->DeleteAllItems();
1798 list->DeleteAllItems();
1799 configPanel->ClearRowChoices("Client");
1800 configPanel->ClearRowChoices("Before");
1801 wxbMainFrame::GetInstance()->EnablePanels();
1802 newstatus = activable;
1805 start->SetLabel("Enter restore mode");
1806 start->Enable(true);
1807 configPanel->Enable(false);
1808 tree->Enable(false);
1809 list->Enable(false);
1810 gauge->Enable(false);
1811 cancel->Enable(false);
1815 wxbMainFrame::GetInstance()->DisablePanels(this);
1817 start->Enable(false);
1818 //start->SetLabel("Choose files to restore");
1819 configPanel->Enable(true);
1820 tree->Enable(false);
1821 list->Enable(false);
1822 cancel->Enable(true);
1829 start->Enable(true);
1830 start->SetLabel("Restore");
1831 centerSizer->Remove(configPanel);
1832 configPanel->Show(false);
1833 centerSizer->Add(treelistPanel, 1, wxEXPAND);
1834 treelistPanel->Show(true);
1835 treelistPanel->Layout();
1836 centerSizer->Layout();
1843 start->Enable(false);
1844 configPanel->Enable(false);
1845 tree->Enable(false);
1846 list->Enable(false);
1847 centerSizer->Remove(treelistPanel);
1848 treelistPanel->Show(false);
1849 centerSizer->Add(restorePanel, 1, wxEXPAND);
1850 restorePanel->Show(true);
1851 restorePanel->Layout();
1852 centerSizer->Layout();
1854 restorePanel->EnableApply(false);
1857 start->SetLabel("Restoring...");
1858 gauge->Enable(true);
1860 start->Enable(false);
1861 configPanel->Enable(false);
1862 tree->Enable(false);
1863 list->Enable(false);
1870 /*----------------------------------------------------------------------------
1872 ----------------------------------------------------------------------------*/
1874 void wxbRestorePanel::SetWorking(bool working) {
1875 this->working = working;
1877 SetCursor(*wxHOURGLASS_CURSOR);
1878 // SetEvtHandlerEnabled(false); //EVTQUEUE
1880 // else if (!processing) { /* Empty event queue if we aren't already doing this */ //EVTQUEUE
1882 // processing = true; //EVTQUEUE
1883 SetCursor(*wxSTANDARD_CURSOR);
1884 // SetEvtHandlerEnabled(true); //EVTQUEUE
1885 /* wxNode *node = pendingEvents->First(); //EVTQUEUE
1887 wxEvent *event = (wxEvent *)node->Data();
1890 wxEvtHandler::ProcessEvent(*event);
1893 node = pendingEvents->First();
1895 processing = false;*/
1899 bool wxbRestorePanel::IsWorking() {
1900 return this->working;
1903 void wxbRestorePanel::EnableConfig(bool enable) {
1904 restorePanel->Enable(enable);
1907 /*----------------------------------------------------------------------------
1909 ----------------------------------------------------------------------------*/
1914 bool wxbRestorePanel::ProcessEvent(wxEvent& event) {
1915 if (IsWorking() || processing) {
1916 wxEvent *eventCopy = event.Clone();
1918 pendingEvents->Append(eventCopy);
1922 return wxEvtHandler::ProcessEvent(event);
1927 void wxbRestorePanel::OnCancel(wxCommandEvent& event) {
1928 cancel->Enable(false);
1929 SetCursor(*wxHOURGLASS_CURSOR);
1931 SetCursor(*wxSTANDARD_CURSOR);
1934 void wxbRestorePanel::OnStart(wxCommandEvent& event) {
1936 AddPendingEvent(event);
1944 void wxbRestorePanel::OnTreeChanging(wxTreeEvent& event) {
1946 AddPendingEvent(event);
1951 void wxbRestorePanel::OnTreeExpanding(wxTreeEvent& event) {
1953 AddPendingEvent(event);
1958 //CmdList(event.GetItem());
1959 if (tree->GetSelection() != event.GetItem()) {
1960 tree->SelectItem(event.GetItem());
1965 void wxbRestorePanel::OnTreeChanged(wxTreeEvent& event) {
1967 AddPendingEvent(event);
1970 if (currentTreeItem == event.GetItem()) {
1973 treeadd->Enable(false);
1974 treeremove->Enable(false);
1975 treerefresh->Enable(false);
1976 markWhenListingDone = false;
1978 currentTreeItem = event.GetItem();
1979 CmdList(event.GetItem());
1980 if (markWhenListingDone) {
1981 CmdMark(event.GetItem(), NULL, 0);
1985 if (event.GetItem().IsOk()) {
1986 int status = ((wxbTreeItemData*)tree->GetItemData(event.GetItem()))->GetMarked();
1987 treeadd->Enable(status != 1);
1988 treeremove->Enable(status != 0);
1990 treerefresh->Enable(true);
1993 void wxbRestorePanel::OnTreeMarked(wxbTreeMarkedEvent& event) {
1994 csprint("Tree marked", CS_DEBUG);
1996 if (tree->GetSelection() == event.GetItem()) {
1997 markWhenListingDone = !markWhenListingDone;
1999 AddPendingEvent(event);
2003 CmdMark(event.GetItem(), NULL, 0);
2007 if (event.GetItem().IsOk()) {
2008 int status = ((wxbTreeItemData*)tree->GetItemData(event.GetItem()))->GetMarked();
2009 treeadd->Enable(status != 1);
2010 treeremove->Enable(status != 0);
2014 void wxbRestorePanel::OnTreeAdd(wxCommandEvent& event) {
2016 AddPendingEvent(event);
2020 if (currentTreeItem.IsOk()) {
2022 CmdMark(currentTreeItem, NULL, 0, 1);
2025 treeremove->Enable(1);
2030 void wxbRestorePanel::OnTreeRemove(wxCommandEvent& event) {
2032 AddPendingEvent(event);
2036 if (currentTreeItem.IsOk()) {
2038 CmdMark(currentTreeItem, NULL, 0, 0);
2041 treeremove->Enable(0);
2046 void wxbRestorePanel::OnTreeRefresh(wxCommandEvent& event) {
2048 AddPendingEvent(event);
2057 void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
2059 AddPendingEvent(event);
2064 if (list->GetSelectedItemCount() == 0) {
2070 long* items = new long[list->GetSelectedItemCount()];
2074 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2075 while (item != -1) {
2078 item = list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2081 CmdMark(wxTreeItemId(), items, num);
2085 wxListEvent listevt;
2087 OnListChanged(listevt);
2094 void wxbRestorePanel::OnListActivated(wxListEvent& event) {
2096 AddPendingEvent(event);
2101 long item = event.GetIndex();
2102 // long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
2104 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(item);
2105 wxString name = itemdata->GetName();
2112 if (name.GetChar(name.Length()-1) == '/') {
2113 wxTreeItemId currentChild = tree->GetFirstChild(currentTreeItem, cookie);
2115 while (currentChild.IsOk()) {
2116 wxString name2 = tree->GetItemText(currentChild);
2117 if (name2 == name) {
2118 //tree->UnselectAll();
2120 tree->Expand(currentTreeItem);
2121 tree->SelectItem(currentChild);
2125 currentChild = tree->GetNextChild(currentTreeItem, cookie);
2132 void wxbRestorePanel::OnListChanged(wxListEvent& event) {
2134 AddPendingEvent(event);
2138 listadd->Enable(false);
2139 listremove->Enable(false);
2141 bool marked = false;
2142 bool unmarked = false;
2144 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2145 while (item != -1) {
2146 switch (((wxbTreeItemData*)list->GetItemData(item))->GetMarked()) {
2159 // Should never happen
2161 if (marked && unmarked) break;
2162 item = list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2165 listadd->Enable(unmarked);
2166 listremove->Enable(marked);
2169 void wxbRestorePanel::OnListAdd(wxCommandEvent& event) {
2171 AddPendingEvent(event);
2177 long* items = new long[list->GetSelectedItemCount()];
2181 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2182 while (item != -1) {
2185 item = list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2188 CmdMark(wxTreeItemId(), items, num, 1);
2195 listadd->Enable(false);
2196 listremove->Enable(true);
2199 void wxbRestorePanel::OnListRemove(wxCommandEvent& event) {
2201 AddPendingEvent(event);
2207 long* items = new long[list->GetSelectedItemCount()];
2211 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2212 while (item != -1) {
2215 item = list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2218 CmdMark(wxTreeItemId(), items, num, 0);
2225 listadd->Enable(true);
2226 listremove->Enable(false);
2229 void wxbRestorePanel::OnListRefresh(wxCommandEvent& event) {
2231 AddPendingEvent(event);
2240 void wxbRestorePanel::OnConfigUpdated(wxCommandEvent& event) {
2241 if (status == entered) {
2242 if (event.GetId() == ConfigJobName) {
2247 UpdateFirstConfig();
2250 else if (event.GetId() == ConfigClient) {
2255 configPanel->Enable(false);
2257 configPanel->Enable(true);
2260 cfgUpdated = cfgUpdated | (1 << event.GetId());
2262 else if (status == configuring) {
2263 restorePanel->EnableApply(true);
2264 cfgUpdated = cfgUpdated | (1 << event.GetId());
2268 void wxbRestorePanel::OnConfigOk(wxCommandEvent& WXUNUSED(event)) {
2269 if (status != configuring) return;
2278 void wxbRestorePanel::OnConfigApply(wxCommandEvent& WXUNUSED(event)) {
2279 if (status != configuring) return;
2285 if (cfgUpdated == 0) {
2286 restorePanel->EnableApply(false);
2291 void wxbRestorePanel::OnConfigCancel(wxCommandEvent& WXUNUSED(event)) {
2292 if (status != configuring) return;