]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbrestorepanel.h
7ebe34cd3c4e3ac9e05f12552b3a76b6790162d6
[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 "wxbtreectrl.h"
39 #include "wxblistctrl.h"
40
41 class wxbTreeListPanel;
42
43 /*
44  * wxbPanel for restoring files
45  */
46 class wxbRestorePanel : public wxbPanel
47 {
48    public:
49       wxbRestorePanel(wxWindow* parent);
50       ~wxbRestorePanel();
51
52       /* wxbPanel overloadings */
53       virtual wxString GetTitle();
54       virtual void EnablePanel(bool enable = true);
55
56    private:
57 /* Commands called by events handler */
58
59       /* The main button has been clicked */
60       void CmdStart();
61
62       /* Apply configuration changes */
63       void CmdConfigApply();
64
65       /* Cancel restore */
66       void CmdConfigCancel();
67
68        /* List jobs for a specified client */
69       void CmdListJobs();
70
71       /* List files and directories for a specified tree item */
72       void CmdList(wxTreeItemId item);
73
74       /* Mark a treeitem (directory) or a listitem (file or directory) */
75       void CmdMark(wxTreeItemId treeitem, long listitem);
76
77 /* General functions and variables */
78       bool ended; /* The last command send has finished */
79
80       long filemessages; /* When restoring, number of files restored */
81       long totfilemessages; /* When restoring, number of files to be restored */
82
83       /* Parse a table in tableParser */
84       wxbTableParser* CreateAndWaitForParser(wxString cmd);
85
86       /* Run a command, and waits until result is fully received,
87        * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
88        * containing the data. */
89       wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false);
90
91       /* Run a dir command, and waits until result is fully received. */
92       void UpdateTreeItem(wxTreeItemId item, bool updatelist);
93
94       /* Parse dir command results. */
95       wxString* ParseList(wxString line);
96
97       /* Sets a list item state, and update its parents and children if it is a directory */
98       void SetListItemState(long listitem, int newstate);
99
100       /* Sets a tree item state, and update its children, parents and list (if necessary) */
101       void SetTreeItemState(wxTreeItemId item, int newstate);
102       
103       /* Update a tree item parents' state */
104       void UpdateTreeItemState(wxTreeItemId item);
105
106       /* Refresh a tree item, and all its children. */
107       void RefreshTree(wxTreeItemId item);
108       
109       /* Update config */
110       bool UpdateConfig(wxbDataTokenizer* dt);
111       
112 /* Status related */
113       enum status_enum
114       {
115          disabled,    // The panel is not activatable
116          activable,   // The panel is activable, but not activated
117          entered,     // The panel is activated
118          choosing,    // The user is choosing files to restore
119          listing,     // Dir listing is in progress
120          configuring, // The user is configuring restore process
121          restoring,   // Bacula is restoring files
122          finished     // Retore done (state will change in activable)
123       };
124
125       status_enum status;
126
127       /* Set current status by enabling/disabling components */
128       void SetStatus(status_enum newstatus);
129
130 /* UI related */
131       bool working; // A command is running, discard GUI events
132       wxTreeItemId currentTreeItem; // Currently selected tree item
133
134       /* Enable or disable config controls status */
135       void EnableConfig(bool enable);
136
137 /* Event handling */
138       void OnStart(wxEvent& WXUNUSED(event));
139       void OnTreeChanging(wxTreeEvent& event);
140       void OnTreeExpanding(wxTreeEvent& event);
141       void OnTreeChanged(wxTreeEvent& event);
142       void OnTreeMarked(wxbTreeMarkedEvent& event);
143       void OnListMarked(wxbListMarkedEvent& event);
144       void OnListActivated(wxListEvent& event);
145       void OnClientChoiceChanged(wxCommandEvent& event);
146       void OnConfigUpdated(wxCommandEvent& event);
147       void OnConfigOk(wxEvent& WXUNUSED(event));
148       void OnConfigApply(wxEvent& WXUNUSED(event));
149       void OnConfigCancel(wxEvent& WXUNUSED(event));
150
151 /* Components */
152       wxBoxSizer *centerSizer; /* Center sizer */
153       wxbTreeListPanel *treelistPanel; /* Panel which contains tree and list */
154       wxPanel *restorePanel; /* Panel which contains restore options */
155
156       wxImageList* imagelist; //image list for tree and list
157
158       wxButton* start;
159       wxChoice* clientChoice;
160       wxChoice* jobChoice;
161       wxbTreeCtrl* tree;
162       wxbListCtrl* list;
163       wxGauge* gauge;
164
165       wxButton*     cfgOk;
166       wxButton*     cfgApply;
167       wxButton*     cfgCancel;
168       
169       long cfgUpdated; //keeps which config fields are updated
170       
171       wxStaticText* cfgJobname;
172       wxStaticText* cfgBootstrap;
173       wxTextCtrl*   cfgWhere;
174       wxChoice*     cfgReplace;
175       wxStaticText* cfgFileset;
176       wxStaticText* cfgClient;
177       wxStaticText* cfgStorage;
178       wxTextCtrl*   cfgWhen;
179       wxTextCtrl*   cfgPriority;
180
181       friend class wxbTreeListPanel;
182
183       DECLARE_EVENT_TABLE();    
184 };
185
186 class wxbTreeListPanel: public wxPanel {
187 public:
188      wxbTreeListPanel(wxbRestorePanel* parent);
189 private:
190      void OnTreeMarked(wxbTreeMarkedEvent& event);
191      void OnListMarked(wxbListMarkedEvent& event);
192      DECLARE_EVENT_TABLE(); 
193      wxbRestorePanel* parent;
194 };
195
196 #endif // WXBRESTOREPANEL_H
197