📄 ctrldownloadtip.cpp
字号:
//
// CtrlDownloadTip.cpp
//
// Copyright (c) Shareaza Development Team, 2002-2004.
// This file is part of SHAREAZA (www.shareaza.com)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "StdAfx.h"
#include "Shareaza.h"
#include "Settings.h"
#include "CoolInterface.h"
#include "ShellIcons.h"
#include "Transfers.h"
#include "Downloads.h"
#include "Download.h"
#include "DownloadSource.h"
#include "DownloadTransfer.h"
#include "DownloadTransferBT.h"
#include "FragmentedFile.h"
#include "FragmentBar.h"
#include "Skin.h"
#include "SHA.h"
#include "GraphLine.h"
#include "GraphItem.h"
#include "CtrlDownloadTip.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CDownloadTipCtrl, CCoolTipCtrl)
BEGIN_MESSAGE_MAP(CDownloadTipCtrl, CCoolTipCtrl)
//{{AFX_MSG_MAP(CDownloadTipCtrl)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDownloadTipCtrl construction
CDownloadTipCtrl::CDownloadTipCtrl()
{
m_pGraph = NULL;
m_nIcon = 0;
}
CDownloadTipCtrl::~CDownloadTipCtrl()
{
if ( m_pGraph ) delete m_pGraph;
}
/////////////////////////////////////////////////////////////////////////////
// CDownloadTipCtrl events
BOOL CDownloadTipCtrl::OnPrepare()
{
CSingleLock pLock( &Transfers.m_pSection );
if ( ! pLock.Lock( 100 ) ) return FALSE;
CalcSizeHelper();
return m_sz.cx > 0;
}
void CDownloadTipCtrl::OnCalcSize(CDC* pDC)
{
if ( Downloads.Check( (CDownload*)m_pContext ) )
{
OnCalcSize( pDC, (CDownload*)m_pContext );
m_sz.cx = max( m_sz.cx, 400 );
}
else if ( Downloads.Check( (CDownloadSource*)m_pContext ) )
{
OnCalcSize( pDC, (CDownloadSource*)m_pContext );
m_sz.cx = max( m_sz.cx, 400 );
}
}
void CDownloadTipCtrl::OnShow()
{
if ( m_pGraph ) delete m_pGraph;
m_pGraph = CreateLineGraph();
m_pItem = new CGraphItem( 0, 0, RGB( 0xFF, 0, 0 ) );
m_pGraph->AddItem( m_pItem );
}
void CDownloadTipCtrl::OnHide()
{
if ( m_pGraph ) delete m_pGraph;
m_pGraph = NULL;
m_pItem = NULL;
}
void CDownloadTipCtrl::OnPaint(CDC* pDC)
{
CSingleLock pLock( &Transfers.m_pSection );
if ( ! pLock.Lock( 100 ) ) return;
if ( Downloads.Check( (CDownload*)m_pContext ) )
{
OnPaint( pDC, (CDownload*)m_pContext );
}
else if ( Downloads.Check( (CDownloadSource*)m_pContext ) )
{
OnPaint( pDC, (CDownloadSource*)m_pContext );
}
else
{
Hide();
}
}
/////////////////////////////////////////////////////////////////////////////
// CDownloadTipCtrl download case
void CDownloadTipCtrl::OnCalcSize(CDC* pDC, CDownload* pDownload)
{
PrepareFileInfo( pDownload );
AddSize( pDC, m_sName );
m_sz.cy += TIP_TEXTHEIGHT;
pDC->SelectObject( &CoolInterface.m_fntNormal );
if ( m_sSHA1.GetLength() )
{
AddSize( pDC, m_sSHA1 );
m_sz.cy += TIP_TEXTHEIGHT;
}
if ( m_sED2K.GetLength() )
{
AddSize( pDC, m_sED2K );
m_sz.cy += TIP_TEXTHEIGHT;
}
if ( m_sBTH.GetLength() )
{
AddSize( pDC, m_sBTH );
m_sz.cy += TIP_TEXTHEIGHT;
}
m_sz.cy += TIP_RULE;
AddSize( pDC, m_sSize, 80 );
AddSize( pDC, m_sType, 80 );
m_sz.cy += 36;
m_sz.cy += TIP_RULE;
m_sz.cy += TIP_TEXTHEIGHT * 4;
if ( m_sURL.GetLength() )
{
m_sz.cy += TIP_RULE;
AddSize( pDC, m_sURL );
m_sz.cy += TIP_TEXTHEIGHT;
}
m_sz.cy += 2;
m_sz.cy += TIP_TEXTHEIGHT;
m_sz.cy += TIP_GAP;
m_sz.cy += 40;
CString str;
LoadString( str, IDS_DLM_ESTIMATED_TIME );
m_nStatWidth = pDC->GetTextExtent( str ).cx + 8;
}
void CDownloadTipCtrl::OnPaint(CDC* pDC, CDownload* pDownload)
{
CPoint pt( 0, 0 );
CString str;
DrawText( pDC, &pt, m_sName );
pt.y += TIP_TEXTHEIGHT;
pDC->SelectObject( &CoolInterface.m_fntNormal );
if ( m_sSHA1.GetLength() )
{
DrawText( pDC, &pt, m_sSHA1 );
pt.y += TIP_TEXTHEIGHT;
}
if ( m_sED2K.GetLength() )
{
DrawText( pDC, &pt, m_sED2K );
pt.y += TIP_TEXTHEIGHT;
}
if ( m_sBTH.GetLength() )
{
DrawText( pDC, &pt, m_sBTH );
pt.y += TIP_TEXTHEIGHT;
}
DrawRule( pDC, &pt );
ImageList_DrawEx( ShellIcons.GetHandle( 32 ), m_nIcon, pDC->GetSafeHdc(),
pt.x, pt.y, 32, 32, CoolInterface.m_crTipBack, CLR_NONE, ILD_NORMAL );
pDC->ExcludeClipRect( pt.x, pt.y, pt.x + 32, pt.y + 32 );
pt.y += 2;
pt.x += 40;
LoadString( str, IDS_TIP_SIZE );
DrawText( pDC, &pt, str + ':' );
DrawText( pDC, &pt, m_sSize, 40 );
pt.y += TIP_TEXTHEIGHT;
LoadString( str, IDS_TIP_TYPE );
DrawText( pDC, &pt, str + ':' );
DrawText( pDC, &pt, m_sType, 40 );
pt.x -= 40;
pt.y -= TIP_TEXTHEIGHT + 2;
pt.y += 34;
DrawRule( pDC, &pt );
CString strFormat, strETA, strSpeed, strVolume, strSources;
int nSourceCount = pDownload->GetSourceCount();
int nTransferCount = pDownload->GetTransferCount();
LoadString( strFormat, IDS_TIP_NA );
if ( pDownload->IsMoving() )
{
strETA = strFormat;
strSpeed = strFormat;
LoadString( strSources, IDS_DLM_COMPLETED_WORD );
}
else if ( pDownload->IsPaused() )
{
strETA = strFormat;
strSpeed = strFormat;
strSources.Format( _T("%i"), nSourceCount );
}
else if ( nTransferCount )
{
DWORD nTime = pDownload->GetTimeRemaining();
if ( nTime != 0xFFFFFFFF )
{
if ( nTime > 3600 )
{
LoadString( strFormat, IDS_DLM_TIME_HAM );
strETA.Format( strFormat, nTime / 3600, ( nTime % 3600 ) / 60 );
}
else if ( nTime > 60 )
{
LoadString( strFormat, IDS_DLM_TIME_MAS );
strETA.Format( strFormat, nTime / 60, nTime % 60 );
}
else
{
LoadString( strFormat, IDS_DLM_TIME_S );
strETA.Format( strFormat, nTime % 60 );
}
}
strSpeed = Settings.SmartVolume( pDownload->GetAverageSpeed() * 8, FALSE, TRUE );
LoadString( strFormat, IDS_TIP_NOFN );
strSources.Format( strFormat, nTransferCount, nSourceCount );
}
else if ( nSourceCount )
{
strETA = strFormat;
strSpeed = strFormat;
strSources.Format( _T("%i"), nSourceCount );
}
else
{
strETA = strFormat;
strSpeed = strFormat;
LoadString( strSources, IDS_DLM_NO_SOURCES );
}
if ( pDownload->IsStarted() )
{
LoadString( strFormat, IDS_DLM_VOLUME );
strVolume.Format( strFormat,
(LPCTSTR)Settings.SmartVolume( pDownload->GetVolumeComplete(), FALSE ),
(LPCTSTR)Settings.SmartVolume( pDownload->m_nSize, FALSE ),
pDownload->GetProgress() * 100.0f );
}
else
{
LoadString( strVolume, IDS_TIP_NA );
}
LoadString( strFormat, IDS_DLM_TOTAL_SPEED );
DrawText( pDC, &pt, strFormat, 3 );
DrawText( pDC, &pt, strSpeed, m_nStatWidth );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -