]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbmainframe.h
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / wx-console / wxbmainframe.h
1 /*
2  *
3  *   Main frame header file
4  *
5  *    Nicolas Boichat, July 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 three of the GNU Affero General Public
18    License as published by the Free Software Foundation and included
19    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 Affero 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 Kern Sibbald.
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 WXBMAINFRAME_H
38 #define WXBMAINFRAME_H
39
40 #include "wx/wxprec.h"
41
42 #ifdef __BORLANDC__
43    #pragma hdrstop
44 #endif
45
46 // for all others, include the necessary headers (this file is usually all you
47 // need because it includes almost all "standard" wxWindows headers)
48 #ifndef WX_PRECOMP
49    #include "wx/wx.h"
50 #endif
51
52 #include <wx/textctrl.h>
53 #include <wx/tokenzr.h>
54 #include <wx/notebook.h>
55
56 #include <wx/dynarray.h>
57
58 #include "console_thread.h"
59
60 #include "wxbutils.h"
61
62 #include "wxbhistorytextctrl.h"
63
64 WX_DEFINE_ARRAY(wxbDataParser*, wxbDataParsers);
65
66 // ----------------------------------------------------------------------------
67 // wxbPrintObject - Used by wxbThreadEvent to contain data sent by director
68 // ----------------------------------------------------------------------------
69
70 class wxbPrintObject: public wxObject {
71    public:
72       wxString str;
73       int status;
74       wxbPrintObject(wxString str, int status): wxObject() {
75          this->str = str;
76          this->status = status;
77       }
78
79       wxbPrintObject(const wxbPrintObject& pe) {
80          this->str = pe.str;
81          this->status = pe.status;
82       }
83 };
84
85 // ----------------------------------------------------------------------------
86 // wxbThreadEvent - Event used by wxbTHREAD_EVENT
87 // ----------------------------------------------------------------------------
88
89 DECLARE_LOCAL_EVENT_TYPE(wxbTHREAD_EVENT, -1)
90
91 class wxbThreadEvent: public wxEvent {
92    public:
93       wxbThreadEvent(int id);
94       ~wxbThreadEvent();
95       wxbThreadEvent(const wxbThreadEvent& te);
96       virtual wxEvent *Clone() const;
97       wxbPrintObject* GetEventPrintObject();
98       void SetEventPrintObject(wxbPrintObject* object);
99 };
100
101 // Define a new frame type: this is going to be our main frame
102 class wxbMainFrame : public wxFrame
103 {
104 public:
105    /* this class is a singleton */
106    static wxbMainFrame* CreateInstance(const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
107    static wxbMainFrame* GetInstance();
108
109    /* event handlers (these functions should _not_ be virtual) */
110    void OnQuit(wxCommandEvent& event);
111    void OnAbout(wxCommandEvent& event);
112    void OnChangeConfig(wxCommandEvent& event);
113    void OnEditConfig(wxCommandEvent& event);
114    void OnConnect(wxCommandEvent& event);
115    void OnDisconnect(wxCommandEvent& event);
116    void OnEnter(wxCommandEvent& event);
117    void OnPrint(wxbThreadEvent& event);
118
119    /* Enable and disable panels */
120    void EnablePanels();
121    void DisablePanels(void* except = NULL);
122
123    void EnableConsole(bool enable = true);
124
125    /*
126     *  Prints data received from director to the console,
127     *  and forwards it to the panels
128     */
129    void Print(wxString str, int status);
130
131    /* Sends data to the director */
132    void Send(wxString str);
133
134    /*
135     *  Starts the thread interacting with the director
136     *  If config is not empty, uses this config file.
137     */
138    void StartConsoleThread(const wxString& config);
139
140    /* Register a new wxbDataParser */
141    void Register(wxbDataParser* dp);
142
143    /* Unregister a wxbDataParser */
144    void Unregister(wxbDataParser* dp);
145
146    console_thread* ct; /* thread interacting with the director */
147
148 private:
149    /* private constructor, singleton */
150    wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style);
151    ~wxbMainFrame();
152
153    static wxbMainFrame *frame; /* this */
154
155    wxMenu *menuFile;
156
157    wxNotebook *notebook; /* main notebook */
158    wxTextCtrl *consoleCtrl; /* wxTextCtrl containing graphical console */
159    wxStaticText *helpCtrl; /* wxStaticText showing help messages */
160    wxbHistoryTextCtrl *typeCtrl; /* wxbHistoryTextCtrl for console user input */
161    wxButton *sendButton; /* wxButton used to send data */
162
163    wxbPanel **panels; /* panels array, contained in the notebook */
164    wxbDataParsers parsers; /* Data parsers, which need to receive director informations */
165
166    wxbPromptParser* promptparser; /* prompt parser catching uncatched questions */
167
168    bool lockedbyconsole; /* true if the panels have been locked by something typed in the console */
169
170    wxString configfile; /* configfile used */
171
172    wxString consoleBuffer; /* Buffer used to print in the console line by line */
173
174    // any class wishing to process wxWindows events must use this macro
175    DECLARE_EVENT_TABLE()
176 };
177
178 #endif // WXBMAINFRAME_H