view src/main.cpp @ 22:92188f60323d default tip

Implement Masking function on Preview Dialog.
author pyon@macmini
date Sat, 04 Apr 2015 17:23:46 +0900
parents 3bb803d8c1d7
children
line wrap: on
line source

// Filename   : main.cpp
// Last Change: 25-Dec-2014.
//
#include "main.h"
#include "myframe.h"
#include "miniframe.h"
#include "wx/cmdline.h"

IMPLEMENT_APP(MyApp)

IMPLEMENT_CLASS( MyApp, wxApp )

MyApp::MyApp()
{
}
MyApp::~MyApp()
{
}

bool MyApp::OnInit()
{
    if ( !wxApp::OnInit() ) return false;

    wxImage::AddHandler( new wxJPEGHandler );
    wxImage::AddHandler( new wxPNGHandler );

    InitLog();
    InitSetting();

    if ( mode == 1 ) {
        MiniFrame *miniframe = new MiniFrame( NULL, ID_MAIN, wxT("Mini Searcher"), wxDefaultPosition, wxSize( 100, 45 ), wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCAPTION|wxCLOSE_BOX|wxCLIP_CHILDREN );
        miniframe->Show( true );
    }
    else {
        MyFrame *mainframe = new MyFrame( NULL, ID_MAIN, wxT("Searcher 03"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE );
        mainframe->SetSize( rect );
        mainframe->Show( true );
        if ( mode == 0 )
            mainframe->DisableMover();
    }

    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("mode"), &mode );
    config->Read( wxT("x"), &rect.x );
    config->Read( wxT("y"), &rect.y );
    config->Read( wxT("w"), &rect.width );
    config->Read( wxT("h"), &rect.height );
    delete config;

    WriteLog( wxT("Setting Parameters read.") );
}

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;

    WriteLog( wxT("Setting Parameters saved.") );
}

void MyApp::InitLog()
{
    log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("log");
    wxTextFile file( log_file );

    if ( file.Exists() ) {
        wxString log_bak = log_file + wxT(".bak");
        wxRenameFile( log_file, log_bak, true );
    }

    file.Create();
    WriteLog( wxT("[Application start...]") );
}

void MyApp::WriteLog( wxString msg )
{
    wxDateTime now = wxDateTime::Now();
    wxTextFile logfile;
    logfile.Open( log_file );
    logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg );
    logfile.Write();
    logfile.Close();
}