]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbrestorepanel.h
Use new '.dir' command to get directory listing (Thank you Kern, good idea .-)).
[bacula/bacula] / bacula / src / wx-console / wxbrestorepanel.h
1 /*
2  *
3  *   wxbPanel for restoring files
4  *
5  *    Nicolas Boichat, April-May 2004
6  *
7  *    Version $Id$
8  */
9 /*
10    Copyright (C) 2004 Kern Sibbald and John Walker
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License
14    as published by the Free Software Foundation; either version 2
15    of the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifndef WXBRESTOREPANEL_H
28 #define WXBRESTOREPANEL_H
29
30 #include "wx/wxprec.h"
31
32 #ifndef WX_PRECOMP
33    #include "wx/wx.h"
34 #endif
35
36 #include "wxbtableparser.h"
37
38 #include <wx/thread.h>
39 #include <wx/listctrl.h>
40 #include <wx/treectrl.h>
41 #include <wx/gauge.h>
42 #include <wx/stattext.h>
43 #include <wx/splitter.h>
44
45 #include "wxbutils.h"
46
47 #include "wxbconfigpanel.h"
48 #include "wxbtreectrl.h"
49 #include "wxblistctrl.h"
50
51 WX_DECLARE_LIST(wxEvent, wxbEventList);
52
53 /* Class for storing directory entries (results from dir commands). */
54 class wxbDirEntry {
55 public:
56    wxString perm;
57    wxString nlink;
58    wxString user;
59    wxString group;
60    wxString size;
61    wxString date;
62    int marked; /* 0 - Not Marked, 1 - Marked, 2 - Some file under is marked */
63    wxString fullname; /* full name with path */
64    wxString filename; /* only filename, no path */
65 };
66
67 /*
68  * wxbPanel for restoring files
69  */
70 class wxbRestorePanel : public wxbPanel
71 {
72    public:
73       wxbRestorePanel(wxWindow* parent);
74       ~wxbRestorePanel();
75
76       /* wxbPanel overloadings */
77       virtual wxString GetTitle();
78       virtual void EnablePanel(bool enable = true);
79
80    private:
81 /* Commands called by events handler */
82
83       /* The main button has been clicked */
84       void CmdStart();
85
86       /* The cancel button has been clicked */
87       void CmdCancel();
88
89       /* Apply configuration changes */
90       void CmdConfigApply();
91
92       /* Cancel restore */
93       void CmdConfigCancel();
94
95        /* List jobs for a specified client */
96       void CmdListJobs();
97
98       /* List files and directories for a specified tree item */
99       void CmdList(wxTreeItemId item);
100
101       /* Mark a treeitem (directory) or several listitems (file or directory),
102        * state defines if it should mark (1), unmark (0), or switch state (-1) */
103       void CmdMark(wxTreeItemId treeitem, long* listitems, int listsize, int state = -1);
104
105 /* General functions and variables */
106       //bool ended; /* The last command send has finished */
107
108       //long filemessages; /* When restoring, number of files restored */
109       long totfilemessages; /* When restoring, number of files to be restored */
110       wxString jobid;
111
112       /* Run a dir command, and waits until result is fully received.
113        * If recurse is true, update the children too. */
114       void UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse);
115
116       /* Parse dir command results. */
117       int ParseList(wxString line, wxbDirEntry* entry);
118
119       /* Sets a list item state, and update its parents and children if it is a directory */
120       void SetListItemState(long listitem, int newstate);
121
122       /* Sets a tree item state, and update its children, parents and list (if necessary) */
123       void SetTreeItemState(wxTreeItemId item, int newstate);
124
125       /* Update a tree item parents' state */
126       void UpdateTreeItemState(wxTreeItemId item);
127
128       /* Refresh the whole tree. */
129       void RefreshTree();
130
131       /* Refresh file list */
132       void RefreshList();
133
134       /* Update first config, adapting settings to the job name selected */
135       void UpdateFirstConfig();
136
137       /* Update second config */
138       bool UpdateSecondConfig(wxbDataTokenizer* dt);
139
140 /* Status related */
141       enum status_enum
142       {
143          disabled,    // The panel is not activatable
144          activable,   // The panel is activable, but not activated
145          entered,     // The panel is activated
146          choosing,    // The user is choosing files to restore
147          listing,     // Dir listing is in progress
148          configuring, // The user is configuring restore process
149          restoring,   // Bacula is restoring files
150          finished     // Retore done (state will change in activable)
151       };
152
153       status_enum status;
154
155       /* Cancelled status :
156        *  - 0 - !cancelled
157        *  - 1 - will be cancelled
158        *  - 2 - has been cancelled */
159       int cancelled;
160
161       /* Set current status by enabling/disabling components */
162       void SetStatus(status_enum newstatus);
163
164 /* UI related */
165       bool working; // A command is running, discard GUI events
166       void SetWorking(bool working);
167       bool IsWorking();
168       bool markWhenCommandDone; //If an item should be (un)marked after the current listing/marking is done
169       wxTreeItemId currentTreeItem; // Currently selected tree item
170
171       /* Enable or disable config controls status */
172       void EnableConfig(bool enable);
173
174 /* Event handling */
175 //      wxbEventList* pendingEvents; /* Stores event sent while working */ //EVTQUEUE
176 //      bool processing; /* True if pendingEvents is being processed */ //EVTQUEUE
177
178 //      virtual void AddPendingEvent(wxEvent& event);
179 //      virtual bool ProcessEvent(wxEvent& event); //EVTQUEUE
180
181       void OnStart(wxCommandEvent& event);
182       void OnCancel(wxCommandEvent& event);
183
184       void OnTreeChanging(wxTreeEvent& event);
185       void OnTreeExpanding(wxTreeEvent& event);
186       void OnTreeChanged(wxTreeEvent& event);
187       void OnTreeMarked(wxbTreeMarkedEvent& event);
188       void OnTreeAdd(wxCommandEvent& event);
189       void OnTreeRemove(wxCommandEvent& event);
190       void OnTreeRefresh(wxCommandEvent& event);
191
192       void OnListMarked(wxbListMarkedEvent& event);
193       void OnListActivated(wxListEvent& event);
194       void OnListChanged(wxListEvent& event);
195       void OnListAdd(wxCommandEvent& event);
196       void OnListRemove(wxCommandEvent& event);
197       void OnListRefresh(wxCommandEvent& event);
198
199       void OnConfigUpdated(wxCommandEvent& event);
200       void OnConfigOk(wxCommandEvent& WXUNUSED(event));
201       void OnConfigApply(wxCommandEvent& WXUNUSED(event));
202       void OnConfigCancel(wxCommandEvent& WXUNUSED(event));
203
204 /* Components */
205       wxBoxSizer *centerSizer; /* Center sizer */
206       wxSplitterWindow *treelistPanel; /* Panel which contains tree and list */
207       wxbConfigPanel *configPanel; /* Panel which contains initial restore options */
208       wxbConfigPanel *restorePanel; /* Panel which contains final restore options */
209
210       wxImageList* imagelist; //image list for tree and list
211
212       wxButton* start;
213       wxButton* cancel;
214
215       wxbTreeCtrl* tree;
216       wxButton* treeadd;
217       wxButton* treeremove;
218       wxButton* treerefresh;
219
220       wxbListCtrl* list;
221       wxButton* listadd;
222       wxButton* listremove;
223       wxButton* listrefresh;
224
225       wxGauge* gauge;
226
227       long cfgUpdated; //keeps which config fields have been updated
228
229       friend class wxbSplitterWindow;
230
231       DECLARE_EVENT_TABLE();
232 };
233
234 #endif // WXBRESTOREPANEL_H