Mercurial > mercurial > hgweb_iklist.hg.cgi
comparison src/iklist.cpp @ 0:520044113ef0 draft
beta release.
| author | pyon <pyon@macmini> |
|---|---|
| date | Sat, 21 Aug 2021 13:03:13 +0900 |
| parents | |
| children | c0f76f8e67fa |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:520044113ef0 |
|---|---|
| 1 // Filename : iklist.cpp | |
| 2 // Last Change: 2021-08-20 金 12:48:51. | |
| 3 // | |
| 4 #include <wx/textfile.h> | |
| 5 #include <wx/utils.h> | |
| 6 #include <wx/dir.h> | |
| 7 #include <wx/filefn.h> | |
| 8 #include <wx/wfstream.h> | |
| 9 #include <wx/txtstrm.h> | |
| 10 #include <wx/fs_zip.h> | |
| 11 #include <wx/filesys.h> | |
| 12 #include <wx/msgdlg.h> | |
| 13 | |
| 14 #include "iklist.h" | |
| 15 | |
| 16 /////////////////////////////////////////////////////////////////////////// | |
| 17 | |
| 18 MainFrame::MainFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) | |
| 19 : wxFrame(parent, id, title, pos, size, style) | |
| 20 { | |
| 21 CreateControls(); | |
| 22 LoadConfig(); | |
| 23 | |
| 24 // Connect Events | |
| 25 m_searchCtrl->Connect(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, wxCommandEventHandler(MainFrame::OnCancel), NULL, this); | |
| 26 m_searchCtrl->Connect(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, wxCommandEventHandler(MainFrame::OnSearch), NULL, this); | |
| 27 m_searchCtrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnSearch), NULL, this); | |
| 28 m_textCtrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnTextEnter), NULL, this); | |
| 29 m_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainFrame::OnClick), NULL, this); | |
| 30 m_choiceCity->Connect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(MainFrame::OnCityChoice), NULL, this); | |
| 31 m_choiceKind->Connect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(MainFrame::OnKindChoice), NULL, this); | |
| 32 m_dataViewListCtrl->Connect(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEventHandler(MainFrame::OnListItemActivated), NULL, this); | |
| 33 } | |
| 34 | |
| 35 MainFrame::~MainFrame() | |
| 36 { | |
| 37 // Clean TempFile | |
| 38 wxString tmpdir, filename; | |
| 39 wxGetEnv(wxT("TEMP"), &tmpdir); | |
| 40 wxDir dir(tmpdir); | |
| 41 dir.IsOpened(); | |
| 42 bool cont = dir.GetFirst(&filename, wxT("iklist-*"), wxDIR_FILES); | |
| 43 while (cont) { | |
| 44 wxRemoveFile(tmpdir + wxFILE_SEP_PATH + filename); | |
| 45 cont = dir.GetNext(&filename); | |
| 46 } | |
| 47 | |
| 48 // Disconnect Events | |
| 49 m_searchCtrl->Disconnect(wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN, wxCommandEventHandler(MainFrame::OnCancel), NULL, this); | |
| 50 m_searchCtrl->Disconnect(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, wxCommandEventHandler(MainFrame::OnSearch), NULL, this); | |
| 51 m_searchCtrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnSearch), NULL, this); | |
| 52 m_textCtrl->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(MainFrame::OnTextEnter), NULL, this); | |
| 53 m_button->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainFrame::OnClick), NULL, this); | |
| 54 m_choiceCity->Disconnect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(MainFrame::OnCityChoice), NULL, this); | |
| 55 m_choiceKind->Disconnect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(MainFrame::OnKindChoice), NULL, this); | |
| 56 m_dataViewListCtrl->Disconnect(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEventHandler(MainFrame::OnListItemActivated), NULL, this); | |
| 57 } | |
| 58 | |
| 59 // Event Handlers | |
| 60 void MainFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) | |
| 61 { | |
| 62 SetList(); | |
| 63 } | |
| 64 | |
| 65 void MainFrame::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
| 66 { | |
| 67 m_searchCtrl->Clear(); | |
| 68 } | |
| 69 | |
| 70 void MainFrame::OnTextEnter(wxCommandEvent& WXUNUSED(event)) | |
| 71 { | |
| 72 CheckPassword(); | |
| 73 } | |
| 74 | |
| 75 void MainFrame::OnClick(wxCommandEvent& WXUNUSED(event)) | |
| 76 { | |
| 77 CheckPassword(); | |
| 78 } | |
| 79 | |
| 80 void MainFrame::OnCityChoice(wxCommandEvent& WXUNUSED(event)) | |
| 81 { | |
| 82 SetList(); | |
| 83 } | |
| 84 | |
| 85 void MainFrame::OnKindChoice(wxCommandEvent& WXUNUSED(event)) | |
| 86 { | |
| 87 SetList(); | |
| 88 } | |
| 89 | |
| 90 void MainFrame::OnListItemActivated(wxDataViewEvent& WXUNUSED(event)) | |
| 91 { | |
| 92 int n = m_dataViewListCtrl->GetSelectedRow(); | |
| 93 wxString index = m_dataViewListCtrl->GetTextValue(n, 0); | |
| 94 wxString pdf = MakePDF(index); | |
| 95 | |
| 96 wxString cmd = wxT("cmd /c start ") + pdf; | |
| 97 wxArrayString output, error; | |
| 98 wxExecute(cmd, output, error, wxEXEC_HIDE_CONSOLE); | |
| 99 } | |
| 100 | |
| 101 // Functions | |
| 102 void MainFrame::SetList() | |
| 103 { | |
| 104 wxString kw = m_searchCtrl->GetValue(); | |
| 105 wxString city = m_choiceCity->GetString(m_choiceCity->GetSelection()); | |
| 106 wxString kind = m_choiceKind->GetString(m_choiceKind->GetSelection()); | |
| 107 | |
| 108 m_dataViewListCtrl->DeleteAllItems(); | |
| 109 wxVector<wxVariant> data; | |
| 110 for (int i = 0; i < m_data.GetCount(); i++) { | |
| 111 wxArrayString str = wxSplit(m_data[i], ':'); | |
| 112 | |
| 113 data.push_back(wxVariant(wxString::Format(wxT("%04d"), i + 1))); // ID | |
| 114 data.push_back(wxVariant(str[0])); // Name | |
| 115 data.push_back(wxVariant(str[1])); // City | |
| 116 data.push_back(wxVariant(str[2])); // Kind | |
| 117 | |
| 118 unsigned int flag = 0; | |
| 119 if (!kw.IsEmpty() && str[0].Find(kw) == wxNOT_FOUND) flag |= 1; | |
| 120 if (!city.IsEmpty() && str[1].IsSameAs(city)) flag |= 2; | |
| 121 if (!kind.IsEmpty() && str[2].IsSameAs(kind)) flag |= 4; | |
| 122 if (flag != 0) | |
| 123 m_dataViewListCtrl->AppendItem(data); | |
| 124 | |
| 125 data.clear(); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 wxString MainFrame::MakePDF(wxString index) | |
| 130 { | |
| 131 wxString file = SearchFile(wxT("data03"), index); | |
| 132 wxFileInputStream si1(file); | |
| 133 file = SearchFile(wxT("data04"), index); | |
| 134 wxFileInputStream si2(file); | |
| 135 file = SearchFile(wxT("data08"), index); | |
| 136 wxFileInputStream si3(file); | |
| 137 | |
| 138 wxString tmpdir; | |
| 139 wxGetEnv(wxT("TEMP"), &tmpdir); | |
| 140 wxString pdf = tmpdir + "/iklist-" + index + ".pdf"; | |
| 141 wxFileOutputStream so(pdf); | |
| 142 so << si1 << si2 << si3; // use chunk buffer to copy if file is big. | |
| 143 | |
| 144 return pdf; | |
| 145 } | |
| 146 | |
| 147 wxString MainFrame::SearchFile(wxString directory, wxString index) | |
| 148 { | |
| 149 wxDir dir(directory); | |
| 150 if (!dir.IsOpened()) | |
| 151 return wxEmptyString; | |
| 152 | |
| 153 wxString filename; | |
| 154 bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES); | |
| 155 while (cont) { | |
| 156 if (filename.Mid(8, 4).IsSameAs(index, false)) | |
| 157 break; | |
| 158 cont = dir.GetNext(&filename); | |
| 159 } | |
| 160 return directory + wxT("/") + filename; | |
| 161 } | |
| 162 | |
| 163 void MainFrame::CreateControls() | |
| 164 { | |
| 165 this->SetIcon(wxIcon(wxT("sample"))); | |
| 166 this->SetSizeHints(wxDefaultSize, wxDefaultSize); | |
| 167 this->SetBackgroundColour(wxColour(130, 170, 210)); | |
| 168 | |
| 169 wxBoxSizer* bSizerTop = new wxBoxSizer(wxVERTICAL); | |
| 170 | |
| 171 //-- | |
| 172 wxBoxSizer* bSizerWord = new wxBoxSizer(wxHORIZONTAL); | |
| 173 | |
| 174 m_staticTextWord = new wxStaticText(this, wxID_ANY, wxT("パスワード:"), wxDefaultPosition, wxDefaultSize, 0); | |
| 175 bSizerWord->Add(m_staticTextWord, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 176 | |
| 177 m_searchCtrl = new wxSearchCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(0, -1), 0); | |
| 178 #ifndef __WXMAC__ | |
| 179 m_searchCtrl->ShowSearchButton(true); | |
| 180 #endif | |
| 181 m_searchCtrl->ShowCancelButton(true); | |
| 182 | |
| 183 bSizerWord->Add(m_searchCtrl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 184 | |
| 185 m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, -1), wxTE_PASSWORD|wxTE_PROCESS_ENTER); | |
| 186 bSizerWord->Add(m_textCtrl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 187 m_textCtrl->SetFocus(); | |
| 188 | |
| 189 m_button = new wxButton(this, wxID_ANY, wxT("OK"), wxDefaultPosition, wxSize(60, -1), 0); | |
| 190 bSizerWord->Add(m_button, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 191 | |
| 192 bSizerTop->Add(bSizerWord, 0, wxEXPAND, 5); | |
| 193 | |
| 194 //-- | |
| 195 wxBoxSizer* bSizerFilter = new wxBoxSizer(wxHORIZONTAL); | |
| 196 | |
| 197 m_staticTextFilter = new wxStaticText(this, wxID_ANY, wxT("フィルター:"), wxDefaultPosition, wxDefaultSize, 0); | |
| 198 bSizerFilter->Add(m_staticTextFilter, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 199 | |
| 200 m_staticTextCity = new wxStaticText(this, wxID_ANY, wxT("市町村"), wxDefaultPosition, wxDefaultSize, 0); | |
| 201 bSizerFilter->Add(m_staticTextCity, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 202 | |
| 203 wxArrayString m_choiceCityChoices; | |
| 204 m_choiceCity = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceCityChoices, 0); | |
| 205 m_choiceCity->SetSelection(0); | |
| 206 bSizerFilter->Add(m_choiceCity, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 207 | |
| 208 m_staticTextKind = new wxStaticText(this, wxID_ANY, wxT("区分"), wxDefaultPosition, wxDefaultSize, 0); | |
| 209 bSizerFilter->Add(m_staticTextKind, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 210 | |
| 211 wxArrayString m_choiceKindChoices; | |
| 212 m_choiceKind = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceKindChoices, 0); | |
| 213 m_choiceKind->SetSelection(0); | |
| 214 bSizerFilter->Add(m_choiceKind, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 215 | |
| 216 bSizerTop->Add(bSizerFilter, 0, wxEXPAND, 5); | |
| 217 | |
| 218 //-- | |
| 219 m_dataViewListCtrl = new wxDataViewListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE|wxDV_VERT_RULES|wxDV_ROW_LINES); | |
| 220 m_dataViewListColumnID = m_dataViewListCtrl->AppendTextColumn(wxT("ID"), wxDATAVIEW_CELL_INERT, 40, static_cast<wxAlignment>(wxALIGN_CENTER), wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE); | |
| 221 m_dataViewListColumnName = m_dataViewListCtrl->AppendTextColumn(wxT(" 名称"), wxDATAVIEW_CELL_INERT, 280, static_cast<wxAlignment>(wxALIGN_LEFT), wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE); | |
| 222 m_dataViewListColumnCity = m_dataViewListCtrl->AppendTextColumn(wxT("市町村"), wxDATAVIEW_CELL_INERT, -1, static_cast<wxAlignment>(wxALIGN_CENTER), wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE); | |
| 223 m_dataViewListColumnKind = m_dataViewListCtrl->AppendTextColumn(wxT(" 区分"), wxDATAVIEW_CELL_INERT, -1, static_cast<wxAlignment>(wxALIGN_LEFT), wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE); | |
| 224 bSizerTop->Add(m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5); | |
| 225 | |
| 226 this->SetSizer(bSizerTop); | |
| 227 this->Layout(); | |
| 228 | |
| 229 this->Centre(wxBOTH); | |
| 230 } | |
| 231 | |
| 232 void MainFrame::LoadConfig() | |
| 233 { | |
| 234 wxFileSystem::AddHandler(new wxZipFSHandler); | |
| 235 wxFileSystem* fs = new wxFileSystem; | |
| 236 wxString archive = wxT("iklist.lib"); | |
| 237 | |
| 238 // Load Password | |
| 239 wxString pwfn = wxT("p8wypswd5c0x"); | |
| 240 wxFSFile* pwfile = fs->OpenFile(archive + wxT("#zip:") + pwfn); | |
| 241 if (pwfile) { | |
| 242 wxInputStream *zstream = pwfile->GetStream(); | |
| 243 wxTextInputStream tstream(*zstream); | |
| 244 m_pswd = tstream.ReadLine(); | |
| 245 delete pwfile; | |
| 246 } | |
| 247 | |
| 248 // Load List | |
| 249 wxString listfn = wxT("q534list8mor"); | |
| 250 wxFSFile* listfile = fs->OpenFile(archive + wxT("#zip:") + listfn); | |
| 251 if (listfile) { | |
| 252 wxInputStream *zstream = listfile->GetStream(); | |
| 253 wxTextInputStream tstream(*zstream); | |
| 254 for (int i = 0; i < 541; i++) { //######################### | |
| 255 //while (!zstream->Eof()) { | |
| 256 m_data.Add(tstream.ReadLine()); | |
| 257 } | |
| 258 delete listfile; | |
| 259 } | |
| 260 | |
| 261 // Set Filter | |
| 262 wxArrayString filter1, filter2; | |
| 263 filter1.Add(wxEmptyString); | |
| 264 filter2.Add(wxEmptyString); | |
| 265 for (int i = 0; i < m_data.GetCount(); i++) { | |
| 266 wxArrayString str = wxSplit(m_data[i], ':'); | |
| 267 bool flag1, flag2; | |
| 268 for (int j = 0; j < filter1.GetCount(); j++) { | |
| 269 if (filter1[j].IsSameAs(str[1])) { | |
| 270 flag1 = false; | |
| 271 } else { | |
| 272 flag1 = true; | |
| 273 } | |
| 274 } | |
| 275 if (flag1) filter1.Add(str[1]); | |
| 276 | |
| 277 for (int j = 0; j < filter2.GetCount(); j++) { | |
| 278 if (filter2[j].IsSameAs(str[2])) { | |
| 279 flag2 = false; | |
| 280 } else { | |
| 281 flag2 = true; | |
| 282 } | |
| 283 } | |
| 284 if (flag2) filter2.Add(str[2]); | |
| 285 } | |
| 286 | |
| 287 for (int i = 0; i < filter1.GetCount(); i++) { | |
| 288 m_choiceCity->Append(filter1[i]); | |
| 289 } | |
| 290 m_choiceCity->SetSelection(0); | |
| 291 for (int i = 0; i < filter2.GetCount(); i++) { | |
| 292 m_choiceKind->Append(filter2[i]); | |
| 293 } | |
| 294 m_choiceKind->SetSelection(0); | |
| 295 | |
| 296 delete fs; | |
| 297 } | |
| 298 | |
| 299 void MainFrame::CheckPassword() | |
| 300 { | |
| 301 if (m_textCtrl->GetValue().IsSameAs(m_pswd, true)) { | |
| 302 m_staticTextWord->SetLabel(wxT("キーワード:")); | |
| 303 m_searchCtrl->SetSize(200, -1); | |
| 304 m_textCtrl->SetSize(0, -1); | |
| 305 m_textCtrl->Hide(); | |
| 306 m_button->SetSize(0, -1); | |
| 307 m_button->Hide(); | |
| 308 SetList(); | |
| 309 } else { | |
| 310 m_textCtrl->SetBackgroundColour(wxColour(255, 160, 160)); | |
| 311 m_textCtrl->SelectAll(); | |
| 312 } | |
| 313 } | |
| 314 |
