]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbrestorepanel.h
015a6d4ceef995fb8f5590f9c466805b91053447
[bacula/bacula] / bacula / src / wx-console / wxbrestorepanel.h
1 /*
2    Copyright (C) 2004 Kern Sibbald and John Walker
3
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.
8
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.
13
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.
17  */
18
19 #ifndef WXBRESTOREPANEL_H
20 #define WXBRESTOREPANEL_H
21
22 #include "wx/wxprec.h"
23
24 #ifndef WX_PRECOMP
25    #include "wx/wx.h"
26 #endif
27
28 #include "wxbtableparser.h"
29
30 #include <wx/thread.h>
31 #include <wx/listctrl.h>
32 #include <wx/treectrl.h>
33 #include <wx/gauge.h>
34 #include <wx/stattext.h>
35
36 #include "wxbutils.h"
37
38 #include "wxbconfigpanel.h"
39 #include "wxbtreectrl.h"
40 #include "wxblistctrl.h"
41
42 class wxbTreeListPanel;
43
44 /*
45  * wxbPanel for restoring files
46  */
47 class wxbRestorePanel : public wxbPanel
48 {
49    public:
50       wxbRestorePanel(wxWindow* parent);
51       ~wxbRestorePanel();
52
53       /* wxbPanel overloadings */
54       virtual wxString GetTitle();
55       virtual void EnablePanel(bool enable = true);
56
57    private:
58 /* Commands called by events handler */
59
60       /* The main button has been clicked */
61       void CmdStart();
62
63       /* The cancel button has been clicked */
64       void CmdCancel();
65
66       /* Apply configuration changes */
67       void CmdConfigApply();
68
69       /* Cancel restore */
70       void CmdConfigCancel();
71
72        /* List jobs for a specified client */
73       void CmdListJobs();
74
75       /* List files and directories for a specified tree item */
76       void CmdList(wxTreeItemId item);
77
78       /* Mark a treeitem (directory) or a listitem (file or directory) */
79       void CmdMark(wxTreeItemId treeitem, long listitem);
80
81 /* General functions and variables */
82       //bool ended; /* The last command send has finished */
83
84       //long filemessages; /* When restoring, number of files restored */
85       long totfilemessages; /* When restoring, number of files to be restored */
86       wxString jobid;
87
88       /* Parse a table in tableParser */
89       wxbTableParser* CreateAndWaitForParser(wxString cmd);
90
91       /* Run a command, and waits until result is fully received,
92        * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
93        * containing the data. */
94       wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false, bool linebyline = true);
95
96       /* Run a command, and waits until prompt result is fully received,
97        * if keepresults is true, returns a valid pointer to a wxbPromptParser
98        * containing the data. */
99       wxbPromptParser* WaitForPrompt(wxString cmd, bool keepresults = false);
100
101       /* Run a dir command, and waits until result is fully received. */
102       void UpdateTreeItem(wxTreeItemId item, bool updatelist);
103
104       /* Parse dir command results. */
105       wxString* ParseList(wxString line);
106
107       /* Sets a list item state, and update its parents and children if it is a directory */
108       void SetListItemState(long listitem, int newstate);
109
110       /* Sets a tree item state, and update its children, parents and list (if necessary) */
111       void SetTreeItemState(wxTreeItemId item, int newstate);
112       
113       /* Update a tree item parents' state */
114       void UpdateTreeItemState(wxTreeItemId item);
115
116       /* Refresh a tree item, and all its children. */
117       void RefreshTree(wxTreeItemId item);
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       bool markWhenListingDone;
152       wxTreeItemId currentTreeItem; // Currently selected tree item
153
154       /* Enable or disable config controls status */
155       void EnableConfig(bool enable);
156
157 /* Event handling */
158       void OnStart(wxEvent& WXUNUSED(event));
159       void OnCancel(wxEvent& WXUNUSED(event));
160       void OnTreeChanging(wxTreeEvent& event);
161       void OnTreeExpanding(wxTreeEvent& event);
162       void OnTreeChanged(wxTreeEvent& event);
163       void OnTreeMarked(wxbTreeMarkedEvent& event);
164       void OnListMarked(wxbListMarkedEvent& event);
165       void OnListActivated(wxListEvent& event);
166       void OnConfigUpdated(wxCommandEvent& event);
167       void OnConfigOk(wxEvent& WXUNUSED(event));
168       void OnConfigApply(wxEvent& WXUNUSED(event));
169       void OnConfigCancel(wxEvent& WXUNUSED(event));
170
171 /* Components */
172       wxBoxSizer *centerSizer; /* Center sizer */
173       wxbTreeListPanel *treelistPanel; /* Panel which contains tree and list */
174       wxbConfigPanel *configPanel; /* Panel which contains initial restore options */
175       wxbConfigPanel *restorePanel; /* Panel which contains final restore options */
176
177       wxImageList* imagelist; //image list for tree and list
178
179       wxButton* start;
180       wxButton* cancel;
181       wxbTreeCtrl* tree;
182       wxbListCtrl* list;
183       wxGauge* gauge;
184
185       /*wxButton*     cfgOk;
186       wxButton*     cfgApply;
187       wxButton*     cfgCancel;*/
188       
189       long cfgUpdated; //keeps which config fields have been updated
190       
191       /*wxStaticText* cfgJobname;
192       wxStaticText* cfgBootstrap;
193       wxTextCtrl*   cfgWhere;
194       wxChoice*     cfgReplace;
195       wxChoice*     cfgFileset;
196       wxChoice*     cfgClient;
197       wxStaticText* cfgStorage;
198       wxTextCtrl*   cfgWhen;
199       wxTextCtrl*   cfgPriority;*/
200
201       friend class wxbTreeListPanel;
202
203       DECLARE_EVENT_TABLE();    
204 };
205
206 class wxbTreeListPanel: public wxPanel {
207 public:
208      wxbTreeListPanel(wxbRestorePanel* parent);
209 private:
210      void OnTreeMarked(wxbTreeMarkedEvent& event);
211      void OnListMarked(wxbListMarkedEvent& event);
212      DECLARE_EVENT_TABLE(); 
213      wxbRestorePanel* parent;
214 };
215
216 #endif // WXBRESTOREPANEL_H
217