]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/main.cpp
90522cdddc587c628a3d870ab5962d640f3ed35e
[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-2006 Kern Sibbald
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    version 2 as amended with additional clauses defined in the
15    file LICENSE in the main source directory.
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    the file LICENSE for additional details.
21
22  */
23
24 // ============================================================================
25 // declarations
26 // ============================================================================
27
28 // ----------------------------------------------------------------------------
29 // headers
30 // ----------------------------------------------------------------------------
31
32 #undef _DEBUG
33
34 #include "bacula.h"
35
36 #undef setlocale
37 #undef textdomain
38 #undef bindtextdomain
39
40 #include <wx/wxprec.h>
41 #include <wx/config.h>
42 #include <wx/intl.h>
43 #include "wxbmainframe.h"
44 #include "csprint.h"
45
46
47 /* Dummy functions */
48 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
49 int generate_job_event(JCR *jcr, const char *event) { return 1; }
50
51
52 // ----------------------------------------------------------------------------
53 // resources
54 // ----------------------------------------------------------------------------
55
56 class MyApp : public wxApp
57 {
58 public:
59    virtual bool OnInit();
60 };
61
62 // ============================================================================
63 // implementation
64 // ============================================================================
65
66 IMPLEMENT_APP(MyApp)
67
68 // ----------------------------------------------------------------------------
69 // the application class
70 // ----------------------------------------------------------------------------
71
72 // 'Main program' equivalent: the program execution "starts" here
73 bool MyApp::OnInit()
74 {
75    /* wxWidgets internationalisation */
76    wxLocale m_locale;
77    m_locale.Init();
78    m_locale.AddCatalog(wxT("bacula"));
79    wxLocale::AddCatalogLookupPathPrefix(wxT(LOCALEDIR));
80
81    long posx, posy, sizex, sizey;
82    int displayx, displayy;
83    OSDependentInit();
84    wxConfig::Get()->Read(wxT("/Position/X"), &posx, 50);
85    wxConfig::Get()->Read(wxT("/Position/Y"), &posy, 50);
86    wxConfig::Get()->Read(wxT("/Size/Width"), &sizex, 780);
87    wxConfig::Get()->Read(wxT("/Size/Height"), &sizey, 500);
88    
89    wxDisplaySize(&displayx, &displayy);
90    
91    /* Check if we are on the screen... */
92    if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
93       /* Try to move the top-left corner first */
94       posx = 50;
95       posy = 50;
96       if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
97          posx = 25;
98          posy = 25;
99          sizex = displayx - 50;
100          sizey = displayy - 50;
101       }
102    }
103
104    wxbMainFrame *frame = wxbMainFrame::CreateInstance(_("Bacula wx-console"),
105                          wxPoint(posx, posy), wxSize(sizex, sizey));
106
107    frame->Show(TRUE);
108
109    frame->Print(wxString::Format(_("Welcome to bacula wx-console %s (%s)!\n"), wxT(VERSION), wxT(BDATE)), CS_DEBUG);
110
111    frame->StartConsoleThread(wxT(""));
112    
113    return TRUE;
114 }