]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbmainframe.h
- wxbRestorePanel : Fixed problem when the newly created job is not at the end of...
[bacula/bacula] / bacula / src / wx-console / wxbmainframe.h
1 /*
2  *
3  *   Main frame header file
4  *
5  *    Nicolas Boichat, July 2004
6  *
7  */
8 /*
9    Copyright (C) 2004 Kern Sibbald and John Walker
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    as published by the Free Software Foundation; either version 2
14    of the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef WXBMAINFRAME_H
27 #define WXBMAINFRAME_H
28
29 #include "wx/wxprec.h"
30
31 #ifdef __BORLANDC__
32    #pragma hdrstop
33 #endif
34
35 // for all others, include the necessary headers (this file is usually all you
36 // need because it includes almost all "standard" wxWindows headers)
37 #ifndef WX_PRECOMP
38    #include "wx/wx.h"
39 #endif
40
41 #include <wx/textctrl.h>
42 #include <wx/tokenzr.h>
43 #include <wx/notebook.h>
44
45 #include <wx/dynarray.h>
46
47 #include "console_thread.h"
48
49 #include "wxbutils.h"
50
51 #include "wxbhistorytextctrl.h"
52
53 WX_DEFINE_ARRAY(wxbDataParser*, wxbDataParsers);
54
55 // ----------------------------------------------------------------------------
56 // wxbPrintObject - Used by wxbThreadEvent to contain data sent by director
57 // ----------------------------------------------------------------------------
58
59 class wxbPrintObject: public wxObject {
60    public:
61       wxString str;
62       int status;
63       wxbPrintObject(wxString str, int status): wxObject() {
64          this->str = str;
65          this->status = status;
66       }
67
68       wxbPrintObject(const wxbPrintObject& pe) {
69          this->str = pe.str;
70          this->status = pe.status;
71       }
72 };
73
74 // ----------------------------------------------------------------------------
75 // wxbThreadEvent - Event used by wxbTHREAD_EVENT
76 // ----------------------------------------------------------------------------
77
78 class wxbThreadEvent: public wxEvent {
79    public:
80       wxbThreadEvent(int id);
81       ~wxbThreadEvent();
82       wxbThreadEvent(const wxbThreadEvent& te);
83       virtual wxEvent *Clone() const;
84       wxbPrintObject* GetEventPrintObject();
85       void SetEventPrintObject(wxbPrintObject* object);
86 };
87
88 // Define a new frame type: this is going to be our main frame
89 class wxbMainFrame : public wxFrame
90 {
91 public:
92    /* this class is a singleton */
93    static wxbMainFrame* CreateInstance(const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
94    static wxbMainFrame* GetInstance();
95
96    /* event handlers (these functions should _not_ be virtual) */
97    void OnQuit(wxCommandEvent& event);
98    void OnAbout(wxCommandEvent& event);
99    void OnChangeConfig(wxCommandEvent& event);
100    void OnEditConfig(wxCommandEvent& event);
101    void OnConnect(wxCommandEvent& event);
102    void OnDisconnect(wxCommandEvent& event);
103    void OnEnter(wxCommandEvent& event);
104    void OnPrint(wxbThreadEvent& event);
105
106    /* Enable and disable panels */
107    void EnablePanels();
108    void DisablePanels(void* except = NULL);
109    
110    void EnableConsole(bool enable = true);
111
112    /*
113     *  Prints data received from director to the console,
114     *  and forwards it to the panels
115     */
116    void Print(wxString str, int status);
117
118    /* Sends data to the director */
119    void Send(wxString str);
120
121    /*
122     *  Starts the thread interacting with the director
123     *  If config is not empty, uses this config file.
124     */
125    void StartConsoleThread(const wxString& config);
126    
127    /* Register a new wxbDataParser */
128    void Register(wxbDataParser* dp);
129    
130    /* Unregister a wxbDataParser */
131    void Unregister(wxbDataParser* dp);
132
133    console_thread* ct; /* thread interacting with the director */
134
135 private:
136    /* private constructor, singleton */
137    wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style);
138    ~wxbMainFrame();
139    
140    static wxbMainFrame *frame; /* this */
141
142    wxMenu *menuFile;
143
144    wxNotebook *notebook; /* main notebook */
145    wxTextCtrl *consoleCtrl; /* wxTextCtrl containing graphical console */
146    wxbHistoryTextCtrl *typeCtrl; /* wxbHistoryTextCtrl for console user input */
147    wxButton *sendButton; /* wxButton used to send data */
148
149    wxbPanel **panels; /* panels array, contained in the notebook */
150    wxbDataParsers parsers; /* Data parsers, which need to receive director informations */
151
152    wxbPromptParser* promptparser; /* prompt parser catching uncatched questions */
153
154    bool lockedbyconsole; /* true if the panels have been locked by something typed in the console */
155    
156    wxString configfile; /* configfile used */
157    
158    wxString consoleBuffer; /* Buffer used to print in the console line by line */
159      
160    // any class wishing to process wxWindows events must use this macro
161    DECLARE_EVENT_TABLE()
162 };
163
164 #endif // WXBMAINFRAME_H
165