示例#1
0
文件: Remote.cpp 项目: GetEnvy/Envy
void CRemote::PageUploads()
{
	if ( CheckCookie() ) return;
	m_nTab = tabUploads;

	CSingleLock pLock( &UploadQueues.m_pSection, FALSE );
	if ( ! SafeLock( pLock ) )
		return;

	Prepare();		// Header

	CString strRandom;
	strRandom.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );
	Add( L"random", strRandom );

	Output( L"uploadsHeader" );

	for ( POSITION posQueue = CUploadsCtrl::GetQueueIterator(); posQueue != NULL; )
	{
		CUploadQueue* pQueue = CUploadsCtrl::GetNextQueue( posQueue );

		CString strQueueID;
		strQueueID.Format( L"%p", pQueue );

		if ( GetKey( L"queue_expand" ) == strQueueID )
			pQueue->m_bExpanded = TRUE;
		else if ( GetKey( L"queue_collapse" ) == strQueueID )
			pQueue->m_bExpanded = FALSE;

		POSITION posFile = CUploadsCtrl::GetFileIterator( pQueue );
		if ( posFile == NULL ) continue;

		Prepare();
		Add( L"queue_id", strQueueID );
		Add( L"queue_caption", pQueue->m_sName );
		if ( pQueue->m_bExpanded )
			Add( L"queue_expanded", L"true" );

		if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue )
		{
			CString str;
			str.Format( L"%u", pQueue->GetTransferCount() );
			Add( L"queue_transfers", str );
			str.Format( L"%u", pQueue->GetQueuedCount() );
			Add( L"queue_queued", str );
			Add( L"queue_bandwidth", Settings.SmartSpeed( pQueue->GetMeasuredSpeed() ) );
		}

		Output( L"uploadsQueueStart" );

		if ( pQueue->m_bExpanded )
		{
			while ( posFile != NULL )
			{
				int nPosition;
				CUploadFile* pFile = CUploadsCtrl::GetNextFile( pQueue, posFile, &nPosition );
				if ( pFile == NULL ) continue;
				CUploadTransfer* pTransfer = pFile->GetActive();

				CString strFileID;
				strFileID.Format( L"%p", pFile );

				if ( GetKey( L"drop" ) == strFileID )
				{
					pFile->Remove();
					continue;
				}

				Add( L"file_id", strFileID );
				Add( L"file_filename", pFile->m_sName );
				Add( L"file_size", Settings.SmartVolume( pFile->m_nSize ) );

				if ( pTransfer != NULL )
				{
					Add( L"file_address", pTransfer->m_sAddress );
					Add( L"file_nick", pTransfer->m_sRemoteNick );
					Add( L"file_user", pTransfer->m_sAddress + L" - " + pTransfer->m_sRemoteNick );
					Add( L"file_agent", pTransfer->m_sUserAgent );
				}

				CString str;
				if ( pTransfer == NULL || pTransfer->m_nState == upsNull )
				{
					LoadString( str, IDS_STATUS_COMPLETED );
				}
				else if ( pTransfer->m_nProtocol == PROTOCOL_BT )
				{
					CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer;

					if ( ! pBT->m_bInterested )
						LoadString( str, IDS_STATUS_UNINTERESTED );
					else if ( pBT->m_bChoked )
						LoadString( str, IDS_STATUS_CHOKED );
					else if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() )
						str = Settings.SmartSpeed( nSpeed );
				}
				else if ( nPosition > 0 )
				{
					LoadString( str, IDS_STATUS_Q );
					str.Format( L"%s %i", (LPCTSTR)str, nPosition );
				}
				else
				{
					if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() )
						str = Settings.SmartSpeed( nSpeed );
					else
						LoadString( str, IDS_STATUS_NEXT );
				}
				Add( L"file_speed", str );
				Add( L"file_status", str );

				Output( L"uploadsFile" );
				Prepare( L"file_" );
			}
		}

		Output( L"uploadsQueueEnd" );
		Prepare( L"queue_" );
	}

	Prepare();
	Output( L"uploadsFooter" );
}
示例#2
0
void CUploadsCtrl::PaintFile(CDC& dc, const CRect& rcRow, CUploadQueue* /*pQueue*/, CUploadFile* pFile, int nPosition, BOOL bFocus)
{
	ASSUME_LOCK( Transfers.m_pSection );

	CUploadTransfer* pTransfer = pFile->GetActive();
	int nFlagImage = Flags.GetFlagIndex( pTransfer->m_sCountry );
	COLORREF crNatural		= CoolInterface.m_crWindow;
	COLORREF crBack			= pFile->m_bSelected ? CoolInterface.m_crHighlight : crNatural;
	COLORREF crLeftAligned	= crBack;
	COLORREF crBorder		= pFile->m_bSelected ? CoolInterface.m_crFragmentBorderSelected : CoolInterface.m_crFragmentBorder;

	dc.SetBkColor( crBack );
	dc.SetBkMode( OPAQUE );
	
	if ( pFile->m_bSelected )
		dc.SetTextColor( CoolInterface.m_crHiText );
	else if ( pTransfer == NULL || pTransfer->m_nState == upsNull )
		dc.SetTextColor( CoolInterface.m_crDisabled );
	else
		dc.SetTextColor( CoolInterface.m_crText );
	
	int nTextLeft = rcRow.right, nTextRight = rcRow.left;
	HDITEM pColumn = {};
	
	pColumn.mask = HDI_FORMAT | HDI_LPARAM;

	for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn++ )
	{
		CString strText;
		CRect rcCell;
		
		m_wndHeader.GetItemRect( nColumn, &rcCell );
		rcCell.left		+= rcRow.left;
		rcCell.right	+= rcRow.left;
		rcCell.top		= rcRow.top;
		rcCell.bottom	= rcRow.bottom;
		
		crLeftAligned = ( rcRow.left == rcCell.left ? crNatural : crBack ) ;

		switch ( pColumn.lParam )
		{
		case UPLOAD_COLUMN_TITLE:
			dc.FillSolidRect( rcCell.left, rcCell.top, 24, rcCell.Height(), crLeftAligned );
			rcCell.left += 24;
			dc.FillSolidRect( rcCell.left, rcCell.bottom - 1, 16, 1, crLeftAligned );
			ShellIcons.Draw( &dc, ShellIcons.Get( ( lstrcmpi(
				PathFindExtension( pFile->m_sPath ), _T(".partial") ) ?
				pFile->m_sPath : pFile->m_sName ), 16 ), 16,
				rcCell.left, rcCell.top, crBack, pFile->m_bSelected );
			rcCell.left += 16;
			dc.FillSolidRect( rcCell.left, rcCell.top, 1, rcCell.Height(), crLeftAligned );
			rcCell.left += 1;
			strText = pFile->m_sName;
			break;
			
		case UPLOAD_COLUMN_USER:
			if ( pTransfer == NULL )
				strText.Empty();
			else if ( pTransfer->m_sRemoteNick.IsEmpty() )
				strText = pTransfer->m_sAddress;
			else
				strText = pTransfer->m_sRemoteNick + _T(" (") + pTransfer->m_sAddress + _T(")");
			break;
			
		case UPLOAD_COLUMN_SIZE:
			strText = Settings.SmartVolume( pFile->m_nSize );
			break;
			
		case UPLOAD_COLUMN_PROGRESS:
			dc.Draw3dRect( &rcCell, crBack, crBack );
			rcCell.DeflateRect( 1, 1 );
			dc.Draw3dRect( &rcCell, crBack, crBack );
			rcCell.DeflateRect( 0, 1 );
			dc.Draw3dRect( &rcCell, crBorder, crBorder );
			rcCell.DeflateRect( 1, 1 );
			CFragmentBar::DrawUpload( &dc, &rcCell, pFile, crNatural );
			break;
			
		case UPLOAD_COLUMN_SPEED:
			if ( pTransfer == NULL || pTransfer->m_nState == upsNull )
				LoadString( strText, IDS_STATUS_COMPLETED );
			else if ( pTransfer->m_nProtocol == PROTOCOL_BT )
			{
				CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer;
				
				if ( ! pBT->m_bInterested )
					LoadString( strText, IDS_STATUS_UNINTERESTED );
				else if ( pBT->m_bChoked )
					LoadString( strText, IDS_STATUS_CHOKED );
				else
				{
					DWORD nSpeed = pTransfer->GetMeasuredSpeed();
					if ( nSpeed )
						strText = Settings.SmartSpeed( nSpeed );
				}
			}
			else if ( nPosition > 0 )
			{
				CString strQ;
				LoadString( strQ, IDS_STATUS_Q );
				strText.Format( _T("%s %i"), (LPCTSTR)strQ, nPosition );
			}
			else
			{
				DWORD nSpeed = pTransfer->GetMeasuredSpeed();
				if ( nSpeed )
					strText = Settings.SmartSpeed( nSpeed );
				else
					LoadString( strText, IDS_STATUS_NEXT );
			}
			break;
			
		case UPLOAD_COLUMN_CLIENT:
			if ( pTransfer != NULL ) strText = pTransfer->m_sUserAgent;
			break;
		case UPLOAD_COLUMN_RATING:
			strText.Format(_T("%u"), pTransfer->m_nUserRating );
			break;
		case UPLOAD_COLUMN_COUNTRY:
			dc.FillSolidRect( rcCell.left, rcCell.top, 20, rcCell.Height(), crBack );
			rcCell.left += 2;
			if ( nFlagImage >= 0 )
				Flags.Draw( nFlagImage, dc.GetSafeHdc(), rcCell.left, rcCell.top + 2, CLR_NONE, CLR_DEFAULT, pFile->m_bSelected ? ILD_SELECTED : ILD_NORMAL );

			rcCell.left += 16;
			dc.FillSolidRect( rcCell.left, rcCell.top, 1, rcCell.Height(), crNatural );

			strText = pTransfer->m_sCountry;
			break;
		}
		
		nTextLeft	= min( (LONG)nTextLeft, rcCell.left );
		nTextRight	= max( (LONG)nTextRight, rcCell.right );
		
		if ( pColumn.lParam == UPLOAD_COLUMN_PROGRESS ) continue;
		
		if ( rcCell.Width() < 8 ) strText.Empty();
		
		if ( dc.GetTextExtent( strText ).cx > rcCell.Width() - 8 )
		{
			while ( dc.GetTextExtent( strText + _T('\x2026') ).cx > ( rcCell.Width() - 8 ) && strText.GetLength() > 0 )
			{
				strText.Truncate( strText.GetLength() - 1 );
			}
			
			if ( strText.GetLength() > 0 ) strText += _T('\x2026');
		}
		
		int nWidth		= dc.GetTextExtent( strText ).cx;
		int nPos	= 0;
		
		switch ( pColumn.fmt & LVCFMT_JUSTIFYMASK )
		{
		default:
			nPos = ( rcCell.left + 4 );
			break;
		case LVCFMT_CENTER:
			nPos = ( ( rcCell.left + rcCell.right ) / 2 ) - ( nWidth / 2 );
			break;
		case LVCFMT_RIGHT:
			nPos = ( rcCell.right - 4 - nWidth );
			break;
		}
		
		dc.SetBkColor( crBack );
		dc.ExtTextOut( nPos, rcCell.top + 2, ETO_CLIPPED|ETO_OPAQUE,
			&rcCell, strText, NULL );
	}
	
	if ( nTextRight < rcRow.right )
	{
		CRect rcBlank( nTextRight, rcRow.top, rcRow.right, rcRow.bottom );
		dc.FillSolidRect( &rcBlank, crBack );
	}
	
	if ( bFocus )
	{
		CRect rcFocus( nTextLeft, rcRow.top, max( (int)rcRow.right, nTextRight ), rcRow.bottom );
		dc.Draw3dRect( &rcFocus, CoolInterface.m_crHiBorder, CoolInterface.m_crHiBorder );
	}
}
示例#3
0
void CUploads::OnRun()
{
	CSingleLock pLock( &UploadQueues.m_pSection, TRUE );
	int nCountTorrent = 0;
	POSITION pos;
	
	m_nCount		= 0;
	m_nBandwidth	= 0;
	
	//Set measured queue speeds to 0
	for ( pos = UploadQueues.GetIterator() ; pos ; )
	{
		UploadQueues.GetNext( pos )->m_nMeasured = 0;
	}
	UploadQueues.m_pTorrentQueue->m_nMeasured = 0;
	UploadQueues.m_pTorrentQueue->m_nMinTransfers = 0;
	UploadQueues.m_pTorrentQueue->m_nMaxTransfers = 0;
	
	for ( pos = GetIterator() ; pos ; )
	{
		CUploadTransfer* pTransfer = GetNext( pos );
		DWORD nMeasured = pTransfer->GetMeasuredSpeed();

		if ( ( pTransfer->m_nProtocol == PROTOCOL_BT ) && ( pTransfer->m_nState != upsNull ) )	
		{
			// This is a torrent transfer
			CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer;
			if ( ( ! pBT->m_bInterested ) || ( pBT->m_bChoked ) )
			{
				// Choked- Increment appropriate torrent counter
				UploadQueues.m_pTorrentQueue->m_nMaxTransfers ++;
			}
			else
			{
				// Active torrent. (Uploading or requesting)
				// Increment normal counters
				m_nCount ++;
				m_nBandwidth += nMeasured;
				// Increment torrent counters
				nCountTorrent ++;
				UploadQueues.m_pTorrentQueue->m_nMinTransfers ++;
				UploadQueues.m_pTorrentQueue->m_nMeasured += nMeasured;

				//theApp.Message( MSG_SYSTEM, pTransfer->m_sAddress );
				//theApp.Message( MSG_SYSTEM, _T("Port: %i "), pTransfer->m_pHost.sin_port );
			}
		}
		else if ( pTransfer->m_nState == upsUploading )
		{
			// Regular transfer that's uploading
			m_nCount ++;
			m_nBandwidth += nMeasured;

			if ( pTransfer->m_pQueue != NULL && UploadQueues.Check( pTransfer->m_pQueue ) )
				pTransfer->m_pQueue->m_nMeasured += nMeasured;
		}
	}
	
	if ( nCountTorrent > 0 )	//If there are any active torrents
	{	//Assign bandwidth to BT (4/5ths by default)
		m_nTorrentSpeed = Settings.Bandwidth.Uploads;
		if ( m_nTorrentSpeed == 0 ) m_nTorrentSpeed = 0xFFFFFFFF;
		m_nTorrentSpeed = min( m_nTorrentSpeed, Settings.Connection.OutSpeed * 128 );
		m_nTorrentSpeed = m_nTorrentSpeed * Settings.BitTorrent.BandwidthPercentage / 100;
		
		m_nTorrentSpeed = m_nTorrentSpeed / nCountTorrent;
		m_nTorrentSpeed = max( m_nTorrentSpeed, Settings.Bandwidth.Request );
	}
	else
	{	//If there are no torrents, set to zero
		m_nTorrentSpeed = 0;
	}
}