comparison src/main.cpp @ 9:ae89ce4793d8

add satellite-view.
author pyon@macmini
date Wed, 31 Oct 2018 20:10:29 +0900
parents 29829e98d510
children 36811fd22bd2
comparison
equal deleted inserted replaced
8:82f9af6aa7e4 9:ae89ce4793d8
1 // Filename : main.cpp 1 // Filename : main.cpp
2 // Last Change: 2018-10-26 金 13:14:54. 2 // Last Change: 2018-10-31 水 15:18:12.
3 // 3 //
4
4 #include "id.h" 5 #include "id.h"
5 #include "main.h" 6 #include "main.h"
6 #include "auth.h" 7 #include "auth.h"
7 #include "rsearcher.h" 8 #include "rsearcher.h"
8 9
22 { 23 {
23 if ( !wxApp::OnInit() ) return false; 24 if ( !wxApp::OnInit() ) return false;
24 25
25 wxImage::AddHandler( new wxJPEGHandler ); 26 wxImage::AddHandler( new wxJPEGHandler );
26 wxImage::AddHandler( new wxPNGHandler ); 27 wxImage::AddHandler( new wxPNGHandler );
28 wxFileSystem::AddHandler( new wxZipFSHandler );
27 InitSetting(); 29 InitSetting();
28 30
29 // Main Window 31 // Main Window
30 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); 32 MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
31 mainframe->SetServer( m_serveraddr, m_serverport ); 33 mainframe->SetServer( m_serveraddr, m_serverport );
32 mainframe->GetDB(); 34 if ( !mainframe->GetDB() ) {
35 mainframe->Destroy();
36 return true;
37 }
33 38
34 // Splash Screen 39 // Splash Screen
35 wxFileSystem::AddHandler( new wxZipFSHandler ); 40 SplashScreen( splash );
36 wxFileSystem* fs = new wxFileSystem();
37 wxString archive = wxT( "file:///./myapp.bin" );
38 for ( int i = 0; i < 11; i++ ) {
39 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) );
40 if ( file ) {
41 wxInputStream* s = file->GetStream();
42 wxImage image( *s, wxBITMAP_TYPE_PNG );
43 wxBitmap bmp = wxBitmap( image );
44 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
45 delete file;
46 }
47 wxMilliSleep( 150 );
48 }
49 delete fs;
50 41
51 // User Dialgo 42 // User Dialgo
52 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); 43 AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION );
53 if ( !authdlg->LoadDB() ) { 44 if ( !authdlg->LoadDB() ) {
54 authdlg->Destroy(); 45 authdlg->Destroy();
62 } else { 53 } else {
63 unsigned int seed = (unsigned int)time( 0 ); 54 unsigned int seed = (unsigned int)time( 0 );
64 srand( seed ); 55 srand( seed );
65 int n = rand() % 13; 56 int n = rand() % 13;
66 wxFileSystem* fs = new wxFileSystem(); 57 wxFileSystem* fs = new wxFileSystem();
58 wxString archive = wxT( "file:///./myapp.bin" );
67 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) ); 59 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) );
68 if ( file ) { 60 if ( file ) {
69 wxInputStream* s = file->GetStream(); 61 wxInputStream* s = file->GetStream();
70 wxFileOutputStream of( wxT( "./image/hello.jpg" ) ); 62 wxFileOutputStream of( wxT( "./image/hello.jpg" ) );
71 s->Read( of ); 63 s->Read( of );
112 config->Read( wxT( "proxy_port" ), &m_serverport ); 104 config->Read( wxT( "proxy_port" ), &m_serverport );
113 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { 105 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) {
114 config->Read( wxT( "address" ), &m_serveraddr ); 106 config->Read( wxT( "address" ), &m_serveraddr );
115 config->Read( wxT( "port" ), &m_serverport ); 107 config->Read( wxT( "port" ), &m_serverport );
116 } 108 }
117 delete config;
118 109
119 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { 110 if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) {
120 m_serveraddr = wxT( "192.168.21.151" ); // nginx 111 m_serveraddr = wxT( "192.168.21.151" ); // nginx
121 m_serverport = 80; 112 m_serverport = 80;
122 } 113 }
114
115 config->SetPath( wxT( "/Misc" ) );
116 config->Read( wxT( "splash" ), &splash );
117
118 delete config;
123 } 119 }
124 120
125 void MyApp::SaveSetting() 121 void MyApp::SaveSetting()
126 { 122 {
127 config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); 123 config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );
132 config->Write( wxT( "w" ), rect.width ); 128 config->Write( wxT( "w" ), rect.width );
133 config->Write( wxT( "h" ), rect.height ); 129 config->Write( wxT( "h" ), rect.height );
134 delete config; 130 delete config;
135 } 131 }
136 132
133 void MyApp::SplashScreen( int ms )
134 {
135 if ( ms < 0 ) return;
136
137 wxFileSystem* fs = new wxFileSystem();
138 wxString archive = wxT( "file:///./myapp.bin" );
139 for ( int i = 0; i < 11; i++ ) {
140 wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) );
141 if ( file ) {
142 wxInputStream* s = file->GetStream();
143 wxImage image( *s, wxBITMAP_TYPE_PNG );
144 wxBitmap bmp = wxBitmap( image );
145 wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
146 delete file;
147 }
148 wxMilliSleep( ms );
149 }
150 delete fs;
151 }
152
137 void MyApp::RemoveFile( wxString pattern ) 153 void MyApp::RemoveFile( wxString pattern )
138 { 154 {
139 wxString file = wxFindFirstFile( pattern ); 155 wxString file = wxFindFirstFile( pattern );
140 while ( !file.empty() ) { 156 while ( !file.empty() ) {
141 wxRemoveFile( file ); 157 wxRemoveFile( file );