00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "CoolInterface.h"
00026 #include "ShellIcons.h"
00027 #include "Transfers.h"
00028 #include "Downloads.h"
00029 #include "Download.h"
00030 #include "DownloadSource.h"
00031 #include "DownloadTransfer.h"
00032 #include "DownloadTransferBT.h"
00033 #include "FragmentedFile.h"
00034 #include "FragmentBar.h"
00035 #include "Skin.h"
00036 #include "SHA.h"
00037 #include "GraphLine.h"
00038 #include "GraphItem.h"
00039 #include "CtrlDownloadTip.h"
00040
00041 #ifdef _DEBUG
00042 #define new DEBUG_NEW
00043 #undef THIS_FILE
00044 static char THIS_FILE[] = __FILE__;
00045 #endif
00046
00047 IMPLEMENT_DYNAMIC(CDownloadTipCtrl, CCoolTipCtrl)
00048
00049 BEGIN_MESSAGE_MAP(CDownloadTipCtrl, CCoolTipCtrl)
00050
00051 ON_WM_TIMER()
00052
00053 END_MESSAGE_MAP()
00054
00055
00057
00058
00059 CDownloadTipCtrl::CDownloadTipCtrl()
00060 {
00061 m_pGraph = NULL;
00062 m_nIcon = 0;
00063 }
00064
00065 CDownloadTipCtrl::~CDownloadTipCtrl()
00066 {
00067 if ( m_pGraph ) delete m_pGraph;
00068 }
00069
00071
00072
00073 BOOL CDownloadTipCtrl::OnPrepare()
00074 {
00075 CSingleLock pLock( &Transfers.m_pSection );
00076 if ( ! pLock.Lock( 100 ) ) return FALSE;
00077
00078 CalcSizeHelper();
00079
00080 return m_sz.cx > 0;
00081 }
00082
00083 void CDownloadTipCtrl::OnCalcSize(CDC* pDC)
00084 {
00085 if ( Downloads.Check( (CDownload*)m_pContext ) )
00086 {
00087 OnCalcSize( pDC, (CDownload*)m_pContext );
00088 m_sz.cx = max( m_sz.cx, LONG(400) );
00089 }
00090 else if ( Downloads.Check( (CDownloadSource*)m_pContext ) )
00091 {
00092 OnCalcSize( pDC, (CDownloadSource*)m_pContext );
00093 m_sz.cx = max( m_sz.cx, LONG(400) );
00094 }
00095 }
00096
00097 void CDownloadTipCtrl::OnShow()
00098 {
00099 if ( m_pGraph ) delete m_pGraph;
00100
00101 m_pGraph = CreateLineGraph();
00102 m_pItem = new CGraphItem( 0, 0, RGB( 0xFF, 0, 0 ) );
00103 m_pGraph->AddItem( m_pItem );
00104 }
00105
00106 void CDownloadTipCtrl::OnHide()
00107 {
00108 if ( m_pGraph ) delete m_pGraph;
00109 m_pGraph = NULL;
00110 m_pItem = NULL;
00111 }
00112
00113 void CDownloadTipCtrl::OnPaint(CDC* pDC)
00114 {
00115 CSingleLock pLock( &Transfers.m_pSection );
00116 if ( ! pLock.Lock( 100 ) ) return;
00117
00118 if ( Downloads.Check( (CDownload*)m_pContext ) )
00119 {
00120 OnPaint( pDC, (CDownload*)m_pContext );
00121 }
00122 else if ( Downloads.Check( (CDownloadSource*)m_pContext ) )
00123 {
00124 OnPaint( pDC, (CDownloadSource*)m_pContext );
00125 }
00126 else
00127 {
00128 Hide();
00129 }
00130 }
00131
00133
00134
00135 void CDownloadTipCtrl::OnCalcSize(CDC* pDC, CDownload* pDownload)
00136 {
00137 PrepareFileInfo( pDownload );
00138
00139 AddSize( pDC, m_sName );
00140 m_sz.cy += TIP_TEXTHEIGHT;
00141 pDC->SelectObject( &CoolInterface.m_fntNormal );
00142
00143 if ( m_sSHA1.GetLength() )
00144 {
00145 AddSize( pDC, m_sSHA1 );
00146 m_sz.cy += TIP_TEXTHEIGHT;
00147 }
00148 if ( m_sED2K.GetLength() )
00149 {
00150 AddSize( pDC, m_sED2K );
00151 m_sz.cy += TIP_TEXTHEIGHT;
00152 }
00153 if ( m_sBTH.GetLength() )
00154 {
00155 AddSize( pDC, m_sBTH );
00156 m_sz.cy += TIP_TEXTHEIGHT;
00157 }
00158 if ( m_sTiger.GetLength() )
00159 {
00160 AddSize( pDC, m_sTiger );
00161 m_sz.cy += TIP_TEXTHEIGHT;
00162 }
00163
00164 m_sz.cy += TIP_RULE;
00165 AddSize( pDC, m_sSize, 80 );
00166 AddSize( pDC, m_sType, 80 );
00167 m_sz.cy += 36;
00168 m_sz.cy += TIP_RULE;
00169
00170
00171 if ( pDownload->m_bTorrentTrackerError && ( pDownload->m_sTorrentTrackerError ) )
00172 {
00173 m_bDrawError = TRUE;
00174 m_sz.cy += TIP_TEXTHEIGHT;
00175 m_sz.cy += TIP_RULE;
00176 }
00177 else
00178 m_bDrawError = FALSE;
00179
00180
00181 if ( pDownload->m_bBTH )
00182 {
00183 m_sz.cy += TIP_TEXTHEIGHT;
00184 }
00185
00186 if ( ! pDownload->IsSeeding() )
00187 {
00188 if ( pDownload->IsCompleted() )
00189 {
00190 m_sz.cy += TIP_TEXTHEIGHT * 2;
00191 }
00192 else
00193 {
00194 m_sz.cy += TIP_TEXTHEIGHT * 4;
00195 }
00196 }
00197
00198
00199 if ( m_sURL.GetLength() )
00200 {
00201 m_sz.cy += TIP_RULE;
00202 AddSize( pDC, m_sURL );
00203 m_sz.cy += TIP_TEXTHEIGHT;
00204 }
00205
00206
00207 if ( ! pDownload->IsSeeding() )
00208 {
00209 m_sz.cy += 2;
00210 m_sz.cy += TIP_TEXTHEIGHT;
00211 }
00212
00213
00214 if ( pDownload->IsCompleted() )
00215 m_bDrawGraph = FALSE;
00216 else
00217 {
00218 m_sz.cy += TIP_GAP;
00219 m_sz.cy += 40;
00220 m_bDrawGraph = TRUE;
00221 }
00222
00223 CString str;
00224 LoadString( str, IDS_DLM_ESTIMATED_TIME );
00225 m_nStatWidth = pDC->GetTextExtent( str ).cx + 8;
00226 }
00227
00228 void CDownloadTipCtrl::OnPaint(CDC* pDC, CDownload* pDownload)
00229 {
00230 CPoint pt( 0, 0 );
00231 CString str, strOf;
00232 LoadString( strOf, IDS_GENERAL_OF );
00233
00234 DrawText( pDC, &pt, m_sName );
00235 pt.y += TIP_TEXTHEIGHT;
00236
00237 if ( m_sSHA1.GetLength() )
00238 {
00239
00240 if ( ( ! Settings.General.VerboseMode ) || ( pDownload->m_bSHA1Trusted ) )
00241 pDC->SelectObject( &CoolInterface.m_fntNormal );
00242 else
00243 pDC->SelectObject( &CoolInterface.m_fntItalic );
00244
00245 DrawText( pDC, &pt, m_sSHA1 );
00246 pt.y += TIP_TEXTHEIGHT;
00247 }
00248 if ( m_sTiger.GetLength() )
00249 {
00250
00251 if ( ( ! Settings.General.VerboseMode ) || ( pDownload->m_bTigerTrusted ) )
00252 pDC->SelectObject( &CoolInterface.m_fntNormal );
00253 else
00254 pDC->SelectObject( &CoolInterface.m_fntItalic );
00255
00256 DrawText( pDC, &pt, m_sTiger );
00257 pt.y += TIP_TEXTHEIGHT;
00258 }
00259 if ( m_sED2K.GetLength() )
00260 {
00261
00262 if ( ( ! Settings.General.VerboseMode ) || ( pDownload->m_bED2KTrusted ) )
00263 pDC->SelectObject( &CoolInterface.m_fntNormal );
00264 else
00265 pDC->SelectObject( &CoolInterface.m_fntItalic );
00266
00267 DrawText( pDC, &pt, m_sED2K );
00268 pt.y += TIP_TEXTHEIGHT;
00269 }
00270 if ( m_sBTH.GetLength() )
00271 {
00272
00273 if ( ( ! Settings.General.VerboseMode ) || ( pDownload->m_bBTHTrusted ) )
00274 pDC->SelectObject( &CoolInterface.m_fntNormal );
00275 else
00276 pDC->SelectObject( &CoolInterface.m_fntItalic );
00277
00278 DrawText( pDC, &pt, m_sBTH );
00279 pt.y += TIP_TEXTHEIGHT;
00280 }
00281
00282 pDC->SelectObject( &CoolInterface.m_fntNormal );
00283
00284 DrawRule( pDC, &pt );
00285
00286 ImageList_DrawEx( ShellIcons.GetHandle( 32 ), m_nIcon, pDC->GetSafeHdc(),
00287 pt.x, pt.y, 32, 32, CoolInterface.m_crTipBack, CLR_NONE, ILD_NORMAL );
00288 pDC->ExcludeClipRect( pt.x, pt.y, pt.x + 32, pt.y + 32 );
00289
00290 pt.y += 2;
00291 pt.x += 40;
00292 LoadString( str, IDS_TIP_SIZE );
00293 DrawText( pDC, &pt, str + ':' );
00294 DrawText( pDC, &pt, m_sSize, 40 );
00295 pt.y += TIP_TEXTHEIGHT;
00296 LoadString( str, IDS_TIP_TYPE );
00297 DrawText( pDC, &pt, str + ':' );
00298 DrawText( pDC, &pt, m_sType, 40 );
00299 pt.x -= 40;
00300 pt.y -= TIP_TEXTHEIGHT + 2;
00301 pt.y += 34;
00302
00303 DrawRule( pDC, &pt );
00304
00305 CString strFormat, strETA, strSpeed, strVolume, strSources, strTorrentUpload;
00306
00307 int nSourceCount = pDownload->GetSourceCount();
00308 int nTransferCount = pDownload->GetTransferCount();
00309
00310 LoadString( strFormat, IDS_TIP_NA );
00311
00312 if ( pDownload->IsMoving() )
00313 {
00314 LoadString( strETA, IDS_DLM_COMPLETED_WORD );
00315 strSpeed = strFormat;
00316 LoadString( strSources, IDS_DLM_COMPLETED_WORD );
00317 }
00318 else if ( pDownload->IsPaused() )
00319 {
00320 strETA = strFormat;
00321 strSpeed = strFormat;
00322 strSources.Format( _T("%i"), nSourceCount );
00323 }
00324 else if ( nTransferCount )
00325 {
00326 DWORD nTime = pDownload->GetTimeRemaining();
00327
00328 if ( nTime != 0xFFFFFFFF )
00329 {
00330 if ( nTime > 86400 )
00331 {
00332 LoadString( strFormat, IDS_DLM_TIME_DAH );
00333 strETA.Format( strFormat, nTime / 86400, ( nTime / 3600 ) % 24 );
00334 }
00335 else if ( nTime > 3600 )
00336 {
00337 LoadString( strFormat, IDS_DLM_TIME_HAM );
00338 strETA.Format( strFormat, nTime / 3600, ( nTime % 3600 ) / 60 );
00339 }
00340 else if ( nTime > 60 )
00341 {
00342 LoadString( strFormat, IDS_DLM_TIME_MAS );
00343 strETA.Format( strFormat, nTime / 60, nTime % 60 );
00344 }
00345 else
00346 {
00347 LoadString( strFormat, IDS_DLM_TIME_S );
00348 strETA.Format( strFormat, nTime % 60 );
00349 }
00350 }
00351
00352 strSpeed = Settings.SmartVolume( pDownload->GetAverageSpeed() * 8, FALSE, TRUE );
00353
00354 strSources.Format( _T("%i %s %i"), nTransferCount, strOf, nSourceCount );
00355 if ( theApp.m_bRTL ) strSources = _T("\x202B") + strSources;
00356 }
00357 else if ( nSourceCount )
00358 {
00359 strETA = strFormat;
00360 strSpeed = strFormat;
00361 strSources.Format( _T("%i"), nSourceCount );
00362 }
00363 else
00364 {
00365 strETA = strFormat;
00366 strSpeed = strFormat;
00367 LoadString( strSources, IDS_DLM_NO_SOURCES );
00368 }
00369
00370 if ( pDownload->IsStarted() )
00371 {
00372 if ( theApp.m_bRTL )
00373 {
00374 strVolume.Format( _T("(%.2f%%) %s %s %s"),
00375 pDownload->GetProgress() * 100.0,
00376 (LPCTSTR)Settings.SmartVolume( pDownload->m_nSize, FALSE ), strOf,
00377 (LPCTSTR)Settings.SmartVolume( pDownload->GetVolumeComplete(), FALSE ) );
00378 }
00379 else
00380 {
00381 strVolume.Format( _T("%s %s %s (%.2f%%)"),
00382 (LPCTSTR)Settings.SmartVolume( pDownload->GetVolumeComplete(), FALSE ),
00383 strOf, (LPCTSTR)Settings.SmartVolume( pDownload->m_nSize, FALSE ),
00384 pDownload->GetProgress() * 100.0 );
00385 }
00386 }
00387 else
00388 {
00389 LoadString( strVolume, IDS_TIP_NA );
00390 }
00391
00392 if ( pDownload->m_nTorrentUploaded )
00393 {
00394 if ( theApp.m_bRTL )
00395 {
00396 strTorrentUpload.Format( _T("(%.2f%%) %s %s %s"),
00397 pDownload->GetRatio() * 100.0,
00398 (LPCTSTR)Settings.SmartVolume( pDownload->m_nTorrentDownloaded, FALSE ),
00399 strOf,
00400 (LPCTSTR)Settings.SmartVolume( pDownload->m_nTorrentUploaded, FALSE ) );
00401 }
00402 else
00403 {
00404 strTorrentUpload.Format( _T("%s %s %s (%.2f%%)"),
00405 (LPCTSTR)Settings.SmartVolume( pDownload->m_nTorrentUploaded, FALSE ),
00406 strOf,
00407 (LPCTSTR)Settings.SmartVolume( pDownload->m_nTorrentDownloaded, FALSE ),
00408 pDownload->GetRatio() * 100.0 );
00409 }
00410 }
00411 else
00412 {
00413 if ( theApp.m_bRTL )
00414 {
00415 strTorrentUpload.Format( _T("(%.2f%%) %s %s %s"), 0.0,
00416 (LPCTSTR)Settings.SmartVolume( pDownload->m_nTorrentDownloaded, FALSE ), strOf, _T("0") );
00417 }
00418 else
00419 {
00420 strTorrentUpload.Format( _T("%s %s %s (%.2f%%)"), _T("0"), strOf,
00421 (LPCTSTR)Settings.SmartVolume( pDownload->m_nTorrentDownloaded, FALSE ), 0.0 );
00422 }
00423 }
00424
00425
00426 if ( m_bDrawError )
00427 {
00428 DrawText( pDC, &pt, pDownload->m_sTorrentTrackerError, 3 );
00429 pt.y += TIP_TEXTHEIGHT;
00430 DrawRule( pDC, &pt );
00431 }
00432
00433 if ( ! pDownload->IsCompleted() )
00434 {
00435 LoadString( strFormat, IDS_DLM_TOTAL_SPEED );
00436 DrawText( pDC, &pt, strFormat, 3 );
00437 DrawText( pDC, &pt, strSpeed, m_nStatWidth );
00438 pt.y += TIP_TEXTHEIGHT;
00439 }
00440 if ( ! pDownload->IsSeeding() )
00441 {
00442 LoadString( strFormat, IDS_DLM_ESTIMATED_TIME );
00443 DrawText( pDC, &pt, strFormat, 3 );
00444 DrawText( pDC, &pt, strETA, m_nStatWidth );
00445 pt.y += TIP_TEXTHEIGHT;
00446 }
00447 if ( ! pDownload->IsSeeding() )
00448 {
00449 LoadString( strFormat, IDS_DLM_VOLUME_DOWNLOADED );
00450 DrawText( pDC, &pt, strFormat, 3 );
00451 DrawText( pDC, &pt, strVolume, m_nStatWidth );
00452 pt.y += TIP_TEXTHEIGHT;
00453 }
00454 if ( pDownload->m_bBTH )
00455 {
00456 LoadString( strFormat, IDS_DLM_VOLUME_UPLOADED );
00457 DrawText( pDC, &pt, strFormat, 3 );
00458 DrawText( pDC, &pt, strTorrentUpload, m_nStatWidth );
00459 pt.y += TIP_TEXTHEIGHT;
00460 }
00461 if ( ! pDownload->IsCompleted() )
00462 {
00463 LoadString( strFormat, IDS_DLM_NUMBER_OF_SOURCES );
00464 DrawText( pDC, &pt, strFormat, 3 );
00465 DrawText( pDC, &pt, strSources, m_nStatWidth );
00466 pt.y += TIP_TEXTHEIGHT;
00467 }
00468 if ( m_sURL.GetLength() )
00469 {
00470 DrawRule( pDC, &pt );
00471 DrawText( pDC, &pt, m_sURL );
00472 pt.y += TIP_TEXTHEIGHT;
00473 }
00474
00475 if ( ! pDownload->IsSeeding() )
00476 {
00477 pt.y += 2;
00478 DrawProgressBar( pDC, &pt, pDownload );
00479 pt.y += TIP_GAP;
00480 }
00481
00482 if ( m_bDrawGraph )
00483 {
00484 CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
00485 pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00486 rc.DeflateRect( 1, 1 );
00487 m_pGraph->BufferedPaint( pDC, &rc );
00488 rc.InflateRect( 1, 1 );
00489 pDC->ExcludeClipRect( &rc );
00490 pt.y += 40;
00491 }
00492 pt.y += TIP_GAP;
00493 }
00494
00495 void CDownloadTipCtrl::PrepareFileInfo(CDownload* pDownload)
00496 {
00497 m_sName = pDownload->m_sRemoteName;
00498 m_sSize = Settings.SmartVolume( pDownload->m_nSize, FALSE );
00499 if ( pDownload->m_nSize == SIZE_UNKNOWN ) m_sSize = _T("?");
00500
00501 m_sSHA1.Empty();
00502 m_sTiger.Empty();
00503 m_sED2K.Empty();
00504 m_sBTH.Empty();
00505 m_sURL.Empty();
00506
00507
00508 if ( Settings.General.GUIMode != GUI_BASIC )
00509 {
00510
00511 CString strNoHashset;
00512 LoadString( strNoHashset, IDS_TIP_NOHASHSET );
00513
00514 if ( pDownload->m_bSHA1 )
00515 {
00516 m_sSHA1 = _T("sha1:") + CSHA::HashToString( &pDownload->m_pSHA1 );
00517 }
00518 if ( pDownload->m_bTiger )
00519 {
00520 m_sTiger = _T("tree:tiger/:") + CTigerNode::HashToString( &pDownload->m_pTiger );
00521 if ( ( Settings.General.VerboseMode ) && ( ! pDownload->m_pTigerBlock ) )
00522 m_sTiger += strNoHashset;
00523 }
00524 if ( pDownload->m_bED2K )
00525 {
00526 m_sED2K = _T("ed2k:") + CED2K::HashToString( &pDownload->m_pED2K );
00527 if ( ( Settings.General.VerboseMode ) && ( ! pDownload->m_pHashsetBlock ) )
00528 m_sED2K += strNoHashset;
00529 }
00530 if ( pDownload->m_bBTH )
00531 {
00532 m_sBTH = _T("btih:") + CSHA::HashToString( &pDownload->m_pBTH );
00533 if ( ( Settings.General.VerboseMode ) && ( ! pDownload->m_pTorrentBlock ) )
00534 m_sBTH += strNoHashset;
00535
00536 m_sURL = pDownload->m_pTorrent.m_sTracker;
00537 }
00538 }
00539
00540 int nPeriod = m_sName.ReverseFind( '.' );
00541
00542 m_sType.Empty();
00543 m_nIcon = 0;
00544
00545 if ( nPeriod > 0 )
00546 {
00547 CString strType = m_sName.Mid( nPeriod );
00548 CString strName, strMime;
00549
00550 ShellIcons.Lookup( strType, NULL, NULL, &strName, &strMime );
00551 m_nIcon = ShellIcons.Get( strType, 32 );
00552
00553 if ( strName.GetLength() )
00554 {
00555 m_sType = strName;
00556 if ( strMime.GetLength() ) m_sType += _T(" (") + strMime + _T(")");
00557 }
00558 else
00559 {
00560 m_sType = strType.Mid( 1 );
00561 }
00562 }
00563
00564 if ( m_sType.IsEmpty() ) m_sType = _T("Unknown");
00565 }
00566
00568
00569
00570 void CDownloadTipCtrl::OnCalcSize(CDC* pDC, CDownloadSource* pSource)
00571 {
00572 CDownload* pDownload = pSource->m_pDownload;
00573
00574 if ( pSource->m_sNick.GetLength() > 0 )
00575 m_sName = pSource->m_sNick + _T(" (") + inet_ntoa( pSource->m_pAddress ) + ')';
00576 else
00577 {
00578 if( ( pSource->m_nProtocol == PROTOCOL_ED2K ) && ( pSource->m_bPushOnly == TRUE ) )
00579 {
00580 m_sName.Format( _T("%lu@%s"), (DWORD)pSource->m_pAddress.S_un.S_addr,
00581 (LPCTSTR)CString( inet_ntoa( (IN_ADDR&)pSource->m_pServerAddress) ) );
00582 }
00583 else
00584 {
00585 m_sName = inet_ntoa( pSource->m_pAddress );
00586 }
00587 }
00588
00589 if( pSource->m_bPushOnly )
00590 {
00591 m_sName += _T(" (push)");
00592 }
00593
00594
00595 m_sURL = pSource->m_sURL;
00596
00597 if ( m_sURL.GetLength() > 128 )
00598 {
00599 if ( LPCTSTR pszSlash = _tcschr( (LPCTSTR)m_sURL + 7, '/' ) )
00600 {
00601 int nFirst = pszSlash - (LPCTSTR)m_sSize;
00602 m_sURL = m_sURL.Left( nFirst + 1 ) + _T("...") + m_sURL.Right( 10 );
00603 }
00604 }
00605
00606 m_pHeaderName.RemoveAll();
00607 m_pHeaderValue.RemoveAll();
00608
00609 if ( pSource->m_pTransfer != NULL && Settings.General.GUIMode != GUI_BASIC )
00610 {
00611 for ( int nHeader = 0 ; nHeader < pSource->m_pTransfer->m_pHeaderName.GetSize() ; nHeader++ )
00612 {
00613 CString strName = pSource->m_pTransfer->m_pHeaderName.GetAt( nHeader );
00614 CString strValue = pSource->m_pTransfer->m_pHeaderValue.GetAt( nHeader );
00615
00616 if ( strValue.GetLength() > 64 ) strValue = strValue.Left( 64 ) + _T("...");
00617
00618 m_pHeaderName.Add( strName );
00619 m_pHeaderValue.Add( strValue );
00620 }
00621 }
00622
00623 AddSize( pDC, m_sName );
00624 pDC->SelectObject( &CoolInterface.m_fntNormal );
00625 m_sz.cy += TIP_TEXTHEIGHT + TIP_RULE;
00626
00627 AddSize( pDC, m_sURL, 80 );
00628 m_sz.cy += TIP_TEXTHEIGHT * 4;
00629
00630 m_sz.cy += TIP_GAP;
00631 m_sz.cy += TIP_TEXTHEIGHT;
00632 m_sz.cy += TIP_GAP;
00633 m_sz.cy += 40;
00634 m_sz.cy += TIP_GAP;
00635
00636 int nValueWidth = 0;
00637 m_nHeaderWidth = 0;
00638
00639 for ( int nHeader = 0 ; nHeader < m_pHeaderName.GetSize() ; nHeader++ )
00640 {
00641 CString strName = m_pHeaderName.GetAt( nHeader );
00642 CString strValue = m_pHeaderValue.GetAt( nHeader );
00643 CSize szKey = pDC->GetTextExtent( strName + ':' );
00644 CSize szValue = pDC->GetTextExtent( strValue );
00645
00646 m_nHeaderWidth = max( m_nHeaderWidth, int(szKey.cx) );
00647 nValueWidth = max( nValueWidth, int(szValue.cx) );
00648
00649 m_sz.cy += TIP_TEXTHEIGHT;
00650 }
00651
00652 if ( m_nHeaderWidth ) m_nHeaderWidth += TIP_GAP;
00653 m_sz.cx = max( m_sz.cx, LONG(m_nHeaderWidth + nValueWidth) );
00654 }
00655
00656 void CDownloadTipCtrl::OnPaint(CDC* pDC, CDownloadSource* pSource)
00657 {
00658 CDownload* pDownload = pSource->m_pDownload;
00659 CPoint pt( 0, 0 );
00660
00661 DrawText( pDC, &pt, m_sName );
00662 pDC->SelectObject( &CoolInterface.m_fntNormal );
00663 pt.y += TIP_TEXTHEIGHT;
00664
00665 DrawRule( pDC, &pt );
00666
00667 CString strStatus, strSpeed, strText;
00668
00669 if ( pSource->m_pTransfer != NULL )
00670 {
00671 DWORD nLimit = pSource->m_pTransfer->m_mInput.pLimit != NULL ?
00672 *pSource->m_pTransfer->m_mInput.pLimit : 0;
00673
00674 strStatus = pSource->m_pTransfer->GetStateText( TRUE );
00675
00676 if ( nLimit > 0 )
00677 {
00678 CString strOf;
00679 LoadString( strOf, IDS_GENERAL_OF );
00680 strSpeed.Format( _T("%s %s %s"),
00681 (LPCTSTR)Settings.SmartVolume( pSource->m_pTransfer->GetMeasuredSpeed() * 8, FALSE, TRUE ),
00682 strOf, (LPCTSTR)Settings.SmartVolume( nLimit * 8, FALSE, TRUE ) );
00683 }
00684 else
00685 {
00686 strSpeed = Settings.SmartVolume( pSource->m_pTransfer->GetMeasuredSpeed() * 8, FALSE, TRUE );
00687 }
00688 }
00689 else
00690 {
00691 LoadString( strStatus, IDS_TIP_INACTIVE );
00692 LoadString( strSpeed, IDS_TIP_NA );
00693 }
00694
00695 LoadString( strText, IDS_TIP_STATUS );
00696 DrawText( pDC, &pt, strText );
00697 DrawText( pDC, &pt, strStatus, 80 );
00698 pt.y += TIP_TEXTHEIGHT;
00699
00700 LoadString( strText, IDS_TIP_SPEED );
00701 DrawText( pDC, &pt, strText );
00702 DrawText( pDC, &pt, strSpeed, 80 );
00703 pt.y += TIP_TEXTHEIGHT;
00704
00705 LoadString( strText, IDS_TIP_URL );
00706 DrawText( pDC, &pt, strText );
00707 DrawText( pDC, &pt, m_sURL, 80 );
00708 pt.y += TIP_TEXTHEIGHT;
00709
00710 LoadString( strText, IDS_TIP_USERAGENT );
00711 DrawText( pDC, &pt, strText );
00712 DrawText( pDC, &pt, pSource->m_sServer, 80 );
00713 pt.y += TIP_TEXTHEIGHT;
00714
00715 pt.y += TIP_GAP;
00716
00717 DrawProgressBar( pDC, &pt, pSource );
00718 pt.y += TIP_GAP;
00719
00720 CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
00721 pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00722 rc.DeflateRect( 1, 1 );
00723 m_pGraph->BufferedPaint( pDC, &rc );
00724 rc.InflateRect( 1, 1 );
00725 pDC->ExcludeClipRect( &rc );
00726 pt.y += 40;
00727 pt.y += TIP_GAP;
00728
00729 for ( int nHeader = 0 ; nHeader < m_pHeaderName.GetSize() ; nHeader++ )
00730 {
00731 CString strName = m_pHeaderName.GetAt( nHeader );
00732 CString strValue = m_pHeaderValue.GetAt( nHeader );
00733
00734 DrawText( pDC, &pt, strName + ':' );
00735 DrawText( pDC, &pt, strValue, m_nHeaderWidth );
00736 pt.y += TIP_TEXTHEIGHT;
00737 }
00738 }
00739
00741
00742
00743 void CDownloadTipCtrl::DrawProgressBar(CDC* pDC, CPoint* pPoint, CDownload* pDownload)
00744 {
00745 CRect rcCell( pPoint->x, pPoint->y, m_sz.cx, pPoint->y + TIP_TEXTHEIGHT );
00746 pPoint->y += TIP_TEXTHEIGHT;
00747
00748 pDC->Draw3dRect( &rcCell, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00749 rcCell.DeflateRect( 1, 1 );
00750
00751 CFragmentBar::DrawDownload( pDC, &rcCell, pDownload, CoolInterface.m_crTipBack );
00752
00753 rcCell.InflateRect( 1, 1 );
00754 pDC->ExcludeClipRect( &rcCell );
00755 }
00756
00757 void CDownloadTipCtrl::DrawProgressBar(CDC* pDC, CPoint* pPoint, CDownloadSource* pSource)
00758 {
00759 CRect rcCell( pPoint->x, pPoint->y, m_sz.cx, pPoint->y + TIP_TEXTHEIGHT );
00760 pPoint->y += TIP_TEXTHEIGHT;
00761
00762 pDC->Draw3dRect( &rcCell, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00763 rcCell.DeflateRect( 1, 1 );
00764
00765 CFragmentBar::DrawSource( pDC, &rcCell, pSource, CoolInterface.m_crTipBack );
00766
00767 rcCell.InflateRect( 1, 1 );
00768 pDC->ExcludeClipRect( &rcCell );
00769 }
00770
00772
00773
00774 void CDownloadTipCtrl::OnTimer(UINT nIDEvent)
00775 {
00776 CCoolTipCtrl::OnTimer( nIDEvent );
00777
00778 if ( m_pGraph == NULL ) return;
00779
00780 CSingleLock pLock( &Transfers.m_pSection );
00781 if ( ! pLock.Lock( 10 ) ) return;
00782
00783 if ( Downloads.Check( (CDownload*)m_pContext ) )
00784 {
00785 CDownload* pDownload = (CDownload*)m_pContext;
00786 DWORD nSpeed = pDownload->GetMeasuredSpeed() * 8;
00787 m_pItem->Add( nSpeed );
00788 m_pGraph->m_nUpdates++;
00789 m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nSpeed );
00790 Invalidate();
00791 }
00792 else if ( Downloads.Check( (CDownloadSource*)m_pContext ) )
00793 {
00794 CDownloadSource* pSource = (CDownloadSource*)m_pContext;
00795
00796 if ( pSource->m_pTransfer )
00797 {
00798 DWORD nSpeed = pSource->m_pTransfer->GetMeasuredSpeed() * 8;
00799 m_pItem->Add( nSpeed );
00800 m_pGraph->m_nUpdates++;
00801 m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nSpeed );
00802 Invalidate();
00803 }
00804 }
00805 }