diff src/rsearcher.cpp @ 2:7fe3417cefc8

GUI.
author pyon@macmini
date Tue, 02 Oct 2018 21:20:05 +0900
parents eaa27e4ed5be
children db4813125eb8
line wrap: on
line diff
--- a/src/rsearcher.cpp	Mon Oct 01 23:18:29 2018 +0900
+++ b/src/rsearcher.cpp	Tue Oct 02 21:20:05 2018 +0900
@@ -1,7 +1,8 @@
 // Filename   : rsearcher.cpp
-// Last Change: 2018-10-01 Mon 23:15:33.
+// Last Change: 2018-10-02 Tue 19:43:14.
 //
 
+#include <wx/arrstr.h> 
 #include "rsearcher.h"
 #include "main.h"
 
@@ -37,13 +38,11 @@
     int kc = event.GetKeyCode();
 
     if ( kc == 13 ) {	// Enter
-		// select all
-		wxString s = GetValue();
+		SelectAll();
 
 		MainFrame* f = (MainFrame*)FindWindowById( ID_MAIN );
-		f->Cmd( s );
+		f->Cmd( GetValue() );
 
-        wxMessageBox( "Enter ed" );
         event.Skip();
         return;
     }
@@ -147,15 +146,20 @@
 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
 	: wxFrame( parent, id, title, pos, size, style )
 {
+	LoadIndex();
 	CreateControls();
 }
 
 MainFrame::~MainFrame()
 {
+	RemoveFile( wxT( "auth.db" ) );
+	RemoveFile( wxT( "hhs.db" ) );
+	RemoveFile( wxT( ".cache/*" )  );
 }
 
 // Event Table
 BEGIN_EVENT_TABLE( MainFrame, wxFrame )
+    EVT_DATAVIEW_SELECTION_CHANGED( ID_LIST, MainFrame::OnItemSelected )
     EVT_DATAVIEW_ITEM_ACTIVATED( ID_LIST, MainFrame::OnItemDClicked )
     EVT_NOTEBOOK_PAGE_CHANGED( ID_NBOOK, MainFrame::OnNBookChanged )
 	EVT_BUTTON( ID_TEST, MainFrame::OnTestButton )
@@ -165,13 +169,23 @@
 
 
 // Event Handler
+void MainFrame::OnItemSelected( wxDataViewEvent& WXUNUSED(event) )
+{
+    int r = m_dataViewListCtrl->GetSelectedRow();
+    wxString ready = m_dataViewListCtrl->GetTextValue( r, 2 );
+	if ( ready.IsSameAs( wxT( "ok" ), true ) ) {
+		wxString buf = m_dataViewListCtrl->GetTextValue( r, 1 );
+		LoadBitmaps( wxT( "00000000" ) );
+	}
+}
+
 void MainFrame::OnItemDClicked( wxDataViewEvent& WXUNUSED(event) )
 {
-    wxMessageBox( "dcli" );
     int r = m_dataViewListCtrl->GetSelectedRow();
-    wxString no = m_dataViewListCtrl->GetTextValue( r, 0 );
-
-    LoadBitmaps();
+    wxString date = m_dataViewListCtrl->GetTextValue( r, 1 );
+	date.Replace( wxT( "-" ), wxEmptyString, true );
+	GetImages( m_hhs, date );
+	LoadBitmaps( wxT( "00000000" ) );
 }
 
 void MainFrame::OnNBookChanged( wxBookCtrlEvent& WXUNUSED(event) )
@@ -183,19 +197,12 @@
 }
 
 /*
-void MainFrame::OnItemSelected( wxDataViewEvent& event )
-{
-    dclick or select ?
-}
-*/
-
-
-/*
 void MainFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
 {
 }
 
 */
+
 void MainFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) )
 {
     if ( !IsIconized() && !IsMaximized() ) {
@@ -206,29 +213,7 @@
 
 void MainFrame::OnTestButton( wxCommandEvent& WXUNUSED(event) )
 {
-    /* ok
-    Cmd( m_searchCtrl->GetValue() );
-    Cmd( wxT( "0100012345" ) );
-    */
-
-    wxBitmap bmp( wxT(".cache/01_1"), wxBITMAP_TYPE_JPEG );
-    int width  = bmp.GetWidth();
-    int height = bmp.GetHeight();
-    wxImage img = bmp.ConvertToImage();
-
-    int ww, wh;
-    m_scrolledWindow6->GetSize( &ww, &wh );
-
-    float w = ww;
-    float h = w * height / width;
-    m_staticBitmap6->SetBitmap( wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
-    m_scrolledWindow6->SetScrollbars( 10, 10, w / 10, h / 10 );
-
-    for ( int i = 0; i < 5; i++ ) {
-        w *= 1.1;
-        h *= 1.1;
-        //m_staticBitmap6->SetImage( i, wxBitmap( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ) );
-    }
+	return;
 }
 
 // Functions
@@ -237,6 +222,7 @@
     this->SetIcon( wxIcon( wxT( "sample" ) ) );
 	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
 	//this->SetBackgroundColour( wxColour( 0, 150, 230 ) );
+	this->SetBackgroundColour( wxColour( 153, 153, 153 ) );
 
 	wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
 	
@@ -287,20 +273,21 @@
 	m_textCtrlName->SetBackgroundColour( wxColour( 180, 210, 240 ) );
 	bSizerRight->Add( m_textCtrlName, 0, wxALL, 5 );
 	
-	m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 120, -1 ), 0 );
+	m_textCtrlAddr = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 160, -1 ), 0 );
 	m_textCtrlAddr->SetBackgroundColour( wxColour( 180, 210, 240 ) );
 	bSizerRight->Add( m_textCtrlAddr, 0, wxALL|wxEXPAND, 5 );
 	
 	m_dataViewListCtrl = new wxDataViewListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxDV_ROW_LINES|wxDV_SINGLE );
