Mercurial > mercurial > hgweb_searcher03.cgi
comparison src/cache.cpp @ 21:a2ad87cad48b
Enhanced the convenience of Cache dialog.
| author | pyon@macmini |
|---|---|
| date | Wed, 17 Dec 2014 00:52:43 +0900 |
| parents | a8e6e5769e3b |
| children |
comparison
equal
deleted
inserted
replaced
| 20:226774bf49fc | 21:a2ad87cad48b |
|---|---|
| 1 // Filename : cache.cpp | 1 // Filename : cache.cpp |
| 2 // Last Change: 21-Nov-2014. | 2 // Last Change: 15-Dec-2014. |
| 3 // | 3 // |
| 4 | 4 |
| 5 #include "cache.h" | 5 #include "cache.h" |
| 6 #include "db.h" | 6 #include "db.h" |
| 7 | 7 |
| 8 // キャッシュ取得ダイアログ | |
| 9 CacheGetDialog::CacheGetDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | |
| 10 : wxDialog( parent, id, title, pos, size, style ) | |
| 11 { | |
| 12 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | |
| 13 this->SetBackgroundColour( wxColour( wxT("WHEAT") ) ); | |
| 14 | |
| 15 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); | |
| 16 | |
| 17 m_dirPicker = new wxDirPickerCtrl( this, wxID_ANY, wxEmptyString, wxT("Select a directory") ); | |
| 18 bSizerTop->Add( m_dirPicker, 0, wxALL|wxEXPAND, 5 ); | |
| 19 | |
| 20 wxBoxSizer* bSizerButton = new wxBoxSizer( wxHORIZONTAL ); | |
| 21 | |
| 22 m_buttonGet = new wxButton( this, ID_GETCACHE, wxT("コピィ"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 23 bSizerButton->Add( m_buttonGet, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 24 | |
| 25 m_buttonCancel = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 26 bSizerButton->Add( m_buttonCancel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 27 | |
| 28 bSizerTop->Add( bSizerButton, 0, wxALIGN_RIGHT, 5 ); | |
| 29 | |
| 30 this->SetSizer( bSizerTop ); | |
| 31 this->Layout(); | |
| 32 | |
| 33 this->Centre( wxBOTH ); | |
| 34 } | |
| 35 | |
| 36 CacheGetDialog::~CacheGetDialog() | |
| 37 { | |
| 38 } | |
| 39 | |
| 40 // Event Table | |
| 41 BEGIN_EVENT_TABLE( CacheGetDialog, wxDialog ) | |
| 42 EVT_BUTTON( ID_GETCACHE, CacheGetDialog::OnGetCache ) | |
| 43 END_EVENT_TABLE() | |
| 44 | |
| 45 // Event Handlers & Functions | |
| 46 void CacheGetDialog::OnGetCache( wxCommandEvent& WXUNUSED(event) ) | |
| 47 { | |
| 48 wxString fromdir = m_dirPicker->GetPath(); | |
| 49 | |
| 50 wxString cachedir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache"); | |
| 51 | |
| 52 for ( int i = 0; i < m_nocache.GetCount(); i++ ) { | |
| 53 | |
| 54 wxString year = m_nocache[i].Left( 4 ); | |
| 55 wxString month = m_nocache[i].Mid( 4, 2 ); | |
| 56 | |
| 57 if ( month.IsSameAs(wxT("01")) || month.IsSameAs(wxT("02")) || month.IsSameAs(wxT("03")) ) { | |
| 58 long y; | |
| 59 year.ToLong( &y, 10 ); | |
| 60 y--; | |
| 61 year = wxString::Format( wxT("%d"), y ); | |
| 62 } | |
| 63 | |
| 64 wxString from = fromdir + wxFILE_SEP_PATH + year + wxFILE_SEP_PATH + m_nocache[i]; | |
| 65 wxString to = cachedir + wxFILE_SEP_PATH + year + wxFILE_SEP_PATH + m_nocache[i]; | |
| 66 | |
| 67 wxArrayString files; | |
| 68 wxDir::GetAllFiles( from, &files, wxT("*.png"), wxDIR_DEFAULT ); | |
| 69 | |
| 70 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), files.GetCount(), NULL, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); | |
| 71 pd.SetSize( wxSize( 320, 140 ) ); | |
| 72 | |
| 73 for ( int j = 0; j < files.GetCount(); j++ ) { | |
| 74 wxFileName fn( files[j] ); | |
| 75 | |
| 76 wxString ccn = fn.GetPath().BeforeLast( wxFILE_SEP_PATH ).AfterLast( wxFILE_SEP_PATH ); | |
| 77 wxString hhs = fn.GetPath().AfterLast( wxFILE_SEP_PATH ); | |
| 78 wxString buf = to + wxFILE_SEP_PATH + ccn + wxFILE_SEP_PATH + hhs + wxFILE_SEP_PATH + fn.GetFullName(); | |
| 79 | |
| 80 wxFileName td( buf ); | |
| 81 if ( !td.Exists() ) td.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); | |
| 82 | |
| 83 wxCopyFile( files[j], buf, true ); | |
| 84 if ( j % 5 == 0 ) wxSleep( 2 ); // ディスクの負荷軽減 | |
| 85 | |
| 86 pd.Update( j, hhs + wxT("@") + ccn + wxT("@") + m_nocache[i] + wxT("を処理しました.") ); | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 wxMessageBox( wxT("Getting cache done."), wxT("Message"), wxOK|wxSTAY_ON_TOP ); | |
| 91 Close(); | |
| 92 } | |
| 93 | |
| 94 void CacheGetDialog::SetSyncDates( wxArrayString dates ) | |
| 95 { | |
| 96 m_nocache = dates; | |
| 97 } | |
| 98 | |
| 99 // メインダイアログ | |
| 8 CacheDialog::CacheDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | 100 CacheDialog::CacheDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) |
| 9 : wxDialog( parent, id, title, pos, size, style ) | 101 : wxDialog( parent, id, title, pos, size, style ) |
| 10 { | 102 { |
| 11 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | 103 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); |
| 12 | 104 |
| 13 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); | 105 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); |
| 14 | 106 |
| 15 m_datePickerBgn = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT ); | 107 // |
| 16 bSizerTop->Add( m_datePickerBgn, 0, wxALL, 5 ); | 108 wxBoxSizer* bSizerList = new wxBoxSizer( wxVERTICAL ); |
| 17 | 109 |
| 18 m_datePickerEnd = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT ); | 110 m_staticText = new wxStaticText( this, wxID_ANY, wxT("作成対象選択"), wxDefaultPosition, wxDefaultSize, 0 ); |
| 19 bSizerTop->Add( m_datePickerEnd, 0, wxALL, 5 ); | 111 bSizerList->Add( m_staticText, 0, wxALL, 5 ); |
| 20 | 112 |
| 21 m_buttonMake = new wxButton( this, ID_MKCACHE, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 ); | 113 m_listCtrl = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT ); |
| 22 bSizerTop->Add( m_buttonMake, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 ); | 114 wxListItem itemCol; |
| 23 | 115 itemCol.SetText( wxT("通番") ); |
| 24 m_buttonClose = new wxButton( this, ID_CLOSE, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | 116 m_listCtrl->InsertColumn( 0, itemCol ); |
| 117 m_listCtrl->SetColumnWidth( 0, 50 ); | |
| 118 itemCol.SetText( wxT("審査会年月日") ); | |
| 119 m_listCtrl->InsertColumn( 1, itemCol ); | |
| 120 m_listCtrl->SetColumnWidth( 1, 100 ); | |
| 121 itemCol.SetText( wxT("キャッシュ有無") ); | |
| 122 m_listCtrl->InsertColumn( 2, itemCol ); | |
| 123 m_listCtrl->SetColumnWidth( 2, 100 ); | |
| 124 bSizerList->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 ); | |
| 125 | |
| 126 // | |
| 127 wxBoxSizer* bSizerRange = new wxBoxSizer( wxHORIZONTAL ); | |
| 128 | |
| 129 m_staticTextRange = new wxStaticText( this, wxID_ANY, wxT("表示範囲指定"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 130 bSizerRange->Add( m_staticTextRange, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 131 | |
| 132 m_datePickerBgn = new wxDatePickerCtrl( this, ID_RGBGN, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN ); | |
| 133 bSizerRange->Add( m_datePickerBgn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 134 | |
| 135 m_staticTextBetween = new wxStaticText( this, wxID_ANY, wxT("~"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 136 bSizerRange->Add( m_staticTextBetween, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 137 | |
| 138 m_datePickerEnd = new wxDatePickerCtrl( this, ID_RGEND, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN ); | |
| 139 bSizerRange->Add( m_datePickerEnd, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | |
| 140 | |
| 141 bSizerList->Add( bSizerRange, 0, wxALL|wxEXPAND, 5 ); | |
| 142 | |
| 143 bSizerTop->Add( bSizerList, 1, wxEXPAND, 5 ); | |
| 144 | |
| 145 // | |
| 146 wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL ); | |
| 147 | |
| 148 m_buttonCache = new wxButton( this, ID_MKCACHE, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 149 bSizerButton->Add( m_buttonCache, 0, wxALL, 5 ); | |
| 150 | |
| 151 m_buttonGet = new wxButton( this, ID_GET, wxT("取得"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 152 bSizerButton->Add( m_buttonGet, 0, wxALL, 5 ); | |
| 153 | |
| 154 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 155 bSizerButton->Add( m_buttonClose, 0, wxALL, 5 ); | |
| 25 m_buttonClose->SetDefault(); | 156 m_buttonClose->SetDefault(); |
| 26 bSizerTop->Add( m_buttonClose, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 ); | 157 |
| 158 bSizerTop->Add( bSizerButton, 0, 0, 5 ); | |
| 159 | |
| 27 | 160 |
| 28 this->SetSizer( bSizerTop ); | 161 this->SetSizer( bSizerTop ); |
| 29 this->Layout(); | 162 this->Layout(); |
| 30 bSizerTop->Fit( this ); | |
| 31 | 163 |
| 32 this->Centre( wxBOTH ); | 164 this->Centre( wxBOTH ); |
| 33 } | 165 } |
| 34 | 166 |
| 35 CacheDialog::~CacheDialog() | 167 CacheDialog::~CacheDialog() |
| 36 { | 168 { |
| 37 } | 169 } |
| 38 | 170 |
| 39 // Event Table | 171 // Event Table |
| 40 BEGIN_EVENT_TABLE( CacheDialog, wxDialog ) | 172 BEGIN_EVENT_TABLE( CacheDialog, wxDialog ) |
| 41 EVT_BUTTON( ID_MKCACHE, CacheDialog::OnMakeCache ) | 173 EVT_DATE_CHANGED( ID_RGBGN, CacheDialog::OnDateChange ) |
| 42 EVT_BUTTON( ID_CLOSE, CacheDialog::OnClose ) | 174 EVT_DATE_CHANGED( ID_RGEND, CacheDialog::OnDateChange ) |
| 175 EVT_BUTTON( ID_MKCACHE, CacheDialog::OnMakeCache ) | |
| 176 EVT_BUTTON( ID_GET, CacheDialog::OnGetCache ) | |
| 43 END_EVENT_TABLE() | 177 END_EVENT_TABLE() |
| 44 | 178 |
| 45 // Event Handlers & Functions | 179 // Event Handlers & Functions |
| 46 void CacheDialog::Setting( wxString rootdir, int w, int h ) | 180 void CacheDialog::Setting( wxString rootdir, int w, int h ) |
| 47 { | 181 { |
| 48 m_rootdir = rootdir; | 182 m_rootdir = rootdir; |
| 49 m_width = w; | 183 m_width = w; |
| 50 m_height = h; | 184 m_height = h; |
| 51 } | 185 |
| 52 | 186 m_datePickerBgn->SetValue( wxDateTime::Today() - wxDateSpan::Month() * 2 ); |
| 53 void CacheDialog::OnMakeCache( wxCommandEvent& WXUNUSED(event) ) | 187 m_datePickerEnd->SetValue( wxDateTime::Today() ); |
| 54 { | 188 } |
| 189 | |
| 190 void CacheDialog::Listup( void ) | |
| 191 { | |
| 192 nocache.Clear(); | |
| 55 wxDateTime b = m_datePickerBgn->GetValue(); | 193 wxDateTime b = m_datePickerBgn->GetValue(); |
| 56 wxDateTime e = m_datePickerEnd->GetValue(); | 194 wxDateTime e = m_datePickerEnd->GetValue(); |
| 195 wxArrayString ccn = GetCcnDate(); | |
| 57 | 196 |
| 58 MakeCache( b.Format( wxT("%Y%m%d")), e.Format( wxT("%Y%m%d")) ); | 197 wxDateTime dt; |
| 59 } | 198 wxRegEx reDate( wxT("(^20[0-9]{2})([0-1][0-9])([0-3][0-9])$") ); |
| 60 | 199 m_listCtrl->DeleteAllItems(); |
| 61 void CacheDialog::MakeCache( wxString from, wxString to ) | 200 |
| 62 { | 201 for ( int i = 0; i < ccn.GetCount(); i++ ) { |
| 63 wxArrayString path = GetPathes( from, to ); | 202 |
| 203 dt.ParseFormat( ccn[i], wxT("%Y%m%d") ); | |
| 204 | |
| 205 if ( dt.IsBetween( b, e ) ) { | |
| 206 | |
| 207 // cache exists ? | |
| 208 wxString month = dt.Format( wxT("%m") ); | |
| 209 wxString year = dt.Format( wxT("%Y") ); | |
| 210 | |
| 211 if ( month.IsSameAs(wxT("01")) || month.IsSameAs(wxT("02")) || month.IsSameAs(wxT("03")) ) { | |
| 212 long y; | |
| 213 year.ToLong( &y, 10 ); | |
| 214 y--; | |
| 215 year = wxString::Format( wxT("%d"), y ); | |
| 216 } | |
| 217 wxString cache_dir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache") + wxFILE_SEP_PATH + year + wxFILE_SEP_PATH + dt.Format( wxT("%Y%m%d") ); | |
| 218 | |
| 219 wxString cache_ok; | |
| 220 wxFileName cd( cache_dir ); | |
| 221 if ( cd.Exists() ) | |
| 222 cache_ok = wxT("○"); | |
| 223 else | |
| 224 nocache.Insert( dt.Format( wxT("%Y%m%d") ), 0 ); | |
| 225 | |
| 226 m_listCtrl->InsertItem( i, -1 ); | |
| 227 m_listCtrl->SetItem( i, 0, wxString::Format( wxT("%d"), i + 1 ) , -1 ); // No | |
| 228 reDate.Replace( &ccn[i], wxT("\\1-\\2-\\3") ); | |
| 229 m_listCtrl->SetItem( i, 1, ccn[i], -1 ); | |
| 230 if ( !cache_ok.IsEmpty() ) m_listCtrl->SetItem( i, 2, cache_ok, -1 ); | |
| 231 | |
| 232 if ( i % 2 ) m_listCtrl->SetItemBackgroundColour( i, wxColour( wxT("WHEAT") ) ); | |
| 233 } | |
| 234 } | |
| 235 } | |
| 236 | |
| 237 void CacheDialog::OnDateChange( wxDateEvent& WXUNUSED(event) ) | |
| 238 { | |
| 239 Listup(); | |
| 240 } | |
| 241 | |
| 242 void CacheDialog::OnMakeCache( wxCommandEvent& WXUNUSED(event) ) | |
| 243 { | |
| 244 if ( m_listCtrl->GetSelectedItemCount() < 1 ) { | |
| 245 wxMessageBox( wxT("項目を少なくともひとつ選択してください.") ); | |
| 246 return; | |
| 247 } | |
| 64 wxString cachedir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache"); | 248 wxString cachedir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache"); |
| 65 | 249 |
| 66 for ( int i = 0; i < path.GetCount(); i++ ) { | 250 long item = -1; |
| 67 | 251 bool done = false; |
| 68 wxArrayString files; | 252 for ( ;; ) { |
| 69 wxDir::GetAllFiles( path[i], &files, wxT("*.jpg"), wxDIR_DEFAULT ); | 253 item = m_listCtrl->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); |
| 70 | 254 if ( item == -1 ) break; |
| 71 for ( int j = 0; j < files.GetCount(); j++ ) { | 255 |
| 72 wxImage image( files[j], wxBITMAP_TYPE_JPEG ); | 256 wxString c = m_listCtrl->GetItemText( item, 2 ); |
| 73 wxImage output = image.Scale( m_width, m_height, wxIMAGE_QUALITY_HIGH ); | 257 if ( c.IsEmpty() ) { |
| 74 | 258 wxString date = m_listCtrl->GetItemText( item, 1 ); |
| 75 wxString buf = files[j]; | 259 date.Replace( wxT("-"), wxEmptyString, true ); |
| 76 buf.Replace( m_rootdir, cachedir, false ); | 260 |
| 77 buf = buf.BeforeLast( '.' ) + wxT(".png"); | 261 wxArrayString path = GetPathesByDate( date ); |
| 78 | 262 |
| 79 wxFileName tf( buf ); | 263 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), path.GetCount(), NULL, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); |
| 80 if ( !tf.Exists() ) tf.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); | 264 pd.SetSize( wxSize( 320, 140 ) ); |
| 81 output.SaveFile( buf, wxBITMAP_TYPE_PNG ); | 265 |
| 266 for ( int i = 0; i < path.GetCount(); i++ ) { | |
| 267 | |
| 268 wxArrayString files; | |
| 269 wxDir::GetAllFiles( path[i], &files, wxT("*.jpg"), wxDIR_DEFAULT ); | |
| 270 | |
| 271 for ( int j = 0; j < files.GetCount(); j++ ) { | |
| 272 wxImage image( files[j], wxBITMAP_TYPE_JPEG ); | |
| 273 wxImage output = image.Scale( m_width, m_height, wxIMAGE_QUALITY_HIGH ); | |
| 274 | |
| 275 wxString buf = files[j]; | |
| 276 buf.Replace( m_rootdir, cachedir, false ); | |
| 277 buf = buf.BeforeLast( '.' ) + wxT(".png"); | |
| 278 | |
| 279 wxFileName tf( buf ); | |
| 280 if ( !tf.Exists() ) tf.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); | |
| 281 output.SaveFile( buf, wxBITMAP_TYPE_PNG ); | |
| 282 } | |
| 283 pd.Update( i, path[i] + wxT("を処理しました.") ); | |
| 284 wxSleep( 10 ); | |
| 285 } | |
| 286 done = true; | |
| 82 } | 287 } |
| 83 wxSleep( 30 ); | 288 } |
| 84 } | 289 |
| 85 | 290 if ( done ) { |
| 86 wxMessageBox( wxT("cache updated.") ); | 291 wxMessageBox( wxT("cache updated."), wxT("Message"), wxOK|wxSTAY_ON_TOP ); |
| 87 } | 292 Listup(); |
| 88 | 293 } |
| 89 void CacheDialog::OnClose( wxCommandEvent& WXUNUSED(event) ) | 294 } |
| 90 { | 295 |
| 91 Close(); | 296 void CacheDialog::OnGetCache( wxCommandEvent& WXUNUSED(event) ) |
| 92 } | 297 { |
| 93 | 298 CacheGetDialog* cd = new CacheGetDialog( this, wxID_ANY, wxT("キャッシュ取得"), wxDefaultPosition, wxSize( 500, 100 ), wxCAPTION|wxFRAME_NO_TASKBAR ); |
| 299 cd->SetSyncDates( nocache ); | |
| 300 cd->ShowModal(); | |
| 301 Listup(); | |
| 302 } | |
| 303 |
