⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wxcasframe.cpp

📁 Linux系统下的P2P协议下载客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		                      WxCasCte::AMULESIG_IMG_NAME,		                      prefs->		                      Read ( WxCasCte::AUTOSTATIMG_TYPE_KEY,		                             WxCasCte::DEFAULT_AUTOSTATIMG_TYPE ).		                      Lower () );		if ( !statImage->SaveFile ( fileName.GetFullPath () ) ) {			wxLogError ( wxT( "No handler for this file type. File was not saved" ) );		}		delete statImage;	}}// Ftp update timervoidWxCasFrame::OnFtpUpdateTimer ( wxTimerEvent& WXUNUSED( event ) ){	// Prefs	wxConfigBase * prefs = wxConfigBase::Get();	// Image must be autogenerated to be uploaded	if ( ( bool ) ( prefs->Read ( WxCasCte::ENABLE_AUTOSTATIMG_KEY,	                              WxCasCte::DEFAULT_AUTOSTATIMG_ISENABLED ) ) &&	        ( bool ) ( prefs->Read ( WxCasCte::ENABLE_FTP_UPDATE_KEY,	                                 WxCasCte::DEFAULT_FTP_UPDATE_ISENABLED ) ) ) {		// Get image file		wxFileName fileName ( prefs->		                      Read ( WxCasCte::AUTOSTATIMG_DIR_KEY,		                             WxCasCte::DEFAULT_AUTOSTATIMG_PATH ),		                      WxCasCte::AMULESIG_IMG_NAME,		                      prefs->		                      Read ( WxCasCte::AUTOSTATIMG_TYPE_KEY,		                             WxCasCte::DEFAULT_AUTOSTATIMG_TYPE ).		                      Lower () );		// If img doenst exist, return		if ( ! fileName.FileExists( fileName.GetFullPath () ) ) {			wxLogError( wxT( "Image file " ) + fileName.GetFullPath () + wxT( " doesn't exist" ) );			return ;		}		// Connect to ftp		wxFTP ftp;		ftp.SetUser( prefs->Read ( WxCasCte::FTP_USER_KEY,		                           WxCasCte::DEFAULT_FTP_USER ) );		ftp.SetPassword( prefs->Read ( WxCasCte::FTP_PASSWD_KEY,		                               WxCasCte::DEFAULT_FTP_PASSWD ) );		if ( ! ftp.Connect( prefs->Read ( WxCasCte::FTP_URL_KEY,		                                  WxCasCte::DEFAULT_FTP_URL ) ) ) {			wxLogError( wxT( "Cannot connect to FTP server " ) + prefs->Read ( WxCasCte::FTP_URL_KEY,			            WxCasCte::DEFAULT_FTP_URL ) );			return ;		}		// Chdir		if ( ! ftp.ChDir( prefs->Read ( WxCasCte::FTP_PATH_KEY,		                                WxCasCte::DEFAULT_FTP_PATH ) ) ) {			wxLogError( wxT( "Cannot chdir to " ) + prefs->Read ( WxCasCte::FTP_PATH_KEY,			            WxCasCte::DEFAULT_FTP_PATH ) );			ftp.Close();			return ;		}		// Upload image		ftp.SetBinary();		wxFileInputStream in( fileName.GetFullPath () );		if ( in.Ok() ) {			wxOutputStream * out = ftp.GetOutputStream( fileName.GetFullName () );			if ( out ) {				out->Write( in );				delete out;			} else {				wxLogError( wxT( "Cannot open FTP upload stream" ) );			}		} else {			wxLogError( wxT( "Cannot open file stream to read image file" ) );		}		// Close connexion		ftp.Close();	}}// Reset wxcas session hitvoidWxCasFrame::OnHitButton ( wxCommandEvent& WXUNUSED( event ) ){	m_aMuleSig->ResetSessionMaxDL();	UpdateStatsPanel ();}// Reset wxcas absolute hitvoidWxCasFrame::OnAbsHitButton ( wxCommandEvent& WXUNUSED( event ) ){	m_aMuleSig->ResetAbsoluteMaxDL();	SaveAbsoluteHits();	UpdateStatsPanel ();}// Update all panels and frame, call Fit if neededvoidWxCasFrame::UpdateAll ( bool forceFitting ){	bool needFit = UpdateStatsPanel ();	if ( needFit || forceFitting ) {		// Fit stats pannel		m_mainPanel->Fit();		// Fit main frame		SetClientSize( m_mainPanel->GetSize() );	}}// Update stat panelboolWxCasFrame::UpdateStatsPanel (){	// Set labels	m_aMuleSig->Refresh ();#ifdef __LINUX__		// System monitoring on Linux	m_sysMonitor->Refresh ();#endif	wxString newline;	wxString status;	unsigned int newMaxLineCount = 0;	Freeze ();	// Stat line 1	newline = MakeStatLine_1();	m_statLine_1->SetLabel ( newline );	newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );	// aMule is running	if ( m_aMuleSig->GetAmuleState () == 1 ) {		// Stat line 2		newline = MakeStatLine_2();		m_statLine_2->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		// Stat line 3		newline = MakeStatLine_3();		m_statLine_3->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		// Stat line 4		newline = MakeStatLine_4();		m_statLine_4->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		// Stat line 5		newline = MakeStatLine_5();		m_statLine_5->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		// Stat line 6		newline = MakeStatLine_6();		m_statLine_6->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		// Hits line 1		if ( m_aMuleSig->IsSessionMaxDlChanged() ) {			newline = MakeHitsLine_1();			m_hitLine->SetLabel ( newline );			newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		}		// Hits line 2		if ( m_aMuleSig->IsAbsoluteMaxDlChanged() ) {			newline = MakeHitsLine_2();			m_absHitLine->SetLabel ( newline );			newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );			// Save new records			SaveAbsoluteHits();		}#ifdef __LINUX__		// System monitoring on Linux		newline = MakeSysLine_1();		m_sysLine_1->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );		newline = MakeSysLine_2();		m_sysLine_2->SetLabel ( newline );		newMaxLineCount = GetMaxUInt( newline.Length (), newMaxLineCount );#endif		status = _( "aMule is running" );	}	// aMule is stopped	else if ( m_aMuleSig->GetAmuleState () == 0 ) {		status = _( "WARNING: aMule is stopped !" );	}	// aMule is connecting	else if ( m_aMuleSig->GetAmuleState () == 2 ) {		status = _( "aMule is connecting..." );	}	// aMule status is unknown	else {		status = _( "Oh Oh, aMule status is unknown..." );	}	Thaw ();	// Set status bar	SetStatusText ( status );	// Resize only if needed	if ( m_maxLineCount != newMaxLineCount ) {		m_maxLineCount = newMaxLineCount;		return ( TRUE );	} else {		return ( FALSE );	}}// Refresh period changingboolWxCasFrame::ChangeRefreshPeriod( const int newPeriod ){	// As the user can stop it, we must let it in the same state	// it was before changing period	bool wasRunning = FALSE;	if ( m_refresh_timer->IsRunning() ) {		wasRunning = TRUE;	}	bool ok = m_refresh_timer->Start( newPeriod );	if ( ! wasRunning ) {		m_refresh_timer->Stop();	}	return ( ok );}// Ftp update period changingboolWxCasFrame::ChangeFtpUpdatePeriod( const int newPeriod ){	// As the user can stop it, we must let it in the same state	// it was before changing period	bool wasRunning = FALSE;	if ( m_ftp_update_timer->IsRunning() ) {		wasRunning = TRUE;	}	bool ok = m_ftp_update_timer->Start( newPeriod );	if ( ! wasRunning ) {		m_ftp_update_timer->Stop();	}	return ( ok );}// Set amulesig.dat filevoidWxCasFrame::SetAmuleSigFile( const wxFileName& file ){	m_aMuleSig->SetAmuleSig ( file );}wxStringWxCasFrame::MakeStatLine_1() const{	wxString newline;	if ( m_aMuleSig->GetAmuleState () == 1 ) {		newline = _( "aMule " )		          + m_aMuleSig->GetVersion ()		          + _( " has been running for " )		          + m_aMuleSig->GetRunTime ();	} else if ( m_aMuleSig->GetAmuleState () == 0 ) {		newline = _( "aMule " )		          + m_aMuleSig->GetVersion ()		          + _( " is STOPPED !" );	} else if ( m_aMuleSig->GetAmuleState () == 2 ) {		newline = _( "aMule " )		          + m_aMuleSig->GetVersion ()		          + _( " is connecting..." );	} else {		newline = _( "aMule " )		          + m_aMuleSig->GetVersion ()		          + _( " is doing something strange, check it !" );	}	return ( newline );}wxStringWxCasFrame::MakeStatLine_2() const{	wxString notTooLongName ( m_aMuleSig->GetServerName () );	if ( notTooLongName.Length() > 32 ) {		notTooLongName = notTooLongName.Left( 32 ) + wxT( "..." );	}	wxString newline = m_aMuleSig->GetUser ()	                   + _( " is on " )	                   + notTooLongName			   + _( " [" )			   + m_aMuleSig->GetServerIP ()			   + _( ":" )			   + m_aMuleSig->GetServerPort ()			   + _( "] with " )			   + m_aMuleSig->GetConnexionIDType ();	return ( newline );}wxStringWxCasFrame::MakeStatLine_3() const{	wxString newline = _( "Total Download: " )	                   + m_aMuleSig->GetConvertedTotalDL ()	                   + _( ", Upload: " )	                   + m_aMuleSig->GetConvertedTotalUL ();	return ( newline );}wxStringWxCasFrame::MakeStatLine_4() const{	wxString newline = _( "Session Download: " )	                   + m_aMuleSig->GetConvertedSessionDL ()	                   + _( ", Upload: " )	                   + m_aMuleSig->GetConvertedSessionUL ();	return ( newline );}wxStringWxCasFrame::MakeStatLine_5() const{	wxString newline = _( "Download: " )	                   + m_aMuleSig->GetDLRate ()	                   + _( " kB/s, Upload: " )	                   + m_aMuleSig->GetULRate ()	                   + _( "kB/s" );	return ( newline );}wxStringWxCasFrame::MakeStatLine_6() const{	wxString newline = _( "Sharing: " )	                   + m_aMuleSig->GetSharedFiles ()	                   + _( " file(s), Clients on queue: " )	                   + m_aMuleSig->GetQueue ();	return ( newline );}wxStringWxCasFrame::MakeHitsLine_1() const{	wxString newline = wxString::Format ( _( "%.2f kB/s" ), m_aMuleSig->GetSessionMaxDL () )	                   + _( " on " )	                   + m_aMuleSig->GetSessionMaxDlDate().Format( wxT( "%c" ) );	return ( newline );}wxStringWxCasFrame::MakeHitsLine_2() const{	wxString newline = wxString::Format ( _( "%.2f kB/s" ), m_aMuleSig->GetAbsoluteMaxDL() )	                   + _( " on " )	                   + m_aMuleSig->GetAbsoluteMaxDlDate().Format( wxT( "%c" ) );	return ( newline );}#ifdef __LINUX__		// System monitoring on LinuxwxStringWxCasFrame::MakeSysLine_1() const{	wxString newline = _( "System Load Average (1-5-15 min): " )	                   + m_sysMonitor->GetSysLoad_1 () + wxT( " " )	                   + m_sysMonitor->GetSysLoad_5 () + wxT( " " )	                   + m_sysMonitor->GetSysLoad_15 ();	return ( newline );}wxStringWxCasFrame::MakeSysLine_2() const{	wxString newline = _( "System uptime: " )	                   + m_sysMonitor->GetUptime ();	return ( newline );}#endifvoid WxCasFrame::SaveAbsoluteHits(){	wxConfigBase * prefs = wxConfigBase::Get();	prefs->Write( WxCasCte::ABSOLUTE_MAX_DL_KEY, ( long ) ( 1024.0 * m_aMuleSig->GetAbsoluteMaxDL() ) );	prefs->Write( WxCasCte::ABSOLUTE_MAX_DL_DATE_KEY, ( long ) ( m_aMuleSig->GetAbsoluteMaxDlDate().GetTicks() ) );	prefs->Flush();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -