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