changeset 7:29829e98d510

add net.cpp
author pyon@macmini
date Fri, 26 Oct 2018 21:05:11 +0900
parents 9a8b581c1993
children 82f9af6aa7e4
files Makefile app.conf go/client.go include/id.h include/main.h include/rsearcher.h src/main.cpp src/rsearcher.cpp
diffstat 8 files changed, 125 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Oct 23 19:15:22 2018 +0900
+++ b/Makefile	Fri Oct 26 21:05:11 2018 +0900
@@ -1,5 +1,5 @@
 # Makefile for wxWidgets Application
-# Last Change: 2018-10-01 Mon 23:12:08.
+# Last Change: 2018-10-25  17:08:35.
 # by Takayuki Mutoh
 #
 
@@ -34,7 +34,8 @@
 
 OBJ = $(OBJDIR)/main.o \
 	  $(OBJDIR)/auth.o \
-	  $(OBJDIR)/rsearcher.o
+	  $(OBJDIR)/rsearcher.o \
+	  $(OBJDIR)/net.o
 
 ifdef COMSPEC
 OBJMSW = $(OBJ) $(OBJDIR)/sample_rc.o
@@ -54,12 +55,15 @@
 	-mkdir -p $(OBJDIR)
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
-$(OBJDIR)/rsearcher.o: rsearcher.cpp rsearcher.h 
+$(OBJDIR)/rsearcher.o: rsearcher.cpp rsearcher.h net.h
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
 $(OBJDIR)/auth.o: auth.cpp auth.h 
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
+$(OBJDIR)/net.o: net.cpp net.h 
+	$(CXX) -c $< -o $@ $(CXXFLAGS)
+
 
 # for icon
 ifdef COMSPEC
