view src/main.cpp @ 4:06342fc544e4

mouse gesture.
author pyon@macmini
date Mon, 15 Oct 2018 20:07:38 +0900
parents db4813125eb8
children e3b10fb860b3
line wrap: on
line source

// Filename   : main.cpp
// Last Change: 2018-10-12 金 16:17:39.
//
#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  );
	InitSetting();

	wxBitmap bmp;
	if ( bmp.LoadFile( wxT( "./image/startup.png" ), wxBITMAP_TYPE_PNG ) ){
		wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 4000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
	}

    AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Check User" ), wxDefaultPosition, wxDefaultSize, wxCAPTION );
	authdlg->SetServer( m_server );

    MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxT( "Re:Searcher" ), wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
	mainframe->SetServer( m_server );

    if ( develop ) {
        authdlg->InDevelop( true );
        mainframe->InDevelop( true );
    }

    if ( authdlg->ShowModal() == wxID_OK ) {
		mainframe->SetUser( authdlg->GetUser() );
		mainframe->Show( true );
	} else {
		mainframe->Destroy();
	}
	authdlg->Destroy();

    return true;
}

int MyApp::OnExit()
{
	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 );

	wxString proxy;
    config->SetPath( wxT( "/Server" ) );
    config->Read( wxT( "server" ), &m_server );
    config->Read( wxT( "proxy" ), &proxy );
    delete config;

    if ( !proxy.IsSameAs( wxEmptyString, false ) ) m_server = proxy;
	//m_server = wxT( "192.168.79.124:80" );
    if ( m_server.IsSameAs( wxEmptyString, false ) ) 
        m_server = wxT( "192.168.21.151:80" );	// nginx
}

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;
}