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);
242 jobChoice->Enable(false);
248 * wxbRestorePanel destructor
250 wxbRestorePanel::~wxbRestorePanel() {
254 /*----------------------------------------------------------------------------
255 wxbPanel overloadings
256 ----------------------------------------------------------------------------*/
258 wxString wxbRestorePanel::GetTitle() {
262 void wxbRestorePanel::EnablePanel(bool enable) {
264 if (status == disabled) {
265 SetStatus(activable);
273 /*----------------------------------------------------------------------------
274 Commands called by events handler
275 ----------------------------------------------------------------------------*/
277 /* The main button has been clicked */
278 void wxbRestorePanel::CmdStart() {
279 if (status == activable) {
280 wxbTableParser* tableparser = CreateAndWaitForParser("list clients\n");
282 clientChoice->Clear();
283 for (unsigned int i = 0; i < tableparser->size(); i++) {
285 (*tableparser)[i][0].ToLong(j);
286 clientChoice->Append((*tableparser)[i][1], (void*)j);
293 else if (status == entered) {
294 if (jobChoice->GetStringSelection().Length() < 1) {
295 wxbMainFrame::GetInstance()->SetStatusText("Please select a client.");
298 WaitForEnd("restore\n");
300 WaitForEnd(wxString() << jobChoice->GetStringSelection() << "\n");
301 WaitForEnd(wxString() << *((long*)clientChoice->GetClientData(clientChoice->GetSelection())) << "\n");
302 WaitForEnd("unmark *\n");
304 wxTreeItemId root = tree->AddRoot(clientChoice->GetStringSelection(), -1, -1, new wxbTreeItemData("/", clientChoice->GetStringSelection(), 0));
306 UpdateTreeItem(root, true);
307 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.");
310 else if (status == choosing) {
311 SetStatus(restoring);
313 wxbMainFrame::GetInstance()->SetStatusText("Restoring, please wait...");
316 wxbDataTokenizer* dt;
318 dt = WaitForEnd("estimate\n");
322 for (unsigned int i = 0; i < dt->GetCount(); i++) {
323 /* 15847 total files; 1 marked to be restored; 1,034 bytes. */
324 if ((j = (*dt)[i].Find(" marked to be restored;")) > -1) {
325 k = (*dt)[i].Find("; ");
326 (*dt)[i].Mid(k+2, j).ToLong(&totfilemessages);
333 dt = WaitForEnd("done\n", true);
335 for (unsigned int i = 0; i < dt->GetCount(); i++) {
336 if ((j = (*dt)[i].Find(" files selected to be restored.")) > -1) {
337 (*dt)[i].Mid(0, j).ToLong(&totfilemessages);
341 if ((j = (*dt)[i].Find(" file selected to be restored.")) > -1) {
342 (*dt)[i].Mid(0, j).ToLong(&totfilemessages);
349 if (totfilemessages == 0) {
350 wxbMainFrame::GetInstance()->Print("Restore failed : no file selected.\n", CS_DEBUG);
351 wxbMainFrame::GetInstance()->SetStatusText("Restore failed : no file selected.");
359 gauge->SetRange(totfilemessages);
361 wxString cmd = "list jobid=";
363 wxbTableParser* tableparser = CreateAndWaitForParser("list jobs\n");
364 /* TODO (#1#): Check more carefully which job we just have run. */
365 cmd << (*tableparser)[tableparser->size()-1][0] << "\n";
372 tableparser = CreateAndWaitForParser(cmd);
373 if ((*tableparser)[0][7] != "C") {
378 dt = WaitForEnd("messages\n", true);
380 for (unsigned int i = 0; i < dt->GetCount(); i++) {
381 wxStringTokenizer tkz((*dt)[i], " ", wxTOKEN_STRTOK);
385 // Date Time name: perm ? user grp size date time
386 //04-Apr-2004 17:19 Tom-fd: -rwx------ 1 nicolas None 514967 2004-03-20 20:03:42 filename
388 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { // Date
389 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { // Time
390 if (tkz.GetNextToken().Last() == ':') { // name:
391 tkz.GetNextToken(); // perm
392 tkz.GetNextToken(); // ?
393 tkz.GetNextToken(); // user
394 tkz.GetNextToken(); // grp
395 tkz.GetNextToken(); // size
396 if (datetime.ParseDate(tkz.GetNextToken()) != NULL) { //date
397 if (datetime.ParseTime(tkz.GetNextToken()) != NULL) { //time
399 //wxbMainFrame::GetInstance()->Print(wxString("(") << filemessages << ")", CS_DEBUG);
400 gauge->SetValue(filemessages);
410 wxbMainFrame::GetInstance()->SetStatusText(wxString("Restoring, please wait (") << filemessages << " of " << totfilemessages << " files done)...");
412 time_t start = wxDateTime::Now().GetTicks();
413 while (((wxDateTime::Now().GetTicks())-start) < 3) {
418 WaitForEnd("messages\n");
420 gauge->SetValue(totfilemessages);
422 if ((*tableparser)[0][7] == "T") {
423 wxbMainFrame::GetInstance()->Print("Restore done successfully.\n", CS_DEBUG);
424 wxbMainFrame::GetInstance()->SetStatusText("Restore done successfully.");
427 wxbMainFrame::GetInstance()->Print("Restore failed, please look at messages.\n", CS_DEBUG);
428 wxbMainFrame::GetInstance()->SetStatusText("Restore failed, please look at messages in console.");
435 /* List jobs for a specified client */
436 void wxbRestorePanel::CmdListJobs() {
437 if (status == entered) {
439 WaitForEnd("query\n");
441 wxbTableParser* tableparser = CreateAndWaitForParser(clientChoice->GetString(clientChoice->GetSelection()) + "\n");
443 for (int i = tableparser->size()-1; i > -1; i--) {
444 wxString str = (*tableparser)[i][3];
447 if ( ( (chr = datetime.ParseDate(str.GetData()) ) != NULL ) && ( datetime.ParseTime(++chr) != NULL ) ) {
448 datetime = datetime.GetTicks() + 1;
449 //wxbMainFrame::GetInstance()->Print(wxString("-") << datetime.Format("%Y-%m-%d %H:%M:%S"), CS_DEBUG);
450 jobChoice->Append(datetime.Format("%Y-%m-%d %H:%M:%S"));
453 jobChoice->Append("Invalid");
459 jobChoice->SetSelection(0);
463 /* List files and directories for a specified tree item */
464 void wxbRestorePanel::CmdList(wxTreeItemId item) {
465 if (status == choosing) {
466 list->DeleteAllItems();
471 UpdateTreeItem(item, (tree->GetSelection() == item));
473 if (list->GetItemCount() > 1) {
474 int firstwidth = list->GetSize().GetWidth();
475 for (int i = 2; i < 7; i++) {
476 list->SetColumnWidth(i, wxLIST_AUTOSIZE);
477 firstwidth -= list->GetColumnWidth(i);
480 list->SetColumnWidth(0, 18);
482 list->SetColumnWidth(1, wxLIST_AUTOSIZE);
483 if (list->GetColumnWidth(1) < firstwidth) {
484 list->SetColumnWidth(1, firstwidth-20);
490 /* Mark a treeitem (directory) or a listitem (file or directory) */
491 void wxbRestorePanel::CmdMark(wxTreeItemId treeitem, long listitem) {
492 if (status == choosing) {
493 wxbTreeItemData* itemdata = NULL;
494 if (listitem != -1) {
495 itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
497 else if (treeitem.IsOk()) {
498 itemdata = (wxbTreeItemData*)tree->GetItemData(treeitem);
504 if (itemdata == NULL) //Should never happen
507 wxString dir = itemdata->GetPath();
511 if (dir.GetChar(dir.Length()-1) == '/') {
515 int i = dir.Find('/', TRUE);
520 else { /* first dir below root */
522 dir = dir.Mid(0, i+1);
530 WaitForEnd(wxString("cd ") << dir << "\n");
531 WaitForEnd(wxString((itemdata->GetMarked() == 1) ? "unmark " : "mark ") << file << "\n");
533 /* TODO: Check commands results */
535 /*if ((dir == "/") && (file == "*")) {
536 itemdata->SetMarked((itemdata->GetMarked() == 1) ? 0 : 1);
539 if (listitem == -1) { /* tree item state changed */
540 SetTreeItemState(treeitem, (itemdata->GetMarked() == 1) ? 0 : 1);
541 /*treeitem = tree->GetSelection();
542 UpdateTree(treeitem, true);
543 treeitem = tree->GetItemParent(treeitem);*/
546 SetListItemState(listitem, (itemdata->GetMarked() == 1) ? 0 : 1);
547 /*UpdateTree(treeitem, (tree->GetSelection() == treeitem));
548 treeitem = tree->GetItemParent(treeitem);*/
551 /*while (treeitem.IsOk()) {
552 WaitForList(treeitem, false);
553 treeitem = tree->GetItemParent(treeitem);
558 /*----------------------------------------------------------------------------
560 ----------------------------------------------------------------------------*/
562 /* Parse a table in tableParser */
563 wxbTableParser* wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
564 wxbTableParser* tableParser = new wxbTableParser();
566 wxbMainFrame::GetInstance()->Send(cmd);
568 //time_t base = wxDateTime::Now().GetTicks();
569 while (!tableParser->hasFinished()) {
570 //innerThread->Yield();
572 //if (base+15 < wxDateTime::Now().GetTicks()) break;
577 /* Run a command, and waits until result is fully received. */
578 wxbDataTokenizer* wxbRestorePanel::WaitForEnd(wxString cmd, bool keepresults) {
579 wxbDataTokenizer* datatokenizer = new wxbDataTokenizer();
581 wxbMainFrame::GetInstance()->Send(cmd);
583 //time_t base = wxDateTime::Now().GetTicks();
584 while (!datatokenizer->hasFinished()) {
585 //innerThread->Yield();
587 //if (base+15 < wxDateTime::Now().GetTicks()) break;
590 return datatokenizer;
593 delete datatokenizer;
598 /* Run a dir command, and waits until result is fully received. */
599 void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist) {
600 // this->updatelist = updatelist;
601 currentTreeItem = item;
603 wxbDataTokenizer* dt;
605 dt = WaitForEnd(wxString("cd \"") <<
606 static_cast<wxbTreeItemData*>(tree->GetItemData(currentTreeItem))
607 ->GetPath() << "\"\n", false);
609 /* TODO: check command result */
616 list->DeleteAllItems();
617 dt = WaitForEnd("dir\n", true);
621 for (unsigned int i = 0; i < dt->GetCount(); i++) {
624 if (str.Find("cwd is:") == 0) { // Sometimes cd command result "infiltrate" into listings.
630 wxString* file = ParseList(str);
637 if (file[8].GetChar(file[8].Length()-1) == '/') {
641 treeid = tree->GetFirstChild(currentTreeItem, cookie);
643 bool updated = false;
645 while (treeid.IsOk()) {
646 itemStr = tree->GetItemText(treeid);
647 if (file[8] == itemStr) {
648 int stat = wxbTreeItemData::GetMarkedStatus(file[6]);
649 if (static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->GetMarked() != stat) {
650 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Normal);
651 tree->SetItemImage(treeid, stat, wxTreeItemIcon_Selected);
652 static_cast<wxbTreeItemData*>(tree->GetItemData(treeid))->SetMarked(file[6]);
657 treeid = tree->GetNextChild(currentTreeItem, cookie);
661 int img = wxbTreeItemData::GetMarkedStatus(file[6]);
662 treeid = tree->AppendItem(currentTreeItem, file[8], img, img, new wxbTreeItemData(file[7], file[8], file[6]));
667 long ind = list->InsertItem(list->GetItemCount(), wxbTreeItemData::GetMarkedStatus(file[6]));
668 wxbTreeItemData* data = new wxbTreeItemData(file[7], file[8], file[6], ind);
670 list->SetItemData(ind, (long)data);
671 list->SetItem(ind, 1, file[8]); // filename
672 list->SetItem(ind, 2, file[4]); //Size
673 list->SetItem(ind, 3, file[5]); //date
674 list->SetItem(ind, 4, file[0]); //perm
675 list->SetItem(ind, 5, file[2]); //user
676 list->SetItem(ind, 6, file[3]); //grp
688 /* Parse dir command results. */
689 wxString* wxbRestorePanel::ParseList(wxString line) {
690 //drwx------ 11 1003 42949672 0 2001-07-30 16:45:14 *filename
691 //+ 10 ++ 4++ 10 ++ 8 ++ 8 + + 19 + *+ ->
692 //0 10 14 24 32 42 62
694 if (line.Length() < 63)
697 wxString* ret = new wxString[9];
699 ret[0] = line.Mid(0, 10).Trim();
700 ret[1] = line.Mid(10, 4).Trim();
701 ret[2] = line.Mid(14, 10).Trim();
702 ret[3] = line.Mid(24, 8).Trim();
703 ret[4] = line.Mid(32, 8).Trim();
704 ret[5] = line.Mid(42, 19).Trim();
705 ret[6] = line.Mid(62, 1);
706 ret[7] = line.Mid(63).Trim();
708 if (ret[6] == " ") ret[6] = "";
710 if (ret[7].GetChar(ret[7].Length()-1) == '/') {
713 ret[8] = ret[7].Mid(ret[8].Find('/', true)+1);
716 ret[8] = ret[7].Mid(ret[7].Find('/', true)+1);
722 /* Sets a list item state, and update its parents and children if it is a directory */
723 void wxbRestorePanel::SetListItemState(long listitem, int newstate) {
724 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(listitem);
726 wxTreeItemId treeitem;
728 itemdata->SetMarked(newstate);
729 list->SetItemImage(listitem, newstate, 0); /* TODO: Find what these ints are for */
730 list->SetItemImage(listitem, newstate, 1);
732 if ((treeitem = itemdata->GetId()).IsOk()) {
733 SetTreeItemState(treeitem, newstate);
736 UpdateTreeItemState(tree->GetSelection());
740 /* Sets a tree item state, and update its children, parents and list (if necessary) */
741 void wxbRestorePanel::SetTreeItemState(wxTreeItemId item, int newstate) {
743 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
745 wxbTreeItemData* itemdata;
747 while (currentChild.IsOk()) {
748 itemdata = (wxbTreeItemData*)tree->GetItemData(currentChild);
749 int state = itemdata->GetMarked();
751 if (state != newstate) {
752 itemdata->SetMarked(newstate);
753 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Normal);
754 tree->SetItemImage(currentChild, newstate, wxTreeItemIcon_Selected);
757 currentChild = tree->GetNextChild(item, cookie);
760 itemdata = (wxbTreeItemData*)tree->GetItemData(item);
761 itemdata->SetMarked(newstate);
762 tree->SetItemImage(item, newstate, wxTreeItemIcon_Normal);
763 tree->SetItemImage(item, newstate, wxTreeItemIcon_Selected);
766 if (tree->GetSelection() == item) {
767 for (long i = 0; i < list->GetItemCount(); i++) {
768 list->SetItemImage(i, newstate, 0); /* TODO: Find what these ints are for */
769 list->SetItemImage(i, newstate, 1);
773 UpdateTreeItemState(tree->GetParent(item));
776 /* Update a tree item state, and its parents' state */
777 void wxbRestorePanel::UpdateTreeItemState(wxTreeItemId item) {
785 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
787 bool onechildmarked = false;
788 bool onechildunmarked = false;
790 while (currentChild.IsOk()) {
791 state = ((wxbTreeItemData*)tree->GetItemData(currentChild))->GetMarked();
794 onechildunmarked = true;
797 onechildmarked = true;
800 onechildmarked = true;
801 onechildunmarked = true;
805 if (onechildmarked && onechildunmarked) {
809 currentChild = tree->GetNextChild(item, cookie);
812 if (tree->GetSelection() == item) {
813 for (long i = 0; i < list->GetItemCount(); i++) {
814 state = ((wxbTreeItemData*)list->GetItemData(i))->GetMarked();
818 onechildunmarked = true;
821 onechildmarked = true;
824 onechildmarked = true;
825 onechildunmarked = true;
829 if (onechildmarked && onechildunmarked) {
837 if (onechildmarked && onechildunmarked) {
840 else if (onechildmarked) {
843 else if (onechildunmarked) {
846 else { // no child, don't change anything
847 UpdateTreeItemState(tree->GetParent(item));
851 wxbTreeItemData* itemdata = (wxbTreeItemData*)tree->GetItemData(item);
853 itemdata->SetMarked(state);
854 tree->SetItemImage(item, state, wxTreeItemIcon_Normal);
855 tree->SetItemImage(item, state, wxTreeItemIcon_Selected);
857 UpdateTreeItemState(tree->GetParent(item));
861 * Refresh a tree item, and all its childs,
862 * by asking the director for new lists
864 void wxbRestorePanel::RefreshTree(wxTreeItemId item) {
865 /* UpdateTreeItem(item, updatelist);*/
867 /* Update all child which are not collapsed */
869 wxTreeItemId currentChild = tree->GetFirstChild(item, cookie);
871 while (currentChild.IsOk()) {
872 if (tree->IsExpanded(currentChild))
873 UpdateTree(currentChild, false);
875 currentChild = tree->GetNextChild(item, cookie);
879 /*----------------------------------------------------------------------------
881 ----------------------------------------------------------------------------*/
883 /* Set current status by enabling/disabling components */
884 void wxbRestorePanel::SetStatus(status_enum newstatus) {
887 start->SetLabel("Enter restore mode");
888 start->Enable(false);
889 clientChoice->Enable(false);
890 jobChoice->Enable(false);
893 gauge->Enable(false);
896 tree->DeleteAllItems();
897 list->DeleteAllItems();
898 clientChoice->Clear();
900 wxbMainFrame::GetInstance()->EnablePanels();
901 newstatus = activable;
903 start->SetLabel("Enter restore mode");
905 clientChoice->Enable(false);
906 jobChoice->Enable(false);
909 gauge->Enable(false);
912 wxbMainFrame::GetInstance()->DisablePanels(this);
914 start->SetLabel("Choose files to restore");
915 clientChoice->Enable(true);
916 jobChoice->Enable(true);
924 start->SetLabel("Restore");
925 clientChoice->Enable(false);
926 jobChoice->Enable(false);
932 start->SetLabel("Restoring...");
935 start->Enable(false);
936 clientChoice->Enable(false);
937 jobChoice->Enable(false);
946 /*----------------------------------------------------------------------------
948 ----------------------------------------------------------------------------*/
950 void wxbRestorePanel::OnClientChoiceChanged(wxCommandEvent& event) {
955 clientChoice->Enable(false);
957 clientChoice->Enable(true);
958 jobChoice->Refresh();
962 void wxbRestorePanel::OnStart(wxEvent& WXUNUSED(event)) {
971 void wxbRestorePanel::OnTreeChanging(wxTreeEvent& event) {
977 void wxbRestorePanel::OnTreeExpanding(wxTreeEvent& event) {
983 //CmdList(event.GetItem());
984 if (tree->GetSelection() != event.GetItem()) {
985 tree->SelectItem(event.GetItem());
990 void wxbRestorePanel::OnTreeChanged(wxTreeEvent& event) {
996 CmdList(event.GetItem());
1000 void wxbRestorePanel::OnTreeMarked(wxbTreeMarkedEvent& event) {
1006 CmdMark(event.GetItem(), -1);
1012 void wxbRestorePanel::OnListMarked(wxbListMarkedEvent& event) {
1018 //long item = event.GetId();
1019 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
1020 CmdMark(wxTreeItemId(), item);
1026 void wxbRestorePanel::OnListActivated(wxListEvent& event) {
1032 long item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
1034 wxbTreeItemData* itemdata = (wxbTreeItemData*)list->GetItemData(item);
1035 wxString name = itemdata->GetName();
1042 if (name.GetChar(name.Length()-1) == '/') {
1043 wxTreeItemId currentChild = tree->GetFirstChild(currentTreeItem, cookie);
1045 while (currentChild.IsOk()) {
1046 wxString name2 = tree->GetItemText(currentChild);
1047 if (name2 == name) {
1048 //tree->UnselectAll();
1050 tree->Expand(currentTreeItem);
1051 tree->SelectItem(currentChild);
1055 currentChild = tree->GetNextChild(currentTreeItem, cookie);