]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbrestorepanel.h
Some Win32 fixes
[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       /* Run a dir command, and waits until result is fully received.
98        * If recurse is true, update the children too. */
99       void UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse);
100
101       /* Parse dir command results. */
102       wxString* ParseList(wxString line);
103
104       /* Sets a list item state, and update its parents and children if it is a directory */
105       void SetListItemState(long listitem, int newstate);
106
107       /* Sets a tree item state, and update its children, parents and list (if necessary) */
108       void SetTreeItemState(wxTreeItemId item, int newstate);
109       
110       /* Update a tree item parents' state */
111       void UpdateTreeItemState(wxTreeItemId item);
112
113       /* Refresh the whole tree. */
114       void RefreshTree();
115       
116       /* Refresh file list */
117       void RefreshList();
118       
119       /* Update first config, adapting settings to the job name selected */
120       void UpdateFirstConfig();
121       
122       /* Update second config */
123       bool UpdateSecondConfig(wxbDataTokenizer* dt);
124       
125 /* Status related */
126       enum status_enum
127       {
128          disabled,    // The panel is not activatable
129          activable,   // The panel is activable, but not activated
130          entered,     // The panel is activated
131          choosing,    // The user is choosing files to restore
132          listing,     // Dir listing is in progress
133          configuring, // The user is configuring restore process
134          restoring,   // Bacula is restoring files
135          finished     // Retore done (state will change in activable)
136       };
137
138       status_enum status;
139
140       /* Cancelled status :
141        *  - 0 - !cancelled
142        *  - 1 - will be cancelled
143        *  - 2 - has been cancelled */
144       int cancelled;
145
146       /* Set current status by enabling/disabling components */
147       void SetStatus(status_enum newstatus);
148
149 /* UI related */
150       bool working; // A command is running, discard GUI events
151       void SetWorking(bool working);
152       bool IsWorking();
153       bool markWhenListingDone;
154       wxTreeItemId currentTreeItem; // Currently selected tree item
155
156       /* Enable or disable config controls status */
157       void EnableConfig(bool enable);
158
159 /* Event handling */
160 //      wxbEventList* pendingEvents; /* Stores event sent while working */ //EVTQUEUE
161 //      bool processing; /* True if pendingEvents is being processed */ //EVTQUEUE
162
163 //      virtual void AddPendingEvent(wxEvent& event);
164 //      virtual bool ProcessEvent(wxEvent& event); //EVTQUEUE
165
166       void OnStart(wxCommandEvent& event);
167       void OnCancel(wxCommandEvent& event);
168       
169       void OnTreeChanging(wxTreeEvent& event);
170       void OnTreeExpanding(wxTreeEvent& event);
171       void OnTreeChanged(wxTreeEvent& event);
172       void OnTreeMarked(wxbTreeMarkedEvent& event);
173       void OnTreeAdd(wxCommandEvent& event);
174       void OnTreeRemove(wxCommandEvent& event);
175       void OnTreeRefresh(wxCommandEvent& event);
176       
177       void OnListMarked(wxbListMarkedEvent& event);
178       void OnListActivated(wxListEvent& event);
179       void OnListChanged(wxListEvent& event);
180       void OnListAdd(wxCommandEvent& event);
181       void OnListRemove(wxCommandEvent& event);
182       void OnListRefresh(wxCommandEvent& event);
183       
184       void OnConfigUpdated(wxCommandEvent& event);
185       void OnConfigOk(wxCommandEvent& WXUNUSED(event));
186       void OnConfigApply(wxCommandEvent& WXUNUSED(event));
187       void OnConfigCancel(wxCommandEvent& WXUNUSED(event));
188
189 /* Components */
190       wxBoxSizer *centerSizer; /* Center sizer */
191       wxSplitterWindow *treelistPanel; /* Panel which contains tree and list */
192       wxbConfigPanel *configPanel; /* Panel which contains initial restore options */
193       wxbConfigPanel *restorePanel; /* Panel which contains final restore options */
194
195       wxImageList* imagelist; //image list for tree and list
196
197       wxButton* start;
198       wxButton* cancel;
199       
200       wxbTreeCtrl* tree;
201       wxButton* treeadd;
202       wxButton* treeremove;
203       wxButton* treerefresh;
204       
205       wxbListCtrl* list;
206       wxButton* listadd;
207       wxButton* listremove;
208       wxButton* listrefresh;
209       
210       wxGauge* gauge;
211      
212       long cfgUpdated; //keeps which config fields have been updated
213
214       friend class wxbSplitterWindow;
215
216       DECLARE_EVENT_TABLE();    
217 };
218
219 #endif // WXBRESTOREPANEL_H
220