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