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