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