Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

CtrlUploadTip.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlUploadTip.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "CoolInterface.h"
00026 #include "Transfers.h"
00027 #include "UploadFile.h"
00028 #include "UploadFiles.h"
00029 #include "UploadQueue.h"
00030 #include "UploadQueues.h"
00031 #include "UploadTransfer.h"
00032 #include "GraphLine.h"
00033 #include "GraphItem.h"
00034 #include "FragmentedFile.h"
00035 #include "FragmentBar.h"
00036 #include "CtrlUploadTip.h"
00037 
00038 #ifdef _DEBUG
00039 #define new DEBUG_NEW
00040 #undef THIS_FILE
00041 static char THIS_FILE[] = __FILE__;
00042 #endif
00043 
00044 IMPLEMENT_DYNAMIC(CUploadTipCtrl, CCoolTipCtrl)
00045 
00046 BEGIN_MESSAGE_MAP(CUploadTipCtrl, CCoolTipCtrl)
00047         //{{AFX_MSG_MAP(CUploadTipCtrl)
00048         ON_WM_TIMER()
00049         //}}AFX_MSG_MAP
00050 END_MESSAGE_MAP()
00051 
00052 
00054 // CUploadTipCtrl construction
00055 
00056 CUploadTipCtrl::CUploadTipCtrl()
00057 {
00058         m_pGraph = NULL;
00059 }
00060 
00061 CUploadTipCtrl::~CUploadTipCtrl()
00062 {
00063         if ( m_pGraph ) delete m_pGraph;
00064 }
00065 
00067 // CUploadTipCtrl events
00068 
00069 BOOL CUploadTipCtrl::OnPrepare()
00070 {
00071         CSingleLock pLock( &Transfers.m_pSection );
00072         if ( ! pLock.Lock( 100 ) ) return FALSE;
00073 
00074         CalcSizeHelper();
00075 
00076         return m_sz.cx > 0;
00077 }
00078 
00079 void CUploadTipCtrl::OnShow()
00080 {
00081         if ( m_pGraph ) delete m_pGraph;
00082 
00083         m_pGraph        = CreateLineGraph();
00084         m_pItem         = new CGraphItem( 0, 0, RGB( 0xFF, 0, 0 ) );
00085 
00086         m_pGraph->AddItem( m_pItem );
00087 }
00088 
00089 void CUploadTipCtrl::OnHide()
00090 {
00091         if ( m_pGraph ) delete m_pGraph;
00092         m_pGraph = NULL;
00093         m_pItem = NULL;
00094 }
00095 
00096 void CUploadTipCtrl::OnCalcSize(CDC* pDC)
00097 {
00098         CUploadFile* pFile = (CUploadFile*)m_pContext;
00099         if ( ! UploadFiles.Check( pFile ) ) return;
00100         CUploadTransfer* pUpload = pFile->GetActive();
00101 
00102         if ( pUpload->m_sNick.GetLength() > 0 )
00103                 m_sAddress = pUpload->m_sNick + _T(" (") + inet_ntoa( pUpload->m_pHost.sin_addr ) + ')';
00104         else
00105                 m_sAddress = inet_ntoa( pUpload->m_pHost.sin_addr );
00106 
00107         m_pHeaderName.RemoveAll();
00108         m_pHeaderValue.RemoveAll();
00109 
00110         if ( Settings.General.GUIMode != GUI_BASIC )
00111         {
00112                 for ( int nHeader = 0 ; nHeader < pUpload->m_pHeaderName.GetSize() ; nHeader++ )
00113                 {
00114                         CString strName         = pUpload->m_pHeaderName.GetAt( nHeader );
00115                         CString strValue        = pUpload->m_pHeaderValue.GetAt( nHeader );
00116 
00117                         if ( strValue.GetLength() > 64 ) strValue = strValue.Left( 64 ) + _T("...");
00118 
00119                         m_pHeaderName.Add( strName );
00120                         m_pHeaderValue.Add( strValue );
00121                 }
00122         }
00123 
00124         AddSize( pDC, pFile->m_sName );
00125         AddSize( pDC, m_sAddress );
00126         pDC->SelectObject( &CoolInterface.m_fntNormal );
00127 
00128         m_sz.cy += TIP_TEXTHEIGHT * 2;
00129         m_sz.cy += TIP_RULE;
00130         m_sz.cy += TIP_TEXTHEIGHT * 3;
00131         m_sz.cy += TIP_GAP;
00132         m_sz.cy += TIP_TEXTHEIGHT;
00133         m_sz.cy += TIP_GAP;
00134         m_sz.cy += 40;
00135         m_sz.cy += TIP_GAP;
00136 
00137         int nValueWidth = 0;
00138         m_nHeaderWidth = 0;
00139 
00140         for ( int nHeader = 0 ; nHeader < m_pHeaderName.GetSize() ; nHeader++ )
00141         {
00142                 CString strName         = m_pHeaderName.GetAt( nHeader );
00143                 CString strValue        = m_pHeaderValue.GetAt( nHeader );
00144                 CSize szKey                     = pDC->GetTextExtent( strName + ':' );
00145                 CSize szValue           = pDC->GetTextExtent( strValue );
00146 
00147                 m_nHeaderWidth          = max( m_nHeaderWidth, int(szKey.cx) );
00148                 nValueWidth                     = max( nValueWidth, int(szValue.cx) );
00149 
00150                 m_sz.cy += TIP_TEXTHEIGHT;
00151         }
00152 
00153         if ( m_nHeaderWidth ) m_nHeaderWidth += TIP_GAP;
00154         m_sz.cx = max( m_sz.cx, LONG(m_nHeaderWidth + nValueWidth) );
00155 
00156         m_sz.cx = max( m_sz.cx, LONG(320) );
00157 }
00158 
00159 void CUploadTipCtrl::OnPaint(CDC* pDC)
00160 {
00161         CString strText;
00162 
00163         CSingleLock pLock( &Transfers.m_pSection );
00164         if ( ! pLock.Lock( 100 ) ) return;
00165 
00166         CUploadFile* pFile = (CUploadFile*)m_pContext;
00167 
00168         if ( ! UploadFiles.Check( pFile ) )
00169         {
00170                 Hide();
00171                 return;
00172         }
00173 
00174         CUploadTransfer* pUpload = pFile->GetActive();
00175 
00176         CPoint pt( 0, 0 );
00177 
00178         DrawText( pDC, &pt, pFile->m_sName );
00179         pt.y += TIP_TEXTHEIGHT;
00180         DrawText( pDC, &pt, m_sAddress );
00181         pt.y += TIP_TEXTHEIGHT;
00182         pDC->SelectObject( &CoolInterface.m_fntNormal );
00183 
00184         DrawRule( pDC, &pt );
00185 
00186         int nQueue = UploadQueues.GetPosition( pUpload, FALSE );
00187         CString strStatus, strSpeed;
00188 
00189         if ( pUpload->m_nProtocol != PROTOCOL_BT )
00190         {
00191                 strSpeed.Format( _T("%s of %s"),
00192                         (LPCTSTR)Settings.SmartVolume( pUpload->GetMeasuredSpeed() * 8, FALSE, TRUE ),
00193                         (LPCTSTR)Settings.SmartVolume( pUpload->m_nBandwidth * 8, FALSE, TRUE ) );
00194         }
00195         else
00196         {
00197                 strSpeed = Settings.SmartVolume( pUpload->GetMeasuredSpeed() * 8, FALSE, TRUE );
00198         }
00199 
00200         if ( pFile != pUpload->m_pBaseFile || pUpload->m_nState == upsNull )
00201         {
00202                 LoadString( strStatus, IDS_TIP_INACTIVE );
00203         }
00204         else if ( nQueue == 0 )
00205         {
00206                 if ( pUpload->m_nState == upsQueued )
00207                 {
00208                         LoadString( strText, IDS_TIP_NEXT );
00209                         strStatus.Format( _T("%s: %s"),
00210                                 (LPCTSTR)pUpload->m_pQueue->m_sName, strText );
00211                 }
00212                 else
00213                 {
00214                         LoadString( strText, IDS_TIP_ACTIVE );
00215                         strStatus.Format( _T("%s: %s"),
00216                                 (LPCTSTR)pUpload->m_pQueue->m_sName, strText );
00217                 }
00218         }
00219         else if ( nQueue > 0 )
00220         {
00221                 strStatus.Format( _T("%s: %i of %i"),
00222                         (LPCTSTR)pUpload->m_pQueue->m_sName,
00223                         nQueue, pUpload->m_pQueue->GetQueuedCount() );
00224         }
00225         else
00226         {
00227                 LoadString( strStatus, IDS_TIP_ACTIVE );
00228         }
00229 
00230         LoadString( strText, IDS_TIP_STATUS );
00231         DrawText( pDC, &pt, strText );
00232         DrawText( pDC, &pt, strStatus, 80 );
00233         pt.y += TIP_TEXTHEIGHT;
00234 
00235         LoadString( strText, IDS_TIP_SPEED );
00236         DrawText( pDC, &pt, strText );
00237         DrawText( pDC, &pt, strSpeed, 80 );
00238         pt.y += TIP_TEXTHEIGHT;
00239 
00240         LoadString( strText, IDS_TIP_USERAGENT );
00241         DrawText( pDC, &pt, strText );
00242         DrawText( pDC, &pt, pUpload->m_sUserAgent, 80 );
00243         pt.y += TIP_TEXTHEIGHT;
00244 
00245         pt.y += TIP_GAP;
00246 
00247         DrawProgressBar( pDC, &pt, pFile );
00248         pt.y += TIP_GAP;
00249 
00250         CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
00251         pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00252         rc.DeflateRect( 1, 1 );
00253         m_pGraph->BufferedPaint( pDC, &rc );
00254         rc.InflateRect( 1, 1 );
00255         pDC->ExcludeClipRect( &rc );
00256         pt.y += 40;
00257         pt.y += TIP_GAP;
00258 
00259         for ( int nHeader = 0 ; nHeader < m_pHeaderName.GetSize() ; nHeader++ )
00260         {
00261                 CString strName         = m_pHeaderName.GetAt( nHeader );
00262                 CString strValue        = m_pHeaderValue.GetAt( nHeader );
00263 
00264                 DrawText( pDC, &pt, strName + ':' );
00265                 DrawText( pDC, &pt, strValue, m_nHeaderWidth );
00266                 pt.y += TIP_TEXTHEIGHT;
00267         }
00268 }
00269 
00270 void CUploadTipCtrl::DrawProgressBar(CDC* pDC, CPoint* pPoint, CUploadFile* pFile)
00271 {
00272         CUploadTransfer* pUpload = pFile->GetActive();
00273 
00274         CRect rcCell( pPoint->x, pPoint->y, m_sz.cx, pPoint->y + TIP_TEXTHEIGHT );
00275         pPoint->y += TIP_TEXTHEIGHT;
00276 
00277         pDC->Draw3dRect( &rcCell, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00278         rcCell.DeflateRect( 1, 1 );
00279 
00280         CFragmentBar::DrawUpload( pDC, &rcCell, pFile, CoolInterface.m_crTipBack );
00281 
00282         rcCell.InflateRect( 1, 1 );
00283         pDC->ExcludeClipRect( &rcCell );
00284 }
00285 
00287 // CUploadTipCtrl message handlers
00288 
00289 void CUploadTipCtrl::OnTimer(UINT nIDEvent)
00290 {
00291         CCoolTipCtrl::OnTimer( nIDEvent );
00292 
00293         if ( m_pGraph == NULL ) return;
00294 
00295         CSingleLock pLock( &Transfers.m_pSection );
00296         if ( ! pLock.Lock( 10 ) ) return;
00297 
00298         CUploadFile* pFile = (CUploadFile*)m_pContext;
00299 
00300         if ( pFile == NULL || ! UploadFiles.Check( pFile ) )
00301         {
00302                 Hide();
00303                 return;
00304         }
00305 
00306         if ( CUploadTransfer* pUpload = pFile->GetActive() )
00307         {
00308                 DWORD nSpeed = pUpload->GetMeasuredSpeed() * 8;
00309                 m_pItem->Add( nSpeed );
00310                 m_pGraph->m_nUpdates++;
00311                 m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nSpeed );
00312                 Invalidate();
00313         }
00314 }

Generated on Thu Dec 15 10:39:38 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2