]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbrestorepanel.h
bf991cd36d3e4e1ec8003b2772322759a020b085
[bacula/bacula] / bacula / src / wx-console / wxbrestorepanel.h
1 /*
2  *
3  *   wxbPanel for restoring files
4  *
5  *    Nicolas Boichat, April-May 2004
6  *
7  */
8 /*
9    Copyright (C) 2004 Kern Sibbald and John Walker
10
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.
15
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.
20
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.
24  */
25
26 #ifndef WXBRESTOREPANEL_H
27 #define WXBRESTOREPANEL_H
28
29 #include "wx/wxprec.h"
30
31 #ifndef WX_PRECOMP
32    #include "wx/wx.h"
33 #endif
34
35 #include "wxbtableparser.h"
36
37 #include <wx/thread.h>
38 #include <wx/listctrl.h>
39 #include <wx/treectrl.h>
40 #include <wx/gauge.h>
41 #include <wx/stattext.h>
42 #include <wx/splitter.h>
43
44 #include "wxbutils.h"
45
46 #include "wxbconfigpanel.h"
47 #include "wxbtreectrl.h"
48 #include "wxblistctrl.h"
49
50 /*
51  * wxbPanel for restoring files
52  */
53 class wxbRestorePanel : public wxbPanel
54 {
55    public:
56       wxbRestorePanel(wxWindow* parent);
57       ~wxbRestorePanel();
58
59       /* wxbPanel overloadings */
60       virtual wxString GetTitle();
61       virtual void EnablePanel(bool enable = true);
62
63    private:
64 /* Commands called by events handler */
65
66       /* The main button has been clicked */
67       void CmdStart();
68
69       /* The cancel button has been clicked */
70       void CmdCancel();
71
72       /* Apply configuration changes */
73       void CmdConfigApply();
74
75       /* Cancel restore */
76       void CmdConfigCancel();
77
78        /* List jobs for a specified client */
79       void CmdListJobs();
80
81       /* List files and directories for a specified tree item */
82       void CmdList(wxTreeItemId item);
83
84       /* Mark a treeitem (directory) or several listitems (file or directory),
85        * state defines if it should mark (1), unmark (0), or switch state (-1) */
86       void CmdMark(wxTreeItemId treeitem, long* listitems, int listsize, int state = -1);
87
88 /* General functions and variables */
89       //bool ended; /* The last command send has finished */
90
91       //long filemessages; /* When restoring, number of files restored */
92       long totfilemessages; /* When restoring, number of files to be restored */
93       wxString jobid;
94
95       /* Parse a table in tableParser */
96       wxbTableParser* CreateAndWaitForParser(wxString cmd);
97
98       /* Run a command, and waits until result is fully received,
99        * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
100        * containing the data. */
101       wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false, bool linebyline = true);
102
103       /* Run a command, and waits until prompt result is fully received,
104        * if keepresults is true, returns a valid pointer to a wxbPromptParser
105        * containing the data. */
106       wxbPromptParser* WaitForPrompt(wxString cmd, bool keepresults = false);
107
108       /* Run a dir command, and waits until result is fully received.
109        * If recurse is true, update the children too. */
110       void UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse);
111
112       /* Parse dir command results. */
113       wxString* ParseList(wxString line);
114
115       /* Sets a list item state, and update its parents and children if it is a directory */
116       void SetListItemState(long listitem, int newstate);
117
118       /* Sets a tree item state, and update its children, parents and list (if necessary) */
119       void SetTreeItemState(wxTreeItemId item, int newstate);
120       
121       /* Update a tree item parents' state */
122       void UpdateTreeItemState(wxTreeItemId item);
123
124       /* Refresh the whole tree. */
125       void RefreshTree();
126       
127       /* Refresh file list */
128       void RefreshList();
129       
130       /* Update first config, adapting settings to the job name selected */
131       void UpdateFirstConfig();
132       
133       /* Update second config */
134       bool UpdateSecondConfig(wxbDataTokenizer* dt);
135       
136 /* Status related */
137       enum status_enum
138       {
139          disabled,    // The panel is not activatable
140          activable,   // The panel is activable, but not activated
141          entered,     // The panel is activated
142          choosing,    // The user is choosing files to restore
143          listing,     // Dir listing is in progress
144          configuring, // The user is configuring restore process
145          restoring,   // Bacula is restoring files
146          finished     // Retore done (state will change in activable)
147       };
148
149       status_enum status;
150
151       /* Cancelled status :
152        *  - 0 - !cancelled
153        *  - 1 - will be cancelled
154        *  - 2 - has been cancelled */
155       int cancelled;
156
157       /* Set current status by enabling/disabling components */
158       void SetStatus(status_enum newstatus);
159
160 /* UI related */
161       bool working; // A command is running, discard GUI events
162       bool markWhenListingDone;
163       wxTreeItemId currentTreeItem; // Currently selected tree item
164
165       /* Enable or disable config controls status */
166       void EnableConfig(bool enable);
167
168 /* Event handling */
169       void OnStart(wxCommandEvent& WXUNUSED(event));
170       void OnCancel(wxCommandEvent& WXUNUSED(event));
171       
172       void OnTreeChanging(wxTreeEvent& event);
173       void OnTreeExpanding(wxTreeEvent& event);
174       void OnTreeChanged(wxTreeEvent& event);
175       void OnTreeMarked(wxbTreeMarkedEvent& event);
176       void OnTreeAdd(wxCommandEvent& WXUNUSED(event));
177       void OnTreeRemove(wxCommandEvent& WXUNUSED(event));
178       void OnTreeRefresh(wxCommandEvent& WXUNUSED(event));
179       
180       void OnListMarked(wxbListMarkedEvent& event);
181       void OnListActivated(wxListEvent& event);
182       void OnListChanged(wxListEvent& event);
183       void OnListAdd(wxCommandEvent& WXUNUSED(event));
184       void OnListRemove(wxCommandEvent& WXUNUSED(event));
185       void OnListRefresh(wxCommandEvent& WXUNUSED(event));
186       
187       void OnConfigUpdated(wxCommandEvent& event);
188       void OnConfigOk(wxCommandEvent& WXUNUSED(event));
189       void OnConfigApply(wxCommandEvent& WXUNUSED(event));
190       void OnConfigCancel(wxCommandEvent& WXUNUSED(event));
191
192 /* Components */
193       wxBoxSizer *centerSizer; /* Center sizer */
194       wxSplitterWindow *treelistPanel; /* Panel which contains tree and list */
195       wxbConfigPanel *configPanel; /* Panel which contains initial restore options */
196       wxbConfigPanel *restorePanel; /* Panel which contains final restore options */
197
198       wxImageList* imagelist; //image list for tree and list
199
200       wxButton* start;
201       wxButton* cancel;
202       
203       wxbTreeCtrl* tree;
204       wxButton* treeadd;
205       wxButton* treeremove;
206       wxButton* treerefresh;
207       
208       wxbListCtrl* list;
209       wxButton* listadd;
210       wxButton* listremove;
211       wxButton* listrefresh;
212       
213       wxGauge* gauge;
214      
215       long cfgUpdated; //keeps which config fields have been updated
216
217       friend class wxbSplitterWindow;
218
219       DECLARE_EVENT_TABLE();    
220 };
221
222 #endif // WXBRESTOREPANEL_H
223