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