]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbutils.h
Fix some trivial errors and implemented the restore of IRIX xattrs.
[bacula/bacula] / bacula / src / wx-console / wxbutils.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *   wxbDataParser, class that receives and analyses data
31  *   wxbPanel, main frame's notebook panels
32  *
33  *    Nicolas Boichat, April-July 2004
34  *
35  *   Version $Id$
36  */
37
38 #ifndef WXBUTILS_H
39 #define WXBUTILS_H
40
41 #include "wx/wxprec.h"
42
43 #ifndef WX_PRECOMP
44    #include "wx/wx.h"
45 #endif
46
47 class wxbTableParser;
48 class wxbDataParser;
49 class wxbDataTokenizer;
50 class wxbPromptParser;
51
52 /*
53  *  General functions
54  */
55 class wxbUtils
56 {
57    public:
58       /* Initialization */
59       static void Init();
60
61       /* Reset state */
62       static void Reset();
63
64       /* Parse a table in tableParser */
65       static wxbTableParser* CreateAndWaitForParser(wxString cmd);
66
67       /* Run a command, and waits until result is fully received,
68        * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
69        * containing the data. */
70       static wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false, bool linebyline = true);
71
72       /* Run a command, and waits until prompt result is fully received,
73        * if keepresults is true, returns a valid pointer to a wxbPromptParser
74        * containing the data. */
75       static wxbPromptParser* WaitForPrompt(wxString cmd, bool keepresults = false);
76       
77       /* Sleeps during milliseconds (wrapper for wxUsleep (2.4) or wxMilliSleep (2.6)) */
78       static void MilliSleep(unsigned long milliseconds);
79       
80       static wxString ConvertToPrintable(wxString& str);
81       
82    private:
83       static bool inited;
84 };
85
86 /*
87  *  abstract class that can receive director information.
88  */
89 class wxbDataParser
90 {
91    public:
92       /* Creates a new wxbDataParser, and register it in wxbMainFrame
93        * lineanalysis : indicate if date is to be analysed line by line (true)
94        * or packet by packet (false).
95        */
96       wxbDataParser(bool lineanalysis);
97
98       /* Destroy a wxbDataParser, and unregister it in wxbMainFrame */
99       virtual ~wxbDataParser();
100
101       /*
102        * Receives director information, forwarded by wxbMainFrame, and sends it
103        * line by line to the virtual function Analyse.
104        *
105        * Returns true if status == CS_PROMPT and the message has been parsed
106        * correctly.
107        */
108       bool Print(wxString str, int status);
109
110       /*
111        *   Receives data to analyse.
112        */
113       virtual bool Analyse(wxString str, int status) = 0;
114    private:
115       bool lineanalysis;
116       wxString buffer;
117 };
118
119 /*
120  *  abstract panel that can receive director information.
121  */
122 class wxbPanel : public wxPanel
123 {
124    public:
125       wxbPanel(wxWindow* parent) : wxPanel(parent) {}
126
127       /*
128        *   Tab title in the notebook.
129        */
130       virtual wxString GetTitle() = 0;
131
132       /*
133        *   Enable or disable this panel
134        */
135       virtual void EnablePanel(bool enable = true) = 0;
136 };
137
138 /*
139  *  Receives director information, and splits it by line.
140  *
141  * datatokenizer[0] retrieves first line
142  */
143 class wxbDataTokenizer: public wxbDataParser, public wxArrayString
144 {
145    public:
146       /* Creates a new wxbDataTokenizer */
147       wxbDataTokenizer(bool linebyline);
148
149       /* Destroy a wxbDataTokenizer */
150       virtual ~wxbDataTokenizer();
151
152       /*
153        *   Receives data to analyse.
154        */
155       virtual bool Analyse(wxString str, int status);
156
157       /* Returns true if the last signal received was an end signal,
158        * indicating that no more data is available */
159       bool hasFinished();
160
161    private:
162       bool finished;
163 };
164
165 /*
166  *  Receives director information, and check if the last messages are questions.
167  */
168 class wxbPromptParser: public wxbDataParser
169 {
170    public:
171       /* Creates a new wxbDataTokenizer */
172       wxbPromptParser();
173
174       /* Destroy a wxbDataTokenizer */
175       virtual ~wxbPromptParser();
176
177       /*
178        *   Receives data to analyse.
179        */
180       virtual bool Analyse(wxString str, int status);
181
182       /* Returns true if the last signal received was an prompt signal,
183        * or an end signal */
184       bool hasFinished();
185
186       /* Returns true if the last message received is a prompt message */
187       bool isPrompt();
188
189       /* Returns multiple choice question's introduction */
190       wxString getIntroString();
191
192       /* Returns question string */
193       wxString getQuestionString();
194
195       /* Returns a wxArrayString containing the indexed choices we have
196        * to answer the question, or NULL if this question is not a multiple
197        * choice one. */
198       wxArrayString* getChoices();
199
200       /* Returns true if the expected answer to the choice list is a number,
201        * false if it is a string (for example yes/mod/no). */
202       bool isNumericalChoice();
203
204    private:
205       bool finished;
206       bool prompt;
207       bool numerical;
208       wxString introStr;
209       wxArrayString* choices;
210       wxString questionStr;
211 };
212
213 #endif // WXBUTILS_H