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