2 Copyright (C) 2004 Kern Sibbald and John Walker
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "wxbrestorepanel.h"
21 #include "wxbmainframe.h"
25 #include <wx/choice.h>
26 #include <wx/datetime.h>
28 #include "unmarked.xpm"
30 #include "partmarked.xpm"
33 * Class which is stored in the tree and in the list to keep informations
36 class wxbTreeItemData : public wxTreeItemData {
38 wxbTreeItemData(wxString path, wxString name, int marked, long listid = -1);
39 wxbTreeItemData(wxString path, wxString name, wxString marked, long listid = -1);
45 void SetMarked(int marked);
46 void SetMarked(wxString marked);
50 static int GetMarkedStatus(wxString file);
52 wxString* path; /* Full path */
53 wxString* name; /* File name */
54 int marked; /* 0 - Not Marked, 1 - Marked, 2 - Some file under is marked */
55 long listid; /* list ID : >-1 if this data is in the list (and/or on the tree) */
58 wxbTreeItemData::wxbTreeItemData(wxString path, wxString name, int marked, long listid): wxTreeItemData() {
59 this->path = new wxString(path);
60 this->name = new wxString(name);
61 this->marked = marked;
62 this->listid = listid;
65 wxbTreeItemData::wxbTreeItemData(wxString path, wxString name, wxString marked, long listid): wxTreeItemData() {
66 this->path = new wxString(path);
67 this->name = new wxString(name);
69 this->listid = listid;
72 wxbTreeItemData::~wxbTreeItemData() {
77 int wxbTreeItemData::GetMarked() {
81 void wxbTreeItemData::SetMarked(wxString marked) {
85 else if (marked == "+") {
93 void wxbTreeItemData::SetMarked(int marked) {
94 this->marked = marked;
97 long wxbTreeItemData::GetListId() {
101 wxString wxbTreeItemData::GetPath() {
105 wxString wxbTreeItemData::GetName() {
109 /*wxbTreeItemData* wxbTreeItemData::GetChild(wxString dirname) {
110 int marked = GetMarkedStatus(dirname);
111 return new wxbTreeItemData(path + (marked ? dirname.Mid(1) : dirname), marked);
114 int wxbTreeItemData::GetMarkedStatus(wxString file) {
115 if (file.Length() == 0)
118 switch (file.GetChar(0)) {
128 // ----------------------------------------------------------------------------
129 // event tables and other macros for wxWindows
130 // ----------------------------------------------------------------------------
140 BEGIN_EVENT_TABLE(wxbRestorePanel, wxPanel)
141 EVT_BUTTON(RestoreStart, wxbRestorePanel::OnStart)
142 EVT_TREE_SEL_CHANGING(TreeCtrl, wxbRestorePanel::OnTreeChanging)
143 EVT_TREE_SEL_CHANGED(TreeCtrl, wxbRestorePanel::OnTreeChanged)
144 EVT_TREE_ITEM_EXPANDING(TreeCtrl, wxbRestorePanel::OnTreeExpanding)
145 EVT_LIST_ITEM_ACTIVATED(ListCtrl, wxbRestorePanel::OnListActivated)
147 EVT_TREE_MARKED_EVENT(wxID_ANY, wxbRestorePanel::OnTreeMarked)
148 EVT_LIST_MARKED_EVENT(wxID_ANY, wxbRestorePanel::OnListMarked)
150 EVT_CHOICE(ClientChoice, wxbRestorePanel::OnClientChoiceChanged)
154 * wxbRestorePanel constructor
156 wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
157 imagelist = new wxImageList(16, 16, TRUE, 3);
158 imagelist->Add(wxIcon(unmarked_xpm));
159 imagelist->Add(wxIcon(marked_xpm));
160 imagelist->Add(wxIcon(partmarked_xpm));
162 wxFlexGridSizer *sizer = new wxFlexGridSizer(3, 1, 10, 10);
163 sizer->AddGrowableCol(0);
164 sizer->AddGrowableRow(1);
166 wxBoxSizer *firstSizer = new wxBoxSizer(wxHORIZONTAL);
168 start = new wxButton(this, RestoreStart, "Enter restore mode", wxDefaultPosition, wxSize(150, 30));
169 firstSizer->Add(start, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
171 wxString* elist = new wxString[1];
173 clientChoice = new wxChoice(this, ClientChoice, wxDefaultPosition, wxSize(150, 30), 0, elist);
174 firstSizer->Add(clientChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
176 jobChoice = new wxChoice(this, -1, wxDefaultPosition, wxSize(150, 30), 0, elist);
177 firstSizer->Add(jobChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
179 sizer->Add(firstSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
181 wxFlexGridSizer *secondSizer = new wxFlexGridSizer(1, 2, 10, 10);
183 tree = new wxbTreeCtrl(this, TreeCtrl, wxDefaultPosition, wxSize(200,50));
184 secondSizer->Add(tree, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 10);
186 tree->SetImageList(imagelist);
188 list = new wxbListCtrl(this, ListCtrl, wxDefaultPosition, wxDefaultSize);
189 secondSizer->Add(list, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 10);
191 list->SetImageList(imagelist, wxIMAGE_LIST_SMALL);
194 info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT);
196 info.SetAlign(wxLIST_FORMAT_CENTER);
197 list->InsertColumn(0, info);
199 info.SetText("Filename");
200 info.SetAlign(wxLIST_FORMAT_LEFT);
201 list->InsertColumn(1, info);
203 info.SetText("Size");
204 info.SetAlign(wxLIST_FORMAT_RIGHT);
205 list->InsertColumn(2, info);
207 info.SetText("Date");
208 info.SetAlign(wxLIST_FORMAT_LEFT);
209 list->InsertColumn(3, info);
211 info.SetText("Perm.");
212 info.SetAlign(wxLIST_FORMAT_LEFT);
213 list->InsertColumn(4, info);
215 info.SetText("User");
216 info.SetAlign(wxLIST_FORMAT_RIGHT);
217 list->InsertColumn(5, info);
219 info.SetText("Group");
220 info.SetAlign(wxLIST_FORMAT_RIGHT);
221 list->InsertColumn(6, info);
223 secondSizer->AddGrowableCol(1);
224 secondSizer->AddGrowableRow(0);
226 sizer->Add(secondSizer, 1, wxEXPAND, 10);
228 gauge = new wxGauge(this, -1, 1, wxDefaultPosition, wxSize(200,20));
230 sizer->Add(gauge, 1, wxEXPAND, 5);
232 gauge->Enable(false);
235 sizer->SetSizeHints(this);
241 jobChoice->Enable(false);
247 * wxbRestorePanel destructor
249 wxbRestorePanel::~wxbRestorePanel() {
253 /*----------------------------------------------------------------------------
254 wxbPanel overloadings
255 ----------------------------------------------------------------------------*/
257 wxString wxbRestorePanel::GetTitle() {
261 void wxbRestorePanel::Print(wxString str, int stat) {
265 else if (status == listing) {
266 if (str.Find("cwd is:") == 0) { // Sometimes cd command result "infiltrate" into listings.
272 wxString* file = ParseList(str);
279 if (file[8].GetChar(file[8].Length()-1) == '/') {
283 treeid = tree->GetFirstChild(currentTreeItem, cookie);
285 bool updated = false;
287 while (treeid.IsOk()) {
288 itemStr = tree->GetItemText(treeid);
289 if (file[8] == itemStr) {
290 int stat = wxbTreeItemData::GetMarkedStatus(file[6]);
291 if (static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->GetMarked() != stat) {
292 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Normal);
293 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Selected);
294 static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->SetMarked(file[6]);
299 treeid = tree->GetNextChild(currentTreeItem, cookie);
303 int img = wxbTreeItemData::GetMarkedStatus(file[6]);
304 treeid = tree->AppendItem(currentTreeItem, file[8], img, img, new wxbTreeItemData(file[7], file[8], file[6]));
309 long ind = list->InsertItem(list->GetItemCount(), wxbTreeItemData::GetMarkedStatus(file[6]));
310 wxbTreeItemData* data = new wxbTreeItemData(file[7], file[8], file[6], ind);
312 list->SetItemData(ind, (long)data);
313 list->SetItem(ind, 1, file[8]); // filename
314 list->SetItem(ind, 2, file[4]); //Size
315 list->SetItem(ind, 3, file[5]); //date
316 list->SetItem(ind, 4, file[0]); //perm
317 list->SetItem(ind, 5, file[2]); //user
318 list->SetItem(ind, 6, file[3]); //grp
324 if (status == restoring) {
326 //15847 total files; 1 marked to be restored; 1,034 bytes.
327 if ((i = str.Find(" marked to be restored;")) > -1) {
328 int j = str.Find("; ");
329 str.Mid(j+2, i).ToLong(&totfilemessages);
330 //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
334 if ((i = str.Find(" files selected to be restored.")) > -1) {
335 str.Mid(0, i).ToLong(&totfilemessages);
336 //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
340 if ((i = str.Find(" file selected to be restored.")) > -1) {
341 str.Mid(0, i).ToLong(&totfilemessages);
342 //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
346 wxStringTokenizer tkz(str, " ", wxTOKEN_STRTOK);
350 // Date Time name: perm ? user grp size date time
351 //04-Apr-2004 17:19 Tom-fd: -rwx------ 1 nicolas None 514967 2004-03-20 20:03:42 filename
353 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { // Date
354 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { // Time
355 if (tkz.GetNextToken().Last() == ':') { // name:
356 tkz.GetNextToken(); // perm
357 tkz.GetNextToken(); // ?
358 tkz.GetNextToken(); // user
359 tkz.GetNextToken(); // grp
360 tkz.GetNextToken(); // size
361 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { //date
362 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { //time
364 //wxbMainFrame::GetInstance()->Print(wxString("(") << filemessages << ")", CS_DEBUG);
365 gauge->SetValue(filemessages);
373 if (tableParser != NULL) {
374 tableParser->Print(str, stat);
376 if (stat == CS_END) {
382 /*----------------------------------------------------------------------------
383 Commands called by events handler
384 ----------------------------------------------------------------------------*/
386 /* The main button has been clicked */
387 void wxbRestorePanel::CmdStart() {
388 if (status == disabled) {
389 CreateAndWaitForParser("list clients\n");
391 clientChoice->Clear();
392 for (unsigned int i = 0; i < tableParser->size(); i++) {
393 /*for (unsigned int k = 0; k < (*tableParser)[i].size(); k++) {
394 wxbMainFrame::GetInstance()->Print(wxString() << (*tableParser)[i][k] << ":", CS_DEBUG);
396 wxbMainFrame::GetInstance()->Print(wxString(";\n"), CS_DEBUG);*/
398 (*tableParser)[i][0].ToLong(j);
399 clientChoice->Append((*tableParser)[i][1], (void*)j);
404 else if (status == entered) {
405 if (jobChoice->GetStringSelection().Length() < 1) {
406 wxbMainFrame::GetInstance()->SetStatusText("Please select a client.");
409 WaitForEnd("restore\n");
411 WaitForEnd(wxString() << jobChoice->GetStringSelection() << "\n");
412 WaitForEnd(wxString() << *((long*)clientChoice->GetClientData(clientChoice->GetSelection())) << "\n");
413 WaitForEnd("unmark *\n");
415 wxTreeItemId root = tree->AddRoot(clientChoice->GetStringSelection(), -1, -1, new wxbTreeItemData("/", clientChoice->GetStringSelection(), 0));
417 WaitForList(root, true);
418 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.");
421 else if (status == choosing) {
422 setStatus(restoring);
424 wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
427 WaitForEnd("estimate\n");
428 WaitForEnd("done\n");
430 if (totfilemessages == 0) {
431 wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
432 wxbMainFrame::GetInstance()->SetStatusText("Restore failed : no file selected.");
440 gauge->SetRange(totfilemessages);
442 wxString cmd = "list jobid=";
444 CreateAndWaitForParser("list jobs\n");
445 /* TODO (#1#): Check more carefully which job we just have run. */
446 cmd << (*tableParser)[tableParser->size()-1][0] << "\n";
451 CreateAndWaitForParser(cmd);
452 if ((*tableParser)[0][7] != "C") {
456 WaitForEnd("messages\n");
458 wxbMainFrame::GetInstance()->SetStatusText(wxString("Restoring, please wait (") << filemessages << " of " << totfilemessages << " files done)...");
460 time_t start = wxDateTime::Now().GetTicks();
461 while (((wxDateTime::Now().GetTicks())-start) < 3) {
466 WaitForEnd("messages\n");
468 gauge->SetValue(totfilemessages);
470 if ((*tableParser)[0][7] == "T") {
471 wxbMainFrame::GetInstance()->Print("Restore done successfully.\n", CS_DEBUG);
472 wxbMainFrame::GetInstance()->SetStatusText("Restore done successfully.");
475 wxbMainFrame::GetInstance()->Print("Restore failed, please look at messages.\n", CS_DEBUG);
476 wxbMainFrame::GetInstance()->SetStatusText("Restore failed, please look at messages in console.");
482 /* List jobs for a specified client */
483 void wxbRestorePanel::CmdListJobs() {
484 if (status == entered) {
486 WaitForEnd("query\n");
488 CreateAndWaitForParser(clientChoice->GetString(clientChoice->GetSelection()) + "\n");
490 for (int i = tableParser->size()-1; i > -1; i--) {
491 wxString str = (*tableParser)[i][3];
494 if ( ( (chr = datetime.ParseDate(str.GetData()) ) != NULL ) && ( datetime.ParseTime(++chr) != NULL ) ) {
495 datetime = datetime.GetTicks() + 1;
496 //wxbMainFrame::GetInstance()->Print(wxString("-") << datetime.Format("%Y-%m-%d %H:%M:%S"), CS_DEBUG);
497 jobChoice->Append(datetime.Format("%Y-%m-%d %H:%M:%S"));
500 jobChoice->Append("Invalid");
504 jobChoice->SetSelection(0);
508 /* List files and directories for a specified tree item */
509 void wxbRestorePanel::CmdList(wxTreeItemId item) {
510 if (status == choosing) {
511 list->DeleteAllItems();
516 WaitForList(item, (tree->GetSelection() == item));
518 if (list->GetItemCount() > 1) {
519 int firstwidth = list->GetSize().GetWidth();
520 for (int i = 2; i < 7; i++) {
521 list->SetColumnWidth(i, wxLIST_AUTOSIZE);
522 firstwidth -= list->GetColumnWidth(i);
525 list->SetColumnWidth(0, 18);
527 list->SetColumnWidth(1, wxLIST_AUTOSIZE);
528 if (list->GetColumnWidth(1) < firstwidth) {
529 list->SetColumnWidth(1, firstwidth-20);
535 /* Mark a treeitem (directory) or a listitem (file or directory) */
536 void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long listitem) {
537 if (status == choosing) {
538 wxbTreeItemData* itemdata = NULL;
539 if (listitem != -1) {
540 itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
542 else if (treeitem.IsOk()) {
543 itemdata = (wxbTreeItemData*)tree->GetItemData(treeitem);
549 if (itemdata == NULL) //Should never happen
552 wxString dir = itemdata->GetPath();
556 if (dir.GetChar(dir.Length()-1) == '/') {
560 int i = dir.Find('/', TRUE);
565 else { /* first dir below root */
567 dir = dir.Mid(0, i+1);
575 WaitForEnd(wxString("cd ") << dir << "\n");
576 WaitForEnd(wxString((itemdata->GetMarked() == 1) ? "unmark " : "mark ") << file << "\n");
578 /*if ((dir == "/") && (file == "*")) {
579 itemdata->SetMarked((itemdata->GetMarked() == 1) ? 0 : 1);
582 if (listitem == -1) { /* tree item state changed */
583 SetTreeItemState(treeitem, (itemdata->GetMarked() == 1) ? 0 : 1);
584 /*treeitem = tree->GetSelection();
585 UpdateTree(treeitem, true);
586 treeitem = tree->GetItemParent(treeitem);*/
589 SetListItemState(listitem, (itemdata->GetMarked() == 1) ? 0 : 1);
590 /*UpdateTree(treeitem, (tree->GetSelection() == treeitem));
591 treeitem = tree->GetItemParent(treeitem);*/
594 /*while (treeitem.IsOk()) {
595 WaitForList(treeitem, false);
596 treeitem = tree->GetItemParent(treeitem);
601 /*----------------------------------------------------------------------------
603 ----------------------------------------------------------------------------*/
605 /* Parse a table in tableParser */
606 void wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
607 if (tableParser != NULL) {
610 tableParser = new wxbTableParser();
612 wxbMainFrame::GetInstance()->Send(cmd);
614 //time_t base = wxDateTime::Now().GetTicks();
615 while (!tableParser->hasFinished()) {
616 //innerThread->Yield();
618 //if (base+15 < wxDateTime::Now().GetTicks()) break;
622 /* Run a command, and waits until result is fully received. */
623 void wxbRestorePanel::WaitForEnd(wxString cmd) {
624 wxbMainFrame::GetInstance()->Send(cmd);
628 //time_t base = wxDateTime::Now().GetTicks();
630 //innerThread->Yield();
632 //if (base+15 < wxDateTime::Now().GetTicks()) break;
636 /* Run a dir command, and waits until result is fully received. */
637 void wxbRestorePanel::WaitForList(wxTreeItemId item, bool updatelist) {
638 this->updatelist = updatelist;
639 currentTreeItem = item;
641 WaitForEnd(wxString("cd \"") << static_cast<wxbTreeItemData*>(tree->GetItemData(currentTreeItem))->GetPath() << "\"\n");
646 list->DeleteAllItems();
653 /* Parse dir command results. */
654 wxString* wxbRestorePanel::ParseList(wxString line) {
655 //drwx------ 11 1003 42949672 0 2001-07-30 16:45:14 *filename
656 //+ 10 ++ 4++ 10 ++ 8 ++ 8 + + 19 + *+ ->
657 //0 10 14 24 32 42 62
659 if (line.Length() < 63)
662 wxString* ret = new wxString[9];
664 ret[0] = line.Mid(0, 10).Trim();
665 ret[1] = line.Mid(10, 4).Trim();
666 ret[2] = line.Mid(14, 10).Trim();
667 ret[3] = line.Mid(24, 8).Trim();
668 ret[4] = line.Mid(32, 8).Trim();
669 ret[5] = line.Mid(42, 19).Trim();
670 ret[6] = line.Mid(62, 1);
671 ret[7] = line.Mid(63).Trim();
673 if (ret[6] == " ") ret[6] = "";
675 if (ret[7].GetChar(ret[7].Length()-1) == '/') {
678 ret[8] = ret[7].Mid(ret[8].Find('/', true)+1);
681 ret[8] = ret[7].Mid(ret[7].Find('/', true)+1);
687 /* Sets a list item state, and update its parents and children if it is a directory */
688 void wxbRestorePanel::SetListItemState(long listitem, int newstate) {
689 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
691 wxTreeItemId treeitem;
693 itemdata->SetMarked(newstate);
694 list->SetItemImage(listitem, newstate, 0); /* TODO: Find what these ints are for */
695 list->SetItemImage(listitem, newstate, 1);
697 if ((treeitem = itemdata->GetId()).IsOk()) {
698 SetTreeItemState(treeitem, newstate);
701 UpdateTreeItemState(tree->GetSelection());
705 /* Sets a tree item state, and update its children, parents and list (if necessary) */
706 void wxbRestorePanel::SetTreeItemState(wxTreeItemId item, int newstate) {
708 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
710 bool onechildmarked = false;
711 bool onechildunmarked = false;
713 wxbTreeItemData* itemdata;
715 while (currentChild.IsOk()) {
716 itemdata = (wxbTreeItemData*)tree->GetItemData(currentChild);
717 int state = itemdata->GetMarked();
719 if (state != newstate) {
720 itemdata->SetMarked(newstate);
721 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Normal);
722 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Selected);
725 currentChild = tree->GetNextChild(item, cookie);
728 itemdata = (wxbTreeItemData*)tree->GetItemData(item);
729 itemdata->SetMarked(newstate);
730 tree->SetItemImage(item, newstate, wxTreeItemIcon_Normal);
731 tree->SetItemImage(item, newstate, wxTreeItemIcon_Selected);
734 if (tree->GetSelection() == item) {
735 for (long i = 0; i < list->GetItemCount(); i++) {
736 list->SetItemImage(i, newstate, 0); /* TODO: Find what these ints are for */
737 list->SetItemImage(i, newstate, 1);
741 UpdateTreeItemState(tree->GetParent(item));
744 /* Update a tree item state, and its parents' state */
745 void wxbRestorePanel::UpdateTreeItemState(wxTreeItemId item) {
753 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
755 bool onechildmarked = false;
756 bool onechildunmarked = false;
758 while (currentChild.IsOk()) {
759 state = ((wxbTreeItemData*)tree->GetItemData(currentChild))->GetMarked();
762 onechildunmarked = true;
765 onechildmarked = true;
768 onechildmarked = true;
769 onechildunmarked = true;
773 if (onechildmarked && onechildunmarked) {
777 currentChild = tree->GetNextChild(item, cookie);
780 if (tree->GetSelection() == item) {
781 for (long i = 0; i < list->GetItemCount(); i++) {
782 state = ((wxbTreeItemData*)list->GetItemData(i))->GetMarked();
786 onechildunmarked = true;
789 onechildmarked = true;
792 onechildmarked = true;
793 onechildunmarked = true;
797 if (onechildmarked && onechildunmarked) {
805 if (onechildmarked && onechildunmarked) {
808 else if (onechildmarked) {
811 else if (onechildunmarked) {
814 else { // no child, don't change anything
815 UpdateTreeItemState(tree->GetParent(item));
819 wxbTreeItemData* itemdata = (wxbTreeItemData*)tree->GetItemData(item);
821 itemdata->SetMarked(state);
822 tree->SetItemImage(item, state, wxTreeItemIcon_Normal);
823 tree->SetItemImage(item, state, wxTreeItemIcon_Selected);
825 UpdateTreeItemState(tree->GetParent(item));
829 * Refresh a tree item, and all its childs,
830 * by asking the director for new lists
832 void wxbRestorePanel::RefreshTree(wxTreeItemId item) {
833 /* WaitForList(item, updatelist);
835 /* Update all child which are not collapsed */
837 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
839 while (currentChild.IsOk()) {
840 if (tree->IsExpanded(currentChild))
841 UpdateTree(currentChild, false);
843 currentChild = tree->GetNextChild(item, cookie);
847 /*----------------------------------------------------------------------------
849 ----------------------------------------------------------------------------*/
851 /* Set current status by enabling/disabling components */
852 void wxbRestorePanel::setStatus(status_enum newstatus) {
855 tree->DeleteAllItems();
856 list->DeleteAllItems();
857 clientChoice->Clear();
859 newstatus = disabled;
861 start->SetLabel("Enter restore mode");
863 clientChoice->Enable(false);
864 jobChoice->Enable(false);
867 gauge->Enable(false);
871 start->SetLabel("Choose files to restore");
872 clientChoice->Enable(true);
873 jobChoice->Enable(true);
881 start->SetLabel("Restore");
882 clientChoice->Enable(false);
883 jobChoice->Enable(false);
889 start->SetLabel("Restoring...");
892 start->Enable(false);
893 clientChoice->Enable(false);
894 jobChoice->Enable(false);
903 /*----------------------------------------------------------------------------
905 ----------------------------------------------------------------------------*/
907 void wxbRestorePanel::OnClientChoiceChanged(wxCommandEvent& event) {
912 clientChoice->Enable(false);
914 clientChoice->Enable(true);
915 jobChoice->Refresh();
919 void wxbRestorePanel::OnStart(wxEvent& WXUNUSED(event)) {
928 void wxbRestorePanel::OnTreeChanging(wxTreeEvent& event) {
934 void wxbRestorePanel::OnTreeExpanding(wxTreeEvent& event) {
940 //CmdList(event.GetItem());
941 tree->SelectItem(event.GetItem());
945 void wxbRestorePanel::OnTreeChanged(wxTreeEvent& event) {
950 CmdList(event.GetItem());
954 void wxbRestorePanel::OnTreeMarked(wxbTreeMarkedEvent& event) {
955 //wxbMainFrame::GetInstance()->Print(wxString("MARKED\n"), CS_DEBUG);
961 CmdMark(event.GetItem(), -1);
967 void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
973 //long item = event.GetId();
974 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
975 CmdMark(wxTreeItemId(), item);
981 void wxbRestorePanel::OnListActivated(wxListEvent& event) {
987 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
989 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(item);
990 wxString name = itemdata->GetName();
997 if (name.GetChar(name.Length()-1) == '/') {
998 wxTreeItemId currentChild = tree->GetFirstChild(currentTreeItem, cookie);
1000 while (currentChild.IsOk()) {
1001 wxString name2 = tree->GetItemText(currentChild);
1002 if (name2 == name) {
1004 tree->UnselectAll();
1005 tree->Expand(currentTreeItem);
1006 tree->SelectItem(currentChild);
1010 currentChild = tree->GetNextChild(currentTreeItem, cookie);