Mercurial > mercurial > hgweb_mover2.cgi
changeset 11:9b0840b0be7e
cache done.
author | pyon@macmini |
---|---|
date | Sun, 23 Oct 2011 07:43:34 +0900 |
parents | 1fda3a06c39b |
children | 6ed3b64ed39a |
files | .hgignore TODO include/cache.h include/common.h include/main.h include/myframe.h include/param.h makefile src/main.cpp src/myframe.cpp src/param.cpp |
diffstat | 9 files changed, 131 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Oct 21 07:58:23 2011 +0900 +++ b/.hgignore Sun Oct 23 07:43:34 2011 +0900 @@ -8,4 +8,5 @@ *.app/* .DS_Store *.conf +log *~
--- a/TODO Fri Oct 21 07:58:23 2011 +0900 +++ b/TODO Sun Oct 23 07:43:34 2011 +0900 @@ -1,8 +1,6 @@ ====================================================================== TODO ====================================================================== -* backgound workdir check -* cache detect result * d&d image ----------------------------------------------------------------------
--- a/include/cache.h Fri Oct 21 07:58:23 2011 +0900 +++ b/include/cache.h Sun Oct 23 07:43:34 2011 +0900 @@ -1,5 +1,5 @@ // Filename : cache.h -// Last Change: 21-Oct-2011. +// Last Change: 22-Oct-2011. // #ifndef __cache__ #define __cache__ @@ -9,30 +9,14 @@ public: wxString filename; // key wxString fullpathname; - wxString z, l; + wxString modtime; + float z; + long l; + bool marksheet; wxBitmap thumbnail; - bool marksheet; + bool exists; }; -WX_DECLARE_HASH_MAP( wxString, CacheItem*, wxStringHash, wxStringEqual, CacheHash ); - -class Cache -{ -public: - wxString key; - CacheHash ch; - wxString m_dir; - - bool IsCached( wxString file ); - void UpdateCache(); -}; - -bool Cache::IsCached( wxString file ) -{ - Cache* i = new Cache; - return false; -} - #endif // __cache__
--- a/include/common.h Fri Oct 21 07:58:23 2011 +0900 +++ b/include/common.h Sun Oct 23 07:43:34 2011 +0900 @@ -1,5 +1,5 @@ // Filename : common.h -// Last Change: 19-Oct-2011. +// Last Change: 22-Oct-2011. // #ifndef __COMMON__ #define __COMMON__ @@ -32,6 +32,7 @@ #include <wx/combobox.h> #include <wx/progdlg.h> #include <wx/frame.h> + #include <wx/textfile.h> #endif enum { @@ -55,7 +56,10 @@ ID_BUTTONDEL, ID_BUTTONUNDO, + ID_TIMER, + // param + }; #endif // __COMMON__
--- a/include/main.h Fri Oct 21 07:58:23 2011 +0900 +++ b/include/main.h Sun Oct 23 07:43:34 2011 +0900 @@ -1,11 +1,10 @@ // Filename : main.h -// Last Change: 19-Oct-2011. +// Last Change: 22-Oct-2011. // #include "wx/wx.h" #include "wx/config.h" #include "wx/fileconf.h" -//#include "symbol.h" #define MYAPPNAME wxT("AMover2") #define VER 2 @@ -24,10 +23,13 @@ virtual bool OnInit(); virtual int OnExit(); void ConfInit(); + void InitLog(); + void WriteLog( wxString msg ); wxFileConfig *config; wxString conf_file; wxRect rect; + wxString workdir; wxString lmin; wxString lmax;
--- a/include/myframe.h Fri Oct 21 07:58:23 2011 +0900 +++ b/include/myframe.h Sun Oct 23 07:43:34 2011 +0900 @@ -1,11 +1,13 @@ // Filename : myframe.h -// Last Change: 20-Oct-2011. +// Last Change: 22-Oct-2011. // #ifndef __myframe__ #define __myframe__ #include "common.h" +#include "cache.h" +WX_DECLARE_HASH_MAP( wxString, CacheItem*, wxStringHash, wxStringEqual, CacheHash ); class MyFrame : public wxFrame { @@ -13,6 +15,8 @@ private: wxImageList* m_imageList; wxArrayString m_undo; + wxTimer m_timer; + CacheHash CH; protected: wxMenuBar* m_menubarFile; @@ -61,8 +65,10 @@ void OnDelete(wxCommandEvent& event); void OnUndo(wxCommandEvent& event); void ReadyImage(void); - void WatchDir(void); + void UpdateCache(void); // $B0J2<!$Dj7?$b$N(B + void OnTimer(wxTimerEvent& event); + void OnIdle(wxIdleEvent& event); void OnWinSize(wxSizeEvent& event); void OnWinMove(wxMoveEvent& event); void TellLocation( void );
--- a/makefile Fri Oct 21 07:58:23 2011 +0900 +++ b/makefile Sun Oct 23 07:43:34 2011 +0900 @@ -1,6 +1,6 @@ # # Makefile for wxWidgets Application -# Last Change: 21-Oct-2011. +# Last Change: 22-Oct-2011. # by Takayuki Mutoh # @@ -98,11 +98,11 @@ endif -$(OBJDIR)/main.o: main.cpp main.h myframe.h common.h testframe.cpp +$(OBJDIR)/main.o: main.cpp main.h myframe.h common.h cache.h -mkdir -p $(OBJDIR) $(CXX) -c $< -o $@ $(CPPFLAGS) -$(OBJDIR)/myframe.o: myframe.cpp myframe.h common.h main.h marksheet.h dndfile.h cache.h +$(OBJDIR)/myframe.o: myframe.cpp myframe.h common.h main.h marksheet.h dndfile.h $(CXX) -c $< -o $@ $(CPPFLAGS) $(OBJDIR)/param.o: param.cpp param.h common.h main.h
--- a/src/main.cpp Fri Oct 21 07:58:23 2011 +0900 +++ b/src/main.cpp Sun Oct 23 07:43:34 2011 +0900 @@ -1,5 +1,5 @@ // Filename : main.cpp -// Last Change: 18-Oct-2011. +// Last Change: 22-Oct-2011. // #include "common.h" @@ -26,6 +26,7 @@ wxImage::AddHandler( new wxPNGHandler ); ConfInit(); + InitLog(); wxString progname = wxT("A Mover"); wxString verstr = wxString::Format( wxT(" - v%d.%d ( build %d )"), VER, REV, BLD ); @@ -86,3 +87,23 @@ config->Read( wxT("zmax"), &zmax ); } +void MyApp::InitLog() +{ + wxDateTime now = wxDateTime::Now(); + wxTextFile logfile; + logfile.Open(wxT("log")); + logfile.Clear(); + logfile.AddLine( now.Format(wxT("%F %T ")) + wxT("[Application start...]") ); + logfile.Write(); + logfile.Close(); +} +void MyApp::WriteLog( wxString msg ) +{ + wxDateTime now = wxDateTime::Now(); + wxTextFile logfile; + logfile.Open(wxT("log")); + logfile.AddLine( now.Format(wxT("%F %T ")) + msg ); + logfile.Write(); + logfile.Close(); +} +
--- a/src/myframe.cpp Fri Oct 21 07:58:23 2011 +0900 +++ b/src/myframe.cpp Sun Oct 23 07:43:34 2011 +0900 @@ -1,5 +1,5 @@ // Filename : myframe.cpp -// Last Change: 21-Oct-2011. +// Last Change: 23-Oct-2011. // #include "main.h" @@ -7,7 +7,6 @@ #include "param.h" #include "dndfile.h" #include "marksheet.h" -#include "cache.h" // resources // the application icon (under Windows and OS/2 it is in resources and even @@ -167,8 +166,7 @@ m_statusBar->SetStatusText( wxEmptyString, 0 ); this->Centre( wxBOTH ); - - Cache cache; + m_timer.SetOwner( this, ID_TIMER ); } // destructor @@ -178,6 +176,8 @@ // Event Table BEGIN_EVENT_TABLE( MyFrame, wxFrame ) + EVT_IDLE( MyFrame::OnIdle ) + EVT_TIMER( ID_TIMER, MyFrame::OnTimer ) EVT_SIZE( MyFrame::OnWinSize ) EVT_MOVE( MyFrame::OnWinMove ) EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam ) @@ -232,6 +232,9 @@ } m_buttonMove->Enable(true); + // TODO. + // make 申請書ふぉるだ + wxMessageBox(wxT("移動先フォルダ準備完了")); wxString cmd = wxT("explorer ") + to; wxExecute( cmd ); @@ -301,6 +304,7 @@ wxString workdir = m_dirPickerWork->GetPath(); wxDir dir( workdir ); if ( !dir.IsOpened() ) return; + // start-up iamge wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); m_bitmapName->SetBitmap( bmp ); @@ -308,6 +312,7 @@ bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); m_bitmapHhsno->SetBitmap( bmp ); + // enum jpeg wxArrayString filenames; unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); @@ -319,6 +324,7 @@ pd.SetSize( wxSize(320,140) ); float z; long l; for ( int i=0; i<n; i++ ) { + /* wxFileName f( filenames[i] ); wxString filename = f.GetFullName(); @@ -354,6 +360,7 @@ } } m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + */ // write log pd.Update( i+1, wxT("画像認識中") ); @@ -365,6 +372,7 @@ /* 画像を選択 */ void MyFrame::GetImageInfo(wxListEvent& event) { + /* SetStatusText( wxEmptyString, 2 ); int i = event.GetIndex(); @@ -377,6 +385,7 @@ msg = wxT("perhaps marksheet !"); } SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, b, l ), 2 ); + */ } /* 画像のスクリーン表示*/ @@ -409,7 +418,76 @@ pd->Destroy(); } +/* キャッシュ作成&更新 */ +void MyFrame::UpdateCache() +{ + wxString workdir = m_dirPickerWork->GetPath(); + wxDir dir( workdir ); + if ( !dir.IsOpened() ) return; + wxArrayString filenames; + + wxListItem item; + wxString first; + float z; long l; + bool m; + + wxGetApp().WriteLog( wxT("start updating cache") ); + SetStatusText( wxT("rebuiling cache..."), 0 ); + + for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) { + CacheItem* ci = new CacheItem; + ci = i->second; + ci->exists = false; + } + unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); + for ( int i=0; i<n; i++ ) { + CacheItem* ci = new CacheItem; + if ( CH.count(filenames[i]) ) { + ci = CH[filenames[i]]; + ci->exists = true; + continue; + } + ci->filename = filenames[i]; + m = IsMarksheet( filenames[i], &z, &l ); + wxImage image( filenames[i], wxBITMAP_TYPE_JPEG ); + wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) ); + ci->marksheet = m; + ci->z = z; + ci->l = l; + ci->exists = true; + ci->thumbnail = bmp; + ci->modtime = wxEmptyString; // TODO. + CH[ci->filename] = ci; // add hash + wxGetApp().WriteLog( filenames[i] + wxString::Format(wxT(" z=%f l=%d m=%d"), z, l, m ? 1 : 0 ) ); + } + for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) { + CacheItem* ci = new CacheItem; + ci = i->second; + if ( !ci->exists ) { + CH.erase(ci->filename); + wxGetApp().WriteLog( ci->filename + wxT(" removed.") ); + } + } + + SetStatusText( wxEmptyString, 0 ); + m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart +} + // 以下,定型もの +void MyFrame::OnTimer(wxTimerEvent& event) +{ + UpdateCache(); +} +/* アイドリング */ +void MyFrame::OnIdle(wxIdleEvent& event) +{ + if ( !m_timer.IsRunning() ) { + m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); + } + event.RequestMore(); + event.Skip(); +} + /* アプリフォルダを開く */ void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event)) {