comparison src/rsearcher.cpp @ 2:7fe3417cefc8

GUI.
author pyon@macmini
date Tue, 02 Oct 2018 21:20:05 +0900
parents eaa27e4ed5be
children db4813125eb8
comparison
equal deleted inserted replaced
1:eaa27e4ed5be 2:7fe3417cefc8
1 // Filename : rsearcher.cpp 1 // Filename : rsearcher.cpp
2 // Last Change: 2018-10-01 Mon 23:15:33. 2 // Last Change: 2018-10-02 Tue 19:43:14.
3 // 3 //
4 4
5 #include <wx/arrstr.h>
5 #include "rsearcher.h" 6 #include "rsearcher.h"
6 #include "main.h" 7 #include "main.h"
7 8
8 /********************/ 9 /********************/
9 /** MySearchCtrl **/ 10 /** MySearchCtrl **/
35 void MySearchCtrl::OnKey( wxKeyEvent& event ) 36 void MySearchCtrl::OnKey( wxKeyEvent& event )
36 { 37 {
37 int kc = event.GetKeyCode(); 38 int kc = event.GetKeyCode();
38 39
39 if ( kc == 13 ) { // Enter 40 if ( kc == 13 ) { // Enter
40 // select all 41 SelectAll();
41 wxString s = GetValue();
42 42
43 MainFrame* f = (MainFrame*)FindWindowById( ID_MAIN ); 43 MainFrame* f = (MainFrame*)FindWindowById( ID_MAIN );
44 f->Cmd( s ); 44 f->Cmd( GetValue() );
45 45
46 wxMessageBox( "Enter ed" );
47 event.Skip(); 46 event.Skip();
48 return; 47 return;
49 } 48 }
50 49
51 if ( kc == 45 ) { // Num-Key '-' as Backspace 50 if ( kc == 45 ) { // Num-Key '-' as Backspace
145 /** Main Frame **/ 144 /** Main Frame **/
146 /********************/ 145 /********************/
147 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 146 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
148 : wxFrame( parent, id, title, pos, size, style ) 147 : wxFrame( parent, id, title, pos, size, style )
149 { 148 {
149 LoadIndex();
150 CreateControls(); 150 CreateControls();
151 } 151 }
152 152
153 MainFrame::~MainFrame() 153 MainFrame::~MainFrame()
154 { 154 {
155 RemoveFile( wxT( "auth.db" ) );
156 RemoveFile( wxT( "hhs.db" ) );
157 RemoveFile( wxT( ".cache/*" ) );
155 } 158 }
156 159
157 // Event Table 160 // Event Table
158 BEGIN_EVENT_TABLE( MainFrame, wxFrame ) 161 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
162 EVT_DATAVIEW_SELECTION_CHANGED( ID_LIST, MainFrame::OnItemSelected )
159 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked ) 163 EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked )
160 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged ) 164 EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
161 EVT_BUTTON( ID_TEST, MainFrame::OnTestButton ) 165 EVT_BUTTON( ID_TEST, MainFrame::OnTestButton )
162 EVT_CLOSE( MainFrame::SaveConfig ) 166 EVT_CLOSE( MainFrame::SaveConfig )
163 //EVT_IDLE( MainFrame::OnIdle ) 167 //EVT_IDLE( MainFrame::OnIdle )
164 END_EVENT_TABLE() 168 END_EVENT_TABLE()
165 169
166 170
167 // Event Handler 171 // Event Handler
172 void MainFrame::OnItemSelected( wxDataViewEvent& WXUNUSED(event) )
173 {
174 int r = m_dataViewListCtrl->GetSelectedRow();
175 wxString ready = m_dataViewListCtrl->GetTextValue( r, 2 );
176 if ( ready.IsSameAs( wxT( "ok" ), true ) ) {
177 wxString buf = m_dataViewListCtrl->GetTextValue( r, 1 );
178 LoadBitmaps( wxT( "00000000" ) );
179 }
180 }
181
168 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) ) 182 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) )
169 { 183 {
170 wxMessageBox( "dcli" );
171 int r = m_dataViewListCtrl->GetSelectedRow(); 184 int r = m_dataViewListCtrl->GetSelectedRow();
172 wxString no = m_dataViewListCtrl->GetTextValue( r, 0 ); 185 wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
173 186 date.Replace( wxT( "-" ), wxEmptyString, true );
174 LoadBitmaps(); 187 GetImages( m_hhs, date );
188 LoadBitmaps( wxT( "00000000" ) );
175 } 189 }
176 190
177 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) ) 191 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) )
178 { 192 {
179 for ( int i = 0; i < m_notebook->GetPageCount(); i++ ) { 193 for ( int i = 0; i < m_notebook->GetPageCount(); i++ ) {
181 } 195 }
182 m_notebook->SetPageImage( m_notebook->GetSelection(), 0 ); 196 m_notebook->SetPageImage( m_notebook->GetSelection(), 0 );
183 } 197 }
184 198
185 /* 199 /*
186 void MainFrame::OnItemSelected( wxDataViewEvent& event ) 200 void MainFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
187 { 201 {
188 dclick or select ? 202 }
189 } 203
190 */ 204 */
191 205
192
193 /*
194 void MainFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
195 {
196 }
197
198 */
199 void MainFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) ) 206 void MainFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) )
200 { 207 {
201 if ( !IsIconized() && !IsMaximized() ) { 208 if ( !IsIconized() && !IsMaximized() ) {
202 wxGetApp().rect = this->GetRect(); 209 wxGetApp().rect = this->GetRect();
203 } 210 }
204 Destroy(); 211 Destroy();
205 } 212 }
206 213
207 void MainFrame::OnTestButton( wxCommandEvent& WXUNUSED(event) ) 214 void MainFrame::OnTestButton( wxCommandEvent& WXUNUSED(event) )
208 { 215 {
209 /* ok 216 return;
210 Cmd( m_searchCtrl->GetValue() );
211 Cmd( wxT( "0100012345" ) );
212 */
213
214 wxBitmap bmp( wxT(".cache/01_1"), wxBITMAP_TYPE_JPEG );
215 int width = bmp.GetWidth();
216 int height = bmp.GetHeight();
217 wxImage img = bmp.ConvertToImage();
218
219 int ww, wh;
220 m_scrolledWindow6->GetSize( &ww, &wh );
221
222 float w = ww;
223 float h = w * height / width;
224 m_staticBitmap6->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
225 m_scrolledWindow6->SetScrollbars( 10, 10, w / 10, h / 10 );
226
227 for ( int i = 0; i < 5; i++ ) {
228 w *= 1.1;
229 h *= 1.1;
230 //m_staticBitmap6->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
231 }
232 } 217 }
233 218
234 // Functions 219 // Functions
235 void MainFrame::CreateControls( void ) 220 void MainFrame::CreateControls( void )
236 { 221 {
237 this->SetIcon( wxIcon( wxT( "sample" ) ) ); 222 this->SetIcon( wxIcon( wxT( "sample" ) ) );
238 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); 223 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
239 //this->SetBackgroundColour( wxColour( 0, 150, 230 ) ); 224 //this->SetBackgroundColour( wxColour( 0, 150, 230 ) );
225 this->SetBackgroundColour( wxColour( 153, 153, 153 ) );
240 226
241 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); 227 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
242 228
243 // Left 229 // Left
244 wxImageList* imgList = new wxImageList( 16, 16, false, 1 ); 230 wxImageList* imgList = new wxImageList( 16, 16, false, 1 );
285 271
286 m_textCtrlName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, -1 ), 0 ); 272 m_textCtrlName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 80, -1 ), 0 );
287 m_textCtrlName->SetBackgroundColour( wxColour( 180, 210, 240 ) ); 273 m_textCtrlName->SetBackgroundColour( wxColour( 180, 210, 240 ) );
288 bSizerRight->Add( m_textCtrlName, 0, wxALL, 5 ); 274 bSizerRight->Add( m_textCtrlName, 0, wxALL, 5 );
289 275
290 m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 120, -1 ), 0 ); 276 m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 160, -1 ), 0 );
291 m_textCtrlAddr->SetBackgroundColour( wxColour( 180, 210, 240 ) ); 277 m_textCtrlAddr->SetBackgroundColour( wxColour( 180, 210, 240 ) );
292 bSizerRight->Add( m_textCtrlAddr, 0, wxALL|wxEXPAND, 5 ); 278 bSizerRight->Add( m_textCtrlAddr, 0, wxALL|wxEXPAND, 5 );
293 279
294 m_dataViewListCtrl = new wxDataViewListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxDV_ROW_LINES|wxDV_SINGLE ); 280 m_dataViewListCtrl = new wxDataViewListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxDV_ROW_LINES|wxDV_SINGLE );
295 m_dataViewListColumnNo = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ), wxDATAVIEW_CELL_INERT, 30, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE ); 281 m_dataViewListColumnNo = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ), wxDATAVIEW_CELL_INERT, 30, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
296 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ), wxDATAVIEW_CELL_INERT, 120, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE ); 282 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ), wxDATAVIEW_CELL_INERT, 80, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
283 m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Ready" ), wxDATAVIEW_CELL_INERT, 60, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
297 284
298 bSizerRight->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 ); 285 bSizerRight->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 );
299 286
300 m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); 287 m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
301 bSizerRight->Add( m_textCtrlLog, 1, wxALL|wxEXPAND, 5 ); 288 bSizerRight->Add( m_textCtrlLog, 1, wxALL|wxEXPAND, 5 );
302 289
303 m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1,200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL ); 290 m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1, 200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL );
304 bSizerRight->Add( m_slider, 0, wxALL, 5 ); 291 bSizerRight->Add( m_slider, 0, wxALL, 5 );
305 292
306 m_buttonPrint = new wxButton( this, ID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 ); 293 m_buttonPrint = new wxButton( this, ID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
307 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 ); 294 bSizerRight->Add( m_buttonPrint, 0, wxALL, 5 );
308 295
324 } 311 }
325 312
326 void MainFrame::Cmd( wxString cmd ) 313 void MainFrame::Cmd( wxString cmd )
327 { 314 {
328 m_dataViewListCtrl->DeleteAllItems(); 315 m_dataViewListCtrl->DeleteAllItems();
329 316 LoadBitmaps( wxEmptyString );
330 if ( cmd.Cmp( wxT( "q" ) ) == 0 || cmd.Cmp( wxT( "9" ) ) == 0 ) { 317
318 if ( cmd.IsSameAs( wxT( "q" ), true ) || cmd.IsSameAs( wxT( "9" ), true ) ) {
331 Close(); 319 Close();
332 } 320 return;
333 321 }
334 if ( cmd.Cmp( wxT( "." ) ) == 0 ) { 322
323 if ( cmd.IsSameAs( wxT( "c" ), true ) || cmd.IsSameAs( wxT( "cmd" ), true ) ) {
324 Close();
325 return;
326 }
327
328 if ( cmd.IsSameAs( wxT( "." ), true ) ) {
335 wxString appdir = wxGetCwd(); 329 wxString appdir = wxGetCwd();
336 wxString execmd = wxT( "explorer " ) + appdir; 330 wxString execmd = wxT( "explorer " ) + appdir;
337 wxExecute( execmd ); 331 wxExecute( execmd );
338 return; 332 return;
339 } 333 }
340 334
341 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) ); 335 wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
342 if ( reHhs.Matches( cmd ) ) { 336 if ( reHhs.Matches( cmd ) ) {
343 wxArrayString output, errors; 337 m_hhs = m_searchCtrl->GetValue();
344 cmd = wxT( "./rsearcher -q " ) + cmd; 338 Search();
345 wxExecute( cmd, output, errors, wxEXEC_SYNC, NULL ); // ok 339 return;
346 340 }
347 if ( output.GetCount() > 0 ) { 341
348 m_textCtrlName->SetValue( output[0] ); 342 wxMessageBox( wxT( "Bad Input!!" ) );
349 m_textCtrlAddr->SetValue( output[2] );
350 for ( int i = 5, n = 1; i < output.GetCount(); i++, n++ ) {
351 wxVector<wxVariant> data;
352 data.push_back( wxString::Format( wxT( "%02d" ), n ) );
353 data.push_back( output[i] );
354 m_dataViewListCtrl->AppendItem( data );
355 data.clear();
356 }
357 }
358
359 if ( errors.GetCount() > 0 ) {
360 wxMessageBox( errors[0], wxT( "Error" ) );
361 }
362 }
363 } 343 }
364 344
365 void MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file ) 345 void MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file )
366 { 346 {
347 if ( startup ) {
348 file = wxT( "image/hw201810.jpg" );
349 startup = false;
350 }
351 if ( !wxFileExists( file ) ) file = wxT( "image/testpattern.jpg" );
367 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG ); 352 wxBitmap bmp( file, wxBITMAP_TYPE_JPEG );
368 int width = bmp.GetWidth(); 353 int width = bmp.GetWidth();
369 int height = bmp.GetHeight(); 354 int height = bmp.GetHeight();
370 wxImage img = bmp.ConvertToImage(); 355 wxImage img = bmp.ConvertToImage();
371 356
382 h *= 1.1; 367 h *= 1.1;
383 //sb->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) ); 368 //sb->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
384 } 369 }
385 } 370 }
386 371
387 void MainFrame::LoadBitmaps( void ) 372 void MainFrame::LoadBitmaps( wxString date )
388 { 373 {
389 int date = 0; 374 LoadBitmap( m_scrolledWindow1, m_staticBitmap1, wxString::Format( wxT( ".cache/%08s_1" ), date ) );
390 LoadBitmap( m_scrolledWindow1, m_staticBitmap1, wxString::Format( ".cache/%08d_1", date ) ); 375 LoadBitmap( m_scrolledWindow2, m_staticBitmap2, wxString::Format( wxT( ".cache/%08s_2" ), date ) );
391 LoadBitmap( m_scrolledWindow2, m_staticBitmap2, wxString::Format( ".cache/%08d_2", date ) ); 376 LoadBitmap( m_scrolledWindow3, m_staticBitmap3, wxString::Format( wxT( ".cache/%08s_3" ), date ) );
392 LoadBitmap( m_scrolledWindow3, m_staticBitmap3, wxString::Format( ".cache/%08d_3", date ) ); 377 LoadBitmap( m_scrolledWindow4, m_staticBitmap4, wxString::Format( wxT( ".cache/%08s_4" ), date ) );
393 LoadBitmap( m_scrolledWindow4, m_staticBitmap4, wxString::Format( ".cache/%08d_4", date ) ); 378 LoadBitmap( m_scrolledWindow5, m_staticBitmap5, wxString::Format( wxT( ".cache/%08s_5" ), date ) );
394 LoadBitmap( m_scrolledWindow5, m_staticBitmap5, wxString::Format( ".cache/%08d_5", date ) ); 379 }
395 } 380
396 381 void MainFrame::GetImages( wxString hhs, wxString date )
397 void MainFrame::GetImage( wxString hhs, wxString no ) 382 {
398 { 383 wxArrayString args; // http get
399 // http get 384 args.Add( wxT( "client.exe" ) );
385 args.Add( m_server );
386 args.Add( hhs );
387 args.Add( date );
388
389 //wxMessageBox( wxJoin( args, ' ', '\\' ) );
390 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_ASYNC|wxEXEC_HIDE_CONSOLE );
391 }
392
393 void MainFrame::Search( void )
394 {
395 wxString date;
396 int match_cnt = 0;
397 for ( int i = 0; i < m_index.GetCount(); i++ ) {
398 if ( m_index[i].StartsWith( m_hhs, &date ) ) {
399 wxVector<wxVariant> data;
400 data.push_back( wxString::Format( wxT( "%02d" ), ++match_cnt ) );
401 date = date.Mid( 1, 4 ) + wxT( "-" ) + date.Mid( 5, 2 ) + wxT( "-" ) + date.Mid( 7, 2 );
402 data.push_back( date );
403 data.push_back( wxEmptyString );
404 m_dataViewListCtrl->AppendItem( data );
405 data.clear();
406 }
407 }
408 if ( match_cnt == 0 ) wxMessageBox( wxT( "Not Matched!!" ) );
409 }
410
411 void MainFrame::LoadIndex( void )
412 {
413 wxTextFile file;
414 file.Open( wxT( "index.db" ) );
415 for ( int i = 0; i < file.GetLineCount(); i++ )
416 m_index.Add( file.GetLine( i ) );
417 file.Close();
418 m_index.Sort( true );
419 }
420
421 void MainFrame::RemoveFile( wxString pattern )
422 {
423 wxString file = wxFindFirstFile( pattern );
424 while ( !file.empty() ) {
425 wxRemoveFile( file );
426 file = wxFindNextFile();
427 }
400 } 428 }
401 429
402 void MainFrame::InDevelop( bool flag ) 430 void MainFrame::InDevelop( bool flag )
403 { 431 {
404 if ( !flag ) return; 432 if ( !flag ) return;
405 LoadBitmaps(); 433 //LoadBitmaps( wxT( "00000000" ) );
434 LoadBitmaps( wxEmptyString );
406 435
407 m_slider->Enable( false ); 436 m_slider->Enable( false );
408 m_slider->Show( false ); 437 m_slider->Show( false );
409 438
439 bool pr = true;
410 m_buttonPrint->Enable( false ); 440 m_buttonPrint->Enable( false );
411 m_buttonPrint->Show( false ); 441 m_buttonPrint->Show( true );
412 442
413 bool tb = false; 443 bool tb = true;
414 m_buttonTest->Enable( tb ); 444 m_buttonTest->Enable( tb );
415 m_buttonTest->Show( tb ); 445 m_buttonTest->Show( tb );
416 446
417 m_searchCtrl->Enable( false ); 447 bool srch = true;
418 } 448 m_searchCtrl->Enable( srch );
419 449 }
450