0
|
1 // Filename : main.cpp
|
5
|
2 // Last Change: 2018-10-22 月 16:14:28.
|
0
|
3 //
|
4
|
4 #include "id.h"
|
0
|
5 #include "main.h"
|
|
6 #include "auth.h"
|
|
7 #include "rsearcher.h"
|
|
8
|
|
9 IMPLEMENT_APP( MyApp )
|
|
10
|
|
11 IMPLEMENT_CLASS( MyApp, wxApp )
|
|
12
|
|
13 MyApp::MyApp()
|
|
14 {
|
1
|
15 develop = true;
|
0
|
16 }
|
|
17 MyApp::~MyApp()
|
|
18 {
|
|
19 }
|
|
20
|
|
21 bool MyApp::OnInit()
|
|
22 {
|
|
23 if ( !wxApp::OnInit() ) return false;
|
|
24
|
|
25 wxImage::AddHandler( new wxJPEGHandler );
|
|
26 wxImage::AddHandler( new wxPNGHandler );
|
|
27 InitSetting();
|
|
28
|
5
|
29 // Splash Screen
|
|
30 wxFileSystem::AddHandler( new wxZipFSHandler );
|
|
31 wxFileSystem* fs = new wxFileSystem();
|
|
32 wxString archive = wxT( "file:///./myapp.bin" );
|
|
33 for ( int i = 0; i < 11; i++ ) {
|
|
34 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) );
|
|
35 if ( file ) {
|
|
36 wxInputStream* s = file->GetStream();
|
|
37 wxImage image( *s, wxBITMAP_TYPE_PNG );
|
|
38 wxBitmap bmp = wxBitmap( image );
|
|
39 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 3000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
|
|
40 delete file;
|
|
41 }
|
|
42 wxMilliSleep( 250 );
|
3
|
43 }
|
|
44
|
5
|
45 unsigned int seed = (unsigned int)time( 0 );
|
|
46 srand( seed );
|
|
47 int n = rand() % 13;
|
|
48 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) );
|
|
49 if ( file ) {
|
|
50 wxInputStream* s = file->GetStream();
|
|
51 wxFileOutputStream of( wxT( "./image/hello.jpg" ) );
|
|
52 s->Read( of );
|
|
53 delete file;
|
|
54 }
|
|
55 delete fs;
|
3
|
56
|
5
|
57 // Login Dialog
|
|
58 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION );
|
|
59 authdlg->SetServer( m_server );
|
|
60 if ( !authdlg->LoadDB() ) {
|
|
61 authdlg->Destroy();
|
|
62 return false;
|
|
63 }
|
1
|
64
|
3
|
65 if ( authdlg->ShowModal() == wxID_OK ) {
|
5
|
66 wxString ui = wxString::Format( wxT( "./image/" ) + authdlg->GetUser() + wxT( ".jpg" ) );
|
|
67 if ( wxFileExists( ui ) ) wxCopyFile( ui, wxT( "./image/hello.jpg" ), true );
|
|
68
|
|
69 // Main Window
|
|
70 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
|
|
71 mainframe->InDevelop( true );
|
|
72 mainframe->SetServer( m_server );
|
3
|
73 mainframe->SetUser( authdlg->GetUser() );
|
5
|
74 mainframe->LoadDB();
|
|
75 mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() );
|
3
|
76 mainframe->Show( true );
|
5
|
77 //mainframe->Destroy();
|
3
|
78 }
|
|
79 authdlg->Destroy();
|
0
|
80
|
|
81 return true;
|
|
82 }
|
|
83
|
|
84 int MyApp::OnExit()
|
|
85 {
|
|
86 SaveSetting();
|
|
87 return 0;
|
|
88 }
|
|
89
|
|
90 void MyApp::InitSetting()
|
|
91 {
|
2
|
92 conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT( "app.conf" );
|
|
93 config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
|
94
|
|
95 config->SetPath( wxT( "/Geometry" ) );
|
|
96 config->Read( wxT( "x" ), &rect.x );
|
|
97 config->Read( wxT( "y" ), &rect.y );
|
|
98 config->Read( wxT( "w" ), &rect.width );
|
|
99 config->Read( wxT( "h" ), &rect.height );
|
0
|
100
|
3
|
101 wxString proxy;
|
2
|
102 config->SetPath( wxT( "/Server" ) );
|
|
103 config->Read( wxT( "server" ), &m_server );
|
3
|
104 config->Read( wxT( "proxy" ), &proxy );
|
0
|
105 delete config;
|
2
|
106
|
3
|
107 if ( !proxy.IsSameAs( wxEmptyString, false ) ) m_server = proxy;
|
2
|
108 //m_server = wxT( "192.168.79.124:80" );
|
|
109 if ( m_server.IsSameAs( wxEmptyString, false ) )
|
|
110 m_server = wxT( "192.168.21.151:80" ); // nginx
|
0
|
111 }
|
|
112
|
|
113 void MyApp::SaveSetting()
|
|
114 {
|
3
|
115 config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
|
0
|
116
|
3
|
117 config->SetPath( wxT( "/Geometry" ) );
|
|
118 config->Write( wxT( "x" ), rect.x );
|
|
119 config->Write( wxT( "y" ), rect.y );
|
|
120 config->Write( wxT( "w" ), rect.width );
|
|
121 config->Write( wxT( "h" ), rect.height );
|
0
|
122 delete config;
|
|
123 }
|
|
124
|