--- a/app.conf	Tue Oct 23 19:15:22 2018 +0900
+++ b/app.conf	Fri Oct 26 21:05:11 2018 +0900
@@ -1,8 +1,11 @@
-[Geometry]
-x=487
-y=118
-w=1136
-h=721
-[Server]
-server=192.168.79.124:3910
-proxy=
+[Geometry]
+x=71
+y=0
+w=1191
+h=724
+
+[Server]
+address=192.168.79.124
+port=3910
+proxy_address=
+proxy_port=
--- a/go/client.go	Tue Oct 23 19:15:22 2018 +0900
+++ b/go/client.go	Fri Oct 26 21:05:11 2018 +0900
@@ -1,7 +1,7 @@
 /*
  client.go  : client-program.
  Version    : 1.1
- Last Change: 2018-10-12 金 13:42:55.
+ Last Change: 2018-10-24 水 17:21:52.
 
  install to: rsearcher_root/
 
@@ -45,7 +45,7 @@
 }
 
 func main() {
-    var upgrade  = flag.Bool( "r", false, "" )  // get grsearcher.exe, client.exe
+    var upgrade  = flag.Bool( "r", false, "" )  // get grsearcher.exe, crypto.exe client.exe
     var update   = flag.Bool( "u", false, "" )  // get auth.db, hhs.db, index.db(14,28)
     var upload   = flag.Bool( "a", false, "" )  // post somefile
     var printver = flag.Bool( "v", false, "" )  // print version
--- a/include/id.h	Tue Oct 23 19:15:22 2018 +0900
+++ b/include/id.h	Fri Oct 26 21:05:11 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : id.h
-// Last Change: 2018-10-23  12:36:12.
+// Last Change: 2018-10-26  10:43:22.
 //
 
 #ifndef __ID_H__
@@ -7,8 +7,8 @@
 
 #include <wx/wx.h>
 
-#define RSVER "1.0"
-#define RSRELEASE "2018.10.25"
+#define RSVER "1.1"
+#define RSRELEASE "2018.10.29"
 
 enum {
 	ID_MAIN = wxID_HIGHEST + 1,
@@ -16,7 +16,10 @@
 	ID_PSEARCH,
 	ID_LIST,
 	ID_NBOOK,
+
+	// invisible for shortcut-key
 	ID_SLDR,
+	ID_FOCUS,
 	ID_PZOOM,
 	ID_MZOOM,
 	ID_DARK,
--- a/include/main.h	Tue Oct 23 19:15:22 2018 +0900
+++ b/include/main.h	Fri Oct 26 21:05:11 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : main.h
-// Last Change: 2018-10-23  10:09:58.
+// Last Change: 2018-10-25  17:24:41.
 //
 #include <wx/wx.h>
 #include <wx/config.h>
@@ -17,7 +17,8 @@
 	private:
 		wxFileConfig *config;
 		wxString      conf_file;
-		wxString	  m_server;
+		wxString	  m_serveraddr;
+		int     	  m_serverport;
         bool          develop;
 
 	public:
--- a/include/rsearcher.h	Tue Oct 23 19:15:22 2018 +0900
+++ b/include/rsearcher.h	Fri Oct 26 21:05:11 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : rsearcher.h
-// Last Change: 2018-10-23  14:26:02.
+// Last Change: 2018-10-26  15:10:47.
 //
 
 #ifndef __RSEARCH_H__
@@ -30,6 +30,7 @@
 #include <wx/textfile.h>
 #include <wx/timer.h>
 #include <wx/hashmap.h>
+#include "net.h"
 
 /* Data Class */
 class HhsClass {
@@ -94,6 +95,7 @@
 		wxArrayString m_index;
 		wxTimer       m_timer;
 		HhsHash       hhash;
+		RsHttp		  http;
 		bool		  m_dark = false;
 	
 	protected:
@@ -124,17 +126,20 @@
 
 		// invisible button for shortcut-key
 		wxSlider*           m_slider;
+		wxButton*           m_buttonFocus;
 		wxButton*           m_buttonPzoom;
 		wxButton*           m_buttonMzoom;
 		wxButton*           m_buttonDark;
 		wxButton*           m_buttonHelp;
+		wxButton*           m_buttonClose;
 		wxButton*           m_buttonLogout;
 	
 	public:
 		MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT( "Searcher Remote" ), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
 		~MainFrame();
 
-		void SetServer( wxString server ) { m_server = server; };
+		void SetServer( wxString addr, int port ) { http.SetServer( addr, port ); m_server = wxString::Format(wxT("%s:%d"),addr,port);};
+		void GetDB( void ) { http.GetDB(); };
 		void SetUser( wxString user ) { m_user = user; WriteLog( wxT( "[login] " ) + m_user ); };
 		void CreateControls( void );
 		void SetAccelerator( void );
@@ -147,9 +152,11 @@
 		void ChangeCZoom( int z );
 		void ChangeZoom( wxScrolledWindow* sc, MyStaticBitmap* sb, int z );
 		void ChangeColor( MyStaticBitmap* sb );
+        void GetImages2( wxString hhs, wxString date );
         void GetImages( wxString hhs, wxString date );
 		void PrintImages( void );
 		void WriteLog( wxString msg );
+		void Close( void );
         void InDevelop( bool );
 
 		void OnItemSelected( wxDataViewEvent& event );
@@ -157,9 +164,13 @@
         void OnNBookChanged( wxBookCtrlEvent& event );
         void OnPasteSearch( wxCommandEvent& event );
         void OnPrint( wxCommandEvent& event );
-		void OnClose( wxCloseEvent& event );	// save config
+		void OnClose( wxCloseEvent& event );
+		void OnBClose( wxCommandEvent& event );
 		void OnIdle( wxIdleEvent& event );
 		void OnTimer( wxTimerEvent& event );
+
+		// for shortcut-key
+        void OnFocus( wxCommandEvent& event );
         void OnPlusZoom( wxCommandEvent& event );
         void OnMinusZoom( wxCommandEvent& event );
         void OnDark( wxCommandEvent& event );
--- a/src/main.cpp	Tue Oct 23 19:15:22 2018 +0900
+++ b/src/main.cpp	Fri Oct 26 21:05:11 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : main.cpp
-// Last Change: 2018-10-23 火 10:09:42.
+// Last Change: 2018-10-26 金 13:14:54.
 //
 #include "id.h"
 #include "main.h"
@@ -26,10 +26,10 @@
     wxImage::AddHandler( new wxPNGHandler  );
 	InitSetting();
 
-	// Login Dialog
-    AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION );
-	authdlg->SetServer( m_server );
-	authdlg->GetDB();
+	// Main Window
+	MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
+	mainframe->SetServer( m_serveraddr, m_serverport );
+	mainframe->GetDB();
 
 	// Splash Screen
 	wxFileSystem::AddHandler( new wxZipFSHandler );
@@ -41,13 +41,15 @@
 			wxInputStream* s = file->GetStream();
 			wxImage image( *s, wxBITMAP_TYPE_PNG );
 			wxBitmap bmp = wxBitmap( image );
-			wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2500, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
+			wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, 2000, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE|wxSTAY_ON_TOP );
 			delete file;
 		}
-		wxMilliSleep( 200 );
+		wxMilliSleep( 150 );
 	}
 	delete fs;
 
+	// User Dialgo
+    AuthDialog *authdlg = new AuthDialog( NULL, wxID_ANY, wxT( "Who are you ?" ), wxDefaultPosition, wxDefaultSize, wxCAPTION );
 	if ( !authdlg->LoadDB() ) {
 		authdlg->Destroy();
 		return false;
@@ -72,15 +74,13 @@
 			delete fs;
 		}
 
