11
|
1 // Filename : cache.cpp
|
21
|
2 // Last Change: 15-Dec-2014.
|
11
|
3 //
|
|
4
|
|
5 #include "cache.h"
|
|
6 #include "db.h"
|
|
7
|
21
|
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 // メインダイアログ
|
11
|
100 CacheDialog::CacheDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
101 : wxDialog( parent, id, title, pos, size, style )
|
|
102 {
|
|
103 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
104
|
21
|
105 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
|
|
106
|
|
107 //
|
|
108 wxBoxSizer* bSizerList = new wxBoxSizer( wxVERTICAL );
|
|
109
|
|
110 m_staticText = new wxStaticText( this, wxID_ANY, wxT("作成対象選択"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
111 bSizerList->Add( m_staticText, 0, wxALL, 5 );
|
11
|
112
|
21
|
113 m_listCtrl = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );
|
|
114 wxListItem itemCol;
|
|
115 itemCol.SetText( wxT("通番") );
|
|
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 );
|
11
|
125
|
21
|
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 );
|
11
|
140
|
21
|
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 );
|
11
|
150
|
21
|
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 );
|
11
|
156 m_buttonClose->SetDefault();
|
21
|
157
|
|
158 bSizerTop->Add( bSizerButton, 0, 0, 5 );
|
|
159
|
11
|
160
|
|
161 this->SetSizer( bSizerTop );
|
|
162 this->Layout();
|
|
163
|
|
164 this->Centre( wxBOTH );
|
|
165 }
|
|
166
|
|
167 CacheDialog::~CacheDialog()
|
|
168 {
|
|
169 }
|
|
170
|
|
171 // Event Table
|
|
172 BEGIN_EVENT_TABLE( CacheDialog, wxDialog )
|
21
|
173 EVT_DATE_CHANGED( ID_RGBGN, CacheDialog::OnDateChange )
|
|
174 EVT_DATE_CHANGED( ID_RGEND, CacheDialog::OnDateChange )
|
|
175 EVT_BUTTON( ID_MKCACHE, CacheDialog::OnMakeCache )
|
|
176 EVT_BUTTON( ID_GET, CacheDialog::OnGetCache )
|
11
|
177 END_EVENT_TABLE()
|
|
178
|
|
179 // Event Handlers & Functions
|
|
180 void CacheDialog::Setting( wxString rootdir, int w, int h )
|
|
181 {
|
|
182 m_rootdir = rootdir;
|
|
183 m_width = w;
|
|
184 m_height = h;
|
21
|
185
|
|
186 m_datePickerBgn->SetValue( wxDateTime::Today() - wxDateSpan::Month() * 2 );
|
|
187 m_datePickerEnd->SetValue( wxDateTime::Today() );
|
|
188 }
|
|
189
|
|
190 void CacheDialog::Listup( void )
|
|
191 {
|
|
192 nocache.Clear();
|
|
193 wxDateTime b = m_datePickerBgn->GetValue();
|
|
194 wxDateTime e = m_datePickerEnd->GetValue();
|
|
195 wxArrayString ccn = GetCcnDate();
|
|
196
|
|
197 wxDateTime dt;
|
|
198 wxRegEx reDate( wxT("(^20[0-9]{2})([0-1][0-9])([0-3][0-9])$") );
|
|
199 m_listCtrl->DeleteAllItems();
|
|
200
|
|
201 for ( int i = 0; i < ccn.GetCount(); i++ ) {
|
|
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();
|
11
|
240 }
|
|
241
|
|
242 void CacheDialog::OnMakeCache( wxCommandEvent& WXUNUSED(event) )
|
|
243 {
|
21
|
244 if ( m_listCtrl->GetSelectedItemCount() < 1 ) {
|
|
245 wxMessageBox( wxT("項目を少なくともひとつ選択してください.") );
|
|
246 return;
|
|
247 }
|
11
|
248 wxString cachedir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache");
|
|
249
|
21
|
250 long item = -1;
|
|
251 bool done = false;
|
|
252 for ( ;; ) {
|
|
253 item = m_listCtrl->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
|
|
254 if ( item == -1 ) break;
|
11
|
255
|
21
|
256 wxString c = m_listCtrl->GetItemText( item, 2 );
|
|
257 if ( c.IsEmpty() ) {
|
|
258 wxString date = m_listCtrl->GetItemText( item, 1 );
|
|
259 date.Replace( wxT("-"), wxEmptyString, true );
|
11
|
260
|
21
|
261 wxArrayString path = GetPathesByDate( date );
|
|
262
|
|
263 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), path.GetCount(), NULL, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
264 pd.SetSize( wxSize( 320, 140 ) );
|
|
265
|
|
266 for ( int i = 0; i < path.GetCount(); i++ ) {
|
11
|
267
|
21
|
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 );
|
11
|
274
|
21
|
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;
|
11
|
287 }
|
|
288 }
|
|
289
|
21
|
290 if ( done ) {
|
|
291 wxMessageBox( wxT("cache updated."), wxT("Message"), wxOK|wxSTAY_ON_TOP );
|
|
292 Listup();
|
|
293 }
|
11
|
294 }
|
|
295
|
21
|
296 void CacheDialog::OnGetCache( wxCommandEvent& WXUNUSED(event) )
|
11
|
297 {
|
21
|
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();
|
11
|
302 }
|
|
303
|