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"
32 /* A macro named Yield is defined under MinGW */
36 * Class which is stored in the tree and in the list to keep informations
39 class wxbTreeItemData : public wxTreeItemData {
41 wxbTreeItemData(wxString path, wxString name, int marked, long listid = -1);
42 wxbTreeItemData(wxString path, wxString name, wxString marked, long listid = -1);
48 void SetMarked(int marked);
49 void SetMarked(wxString marked);
53 static int GetMarkedStatus(wxString file);
55 wxString* path; /* Full path */
56 wxString* name; /* File name */
57 int marked; /* 0 - Not Marked, 1 - Marked, 2 - Some file under is marked */
58 long listid; /* list ID : >-1 if this data is in the list (and/or on the tree) */
61 wxbTreeItemData::wxbTreeItemData(wxString path, wxString name, int marked, long listid): wxTreeItemData() {
62 this->path = new wxString(path);
63 this->name = new wxString(name);
64 this->marked = marked;
65 this->listid = listid;
68 wxbTreeItemData::wxbTreeItemData(wxString path, wxString name, wxString marked, long listid): wxTreeItemData() {
69 this->path = new wxString(path);
70 this->name = new wxString(name);
72 this->listid = listid;
75 wxbTreeItemData::~wxbTreeItemData() {
80 int wxbTreeItemData::GetMarked() {
84 void wxbTreeItemData::SetMarked(wxString marked) {
88 else if (marked == "+") {
96 void wxbTreeItemData::SetMarked(int marked) {
97 this->marked = marked;
100 long wxbTreeItemData::GetListId() {
104 wxString wxbTreeItemData::GetPath() {
108 wxString wxbTreeItemData::GetName() {
112 /*wxbTreeItemData* wxbTreeItemData::GetChild(wxString dirname) {
113 int marked = GetMarkedStatus(dirname);
114 return new wxbTreeItemData(path + (marked ? dirname.Mid(1) : dirname), marked);
117 int wxbTreeItemData::GetMarkedStatus(wxString file) {
118 if (file.Length() == 0)
121 switch (file.GetChar(0)) {
131 // ----------------------------------------------------------------------------
132 // event tables and other macros for wxWindows
133 // ----------------------------------------------------------------------------
143 BEGIN_EVENT_TABLE(wxbRestorePanel, wxPanel)
144 EVT_BUTTON(RestoreStart, wxbRestorePanel::OnStart)
145 EVT_TREE_SEL_CHANGING(TreeCtrl, wxbRestorePanel::OnTreeChanging)
146 EVT_TREE_SEL_CHANGED(TreeCtrl, wxbRestorePanel::OnTreeChanged)
147 EVT_TREE_ITEM_EXPANDING(TreeCtrl, wxbRestorePanel::OnTreeExpanding)
148 EVT_LIST_ITEM_ACTIVATED(ListCtrl, wxbRestorePanel::OnListActivated)
150 EVT_TREE_MARKED_EVENT(wxID_ANY, wxbRestorePanel::OnTreeMarked)
151 EVT_LIST_MARKED_EVENT(wxID_ANY, wxbRestorePanel::OnListMarked)
153 EVT_CHOICE(ClientChoice, wxbRestorePanel::OnClientChoiceChanged)
157 * wxbRestorePanel constructor
159 wxbRestorePanel::wxbRestorePanel(wxWindow* parent): wxbPanel(parent) {
160 imagelist = new wxImageList(16, 16, TRUE, 3);
161 imagelist->Add(wxIcon(unmarked_xpm));
162 imagelist->Add(wxIcon(marked_xpm));
163 imagelist->Add(wxIcon(partmarked_xpm));
165 wxFlexGridSizer *sizer = new wxFlexGridSizer(3, 1, 10, 10);
166 sizer->AddGrowableCol(0);
167 sizer->AddGrowableRow(1);
169 wxBoxSizer *firstSizer = new wxBoxSizer(wxHORIZONTAL);
171 start = new wxButton(this, RestoreStart, "Enter restore mode", wxDefaultPosition, wxSize(150, 30));
172 firstSizer->Add(start, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
174 wxString* elist = new wxString[1];
176 clientChoice = new wxChoice(this, ClientChoice, wxDefaultPosition, wxSize(150, 30), 0, elist);
177 firstSizer->Add(clientChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
179 jobChoice = new wxChoice(this, -1, wxDefaultPosition, wxSize(150, 30), 0, elist);
180 firstSizer->Add(jobChoice, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
182 sizer->Add(firstSizer, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 10);
184 wxFlexGridSizer *secondSizer = new wxFlexGridSizer(1, 2, 10, 10);
186 tree = new wxbTreeCtrl(this, TreeCtrl, wxDefaultPosition, wxSize(200,50));
187 secondSizer->Add(tree, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 10);
189 tree->SetImageList(imagelist);
191 list = new wxbListCtrl(this, ListCtrl, wxDefaultPosition, wxDefaultSize);
192 secondSizer->Add(list, 1, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 10);
194 list->SetImageList(imagelist, wxIMAGE_LIST_SMALL);
197 info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT);
199 info.SetAlign(wxLIST_FORMAT_CENTER);
200 list->InsertColumn(0, info);
202 info.SetText("Filename");
203 info.SetAlign(wxLIST_FORMAT_LEFT);
204 list->InsertColumn(1, info);
206 info.SetText("Size");
207 info.SetAlign(wxLIST_FORMAT_RIGHT);
208 list->InsertColumn(2, info);
210 info.SetText("Date");
211 info.SetAlign(wxLIST_FORMAT_LEFT);
212 list->InsertColumn(3, info);
214 info.SetText("Perm.");
215 info.SetAlign(wxLIST_FORMAT_LEFT);
216 list->InsertColumn(4, info);
218 info.SetText("User");
219 info.SetAlign(wxLIST_FORMAT_RIGHT);
220 list->InsertColumn(5, info);
222 info.SetText("Group");
223 info.SetAlign(wxLIST_FORMAT_RIGHT);
224 list->InsertColumn(6, info);
226 secondSizer->AddGrowableCol(1);
227 secondSizer->AddGrowableRow(0);
229 sizer->Add(secondSizer, 1, wxEXPAND, 10);
231 gauge = new wxGauge(this, -1, 1, wxDefaultPosition, wxSize(200,20));
233 sizer->Add(gauge, 1, wxEXPAND, 5);
235 gauge->Enable(false);
238 sizer->SetSizeHints(this);
244 jobChoice->Enable(false);
250 * wxbRestorePanel destructor
252 wxbRestorePanel::~wxbRestorePanel() {
256 /*----------------------------------------------------------------------------
257 wxbPanel overloadings
258 ----------------------------------------------------------------------------*/
260 wxString wxbRestorePanel::GetTitle() {
264 void wxbRestorePanel::Print(wxString str, int stat) {
268 else if (status == listing) {
269 if (str.Find("cwd is:") == 0) { // Sometimes cd command result "infiltrate" into listings.
275 wxString* file = ParseList(str);
282 if (file[8].GetChar(file[8].Length()-1) == '/') {
286 treeid = tree->GetFirstChild(currentTreeItem, cookie);
288 bool updated = false;
290 while (treeid.IsOk()) {
291 itemStr = tree->GetItemText(treeid);
292 if (file[8] == itemStr) {
293 int stat = wxbTreeItemData::GetMarkedStatus(file[6]);
294 if (static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->GetMarked() != stat) {
295 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Normal);
296 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Selected);
297 static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->SetMarked(file[6]);
302 treeid = tree->GetNextChild(currentTreeItem, cookie);
306 int img = wxbTreeItemData::GetMarkedStatus(file[6]);
307 treeid = tree->AppendItem(currentTreeItem, file[8], img, img, new wxbTreeItemData(file[7], file[8], file[6]));
312 long ind = list->InsertItem(list->GetItemCount(), wxbTreeItemData::GetMarkedStatus(file[6]));
313 wxbTreeItemData* data = new wxbTreeItemData(file[7], file[8], file[6], ind);
315 list->SetItemData(ind, (long)data);
316 list->SetItem(ind, 1, file[8]); // filename
317 list->SetItem(ind, 2, file[4]); //Size
318 list->SetItem(ind, 3, file[5]); //date
319 list->SetItem(ind, 4, file[0]); //perm
320 list->SetItem(ind, 5, file[2]); //user
321 list->SetItem(ind, 6, file[3]); //grp
327 if (status == restoring) {
329 //15847 total files; 1 marked to be restored; 1,034 bytes.
330 if ((i = str.Find(" marked to be restored;")) > -1) {
331 int j = str.Find("; ");
332 str.Mid(j+2, i).ToLong(&totfilemessages);
333 //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
337 if ((i = str.Find(" files selected to be restored.")) > -1) {
338 str.Mid(0, i).ToLong(&totfilemessages);
339 //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
343 if ((i = str.Find(" file selected to be restored.")) > -1) {
344 str.Mid(0, i).ToLong(&totfilemessages);
345 //wxbMainFrame::GetInstance()->Print(wxString("TOT(") << totfilemessages << ")\n", CS_DEBUG);
349 wxStringTokenizer tkz(str, " ", wxTOKEN_STRTOK);
353 // Date Time name: perm ? user grp size date time
354 //04-Apr-2004 17:19 Tom-fd: -rwx------ 1 nicolas None 514967 2004-03-20 20:03:42 filename
356 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { // Date
357 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { // Time
358 if (tkz.GetNextToken().Last() == ':') { // name:
359 tkz.GetNextToken(); // perm
360 tkz.GetNextToken(); // ?
361 tkz.GetNextToken(); // user
362 tkz.GetNextToken(); // grp
363 tkz.GetNextToken(); // size
364 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { //date
365 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { //time
367 //wxbMainFrame::GetInstance()->Print(wxString("(") << filemessages << ")", CS_DEBUG);
368 gauge->SetValue(filemessages);
376 if (tableParser != NULL) {
377 tableParser->Print(str, stat);
379 if (stat == CS_END) {
385 void wxbRestorePanel::EnablePanel(bool enable) {
387 if (status == disabled) {
388 SetStatus(activable);
396 /*----------------------------------------------------------------------------
397 Commands called by events handler
398 ----------------------------------------------------------------------------*/
400 /* The main button has been clicked */
401 void wxbRestorePanel::CmdStart() {
402 if (status == activable) {
403 CreateAndWaitForParser("list clients\n");
405 clientChoice->Clear();
406 for (unsigned int i = 0; i < tableParser->size(); i++) {
407 /*for (unsigned int k = 0; k < (*tableParser)[i].size(); k++) {
408 wxbMainFrame::GetInstance()->Print(wxString() << (*tableParser)[i][k] << ":", CS_DEBUG);
410 wxbMainFrame::GetInstance()->Print(wxString(";\n"), CS_DEBUG);*/
412 (*tableParser)[i][0].ToLong(j);
413 clientChoice->Append((*tableParser)[i][1], (void*)j);
418 else if (status == entered) {
419 if (jobChoice->GetStringSelection().Length() < 1) {
420 wxbMainFrame::GetInstance()->SetStatusText("Please select a client.");
423 WaitForEnd("restore\n");
425 WaitForEnd(wxString() << jobChoice->GetStringSelection() << "\n");
426 WaitForEnd(wxString() << *((long*)clientChoice->GetClientData(clientChoice->GetSelection())) << "\n");
427 WaitForEnd("unmark *\n");
429 wxTreeItemId root = tree->AddRoot(clientChoice->GetStringSelection(), -1, -1, new wxbTreeItemData("/", clientChoice->GetStringSelection(), 0));
431 WaitForList(root, true);
432 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.");
435 else if (status == choosing) {
436 SetStatus(restoring);
438 wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
441 WaitForEnd("estimate\n");
442 WaitForEnd("done\n");
444 if (totfilemessages == 0) {
445 wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
446 wxbMainFrame::GetInstance()->SetStatusText("Restore failed : no file selected.");
454 gauge->SetRange(totfilemessages);
456 wxString cmd = "list jobid=";
458 CreateAndWaitForParser("list jobs\n");
459 /* TODO (#1#): Check more carefully which job we just have run. */
460 cmd << (*tableParser)[tableParser->size()-1][0] << "\n";
465 CreateAndWaitForParser(cmd);
466 if ((*tableParser)[0][7] != "C") {
470 WaitForEnd("messages\n");
472 wxbMainFrame::GetInstance()->SetStatusText(wxString("Restoring, please wait (") << filemessages << " of " << totfilemessages << " files done)...");
474 time_t start = wxDateTime::Now().GetTicks();
475 while (((wxDateTime::Now().GetTicks())-start) < 3) {
480 WaitForEnd("messages\n");
482 gauge->SetValue(totfilemessages);
484 if ((*tableParser)[0][7] == "T") {
485 wxbMainFrame::GetInstance()->Print("Restore done successfully.\n", CS_DEBUG);
486 wxbMainFrame::GetInstance()->SetStatusText("Restore done successfully.");
489 wxbMainFrame::GetInstance()->Print("Restore failed, please look at messages.\n", CS_DEBUG);
490 wxbMainFrame::GetInstance()->SetStatusText("Restore failed, please look at messages in console.");
496 /* List jobs for a specified client */
497 void wxbRestorePanel::CmdListJobs() {
498 if (status == entered) {
500 WaitForEnd("query\n");
502 CreateAndWaitForParser(clientChoice->GetString(clientChoice->GetSelection()) + "\n");
504 for (int i = tableParser->size()-1; i > -1; i--) {
505 wxString str = (*tableParser)[i][3];
508 if ( ( (chr = datetime.ParseDate(str.GetData()) ) != NULL ) && ( datetime.ParseTime(++chr) != NULL ) ) {
509 datetime = datetime.GetTicks() + 1;
510 //wxbMainFrame::GetInstance()->Print(wxString("-") << datetime.Format("%Y-%m-%d %H:%M:%S"), CS_DEBUG);
511 jobChoice->Append(datetime.Format("%Y-%m-%d %H:%M:%S"));
514 jobChoice->Append("Invalid");
518 jobChoice->SetSelection(0);
522 /* List files and directories for a specified tree item */
523 void wxbRestorePanel::CmdList(wxTreeItemId item) {
524 if (status == choosing) {
525 list->DeleteAllItems();
530 WaitForList(item, (tree->GetSelection() == item));
532 if (list->GetItemCount() > 1) {
533 int firstwidth = list->GetSize().GetWidth();
534 for (int i = 2; i < 7; i++) {
535 list->SetColumnWidth(i, wxLIST_AUTOSIZE);
536 firstwidth -= list->GetColumnWidth(i);
539 list->SetColumnWidth(0, 18);
541 list->SetColumnWidth(1, wxLIST_AUTOSIZE);
542 if (list->GetColumnWidth(1) < firstwidth) {
543 list->SetColumnWidth(1, firstwidth-20);
549 /* Mark a treeitem (directory) or a listitem (file or directory) */
550 void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long listitem) {
551 if (status == choosing) {
552 wxbTreeItemData* itemdata = NULL;
553 if (listitem != -1) {
554 itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
556 else if (treeitem.IsOk()) {
557 itemdata = (wxbTreeItemData*)tree->GetItemData(treeitem);
563 if (itemdata == NULL) //Should never happen
566 wxString dir = itemdata->GetPath();
570 if (dir.GetChar(dir.Length()-1) == '/') {
574 int i = dir.Find('/', TRUE);
579 else { /* first dir below root */
581 dir = dir.Mid(0, i+1);
589 WaitForEnd(wxString("cd ") << dir << "\n");
590 WaitForEnd(wxString((itemdata->GetMarked() == 1) ? "unmark " : "mark ") << file << "\n");
592 /*if ((dir == "/") && (file == "*")) {
593 itemdata->SetMarked((itemdata->GetMarked() == 1) ? 0 : 1);
596 if (listitem == -1) { /* tree item state changed */
597 SetTreeItemState(treeitem, (itemdata->GetMarked() == 1) ? 0 : 1);
598 /*treeitem = tree->GetSelection();
599 UpdateTree(treeitem, true);
600 treeitem = tree->GetItemParent(treeitem);*/
603 SetListItemState(listitem, (itemdata->GetMarked() == 1) ? 0 : 1);
604 /*UpdateTree(treeitem, (tree->GetSelection() == treeitem));
605 treeitem = tree->GetItemParent(treeitem);*/
608 /*while (treeitem.IsOk()) {
609 WaitForList(treeitem, false);
610 treeitem = tree->GetItemParent(treeitem);
615 /*----------------------------------------------------------------------------
617 ----------------------------------------------------------------------------*/
619 /* Parse a table in tableParser */
620 void wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
621 if (tableParser != NULL) {
624 tableParser = new wxbTableParser();
626 wxbMainFrame::GetInstance()->Send(cmd);
628 //time_t base = wxDateTime::Now().GetTicks();
629 while (!tableParser->hasFinished()) {
630 //innerThread->Yield();
632 //if (base+15 < wxDateTime::Now().GetTicks()) break;
636 /* Run a command, and waits until result is fully received. */
637 void wxbRestorePanel::WaitForEnd(wxString cmd) {
638 wxbMainFrame::GetInstance()->Send(cmd);
642 //time_t base = wxDateTime::Now().GetTicks();
644 //innerThread->Yield();
646 //if (base+15 < wxDateTime::Now().GetTicks()) break;
650 /* Run a dir command, and waits until result is fully received. */
651 void wxbRestorePanel::WaitForList(wxTreeItemId item, bool updatelist) {
652 this->updatelist = updatelist;
653 currentTreeItem = item;
655 WaitForEnd(wxString("cd \"") << static_cast<wxbTreeItemData*>(tree->GetItemData(currentTreeItem))->GetPath() << "\"\n");
660 list->DeleteAllItems();
667 /* Parse dir command results. */
668 wxString* wxbRestorePanel::ParseList(wxString line) {
669 //drwx------ 11 1003 42949672 0 2001-07-30 16:45:14 *filename
670 //+ 10 ++ 4++ 10 ++ 8 ++ 8 + + 19 + *+ ->
671 //0 10 14 24 32 42 62
673 if (line.Length() < 63)
676 wxString* ret = new wxString[9];
678 ret[0] = line.Mid(0, 10).Trim();
679 ret[1] = line.Mid(10, 4).Trim();
680 ret[2] = line.Mid(14, 10).Trim();
681 ret[3] = line.Mid(24, 8).Trim();
682 ret[4] = line.Mid(32, 8).Trim();
683 ret[5] = line.Mid(42, 19).Trim();
684 ret[6] = line.Mid(62, 1);
685 ret[7] = line.Mid(63).Trim();
687 if (ret[6] == " ") ret[6] = "";
689 if (ret[7].GetChar(ret[7].Length()-1) == '/') {
692 ret[8] = ret[7].Mid(ret[8].Find('/', true)+1);
695 ret[8] = ret[7].Mid(ret[7].Find('/', true)+1);
701 /* Sets a list item state, and update its parents and children if it is a directory */
702 void wxbRestorePanel::SetListItemState(long listitem, int newstate) {
703 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
705 wxTreeItemId treeitem;
707 itemdata->SetMarked(newstate);
708 list->SetItemImage(listitem, newstate, 0); /* TODO: Find what these ints are for */
709 list->SetItemImage(listitem, newstate, 1);
711 if ((treeitem = itemdata->GetId()).IsOk()) {
712 SetTreeItemState(treeitem, newstate);
715 UpdateTreeItemState(tree->GetSelection());
719 /* Sets a tree item state, and update its children, parents and list (if necessary) */
720 void wxbRestorePanel::SetTreeItemState(wxTreeItemId item, int newstate) {
722 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
724 wxbTreeItemData* itemdata;
726 while (currentChild.IsOk()) {
727 itemdata = (wxbTreeItemData*)tree->GetItemData(currentChild);
728 int state = itemdata->GetMarked();
730 if (state != newstate) {
731 itemdata->SetMarked(newstate);
732 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Normal);
733 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Selected);
736 currentChild = tree->GetNextChild(item, cookie);
739 itemdata = (wxbTreeItemData*)tree->GetItemData(item);
740 itemdata->SetMarked(newstate);
741 tree->SetItemImage(item, newstate, wxTreeItemIcon_Normal);
742 tree->SetItemImage(item, newstate, wxTreeItemIcon_Selected);
745 if (tree->GetSelection() == item) {
746 for (long i = 0; i < list->GetItemCount(); i++) {
747 list->SetItemImage(i, newstate, 0); /* TODO: Find what these ints are for */
748 list->SetItemImage(i, newstate, 1);
752 UpdateTreeItemState(tree->GetParent(item));
755 /* Update a tree item state, and its parents' state */
756 void wxbRestorePanel::UpdateTreeItemState(wxTreeItemId item) {
764 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
766 bool onechildmarked = false;
767 bool onechildunmarked = false;
769 while (currentChild.IsOk()) {
770 state = ((wxbTreeItemData*)tree->GetItemData(currentChild))->GetMarked();
773 onechildunmarked = true;
776 onechildmarked = true;
779 onechildmarked = true;
780 onechildunmarked = true;
784 if (onechildmarked && onechildunmarked) {
788 currentChild = tree->GetNextChild(item, cookie);
791 if (tree->GetSelection() == item) {
792 for (long i = 0; i < list->GetItemCount(); i++) {
793 state = ((wxbTreeItemData*)list->GetItemData(i))->GetMarked();
797 onechildunmarked = true;
800 onechildmarked = true;
803 onechildmarked = true;
804 onechildunmarked = true;
808 if (onechildmarked && onechildunmarked) {
816 if (onechildmarked && onechildunmarked) {
819 else if (onechildmarked) {
822 else if (onechildunmarked) {
825 else { // no child, don't change anything
826 UpdateTreeItemState(tree->GetParent(item));
830 wxbTreeItemData* itemdata = (wxbTreeItemData*)tree->GetItemData(item);
832 itemdata->SetMarked(state);
833 tree->SetItemImage(item, state, wxTreeItemIcon_Normal);
834 tree->SetItemImage(item, state, wxTreeItemIcon_Selected);
836 UpdateTreeItemState(tree->GetParent(item));
840 * Refresh a tree item, and all its childs,
841 * by asking the director for new lists
843 void wxbRestorePanel::RefreshTree(wxTreeItemId item) {
844 /* WaitForList(item, updatelist);
846 /* Update all child which are not collapsed */
848 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
850 while (currentChild.IsOk()) {
851 if (tree->IsExpanded(currentChild))
852 UpdateTree(currentChild, false);
854 currentChild = tree->GetNextChild(item, cookie);
858 /*----------------------------------------------------------------------------
860 ----------------------------------------------------------------------------*/
862 /* Set current status by enabling/disabling components */
863 void wxbRestorePanel::SetStatus(status_enum newstatus) {
866 start->SetLabel("Enter restore mode");
867 start->Enable(false);
868 clientChoice->Enable(false);
869 jobChoice->Enable(false);
872 gauge->Enable(false);
875 tree->DeleteAllItems();
876 list->DeleteAllItems();
877 clientChoice->Clear();
879 wxbMainFrame::GetInstance()->EnablePanels();
880 newstatus = activable;
882 start->SetLabel("Enter restore mode");
884 clientChoice->Enable(false);
885 jobChoice->Enable(false);
888 gauge->Enable(false);
891 wxbMainFrame::GetInstance()->DisablePanels(this);
893 start->SetLabel("Choose files to restore");
894 clientChoice->Enable(true);
895 jobChoice->Enable(true);
903 start->SetLabel("Restore");
904 clientChoice->Enable(false);
905 jobChoice->Enable(false);
911 start->SetLabel("Restoring...");
914 start->Enable(false);
915 clientChoice->Enable(false);
916 jobChoice->Enable(false);
925 /*----------------------------------------------------------------------------
927 ----------------------------------------------------------------------------*/
929 void wxbRestorePanel::OnClientChoiceChanged(wxCommandEvent& event) {
934 clientChoice->Enable(false);
936 clientChoice->Enable(true);
937 jobChoice->Refresh();
941 void wxbRestorePanel::OnStart(wxEvent& WXUNUSED(event)) {
950 void wxbRestorePanel::OnTreeChanging(wxTreeEvent& event) {
956 void wxbRestorePanel::OnTreeExpanding(wxTreeEvent& event) {
962 //CmdList(event.GetItem());
963 if (tree->GetSelection() != event.GetItem()) {
964 tree->SelectItem(event.GetItem());
969 void wxbRestorePanel::OnTreeChanged(wxTreeEvent& event) {
975 CmdList(event.GetItem());
979 void wxbRestorePanel::OnTreeMarked(wxbTreeMarkedEvent& event) {
985 CmdMark(event.GetItem(), -1);
991 void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
997 //long item = event.GetId();
998 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
999 CmdMark(wxTreeItemId(), item);
1005 void wxbRestorePanel::OnListActivated(wxListEvent& event) {
1011 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
1013 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(item);
1014 wxString name = itemdata->GetName();
1021 if (name.GetChar(name.Length()-1) == '/') {
1022 wxTreeItemId currentChild = tree->GetFirstChild(currentTreeItem, cookie);
1024 while (currentChild.IsOk()) {
1025 wxString name2 = tree->GetItemText(currentChild);
1026 if (name2 == name) {
1027 //tree->UnselectAll();
1029 tree->Expand(currentTreeItem);
1030 tree->SelectItem(currentChild);
1034 currentChild = tree->GetNextChild(currentTreeItem, cookie);