Mercurial > mercurial > hgweb_searcher03.cgi
diff src/cache.cpp @ 11:dfcf8c973219
Implement Cache maker.
author | pyon@macmini |
---|---|
date | Wed, 07 May 2014 20:38:57 +0900 |
parents | |
children | 52958cd4a073 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cache.cpp Wed May 07 20:38:57 2014 +0900 @@ -0,0 +1,93 @@ +// Filename : cache.cpp +// Last Change: 07-May-2014. +// + +#include "cache.h" +#include "db.h" + +CacheDialog::CacheDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) + : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); + + m_datePickerBgn = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT ); + bSizerTop->Add( m_datePickerBgn, 0, wxALL, 5 ); + + m_datePickerEnd = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT ); + bSizerTop->Add( m_datePickerEnd, 0, wxALL, 5 ); + + m_buttonMake = new wxButton( this, ID_MKCACHE, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerTop->Add( m_buttonMake, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 ); + + m_buttonClose = new wxButton( this, ID_CLOSE, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonClose->SetDefault(); + bSizerTop->Add( m_buttonClose, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 ); + + this->SetSizer( bSizerTop ); + this->Layout(); + bSizerTop->Fit( this ); + + this->Centre( wxBOTH ); +} + +CacheDialog::~CacheDialog() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( CacheDialog, wxDialog ) + EVT_BUTTON( ID_MKCACHE, CacheDialog::OnMakeCache ) + EVT_BUTTON( ID_CLOSE, CacheDialog::OnClose ) +END_EVENT_TABLE() + +// Event Handlers & Functions +void CacheDialog::Setting( wxString rootdir, int w, int h ) +{ + m_rootdir = rootdir; + m_width = w; + m_height = h; +} + +void CacheDialog::OnMakeCache( wxCommandEvent& WXUNUSED(event) ) +{ + wxDateTime b = m_datePickerBgn->GetValue(); + wxDateTime e = m_datePickerEnd->GetValue(); + + MakeCache( b.Format( wxT("%Y%m%d")), e.Format( wxT("%Y%m%d")) ); +} + +void CacheDialog::MakeCache( wxString from, wxString to ) +{ + wxArrayString path = GetPathes( from, to ); + wxString cachedir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache"); + + for ( int i = 0; i < path.GetCount(); i++ ) { + + wxArrayString files; + wxDir::GetAllFiles( path[i], &files, wxT("*.*"), wxDIR_DEFAULT ); + + for ( int j = 0; j < files.GetCount(); j++ ) { + wxImage image( files[j], wxBITMAP_TYPE_JPEG ); + wxImage output = image.Scale( m_width, m_height, wxIMAGE_QUALITY_HIGH ); + + wxString buf = files[j]; + buf.Replace( m_rootdir, cachedir, false ); + buf = buf.BeforeLast( '.' ) + wxT(".png"); + + wxFileName tf( buf ); + if ( !tf.Exists() ) tf.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); + output.SaveFile( buf, wxBITMAP_TYPE_PNG ); + } + + } + + wxMessageBox( wxT("cache updated.") ); +} + +void CacheDialog::OnClose( wxCommandEvent& WXUNUSED(event) ) +{ + Close(); +} +