-		// Main Window
-		MainFrame *mainframe = new MainFrame( NULL, ID_MAIN, wxEmptyString, wxPoint( rect.x, rect.y ), rect.GetSize(), wxDEFAULT_FRAME_STYLE );
+		mainframe->SetUser( authdlg->GetUser() );
+		mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() );
+		mainframe->LoadDB();
 		mainframe->InDevelop( true );
-		mainframe->SetServer( m_server );
-		mainframe->SetUser( authdlg->GetUser() );
-		mainframe->LoadDB();
-		mainframe->SetTitle( wxT( "Re:Searcher - " ) + authdlg->GetUser() );
 		mainframe->Show( true );
-		//mainframe->Destroy();
+	} else {
+		mainframe->Destroy();
 	}
 	authdlg->Destroy();
 
@@ -107,16 +107,19 @@
     config->Read( wxT( "w" ), &rect.width );
     config->Read( wxT( "h" ), &rect.height );
 
-	wxString proxy;
     config->SetPath( wxT( "/Server" ) );
-    config->Read( wxT( "server" ), &m_server );
-    config->Read( wxT( "proxy" ), &proxy );
+    config->Read( wxT( "proxy_address" ), &m_serveraddr );
+    config->Read( wxT( "proxy_port" ),    &m_serverport );
+    if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) {
+		config->Read( wxT( "address" ), &m_serveraddr );
+		config->Read( wxT( "port" ),    &m_serverport );
+	}
     delete config;
 
-    if ( !proxy.IsSameAs( wxEmptyString, false ) ) m_server = proxy;
-	//m_server = wxT( "192.168.79.124:80" );
-    if ( m_server.IsSameAs( wxEmptyString, false ) ) 
-        m_server = wxT( "192.168.21.151:80" );	// nginx
+    if ( m_serveraddr.IsSameAs( wxEmptyString, false ) ) {
+        m_serveraddr = wxT( "192.168.21.151" );	// nginx
+        m_serverport = 80;
+	}
 }
 
 void MyApp::SaveSetting()
--- a/src/rsearcher.cpp	Tue Oct 23 19:15:22 2018 +0900
+++ b/src/rsearcher.cpp	Fri Oct 26 21:05:11 2018 +0900
@@ -1,5 +1,5 @@
 // Filename   : rsearcher.cpp
-// Last Change: 2018-10-23  13:09:30.
+// Last Change: 2018-10-26  15:12:02.
 //
 
 #include <wx/arrstr.h> 
@@ -218,6 +218,7 @@
 MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
 	: wxFrame( parent, id, title, pos, size, style )
 {
+	http = RsHttp();
 	CreateControls();
 	SetAccelerator();
     LoadBitmaps( wxEmptyString, false );
@@ -233,16 +234,19 @@
     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_PSEARCH, MainFrame::OnPasteSearch )
 	EVT_BUTTON( wxID_PRINT, MainFrame::OnPrint )
-	EVT_BUTTON( ID_PSEARCH, MainFrame::OnPasteSearch )
+	EVT_CLOSE( MainFrame::OnClose )
+    EVT_IDLE( MainFrame::OnIdle )
+    EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
+	// shortcut-key
+	EVT_BUTTON( ID_FOCUS, MainFrame::OnFocus )
 	EVT_BUTTON( ID_PZOOM, MainFrame::OnPlusZoom )
 	EVT_BUTTON( ID_MZOOM, MainFrame::OnMinusZoom )
 	EVT_BUTTON( ID_DARK, MainFrame::OnDark )
 	EVT_BUTTON( wxID_HELP, MainFrame::OnHelp )
+	EVT_BUTTON( wxID_CLOSE, MainFrame::OnBClose )
 	EVT_BUTTON( ID_LOGOUT, MainFrame::OnLogout )
-	EVT_CLOSE( MainFrame::OnClose )
-    EVT_IDLE( MainFrame::OnIdle )
-    EVT_TIMER( ID_TIMER, MainFrame::OnTimer )
 END_EVENT_TABLE()
 
 
@@ -281,13 +285,19 @@
     m_notebook->SetPageImage( m_notebook->GetSelection(), 0 );
 }
 
