]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/main.cpp
7fd717a08566a3baa53ba506591d2d0c3dbe46b7
[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    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 two of the GNU General Public
18    License as published by the Free Software Foundation plus additions
19    that are listed 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 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 John Walker.
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 // ============================================================================
38 // declarations
39 // ============================================================================
40
41 // ----------------------------------------------------------------------------
42 // headers
43 // ----------------------------------------------------------------------------
44
45 /*  Windows debug builds set _DEBUG which is used by wxWidgets to select their
46  *  debug memory allocator.  Unfortunately it conflicts with Bacula's SmartAlloc.
47  * So we turn _DEBUG off since we aren't interested in things it enables.
48  */
49
50 #undef _DEBUG
51
52 #include "bacula.h"
53
54 #undef setlocale
55 #undef textdomain
56 #undef bindtextdomain
57
58 #include <wx/wxprec.h>
59 #include <wx/config.h>
60 #include <wx/intl.h>
61 #include "wxbmainframe.h"
62 #include "csprint.h"
63
64
65 /* Dummy functions */
66 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
67 int generate_job_event(JCR *jcr, const char *event) { return 1; }
68
69
70 // ----------------------------------------------------------------------------
71 // resources
72 // ----------------------------------------------------------------------------
73
74 class MyApp : public wxApp
75 {
76 public:
77    virtual bool OnInit();
78 };
79
80 // ============================================================================
81 // implementation
82 // ============================================================================
83
84 IMPLEMENT_APP(MyApp)
85
86 // ----------------------------------------------------------------------------
87 // the application class
88 // ----------------------------------------------------------------------------
89
90 // 'Main program' equivalent: the program execution "starts" here
91 bool MyApp::OnInit()
92 {
93    /* wxWidgets internationalisation */
94    wxLocale m_locale;
95    m_locale.Init();
96    m_locale.AddCatalog(wxT("bacula"));
97    wxLocale::AddCatalogLookupPathPrefix(wxT(LOCALEDIR));
98
99    long posx, posy, sizex, sizey;
100    int displayx, displayy;
101    OSDependentInit();
102    wxConfig::Get()->Read(wxT("/Position/X"), &posx, 50);
103    wxConfig::Get()->Read(wxT("/Position/Y"), &posy, 50);
104    wxConfig::Get()->Read(wxT("/Size/Width"), &sizex, 780);
105    wxConfig::Get()->Read(wxT("/Size/Height"), &sizey, 500);
106    
107    wxDisplaySize(&displayx, &displayy);
108    
109    /* Check if we are on the screen... */
110    if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
111       /* Try to move the top-left corner first */
112       posx = 50;
113       posy = 50;
114       if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
115          posx = 25;
116          posy = 25;
117          sizex = displayx - 50;
118          sizey = displayy - 50;
119       }
120    }
121
122    wxbMainFrame *frame = wxbMainFrame::CreateInstance(_("Bacula wx-console"),
123                          wxPoint(posx, posy), wxSize(sizex, sizey));
124
125    frame->Show(TRUE);
126
127    frame->Print(wxString::Format(_("Welcome to bacula wx-console %s (%s)!\n"), wxT(VERSION), wxT(BDATE)), CS_DEBUG);
128
129    frame->StartConsoleThread(wxT(""));
130    
131    return TRUE;
132 }