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 "Neighbours.h"
00026 #include "Neighbour.h"
00027 #include "Network.h"
00028 #include "GProfile.h"
00029 #include "CoolInterface.h"
00030 #include "CtrlNeighbourTip.h"
00031 #include "GraphLine.h"
00032 #include "GraphItem.h"
00033
00034 #include "EDPacket.h"
00035 #include "EDNeighbour.h"
00036
00037 #ifdef _DEBUG
00038 #define new DEBUG_NEW
00039 #undef THIS_FILE
00040 static char THIS_FILE[] = __FILE__;
00041 #endif
00042
00043 BEGIN_MESSAGE_MAP(CNeighbourTipCtrl, CCoolTipCtrl)
00044
00045 ON_WM_TIMER()
00046
00047 END_MESSAGE_MAP()
00048
00049
00051
00052
00053 CNeighbourTipCtrl::CNeighbourTipCtrl()
00054 {
00055 m_pGraph = NULL;
00056 }
00057
00058 CNeighbourTipCtrl::~CNeighbourTipCtrl()
00059 {
00060 if ( m_pGraph ) delete m_pGraph;
00061 }
00062
00064
00065
00066 BOOL CNeighbourTipCtrl::OnPrepare()
00067 {
00068 CSingleLock pLock( &Network.m_pSection );
00069 if ( ! pLock.Lock( 100 ) ) return FALSE;
00070
00071 CNeighbour* pNeighbour = Neighbours.Get( (DWORD)m_pContext );
00072 if ( pNeighbour == NULL ) return FALSE;
00073
00074 CalcSizeHelper();
00075
00076 return TRUE;
00077 }
00078
00080
00081
00082 void CNeighbourTipCtrl::OnShow()
00083 {
00084 if ( m_pGraph ) delete m_pGraph;
00085
00086 m_pGraph = CreateLineGraph();
00087 m_pItemIn = new CGraphItem( 0, 0, RGB( 0, 0, 0xFF ) );
00088 m_pItemOut = new CGraphItem( 0, 0, RGB( 0xFF, 0, 0 ) );
00089
00090 m_pGraph->AddItem( m_pItemIn );
00091 m_pGraph->AddItem( m_pItemOut );
00092 }
00093
00094 void CNeighbourTipCtrl::OnHide()
00095 {
00096 if ( m_pGraph ) delete m_pGraph;
00097 m_pGraph = NULL;
00098 }
00099
00101
00102
00103 void CNeighbourTipCtrl::OnCalcSize(CDC* pDC)
00104 {
00105 CNeighbour* pNeighbour = Neighbours.Get( (DWORD)m_pContext );
00106 CString str;
00107
00108 if ( pNeighbour->m_pProfile && pNeighbour->m_pProfile->IsValid() )
00109 {
00110 str = pNeighbour->m_pProfile->GetNick();
00111 if ( str.GetLength() )
00112 {
00113 pDC->SelectObject( &CoolInterface.m_fntBold );
00114 AddSize( pDC, str );
00115 m_sz.cy += TIP_TEXTHEIGHT;
00116 }
00117
00118 str = pNeighbour->m_pProfile->GetLocation();
00119 if ( str.GetLength() )
00120 {
00121 pDC->SelectObject( &CoolInterface.m_fntNormal );
00122 AddSize( pDC, str );
00123 m_sz.cy += TIP_TEXTHEIGHT;
00124 }
00125
00126 m_sz.cy += TIP_RULE;
00127 }
00128 else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
00129 {
00130 str = ((CEDNeighbour*)pNeighbour)->m_sServerName;
00131
00132 if ( str.GetLength() )
00133 {
00134 pDC->SelectObject( &CoolInterface.m_fntNormal );
00135 AddSize( pDC, str );
00136 m_sz.cy += TIP_TEXTHEIGHT;
00137 m_sz.cy += TIP_RULE;
00138 }
00139 }
00140
00141 pDC->SelectObject( &CoolInterface.m_fntBold );
00142 AddSize( pDC, pNeighbour->m_sAddress );
00143 pDC->SelectObject( &CoolInterface.m_fntNormal );
00144 m_sz.cy += TIP_TEXTHEIGHT;
00145
00146 if ( pNeighbour->m_sUserAgent.GetLength() )
00147 {
00148 AddSize( pDC, pNeighbour->m_sUserAgent );
00149 m_sz.cy += TIP_TEXTHEIGHT;
00150 }
00151
00152 m_sz.cy += TIP_TEXTHEIGHT;
00153 m_sz.cy += TIP_RULE;
00154
00155 m_sz.cy += TIP_TEXTHEIGHT * 6;
00156
00157 m_sz.cx = max( m_sz.cx, LONG(128 + 160) );
00158 m_sz.cy += 40;
00159 }
00160
00162
00163
00164 void CNeighbourTipCtrl::OnPaint(CDC* pDC)
00165 {
00166 CSingleLock pLock( &Network.m_pSection );
00167 if ( ! pLock.Lock( 100 ) ) return;
00168
00169 CNeighbour* pNeighbour = Neighbours.Get( (DWORD)m_pContext );
00170 if ( pNeighbour == NULL ) return;
00171
00172 CPoint pt( 0, 0 );
00173 CString str;
00174
00175 if ( pNeighbour->m_pProfile != NULL && pNeighbour->m_pProfile->IsValid() )
00176 {
00177 str = pNeighbour->m_pProfile->GetNick();
00178 if ( str.GetLength() )
00179 {
00180 pDC->SelectObject( &CoolInterface.m_fntBold );
00181 DrawText( pDC, &pt, str );
00182 pt.y += TIP_TEXTHEIGHT;
00183 }
00184 pDC->SelectObject( &CoolInterface.m_fntNormal );
00185 str = pNeighbour->m_pProfile->GetLocation();
00186 if ( str.GetLength() )
00187 {
00188 DrawText( pDC, &pt, str );
00189 pt.y += TIP_TEXTHEIGHT;
00190 }
00191 DrawRule( pDC, &pt );
00192 }
00193 else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
00194 {
00195 str = ((CEDNeighbour*)pNeighbour)->m_sServerName;
00196
00197 if ( str.GetLength() )
00198 {
00199 pDC->SelectObject( &CoolInterface.m_fntBold );
00200 DrawText( pDC, &pt, str );
00201 pt.y += TIP_TEXTHEIGHT;
00202 DrawRule( pDC, &pt );
00203 }
00204 }
00205
00206 pDC->SelectObject( &CoolInterface.m_fntBold );
00207 DrawText( pDC, &pt, pNeighbour->m_sAddress );
00208 pDC->SelectObject( &CoolInterface.m_fntNormal );
00209 pt.y += TIP_TEXTHEIGHT;
00210
00211 if ( pNeighbour->m_nState < nrsConnected )
00212 {
00213 LoadString( str, IDS_NEIGHBOUR_HANDSHAKE );
00214 }
00215 else
00216 {
00217 switch ( pNeighbour->m_nProtocol )
00218 {
00219 case PROTOCOL_G1:
00220 switch ( pNeighbour->m_nNodeType )
00221 {
00222 case ntNode:
00223 LoadString( str, IDS_NEIGHBOUR_G1PP );
00224 break;
00225 case ntHub:
00226 LoadString( str, IDS_NEIGHBOUR_G1LU );
00227 break;
00228 case ntLeaf:
00229 LoadString( str, IDS_NEIGHBOUR_G1UL );
00230 break;
00231 }
00232 break;
00233 case PROTOCOL_G2:
00234 switch ( pNeighbour->m_nNodeType )
00235 {
00236 case ntNode:
00237 LoadString( str, IDS_NEIGHBOUR_G2HH );
00238 break;
00239 case ntHub:
00240 LoadString( str, IDS_NEIGHBOUR_G2LH );
00241 break;
00242 case ntLeaf:
00243 LoadString( str, IDS_NEIGHBOUR_G2HL );
00244 break;
00245 }
00246 break;
00247 case PROTOCOL_ED2K:
00248 if ( CEDNeighbour* pED = (CEDNeighbour*)pNeighbour )
00249 {
00250 if ( CEDPacket::IsLowID( pED->m_nClientID ) )
00251 {
00252 CString sFormat;
00253 LoadString( sFormat, IDS_NEIGHBOUR_ED2K_LOW );
00254 str.Format( sFormat, pED->m_nClientID );
00255 }
00256 else
00257 {
00258 LoadString( str, IDS_NEIGHBOUR_ED2K_HIGH );
00259 }
00260 }
00261 break;
00262 default:
00263 LoadString( str, IDS_NEIGHBOUR_HANDSHAKE );
00264 break;
00265 }
00266 }
00267
00268 if ( pNeighbour->m_sUserAgent.GetLength() )
00269 {
00270 DrawText( pDC, &pt, pNeighbour->m_sUserAgent );
00271 pt.y += TIP_TEXTHEIGHT;
00272 }
00273
00274 DrawText( pDC, &pt, str );
00275 pt.y += TIP_TEXTHEIGHT;
00276
00277 DrawRule( pDC, &pt );
00278
00279 pDC->SelectObject( &CoolInterface.m_fntBold );
00280 pDC->SetTextColor( m_pItemIn->m_nColour );
00281 LoadString( str, IDS_NEIGHBOUR_INBOUND );
00282 DrawText( pDC, &pt, str, 128 );
00283 pDC->SetTextColor( m_pItemOut->m_nColour );
00284 LoadString( str, IDS_NEIGHBOUR_OUTBOUND );
00285 DrawText( pDC, &pt, str, 128 + 80 );
00286 pDC->SelectObject( &CoolInterface.m_fntNormal );
00287 pDC->SetTextColor( 0 );
00288
00289 pt.y += TIP_TEXTHEIGHT;
00290
00291 LoadString( str, IDS_NEIGHBOUR_CURRENT );
00292 DrawText( pDC, &pt, str );
00293 str = Settings.SmartVolume( pNeighbour->m_mInput.nMeasure * 8, FALSE, TRUE );
00294 DrawText( pDC, &pt, str, 128 );
00295 str = Settings.SmartVolume( pNeighbour->m_mOutput.nMeasure * 8, FALSE, TRUE );
00296 DrawText( pDC, &pt, str, 128 + 80 );
00297 pt.y += TIP_TEXTHEIGHT;
00298
00299 LoadString( str, IDS_NEIGHBOUR_TOTAL );
00300 DrawText( pDC, &pt, str );
00301 str = Settings.SmartVolume( pNeighbour->m_mInput.nTotal, FALSE );
00302 DrawText( pDC, &pt, str, 128 );
00303 str = Settings.SmartVolume( pNeighbour->m_mOutput.nTotal, FALSE );
00304 DrawText( pDC, &pt, str, 128 + 80 );
00305 pt.y += TIP_TEXTHEIGHT;
00306
00307 float nCompIn, nCompOut;
00308 pNeighbour->GetCompression( &nCompIn, &nCompOut );
00309
00310 LoadString( str, IDS_NEIGHBOUR_COMPRESSION );
00311 DrawText( pDC, &pt, str );
00312 LoadString( str, nCompIn > 0 ? IDS_NEIGHBOUR_COMPRESSION_DF : IDS_NEIGHBOUR_COMPRESSION_NONE );
00313 DrawText( pDC, &pt, str, 128 );
00314 LoadString( str, nCompOut > 0 ? IDS_NEIGHBOUR_COMPRESSION_DF : IDS_NEIGHBOUR_COMPRESSION_NONE );
00315 DrawText( pDC, &pt, str, 128 + 80 );
00316 pt.y += TIP_TEXTHEIGHT;
00317
00318 if ( nCompIn > 0 || nCompOut > 0 )
00319 {
00320 LoadString( str, IDS_NEIGHBOUR_RATIO );
00321 DrawText( pDC, &pt, str, 8 );
00322 if ( nCompIn > 0 ) str.Format( _T("%.2f%%"), nCompIn * 100.0 ); else str.Empty();
00323 DrawText( pDC, &pt, str, 128 );
00324 if ( nCompOut > 0 ) str.Format( _T("%.2f%%"), nCompOut * 100.0 ); else str.Empty();
00325 DrawText( pDC, &pt, str, 128 + 80 );
00326 pt.y += TIP_TEXTHEIGHT;
00327 }
00328
00329 pt.y += TIP_TEXTHEIGHT;
00330
00331 CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
00332 pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
00333 rc.DeflateRect( 1, 1 );
00334 m_pGraph->BufferedPaint( pDC, &rc );
00335 rc.InflateRect( 1, 1 );
00336 pDC->ExcludeClipRect( &rc );
00337 pt.y += 40;
00338 }
00339
00341
00342
00343 void CNeighbourTipCtrl::OnTimer(UINT nIDEvent)
00344 {
00345 CCoolTipCtrl::OnTimer( nIDEvent );
00346
00347 if ( m_pGraph == NULL ) return;
00348
00349 CSingleLock pLock( &Network.m_pSection );
00350 if ( ! pLock.Lock( 100 ) ) return;
00351
00352 CNeighbour* pNeighbour = Neighbours.Get( (DWORD)m_pContext );
00353 if ( pNeighbour == NULL ) return;
00354
00355 pNeighbour->Measure();
00356
00357 DWORD nIn = pNeighbour->m_mInput.nMeasure * 8;
00358 DWORD nOut = pNeighbour->m_mOutput.nMeasure * 8;
00359
00360 m_pItemIn->Add( nIn );
00361 m_pItemOut->Add( nOut );
00362
00363 m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nIn );
00364 m_pGraph->m_nMaximum = max( m_pGraph->m_nMaximum, nOut );
00365 m_pGraph->m_nUpdates++;
00366
00367 Invalidate();
00368 }