annotate src/cache.cpp @ 22:92188f60323d default tip

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