Mercurial > mercurial > hgweb_rsearcher.cgi
view src/main.cpp @ 9:ae89ce4793d8
add satellite-view.
author | pyon@macmini |
---|---|
date | Wed, 31 Oct 2018 20:10:29 +0900 |
parents | 29829e98d510 |
children | 36811fd22bd2 |
line wrap: on
line source
// Filename : main.cpp // Last Change: 2018-10-31 水 15:18:12. // #include "id.h" #include "main.h" #include "auth.h" #include "rsearcher.h" IMPLEMENT_APP( MyApp ) IMPLEMENT_CLASS( MyApp, wxApp ) MyApp::MyApp() { develop = true; } MyApp::~MyApp() { } bool MyApp::OnInit() { if ( !wxApp::OnInit() ) return false; wxImage::AddHandler( new wxJPEGHandler ); wxImage::AddHandler( new wxPNGHandler ); wxFileSystem::AddHandler( new wxZipFSHandler ); InitSetting(); // Main Window MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE ); mainframe->SetServer( m_serveraddr, m_serverport ); if ( !mainframe->GetDB() ) { mainframe->Destroy(); return true; } // Splash Screen SplashScreen( splash ); // User Dialgo AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION ); if ( !authdlg->LoadDB() ) { authdlg->Destroy(); return false; } if ( authdlg->ShowModal() == wxID_OK ) { wxString ui = wxString::Format( wxT( "./image/" ) + authdlg->GetUser() + wxT( ".jpg" ) ); if ( wxFileExists( ui ) ) { wxCopyFile( ui, wxT( "./image/hello.jpg" ), true ); } else { unsigned int seed = (unsigned int)time( 0 ); srand( seed ); int n = rand() % 13; wxFileSystem* fs = new wxFileSystem(); wxString archive = wxT( "file:///./myapp.bin" ); wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:%02d.jpg" ), n ) ); if ( file ) { wxInputStream* s = file->GetStream(); wxFileOutputStream of( wxT( "./image/hello.jpg" ) ); s->Read( of ); delete file; } delete fs; } mainframe->SetUser( authdlg->GetUser() ); mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() ); mainframe->LoadDB(); mainframe->InDevelop( true ); mainframe->Show( true ); } else { mainframe->Destroy(); } authdlg->Destroy(); return true; } int MyApp::OnExit() { RemoveFile( wxT( "auth.db" ) ); RemoveFile( wxT( "hhs.db" ) ); RemoveFile( wxT( ".cache/*" ) ); SaveSetting(); return 0; } void MyApp::InitSetting() { conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT( "app.conf" ); config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); config->SetPath( wxT( "/Geometry" ) ); config->Read( wxT( "x" ), &rect.x ); config->Read( wxT( "y" ), &rect.y ); config->Read( wxT( "w" ), &rect.width ); config->Read( wxT( "h" ), &rect.height ); config->SetPath( wxT( "/Server" ) ); config->Read( wxT( "proxy_address" ), &m_serveraddr ); config->Read( wxT( "proxy_port" ), &m_serverport ); if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { config->Read( wxT( "address" ), &m_serveraddr ); config->Read( wxT( "port" ), &m_serverport ); } if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) { m_serveraddr = wxT( "192.168.21.151" ); // nginx m_serverport = 80; } config->SetPath( wxT( "/Misc" ) ); config->Read( wxT( "splash" ), &splash ); delete config; } void MyApp::SaveSetting() { config = new wxFileConfig( wxT( "MyApp" ), wxT( "T.Mutoh" ), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); config->SetPath( wxT( "/Geometry" ) ); config->Write( wxT( "x" ), rect.x ); config->Write( wxT( "y" ), rect.y ); config->Write( wxT( "w" ), rect.width ); config->Write( wxT( "h" ), rect.height ); delete config; } void MyApp::SplashScreen( int ms ) { if ( ms < 0 ) return; wxFileSystem* fs = new wxFileSystem(); wxString archive = wxT( "file:///./myapp.bin" ); for ( int i = 0; i < 11; i++ ) { wxFSFile* file = fs->OpenFile( archive + wxString::Format( wxT( "#zip:startup%02d.png" ), i ) ); if ( file ) { wxInputStream* s = file->GetStream(); wxImage image( *s, wxBITMAP_TYPE_PNG ); wxBitmap bmp = wxBitmap( image ); wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP ); delete file; } wxMilliSleep( ms ); } delete fs; } void MyApp::RemoveFile( wxString pattern ) { wxString file = wxFindFirstFile( pattern ); while ( !file.empty() ) { wxRemoveFile( file ); file = wxFindNextFile(); } }