]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbrestorepanel.h
kes Fix code to check for two resources of same name. It forgot
[bacula/bacula] / bacula / src / wx-console / wxbrestorepanel.h
1 /*
2  *
3  *   wxbPanel for restoring files
4  *
5  *    Nicolas Boichat, April-May 2004
6  *
7  *    Version $Id$
8  */
9 /*
10    Bacula® - The Network Backup Solution
11
12    Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
13
14    The main author of Bacula is Kern Sibbald, with contributions from
15    many others, a complete list can be found in the file AUTHORS.
16    This program is Free Software; you can redistribute it and/or
17    modify it under the terms of version two of the GNU General Public
18    License as published by the Free Software Foundation plus additions
19    that are listed in the file LICENSE.
20
21    This program is distributed in the hope that it will be useful, but
22    WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24    General Public License for more details.
25
26    You should have received a copy of the GNU General Public License
27    along with this program; if not, write to the Free Software
28    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29    02110-1301, USA.
30
31    Bacula® is a registered trademark of John Walker.
32    The licensor of Bacula is the Free Software Foundation Europe
33    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34    Switzerland, email:ftf@fsfeurope.org.
35 */
36
37 #ifndef WXBRESTOREPANEL_H
38 #define WXBRESTOREPANEL_H
39
40 #include "wx/wxprec.h"
41
42 #ifndef WX_PRECOMP
43    #include "wx/wx.h"
44 #endif
45
46 #include "wxbtableparser.h"
47
48 #include <wx/thread.h>
49 #include <wx/listctrl.h>
50 #include <wx/treectrl.h>
51 #include <wx/gauge.h>
52 #include <wx/stattext.h>
53 #include <wx/splitter.h>
54
55 #include "wxbutils.h"
56
57 #include "wxbconfigpanel.h"
58 #include "wxbtreectrl.h"
59 #include "wxblistctrl.h"
60
61 WX_DECLARE_LIST(wxEvent, wxbEventList);
62
63 /* Class for storing directory entries (results from dir commands). */
64 class wxbDirEntry {
65 public:
66    wxString perm;
67    wxString nlink;
68    wxString user;
69    wxString group;
70    wxString size;
71    wxString date;
72    int marked; /* 0 - Not Marked, 1 - Marked, 2 - Some file under is marked */
73    wxString fullname; /* full name with path */
74    wxString filename; /* only filename, no path */
75 };
76
77 /*
78  * wxbPanel for restoring files
79  */
80 class wxbRestorePanel : public wxbPanel
81 {
82    public:
83       wxbRestorePanel(wxWindow* parent);
84       ~wxbRestorePanel();
85
86       /* wxbPanel overloadings */
87       virtual wxString GetTitle();
88       virtual void EnablePanel(bool enable = true);
89
90    private:
91 /* Commands called by events handler */
92
93       /* The main button has been clicked */
94       void CmdStart();
95
96       /* The cancel button has been clicked */
97       void CmdCancel();
98
99       /* Apply configuration changes */
100       void CmdConfigApply();
101
102       /* Cancel restore */
103       void CmdConfigCancel();
104
105        /* List jobs for a specified client */
106       void CmdListJobs();
107
108       /* List files and directories for a specified tree item */
109       void CmdList(wxTreeItemId item);
110
111       /* Mark a treeitem (directory) or several listitems (file or directory),
112        * state defines if it should mark (1), unmark (0), or switch state (-1) */
113       void CmdMark(wxTreeItemId treeitem, long* listitems, int listsize, int state = -1);
114
115 /* General functions and variables */
116       //bool ended; /* The last command send has finished */
117
118       //long filemessages; /* When restoring, number of files restored */
119       long totfilemessages; /* When restoring, number of files to be restored */
120       wxString jobid;
121
122       /* Run a dir command, and waits until result is fully received.
123        * If recurse is true, update the children too. */
124       void UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse);
125
126       /* Parse dir command results. */
127       int ParseList(wxString line, wxbDirEntry* entry);
128
129       /* Sets a list item state, and update its parents and children if it is a directory */
130       void SetListItemState(long listitem, int newstate);
131
132       /* Sets a tree item state, and update its children, parents and list (if necessary) */
133       void SetTreeItemState(wxTreeItemId item, int newstate);
134
135       /* Update a tree item parents' state */
136       void UpdateTreeItemState(wxTreeItemId item);
137
138       /* Refresh the whole tree. */
139       void RefreshTree();
140
141       /* Refresh file list */
142       void RefreshList();
143
144       /* Update first config, adapting settings to the job name selected */
145       void UpdateFirstConfig();
146
147       /* Update second config */
148       bool UpdateSecondConfig(wxbDataTokenizer* dt);
149
150 /* Status related */
151       enum status_enum
152       {
153          disabled,    // The panel is not activatable
154          activable,   // The panel is activable, but not activated
155          entered,     // The panel is activated
156          choosing,    // The user is choosing files to restore
157          listing,     // Dir listing is in progress
158          configuring, // The user is configuring restore process
159          restoring,   // Bacula is restoring files
160          finished     // Retore done (state will change in activable)
161       };
162
163       status_enum status;
164
165       /* Cancelled status :
166        *  - 0 - !cancelled
167        *  - 1 - will be cancelled
168        *  - 2 - has been cancelled */
169       int cancelled;
170
171       /* Set current status by enabling/disabling components */
172       void SetStatus(status_enum newstatus);
173
174 /* UI related */
175       bool working; // A command is running, discard GUI events
176       void SetWorking(bool working);
177       bool IsWorking();
178       bool markWhenCommandDone; //If an item should be (un)marked after the current listing/marking is done
179       wxTreeItemId currentTreeItem; // Currently selected tree item
180
181       /* Enable or disable config controls status */
182       void EnableConfig(bool enable);
183
184 /* Event handling */
185 //      wxbEventList* pendingEvents; /* Stores event sent while working */ //EVTQUEUE
186 //      bool processing; /* True if pendingEvents is being processed */ //EVTQUEUE
187
188 //      virtual void AddPendingEvent(wxEvent& event);
189 //      virtual bool ProcessEvent(wxEvent& event); //EVTQUEUE
190
191       void OnStart(wxCommandEvent& event);
192       void OnCancel(wxCommandEvent& event);
193
194       void OnTreeChanging(wxTreeEvent& event);
195       void OnTreeExpanding(wxTreeEvent& event);
196       void OnTreeChanged(wxTreeEvent& event);
197       void OnTreeMarked(wxbTreeMarkedEvent& event);
198       void OnTreeAdd(wxCommandEvent& event);
199       void OnTreeRemove(wxCommandEvent& event);
200       void OnTreeRefresh(wxCommandEvent& event);
201
202       void OnListMarked(wxbListMarkedEvent& event);
203       void OnListActivated(wxListEvent& event);
204       void OnListChanged(wxListEvent& event);
205       void OnListAdd(wxCommandEvent& event);
206       void OnListRemove(wxCommandEvent& event);
207       void OnListRefresh(wxCommandEvent& event);
208
209       void OnConfigUpdated(wxCommandEvent& event);
210       void OnConfigOk(wxCommandEvent& WXUNUSED(event));
211       void OnConfigApply(wxCommandEvent& WXUNUSED(event));
212       void OnConfigCancel(wxCommandEvent& WXUNUSED(event));
213
214 /* Components */
215       wxBoxSizer *centerSizer; /* Center sizer */
216       wxSplitterWindow *treelistPanel; /* Panel which contains tree and list */
217       wxbConfigPanel *configPanel; /* Panel which contains initial restore options */
218       wxbConfigPanel *restorePanel; /* Panel which contains final restore options */
219
220       wxImageList* imagelist; //image list for tree and list
221
222       wxButton* start;
223       wxButton* cancel;
224
225       wxbTreeCtrl* tree;
226       wxButton* treeadd;
227       wxButton* treeremove;
228       wxButton* treerefresh;
229
230       wxbListCtrl* list;
231       wxButton* listadd;
232       wxButton* listremove;
233       wxButton* listrefresh;
234
235       wxGauge* gauge;
236
237       long cfgUpdated; //keeps which config fields have been updated
238
239       friend class wxbSplitterWindow;
240
241       DECLARE_EVENT_TABLE();
242 };
243
244 #endif // WXBRESTOREPANEL_H