📄 ctrldownloadtip.cpp
字号:
pt.y += TIP_TEXTHEIGHT;
LoadString( strFormat, IDS_DLM_ESTIMATED_TIME );
DrawText( pDC, &pt, strFormat, 3 );
DrawText( pDC, &pt, strETA, m_nStatWidth );
pt.y += TIP_TEXTHEIGHT;
LoadString( strFormat, IDS_DLM_VOLUME_DOWNLOADED );
DrawText( pDC, &pt, strFormat, 3 );
DrawText( pDC, &pt, strVolume, m_nStatWidth );
pt.y += TIP_TEXTHEIGHT;
LoadString( strFormat, IDS_DLM_NUMBER_OF_SOURCES );
DrawText( pDC, &pt, strFormat, 3 );
DrawText( pDC, &pt, strSources, m_nStatWidth );
pt.y += TIP_TEXTHEIGHT;
if ( m_sURL.GetLength() )
{
DrawRule( pDC, &pt );
DrawText( pDC, &pt, m_sURL );
pt.y += TIP_TEXTHEIGHT;
}
pt.y += 2;
DrawProgressBar( pDC, &pt, pDownload );
pt.y += TIP_GAP;
CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
rc.DeflateRect( 1, 1 );
m_pGraph->BufferedPaint( pDC, &rc );
rc.InflateRect( 1, 1 );
pDC->ExcludeClipRect( &rc );
pt.y += 40;
pt.y += TIP_GAP;
}
void CDownloadTipCtrl::PrepareFileInfo(CDownload* pDownload)
{
m_sName = pDownload->m_sRemoteName;
m_sSize = Settings.SmartVolume( pDownload->m_nSize, FALSE );
if ( pDownload->m_nSize == SIZE_UNKNOWN ) m_sSize = _T("?");
m_sSHA1.Empty();
m_sED2K.Empty();
m_sBTH.Empty();
m_sURL.Empty();
if ( pDownload->m_bSHA1 )
{
m_sSHA1 = _T("sha1:") + CSHA::HashToString( &pDownload->m_pSHA1 );
}
if ( pDownload->m_bED2K )
{
m_sED2K = _T("ed2k:") + CED2K::HashToString( &pDownload->m_pED2K );
}
if ( pDownload->m_bBTH )
{
m_sBTH = _T("btih:") + CSHA::HashToString( &pDownload->m_pBTH );
m_sURL = pDownload->m_pTorrent.m_sTracker;
}
int nPeriod = m_sName.ReverseFind( '.' );
m_sType.Empty();
m_nIcon = 0;
if ( nPeriod > 0 )
{
CString strType = m_sName.Mid( nPeriod );
CString strName, strMime;
ShellIcons.Lookup( strType, NULL, NULL, &strName, &strMime );
m_nIcon = ShellIcons.Get( strType, 32 );
if ( strName.GetLength() )
{
m_sType = strName;
if ( strMime.GetLength() ) m_sType += _T(" (") + strMime + _T(")");
}
else
{
m_sType = strType.Mid( 1 );
}
}
if ( m_sType.IsEmpty() ) m_sType = _T("Unknown");
}
/////////////////////////////////////////////////////////////////////////////
// CDownloadTipCtrl source case
void CDownloadTipCtrl::OnCalcSize(CDC* pDC, CDownloadSource* pSource)
{
CDownload* pDownload = pSource->m_pDownload;
if ( pSource->m_sNick.GetLength() > 0 )
m_sName = pSource->m_sNick + _T(" (") + inet_ntoa( pSource->m_pAddress ) + ')';
else
m_sName = inet_ntoa( pSource->m_pAddress );
m_sURL = pSource->m_sURL;
if ( m_sURL.GetLength() > 128 )
{
if ( LPCTSTR pszSlash = _tcschr( (LPCTSTR)m_sURL + 7, '/' ) )
{
int nFirst = pszSlash - (LPCTSTR)m_sSize;
m_sURL = m_sURL.Left( nFirst + 1 ) + _T("...") + m_sURL.Right( 10 );
}
}
m_pHeaderName.RemoveAll();
m_pHeaderValue.RemoveAll();
if ( pSource->m_pTransfer != NULL && Settings.General.GUIMode != GUI_BASIC )
{
for ( int nHeader = 0 ; nHeader < pSource->m_pTransfer->m_pHeaderName.GetSize() ; nHeader++ )
{
CString strName = pSource->m_pTransfer->m_pHeaderName.GetAt( nHeader );
CString strValue = pSource->m_pTransfer->m_pHeaderValue.GetAt( nHeader );
if ( strValue.GetLength() > 64 ) strValue = strValue.Left( 64 ) + _T("...");
m_pHeaderName.Add( strName );
m_pHeaderValue.Add( strValue );
}
}
AddSize( pDC, m_sName );
pDC->SelectObject( &CoolInterface.m_fntNormal );
m_sz.cy += TIP_TEXTHEIGHT + TIP_RULE;
AddSize( pDC, m_sURL, 80 );
m_sz.cy += TIP_TEXTHEIGHT * 4;
m_sz.cy += TIP_GAP;
m_sz.cy += TIP_TEXTHEIGHT;
m_sz.cy += TIP_GAP;
m_sz.cy += 40;
m_sz.cy += TIP_GAP;
int nValueWidth = 0;
m_nHeaderWidth = 0;
for ( int nHeader = 0 ; nHeader < m_pHeaderName.GetSize() ; nHeader++ )
{
CString strName = m_pHeaderName.GetAt( nHeader );
CString strValue = m_pHeaderValue.GetAt( nHeader );
CSize szKey = pDC->GetTextExtent( strName + ':' );
CSize szValue = pDC->GetTextExtent( strValue );
m_nHeaderWidth = max( m_nHeaderWidth, szKey.cx );
nValueWidth = max( nValueWidth, szValue.cx );
m_sz.cy += TIP_TEXTHEIGHT;
}
if ( m_nHeaderWidth ) m_nHeaderWidth += TIP_GAP;
m_sz.cx = max( m_sz.cx, m_nHeaderWidth + nValueWidth );
}
void CDownloadTipCtrl::OnPaint(CDC* pDC, CDownloadSource* pSource)
{
CDownload* pDownload = pSource->m_pDownload;
CPoint pt( 0, 0 );
DrawText( pDC, &pt, m_sName );
pDC->SelectObject( &CoolInterface.m_fntNormal );
pt.y += TIP_TEXTHEIGHT;
DrawRule( pDC, &pt );
CString strStatus, strSpeed;
if ( pSource->m_pTransfer != NULL )
{
DWORD nLimit = pSource->m_pTransfer->m_mInput.pLimit != NULL ?
*pSource->m_pTransfer->m_mInput.pLimit : 0;
strStatus = pSource->m_pTransfer->GetStateText( TRUE );
if ( nLimit > 0 )
{
strSpeed.Format( _T("%s of %s"),
(LPCTSTR)Settings.SmartVolume( pSource->m_pTransfer->GetMeasuredSpeed() * 8, FALSE, TRUE ),
(LPCTSTR)Settings.SmartVolume( nLimit * 8, FALSE, TRUE ) );
}
else
{
strSpeed = Settings.SmartVolume( pSource->m_pTransfer->GetMeasuredSpeed() * 8, FALSE, TRUE );
}
}
else
{
strStatus = _T("Inactive");
strSpeed = _T("N/A");
}
DrawText( pDC, &pt, _T("Status:") );
DrawText( pDC, &pt, strStatus, 80 );
pt.y += TIP_TEXTHEIGHT;
DrawText( pDC, &pt, _T("Speed:") );
DrawText( pDC, &pt, strSpeed, 80 );
pt.y += TIP_TEXTHEIGHT;
DrawText( pDC, &pt, _T("URL:") );
DrawText( pDC, &pt, m_sURL, 80 );
pt.y += TIP_TEXTHEIGHT;
DrawText( pDC, &pt, _T("User Agent:") );
DrawText( pDC, &pt, pSource->m_sServer, 80 );
pt.y += TIP_TEXTHEIGHT;
pt.y += TIP_GAP;
DrawProgressBar( pDC, &pt, pSource );
pt.y += TIP_GAP;
CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
rc.DeflateRect( 1, 1 );
m_pGraph->BufferedPaint( pDC, &rc );
rc.InflateRect( 1, 1 );
pDC->ExcludeClipRect( &rc );
pt.y += 40;
pt.y += TIP_GAP;
for ( int nHeader = 0 ; nHeader < m_pHeaderName.GetSize() ; nHeader++ )
{
CString strName = m_pHeaderName.GetAt( nHeader );
CString strValue = m_pHeaderValue.GetAt( nHeader );
DrawText( pDC, &pt, strName + ':' );
DrawText( pDC, &pt, strValue, m_nHeaderWidth );
pt.y += TIP_TEXTHEIGHT;
}
}
/////////////////////////////////////////////////////////////////////////////
// CDownloadTipCtrl progress case
void CDownloadTipCtrl::DrawProgressBar(CDC* pDC, CPoint* pPoint, CDownload* pDownload)
{
CRect rcCell( pPoint->x, pPoint->y, m_sz.cx, pPoint->y + TIP_TEXTHEIGHT );
pPoint->y += TIP_TEXTHEIGHT;
pDC->Draw3dRect( &rcCell, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
rcCell.DeflateRect( 1, 1 );
CFragmentBar::DrawDownload( pDC, &rcCell, pDownload, CoolInterface.m_crTipBack );
rcCell.InflateRect( 1, 1 );
pDC->ExcludeClipRect( &rcCell );
}
void CDownloadTipCtrl::DrawProgressBar(CDC* pDC, CPoint* pPoint, CDownloadSource* pSource)
{
CRect rcCell( pPoint->x, pPoint->y, m_sz.cx, pPoint->y + TIP_TEXTHEIGHT );
pPoint->y += TIP_TEXTHEIGHT;
pDC->Draw3dRect( &rcCell, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
rcCell.DeflateRect( 1, 1 );
CFragmentBar::DrawSource( pDC, &rcCell, pSource, CoolInterface.m_crTipBack );
rcCell.InflateRect( 1, 1 );
pDC->ExcludeClipRect( &rcCell );
}
/////////////////////////////////////////////////////////////////////////////
// CDownloadTipCtrl timer
void CDownloadTipCtrl::OnTimer(UINT nIDEvent)
{
CCoolTipCtrl::OnTimer( nIDEvent );
if ( m_pGraph == NULL ) return;
CSingleLock pLock( &Transfers.m_pSection );
if ( ! pLock.Lock( 10 ) ) return;
if ( Downloads.Check( (CDownload*)m_pContext ) )
{
CDownload* pDownload = (CDownload*)m_pContext;
DWORD nSpeed = pDownload->GetMeasuredSpeed() * 8;
m_pItem->Add( nSpeed );
m_pGraph->m_nUpdates++;
m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nSpeed );
Invalidate();
}
else if ( Downloads.Check( (CDownloadSource*)m_pContext ) )
{
CDownloadSource* pSource = (CDownloadSource*)m_pContext;
if ( pSource->m_pTransfer )
{
DWORD nSpeed = pSource->m_pTransfer->GetMeasuredSpeed() * 8;
m_pItem->Add( nSpeed );
m_pGraph->m_nUpdates++;
m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nSpeed );
Invalidate();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -