0
|
1 // Filename : main.cpp
|
22
|
2 // Last Change: 25-Dec-2014.
|
0
|
3 //
|
|
4 #include "main.h"
|
|
5 #include "myframe.h"
|
19
|
6 #include "miniframe.h"
|
|
7 #include "wx/cmdline.h"
|
0
|
8
|
|
9 IMPLEMENT_APP(MyApp)
|
|
10
|
|
11 IMPLEMENT_CLASS( MyApp, wxApp )
|
|
12
|
|
13 MyApp::MyApp()
|
|
14 {
|
|
15 }
|
|
16 MyApp::~MyApp()
|
|
17 {
|
|
18 }
|
|
19
|
|
20 bool MyApp::OnInit()
|
|
21 {
|
|
22 if ( !wxApp::OnInit() ) return false;
|
|
23
|
|
24 wxImage::AddHandler( new wxJPEGHandler );
|
|
25 wxImage::AddHandler( new wxPNGHandler );
|
|
26
|
|
27 InitLog();
|
|
28 InitSetting();
|
|
29
|
19
|
30 if ( mode == 1 ) {
|
|
31 MiniFrame *miniframe = new MiniFrame( NULL, ID_MAIN, wxT("Mini Searcher"), wxDefaultPosition, wxSize( 100, 45 ), wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCAPTION|wxCLOSE_BOX|wxCLIP_CHILDREN );
|
|
32 miniframe->Show( true );
|
|
33 }
|
|
34 else {
|
|
35 MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, wxT("Searcher 03"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE );
|
|
36 mainframe->SetSize( rect );
|
|
37 mainframe->Show( true );
|
22
|
38 if ( mode == 0 )
|
|
39 mainframe->DisableMover();
|
19
|
40 }
|
0
|
41
|
|
42 return true;
|
|
43 }
|
|
44
|
|
45 int MyApp::OnExit()
|
|
46 {
|
|
47 SaveSetting();
|
|
48 return 0;
|
|
49 }
|
|
50
|
|
51 void MyApp::InitSetting()
|
|
52 {
|
|
53 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf");
|
|
54 config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
|
55
|
|
56 config->SetPath( wxT("/Geometry") );
|
19
|
57 config->Read( wxT("mode"), &mode );
|
0
|
58 config->Read( wxT("x"), &rect.x );
|
|
59 config->Read( wxT("y"), &rect.y );
|
|
60 config->Read( wxT("w"), &rect.width );
|
|
61 config->Read( wxT("h"), &rect.height );
|
1
|
62 delete config;
|
0
|
63
|
|
64 WriteLog( wxT("Setting Parameters read.") );
|
|
65 }
|
|
66
|
|
67 void MyApp::SaveSetting()
|
|
68 {
|
1
|
69 config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
|
70
|
0
|
71 config->SetPath( wxT("/Geometry") );
|
|
72 config->Write( wxT("x"), rect.x );
|
|
73 config->Write( wxT("y"), rect.y );
|
|
74 config->Write( wxT("w"), rect.width );
|
|
75 config->Write( wxT("h"), rect.height );
|
|
76 delete config;
|
|
77
|
|
78 WriteLog( wxT("Setting Parameters saved.") );
|
|
79 }
|
|
80
|
|
81 void MyApp::InitLog()
|
|
82 {
|
|
83 log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("log");
|
|
84 wxTextFile file( log_file );
|
|
85
|
|
86 if ( file.Exists() ) {
|
|
87 wxString log_bak = log_file + wxT(".bak");
|
|
88 wxRenameFile( log_file, log_bak, true );
|
|
89 }
|
|
90
|
|
91 file.Create();
|
|
92 WriteLog( wxT("[Application start...]") );
|
|
93 }
|
|
94
|
|
95 void MyApp::WriteLog( wxString msg )
|
|
96 {
|
|
97 wxDateTime now = wxDateTime::Now();
|
|
98 wxTextFile logfile;
|
|
99 logfile.Open( log_file );
|
|
100 logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg );
|
|
101 logfile.Write();
|
|
102 logfile.Close();
|
|
103 }
|
|
104
|