]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/main.cpp
Remember the last window position and size.
[bacula/bacula] / bacula / src / wx-console / main.cpp
1 /*
2  *
3  *    Bacula wx-console application
4  *
5  *    Nicolas Boichat, April 2004
6  *
7  *    Version $Id$
8  */
9 /*
10    Copyright (C) 2004 Kern Sibbald and John Walker
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    as published by the Free Software Foundation; either version 2
15    of the License, or (at your option) any later version.
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    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 // ============================================================================
28 // declarations
29 // ============================================================================
30
31 // ----------------------------------------------------------------------------
32 // headers
33 // ----------------------------------------------------------------------------
34
35 #include <wx/wxprec.h>
36 #include <wx/config.h>
37
38 #include "wxbmainframe.h"
39
40 #include "csprint.h"
41
42 /* Dummy functions */
43 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
44 int generate_job_event(JCR *jcr, const char *event) { return 1; }
45
46
47 // ----------------------------------------------------------------------------
48 // resources
49 // ----------------------------------------------------------------------------
50
51 class MyApp : public wxApp
52 {
53 public:
54    virtual bool OnInit();
55 };
56
57 // ============================================================================
58 // implementation
59 // ============================================================================
60
61 IMPLEMENT_APP(MyApp)
62
63 // ----------------------------------------------------------------------------
64 // the application class
65 // ----------------------------------------------------------------------------
66
67 // 'Main program' equivalent: the program execution "starts" here
68 bool MyApp::OnInit()
69 {
70    long posx, posy, sizex, sizey;
71    int displayx, displayy;
72    wxConfig::Get()->Read("/Position/X", &posx, 50);
73    wxConfig::Get()->Read("/Position/Y", &posy, 50);
74    wxConfig::Get()->Read("/Size/Width", &sizex, 780);
75    wxConfig::Get()->Read("/Size/Height", &sizey, 500);
76    
77    wxDisplaySize(&displayx, &displayy);
78    
79    /* Check if we are on the screen... */
80    if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
81       /* Try to move the top-left corner first */
82       posx = 50;
83       posy = 50;
84       if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
85          posx = 25;
86          posy = 25;
87          sizex = displayx - 50;
88          sizey = displayy - 50;
89       }
90    }
91
92    wxbMainFrame *frame = wxbMainFrame::CreateInstance(_T("Bacula wx-console"),
93                          wxPoint(posx, posy), wxSize(sizex, sizey));
94
95    frame->Show(TRUE);
96
97    frame->Print(wxString("Welcome to bacula wx-console ") << VERSION << " (" << BDATE << ")!\n", CS_DEBUG);
98
99    frame->StartConsoleThread("");
100    
101    return TRUE;
102 }