-	m_dataViewListColumnNo   = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ),   wxDATAVIEW_CELL_INERT,  30, wxALIGN_RIGHT,  wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
-	m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ), wxDATAVIEW_CELL_INERT, 120, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
+	m_dataViewListColumnNo   = m_dataViewListCtrl->AppendTextColumn( wxT( "No" ),    wxDATAVIEW_CELL_INERT, 30, wxALIGN_RIGHT,  wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
+	m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Date" ),  wxDATAVIEW_CELL_INERT, 80, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
+	m_dataViewListColumnDate = m_dataViewListCtrl->AppendTextColumn( wxT( "Ready" ), wxDATAVIEW_CELL_INERT, 60, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
 
 	bSizerRight->Add( m_dataViewListCtrl, 1, wxALL|wxEXPAND, 5 );
 	
 	m_textCtrlLog = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
 	bSizerRight->Add( m_textCtrlLog, 1, wxALL|wxEXPAND, 5 );
 
-	m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1,200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL );
+	m_slider = new wxSlider( this, ID_SLDR, 1, 1, 5, wxDefaultPosition, wxSize( -1, 200 ), wxSL_AUTOTICKS|wxSL_INVERSE|wxSL_LABELS|wxSL_VERTICAL );
 	bSizerRight->Add( m_slider, 0, wxALL, 5 );
 	
 	m_buttonPrint = new wxButton( this, ID_PRINT, wxT( "Print" ), wxDefaultPosition, wxDefaultSize, 0 );
@@ -326,12 +313,19 @@
 void MainFrame::Cmd( wxString cmd )
 {
 	m_dataViewListCtrl->DeleteAllItems();
+	LoadBitmaps( wxEmptyString );
 
-    if ( cmd.Cmp( wxT( "q" ) ) == 0 || cmd.Cmp( wxT( "9" ) ) == 0 ) {
+    if ( cmd.IsSameAs( wxT( "q" ), true ) || cmd.IsSameAs( wxT( "9" ), true ) ) {
         Close();
+		return;
     }
 
-    if ( cmd.Cmp( wxT( "." ) ) == 0 ) {
+    if ( cmd.IsSameAs( wxT( "c" ), true ) || cmd.IsSameAs( wxT( "cmd" ), true ) ) {
+        Close();
+		return;
+    }
+
+    if ( cmd.IsSameAs( wxT( "." ), true ) ) {
         wxString appdir = wxGetCwd();
         wxString execmd = wxT( "explorer " ) + appdir;
         wxExecute( execmd );
@@ -340,30 +334,21 @@
 
     wxRegEx reHhs( wxT( "^0[1238][0-9]{8}$" ) );
     if ( reHhs.Matches( cmd ) ) {
-        wxArrayString output, errors;
-        cmd = wxT( "./rsearcher -q " ) + cmd;
-        wxExecute( cmd, output, errors, wxEXEC_SYNC, NULL ); // ok
+		m_hhs = m_searchCtrl->GetValue();
+		Search();
+		return;
+	}
 
-        if ( output.GetCount() > 0 ) {
-            m_textCtrlName->SetValue( output[0] );
-            m_textCtrlAddr->SetValue( output[2] );
-            for ( int i = 5, n = 1; i < output.GetCount(); i++, n++ ) {
-                wxVector<wxVariant> data;
-                data.push_back( wxString::Format( wxT( "%02d" ), n ) );
-                data.push_back( output[i] );
-                m_dataViewListCtrl->AppendItem( data );
-                data.clear();
-            }
-        }
-    
-        if ( errors.GetCount() > 0 ) {
-            wxMessageBox( errors[0], wxT( "Error" ) );
-        }
-    }
+	wxMessageBox( wxT( "Bad Input!!" ) );
 }
 
 void MainFrame::LoadBitmap( wxScrolledWindow* sc, wxStaticBitmap* sb, wxString file )
 {
+	if ( startup ) {
+		file = wxT( "image/hw201810.jpg" );
+		startup = false;
+	}
+	if ( !wxFileExists( file ) ) file = wxT( "image/testpattern.jpg" );
     wxBitmap bmp( file, wxBITMAP_TYPE_JPEG );
     int width  = bmp.GetWidth();
     int height = bmp.GetHeight();
@@ -384,36 +369,82 @@
     }
 }
 
-void MainFrame::LoadBitmaps( void )
+void MainFrame::LoadBitmaps( wxString date )
 {
-    int date = 0;
-    LoadBitmap( m_scrolledWindow1, m_staticBitmap1, wxString::Format( ".cache/%08d_1", date ) );
-    LoadBitmap( m_scrolledWindow2, m_staticBitmap2, wxString::Format( ".cache/%08d_2", date ) );
-    LoadBitmap( m_scrolledWindow3, m_staticBitmap3, wxString::Format( ".cache/%08d_3", date ) );
-    LoadBitmap( m_scrolledWindow4, m_staticBitmap4, wxString::Format( ".cache/%08d_4", date ) );
-    LoadBitmap( m_scrolledWindow5, m_staticBitmap5, wxString::Format( ".cache/%08d_5", date ) );
+    LoadBitmap( m_scrolledWindow1, m_staticBitmap1, wxString::Format( wxT( ".cache/%08s_1" ), date ) );
+    LoadBitmap( m_scrolledWindow2, m_staticBitmap2, wxString::Format( wxT( ".cache/%08s_2" ), date ) );
+    LoadBitmap( m_scrolledWindow3, m_staticBitmap3, wxString::Format( wxT( ".cache/%08s_3" ), date ) );
+    LoadBitmap( m_scrolledWindow4, m_staticBitmap4, wxString::Format( wxT( ".cache/%08s_4" ), date ) );
+    LoadBitmap( m_scrolledWindow5, m_staticBitmap5, wxString::Format( wxT( ".cache/%08s_5" ), date ) );
+}
+
+void MainFrame::GetImages( wxString hhs, wxString date )
+{
+	wxArrayString args;	// http get
+	args.Add( wxT( "client.exe" ) );
+	args.Add( m_server );
+	args.Add( hhs );
+	args.Add( date );
+
+	//wxMessageBox( wxJoin( args, ' ', '\\' ) );
+	wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_ASYNC|wxEXEC_HIDE_CONSOLE );
 }
 
-void MainFrame::GetImage( wxString hhs, wxString no )
+void MainFrame::Search( void )
 {
-    // http get
+	wxString date;
+	int match_cnt = 0;
+	for ( int i = 0; i < m_index.GetCount(); i++ ) {
+		if ( m_index[i].StartsWith( m_hhs, &date ) ) {
+			wxVector<wxVariant> data;
+			data.push_back( wxString::Format( wxT( "%02d" ), ++match_cnt ) );
+			date = date.Mid( 1, 4 ) + wxT( "-" ) + date.Mid( 5, 2 ) + wxT( "-" ) + date.Mid( 7, 2 );
+			data.push_back( date );
+			data.push_back( wxEmptyString );
+			m_dataViewListCtrl->AppendItem( data );
+			data.clear();
+		}
+	}
+	if ( match_cnt == 0 ) wxMessageBox( wxT( "Not Matched!!" ) );
+}
+
+void MainFrame::LoadIndex( void )
+{
+	wxTextFile file;
+	file.Open( wxT( "index.db" ) );
+	for ( int i = 0; i < file.GetLineCount(); i++ )
+		m_index.Add( file.GetLine( i ) );
+	file.Close();
+	m_index.Sort( true );
+}
+
+void MainFrame::RemoveFile( wxString pattern )
+{
+	wxString file = wxFindFirstFile( pattern );
+	while ( !file.empty() ) {
+		wxRemoveFile( file  );
+		file = wxFindNextFile();
+	}
 }
 
 void MainFrame::InDevelop( bool flag )
 {
     if ( !flag ) return;
-    LoadBitmaps();
+    //LoadBitmaps( wxT( "00000000" ) );
+    LoadBitmaps( wxEmptyString );
     
 	m_slider->Enable( false );
 	m_slider->Show( false );
 
+	bool pr = true;
 	m_buttonPrint->Enable( false );
-	m_buttonPrint->Show( false );
+	m_buttonPrint->Show( true );
 
-	bool tb = false;
+	bool tb = true;
 	m_buttonTest->Enable( tb );
 	m_buttonTest->Show( tb );
 
-	m_searchCtrl->Enable( false );
+	bool srch = true;
+	m_searchCtrl->Enable( srch );
 }