-void MainFrame::OnClose( wxCloseEvent& WXUNUSED(event) )	// save config
+void MainFrame::OnBClose( wxCommandEvent& WXUNUSED(event) )
+{
+	Close();
+}
+
+void MainFrame::OnClose( wxCloseEvent& WXUNUSED(event) )
 {
-	WriteLog( wxT( "[logout]" ) );
-    if ( !IsIconized() && !IsMaximized() ) {
-        wxGetApp().rect = this->GetRect();
-    }
-    Destroy();
+	Close();
+}
+
+void MainFrame::OnFocus( wxCommandEvent& WXUNUSED(event) )
+{
+	m_searchCtrl->SetFocus();
 }
 
 void MainFrame::OnPasteSearch( wxCommandEvent& WXUNUSED(event) )
@@ -435,12 +445,16 @@
 	bSizerRight->Add( m_buttonLogout, 0, wxALL, 5 );
 	
 	// invisible buttons for shortcut-key
+	m_buttonFocus = new wxButton( this, ID_FOCUS, wxT( "Focus" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonFocus->Hide();
 	m_buttonPzoom = new wxButton( this, ID_PZOOM, wxT( "ZOOM" ), wxDefaultPosition, wxDefaultSize, 0 );
 	m_buttonPzoom->Hide();
 	m_buttonMzoom = new wxButton( this, ID_MZOOM, wxT( "zoom" ), wxDefaultPosition, wxDefaultSize, 0 );
 	m_buttonMzoom->Hide();
 	m_buttonDark = new wxButton( this, ID_DARK, wxT( "Dark" ), wxDefaultPosition, wxDefaultSize, 0 );
 	m_buttonDark->Hide();
+	m_buttonClose  = new wxButton( this, wxID_CLOSE, wxT( "Close" ), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonClose->Hide();
 	m_buttonHelp  = new wxButton( this, wxID_HELP, wxT( "Help" ), wxDefaultPosition, wxDefaultSize, 0 );
 	m_buttonHelp->Hide();
 	
@@ -460,13 +474,16 @@
 
 void MainFrame::SetAccelerator( void )
 {
-	wxAcceleratorEntry entries[5];
+	wxAcceleratorEntry entries[8];
 	entries[0].Set( wxACCEL_CTRL,   (int)'P', wxID_PRINT );
 	entries[1].Set( wxACCEL_NORMAL, WXK_F1,   wxID_HELP );
-	entries[2].Set( wxACCEL_NORMAL, (int)'Z', ID_PZOOM );
-	entries[3].Set( wxACCEL_NORMAL, (int)'X', ID_MZOOM );
-	entries[4].Set( wxACCEL_NORMAL, (int)'D', ID_DARK );
-	wxAcceleratorTable accel( 5, entries );
+	entries[2].Set( wxACCEL_NORMAL, WXK_F4,   ID_FOCUS );
+	entries[3].Set( wxACCEL_NORMAL, (int)'Z', ID_PZOOM );
+	entries[4].Set( wxACCEL_NORMAL, (int)'X', ID_MZOOM );
+	entries[5].Set( wxACCEL_NORMAL, (int)'D', ID_DARK );
+	entries[6].Set( wxACCEL_SHIFT,  (int)'Q', wxID_CLOSE );
+	entries[7].Set( wxACCEL_SHIFT,  (int)'L', ID_DARK );	// now building ( logout )
+	wxAcceleratorTable accel( 8, entries );
 	SetAcceleratorTable( accel );
 }
 
@@ -562,7 +579,7 @@
 
 	if ( !ok && reload ) {
 		wxSleep( 5 );
-		LoadBitmaps( date, false );
+		ok = LoadBitmaps( date, false );
 	}
 	return ok;
 }
@@ -623,6 +640,21 @@
 
 void MainFrame::GetImages( wxString hhs, wxString date )
 {
+	GetImages2( hhs, date); return;	// here comment out
+
+	int estimate = 5;
+    wxProgressDialog pd( wxT( "Connecting Server" ), wxT( "Start..." ), estimate, NULL, wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
+    pd.SetSize( wxSize( 320, 140 ) );
+	
+	http.GetImages( hhs, date );
+	for ( int i = 0; i < estimate; i++ ) {
+		wxSleep( 1 );
+		pd.Update( i, wxT( "Now Loading..." ) );
+	}
+}
+
+void MainFrame::GetImages2( wxString hhs, wxString date )
+{
 	wxArrayString args;	// http get
 	args.Add( wxT( "client.exe" ) );
 	args.Add( m_server );
@@ -796,6 +828,15 @@
     logfile.Close();
 }
 
+void MainFrame::Close( void )
+{
+	WriteLog( wxT( "[logout]" ) );
+    if ( !IsIconized() && !IsMaximized() ) {
+        wxGetApp().rect = this->GetRect();
+    }
+    Destroy();
+}
+
 void MainFrame::InDevelop( bool flag )
 {
     if ( !flag ) return;