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 "Network.h"
00026 #include "Neighbours.h"
00027 #include "G1Neighbour.h"
00028 #include "G2Neighbour.h"
00029 #include "EDNeighbour.h"
00030 #include "EDPacket.h"
00031 #include "HostCache.h"
00032 #include "Security.h"
00033 #include "LiveList.h"
00034 #include "GProfile.h"
00035 #include "ChatWindows.h"
00036 #include "Skin.h"
00037
00038 #include "WndMain.h"
00039 #include "WndNeighbours.h"
00040 #include "WndPacket.h"
00041 #include "WndBrowseHost.h"
00042 #include "DlgURLCopy.h"
00043 #include "DlgSettingsManager.h"
00044
00045 #ifdef _DEBUG
00046 #define new DEBUG_NEW
00047 #undef THIS_FILE
00048 static char THIS_FILE[] = __FILE__;
00049 #endif
00050
00051 IMPLEMENT_SERIAL(CNeighboursWnd, CPanelWnd, 0)
00052
00053 BEGIN_MESSAGE_MAP(CNeighboursWnd, CPanelWnd)
00054
00055 ON_WM_CREATE()
00056 ON_WM_SIZE()
00057 ON_WM_TIMER()
00058 ON_WM_CONTEXTMENU()
00059 ON_WM_DESTROY()
00060 ON_WM_ACTIVATE()
00061 ON_WM_QUERYNEWPALETTE()
00062 ON_NOTIFY(LVN_COLUMNCLICK, IDC_NEIGHBOURS, OnSortList)
00063 ON_NOTIFY(NM_CUSTOMDRAW, IDC_NEIGHBOURS, OnCustomDrawList)
00064 ON_UPDATE_COMMAND_UI(ID_NEIGHBOURS_DISCONNECT, OnUpdateNeighboursDisconnect)
00065 ON_COMMAND(ID_NEIGHBOURS_DISCONNECT, OnNeighboursDisconnect)
00066 ON_UPDATE_COMMAND_UI(ID_NEIGHBOURS_VIEW_ALL, OnUpdateNeighboursViewAll)
00067 ON_COMMAND(ID_NEIGHBOURS_VIEW_ALL, OnNeighboursViewAll)
00068 ON_UPDATE_COMMAND_UI(ID_NEIGHBOURS_VIEW_INCOMING, OnUpdateNeighboursViewIncoming)
00069 ON_COMMAND(ID_NEIGHBOURS_VIEW_INCOMING, OnNeighboursViewIncoming)
00070 ON_UPDATE_COMMAND_UI(ID_NEIGHBOURS_VIEW_OUTGOING, OnUpdateNeighboursViewOutgoing)
00071 ON_COMMAND(ID_NEIGHBOURS_VIEW_OUTGOING, OnNeighboursViewOutgoing)
00072 ON_UPDATE_COMMAND_UI(ID_NEIGHBOURS_CHAT, OnUpdateNeighboursChat)
00073 ON_COMMAND(ID_NEIGHBOURS_CHAT, OnNeighboursChat)
00074 ON_UPDATE_COMMAND_UI(ID_SECURITY_BAN, OnUpdateSecurityBan)
00075 ON_COMMAND(ID_SECURITY_BAN, OnSecurityBan)
00076 ON_UPDATE_COMMAND_UI(ID_BROWSE_LAUNCH, OnUpdateBrowseLaunch)
00077 ON_COMMAND(ID_BROWSE_LAUNCH, OnBrowseLaunch)
00078 ON_UPDATE_COMMAND_UI(ID_NEIGHBOURS_COPY, OnUpdateNeighboursCopy)
00079 ON_COMMAND(ID_NEIGHBOURS_COPY, OnNeighboursCopy)
00080 ON_COMMAND(ID_NEIGHBOURS_SETTINGS, OnNeighboursSettings)
00081
00082 END_MESSAGE_MAP()
00083
00084
00086
00087
00088 CNeighboursWnd::CNeighboursWnd() : CPanelWnd( TRUE, TRUE )
00089 {
00090 Create( IDR_NEIGHBOURSFRAME );
00091 }
00092
00093 CNeighboursWnd::~CNeighboursWnd()
00094 {
00095 }
00096
00098
00099
00100 int CNeighboursWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00101 {
00102 if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00103
00104 if ( ! m_wndToolBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
00105 m_wndToolBar.SetBarStyle( m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_BORDER_TOP );
00106
00107 m_wndList.Create( WS_VISIBLE|LVS_ICON|LVS_AUTOARRANGE|LVS_REPORT|LVS_SHOWSELALWAYS,
00108 rectDefault, this, IDC_NEIGHBOURS );
00109 m_pSizer.Attach( &m_wndList );
00110
00111 m_wndTip.Create( &m_wndList, &Settings.Interface.TipNeighbours );
00112 m_wndList.SetTip( &m_wndTip );
00113
00114 m_wndList.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE,
00115 LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP,
00116 LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP );
00117
00118 CBitmap bmImages;
00119 bmImages.LoadBitmap( IDB_PROTOCOLS );
00120 if ( theApp.m_bRTL )
00121 bmImages.m_hObject = CreateMirroredBitmap( (HBITMAP)bmImages.m_hObject );
00122 m_gdiImageList.Create( 16, 16, ILC_COLOR16|ILC_MASK, 7, 1 );
00123 m_gdiImageList.Add( &bmImages, RGB( 0, 255, 0 ) );
00124 m_wndList.SetImageList( &m_gdiImageList, LVSIL_SMALL );
00125
00126 m_wndList.InsertColumn( 0, _T("Address"), LVCFMT_LEFT, 110, -1 );
00127 m_wndList.InsertColumn( 1, _T("Port"), LVCFMT_CENTER, 45, 0 );
00128 m_wndList.InsertColumn( 2, _T("Time"), LVCFMT_CENTER, 80, 1 );
00129 m_wndList.InsertColumn( 3, _T("Packets"), LVCFMT_CENTER, 80, 2 );
00130 m_wndList.InsertColumn( 4, _T("Bandwidth"), LVCFMT_CENTER, 80, 3 );
00131 m_wndList.InsertColumn( 5, _T("Total"), LVCFMT_CENTER, 85, 4 );
00132 m_wndList.InsertColumn( 6, _T("Flow"), LVCFMT_CENTER, 0, 5 );
00133 m_wndList.InsertColumn( 7, _T("Leaves"), LVCFMT_CENTER, 45, 6 );
00134 m_wndList.InsertColumn( 8, _T("Mode"), LVCFMT_CENTER, 60, 7 );
00135 m_wndList.InsertColumn( 9, _T("Client"), LVCFMT_LEFT, 100, 8 );
00136 m_wndList.InsertColumn( 10, _T("Name"), LVCFMT_LEFT, 100, 9 );
00137
00138 m_wndList.SetFont( &theApp.m_gdiFont );
00139
00140 LoadState( _T("CNeighboursWnd"), FALSE );
00141
00142 m_tLastUpdate = 0;
00143
00144 PostMessage( WM_TIMER, 1 );
00145
00146 return 0;
00147 }
00148
00149 void CNeighboursWnd::OnDestroy()
00150 {
00151 Settings.SaveList( _T("CNeighboursWnd"), &m_wndList );
00152 SaveState( _T("CNeighboursWnd") );
00153 CPanelWnd::OnDestroy();
00154 }
00155
00157
00158
00159 void CNeighboursWnd::Update()
00160 {
00161 CSingleLock pLock( &Network.m_pSection );
00162 if ( ! pLock.Lock( 50 ) ) return;
00163
00164 CLiveList pLiveList( 11 );
00165
00166 m_tLastUpdate = GetTickCount();
00167 int nProtocolRev = m_gdiImageList.GetImageCount() - 1;
00168
00169 for ( POSITION pos = Neighbours.GetIterator() ; pos ; )
00170 {
00171 CString str;
00172 CNeighbour* pNeighbour = Neighbours.GetNext( pos );
00173 CLiveItem* pItem = pLiveList.Add( pNeighbour->m_nUnique );
00174
00175 pItem->Set( 0, pNeighbour->m_sAddress );
00176 pItem->Format( 1, _T("%hu"), htons( pNeighbour->m_pHost.sin_port ) );
00177
00178 DWORD nTime = ( m_tLastUpdate - pNeighbour->m_tConnected ) / 1000;
00179
00180 switch ( pNeighbour->m_nState )
00181 {
00182 case nrsConnecting:
00183 LoadString ( str,IDS_NEIGHBOUR_CONNECTING );
00184 break;
00185 case nrsHandshake1:
00186 case nrsHandshake2:
00187 case nrsHandshake3:
00188 LoadString ( str,IDS_NEIGHBOUR_HANDSHAKING );
00189 break;
00190 case nrsRejected:
00191 LoadString ( str,IDS_NEIGHBOUR_REJECTED );
00192 break;
00193 case nrsClosing:
00194 LoadString ( str,IDS_NEIGHBOUR_CLOSING );
00195 break;
00196 case nrsConnected:
00197 if ( nTime > 86400 )
00198 str.Format( _T("%i:%.2i:%.2i:%.2i"), nTime / 86400, ( nTime / 3600 ) % 24, ( nTime / 60 ) % 60, nTime % 60 );
00199 else
00200 str.Format( _T("%i:%.2i:%.2i"), nTime / 3600, ( nTime / 60 ) % 60, nTime % 60 );
00201 break;
00202 default:
00203 LoadString ( str,IDS_NEIGHBOUR_UNKNOWN );
00204 break;
00205 }
00206
00207 pItem->Set( 2, str );
00208
00209 pNeighbour->Measure();
00210
00211 pItem->Format( 3, _T("%u/%u"), pNeighbour->m_nInputCount, pNeighbour->m_nOutputCount );
00212 pItem->Format( 5, _T("%s/%s"), (LPCTSTR)Settings.SmartVolume( pNeighbour->m_mInput.nTotal, FALSE ), (LPCTSTR)Settings.SmartVolume( pNeighbour->m_mOutput.nTotal, FALSE ) );
00213 pItem->Format( 6, _T("%u (%u)"), pNeighbour->m_nOutbound, pNeighbour->m_nLostCount );
00214
00215 if ( Settings.General.RatesInBytes )
00216 {
00217 pItem->Format( 4, _T("%.3f/%.3f"), pNeighbour->m_mInput.nMeasure / 1024.0,
00218 pNeighbour->m_mOutput.nMeasure / 1024.0 );
00219 }
00220 else
00221 {
00222 pItem->Format( 4, _T("%.3f/%.3f"), pNeighbour->m_mInput.nMeasure / 128.0,
00223 pNeighbour->m_mOutput.nMeasure / 128.0 );
00224 }
00225
00226 pItem->Set( 9, pNeighbour->m_sUserAgent );
00227
00228 if ( pNeighbour->m_nState >= nrsConnected )
00229 {
00230 if ( pNeighbour->m_nProtocol == PROTOCOL_G1 )
00231 {
00232 CG1Neighbour* pG1 = reinterpret_cast<CG1Neighbour*>(pNeighbour);
00233
00234 switch ( pNeighbour->m_nNodeType )
00235 {
00236 case ntNode:
00237 LoadString ( str,IDS_NEIGHBOUR_G1PEER );
00238 break;
00239 case ntHub:
00240 LoadString ( str,IDS_NEIGHBOUR_G1ULTRA );
00241 break;
00242 case ntLeaf:
00243 LoadString ( str,IDS_NEIGHBOUR_G1LEAF );
00244 break;
00245 }
00246
00247 pItem->Set( 8, str );
00248 pItem->m_nImage = theApp.m_bRTL ? nProtocolRev - PROTOCOL_G1 : PROTOCOL_G1;
00249 }
00250 else if ( pNeighbour->m_nProtocol == PROTOCOL_G2 )
00251 {
00252 CG2Neighbour* pG2 = reinterpret_cast<CG2Neighbour*>(pNeighbour);
00253
00254 switch ( pNeighbour->m_nNodeType )
00255 {
00256 case ntNode:
00257 LoadString ( str,IDS_NEIGHBOUR_G2PEER );
00258 break;
00259 case ntHub:
00260 LoadString ( str,IDS_NEIGHBOUR_G2HUB );
00261 break;
00262 case ntLeaf:
00263 LoadString ( str,IDS_NEIGHBOUR_G2LEAF );
00264 break;
00265 }
00266 pItem->Set( 8, str );
00267
00268 if ( pG2->m_nLeafCount > 0 )
00269 {
00270 if ( pG2->m_nLeafLimit > 0 )
00271 {
00272 pItem->Format( 7, _T("%u/%u"), pG2->m_nLeafCount, pG2->m_nLeafLimit );
00273 }
00274 else
00275 {
00276 pItem->Format( 7, _T("%u"), pG2->m_nLeafCount );
00277 }
00278 }
00279 else if ( pG2->m_nNodeType != ntLeaf )
00280 {
00281 pItem->Set( 7, _T("?") );
00282 }
00283
00284 pItem->m_nImage = theApp.m_bRTL ? nProtocolRev - PROTOCOL_G2 : PROTOCOL_G2;
00285 }
00286 else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
00287 {
00288 CEDNeighbour* pED2K = reinterpret_cast<CEDNeighbour*>(pNeighbour);
00289
00290 pItem->m_nImage = theApp.m_bRTL ? nProtocolRev - PROTOCOL_ED2K : PROTOCOL_ED2K;
00291 pItem->Set( 8, _T("eDonkey") );
00292 pItem->Set( 10, pED2K->m_sServerName );
00293
00294 if ( pED2K->m_nClientID > 0 )
00295 {
00296 if ( pED2K->m_nUserLimit > 0 )
00297 {
00298 pItem->Format( 7, _T("%u/%u"), pED2K->m_nUserCount, pED2K->m_nUserLimit );
00299 }
00300 else
00301 {
00302 pItem->Format( 7, _T("%u"), pED2K->m_nUserCount );
00303 }
00304
00305 LoadString( str, CEDPacket::IsLowID( pED2K->m_nClientID ) ? IDS_NEIGHBOUR_ED2K_LOWID : IDS_NEIGHBOUR_ED2K_HIGHID );
00306 pItem->Set( 9, str );
00307 }
00308 else
00309 {
00310 LoadString ( str,IDS_NEIGHBOUR_ED2K_SERVER );
00311 pItem->Set( 9, str );
00312 }
00313 }
00314 else
00315 {
00316 pItem->m_nImage = theApp.m_bRTL ? nProtocolRev : PROTOCOL_NULL;
00317 }
00318 }
00319 else
00320 {
00321 pItem->m_nImage = theApp.m_bRTL ? nProtocolRev : PROTOCOL_NULL;
00322 }
00323
00324 if ( pNeighbour->m_pProfile != NULL )
00325 {
00326 pItem->Set( 10, pNeighbour->m_pProfile->GetNick() );
00327 }
00328 }
00329
00330 pLiveList.Apply( &m_wndList, TRUE );
00331 }
00332
00333 CNeighbour* CNeighboursWnd::GetItem(int nItem)
00334 {
00335 if ( m_wndList.GetItemState( nItem, LVIS_SELECTED ) )
00336 {
00337 return Neighbours.Get( m_wndList.GetItemData( nItem ) );
00338 }
00339
00340 return NULL;
00341 }
00342
00343 void CNeighboursWnd::OnSkinChange()
00344 {
00345 CPanelWnd::OnSkinChange();
00346 Settings.LoadList( _T("CNeighboursWnd"), &m_wndList );
00347 Skin.CreateToolBar( _T("CNeighboursWnd"), &m_wndToolBar );
00348 }
00349
00351
00352
00353 BOOL CNeighboursWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00354 {
00355 if ( m_wndToolBar.m_hWnd )
00356 {
00357 if ( m_wndToolBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00358 }
00359
00360 return CPanelWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00361 }
00362
00363 void CNeighboursWnd::OnSize(UINT nType, int cx, int cy)
00364 {
00365 CPanelWnd::OnSize( nType, cx, cy );
00366
00367 BOOL bSized = m_pSizer.Resize( cx );
00368
00369 SizeListAndBar( &m_wndList, &m_wndToolBar );
00370
00371 if ( bSized && m_wndList.GetItemCount() == 0 ) m_wndList.Invalidate();
00372 }
00373
00374 void CNeighboursWnd::OnTimer(UINT nIDEvent)
00375 {
00376 if ( nIDEvent == 1 )
00377 {
00378 if ( ( IsPartiallyVisible() ) || ( GetTickCount() - m_tLastUpdate > 30000 ) )
00379 Update();
00380 }
00381 }
00382
00383 void CNeighboursWnd::OnSortList(NMHDR* pNotifyStruct, LRESULT *pResult)
00384 {
00385 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNotifyStruct;
00386 CLiveList::Sort( &m_wndList, pNMListView->iSubItem );
00387 *pResult = 0;
00388 }
00389
00390 void CNeighboursWnd::OnContextMenu(CWnd* pWnd, CPoint point)
00391 {
00392 TrackPopupMenu( _T("CNeighboursWnd"), point );
00393 }
00394
00395 void CNeighboursWnd::OnUpdateNeighboursDisconnect(CCmdUI* pCmdUI)
00396 {
00397 pCmdUI->Enable( m_wndList.GetSelectedCount() > 0 );
00398 }
00399
00400 void CNeighboursWnd::OnNeighboursDisconnect()
00401 {
00402 CSingleLock pLock( &Network.m_pSection, TRUE );
00403
00404 for ( int nItem = -1 ; ( nItem = m_wndList.GetNextItem( nItem, LVNI_SELECTED ) ) >= 0 ; )
00405 {
00406 if ( CNeighbour* pNeighbour = GetItem( nItem ) )
00407 {
00408 HostCache.OnFailure( &pNeighbour->m_pHost.sin_addr,
00409 htons( pNeighbour->m_pHost.sin_port ) );
00410
00411 pNeighbour->Close();
00412 }
00413 }
00414 }
00415
00416 void CNeighboursWnd::OnUpdateNeighboursCopy(CCmdUI* pCmdUI)
00417 {
00418 pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
00419
00420 }
00421
00422 void CNeighboursWnd::OnNeighboursCopy()
00423 {
00424 CSingleLock pLock( &Network.m_pSection, TRUE );
00425
00426 CNeighbour* pNeighbour = GetItem( m_wndList.GetNextItem( -1, LVNI_SELECTED ) );
00427 if ( ! pNeighbour ) return;
00428
00429 CString strURL;
00430
00431 if ( pNeighbour->m_nProtocol == PROTOCOL_G1 || pNeighbour->m_nProtocol == PROTOCOL_G2 )
00432 {
00433 strURL.Format( _T("gnutella:host:%s:%lu"),
00434 (LPCTSTR)pNeighbour->m_sAddress, htons( pNeighbour->m_pHost.sin_port ) );
00435 }
00436 else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
00437 {
00438 strURL.Format( _T("ed2k://|server|%s|%lu|/"),
00439 (LPCTSTR)pNeighbour->m_sAddress, htons( pNeighbour->m_pHost.sin_port ) );
00440 }
00441
00442 CURLCopyDlg::SetClipboardText( strURL );
00443 }
00444
00445 void CNeighboursWnd::OnUpdateNeighboursChat(CCmdUI* pCmdUI)
00446 {
00447 if ( m_wndList.GetSelectedCount() == 1 && Settings.Community.ChatEnable )
00448 {
00449 CSingleLock pNetworkLock( &Network.m_pSection );
00450 if ( pNetworkLock.Lock( 500 ) )
00451 {
00452 CNeighbour* pNeighbour = GetItem( m_wndList.GetNextItem( -1, LVNI_SELECTED ) );
00453 if ( pNeighbour && pNeighbour->m_nProtocol != PROTOCOL_ED2K )
00454 {
00455 pCmdUI->Enable( TRUE );
00456 return;
00457 }
00458 }
00459 }
00460 pCmdUI->Enable( FALSE );
00461 }
00462
00463 void CNeighboursWnd::OnNeighboursChat()
00464 {
00465 CSingleLock pLock( &Network.m_pSection, TRUE );
00466
00467 for ( int nItem = -1 ; ( nItem = m_wndList.GetNextItem( nItem, LVNI_SELECTED ) ) >= 0 ; )
00468 {
00469 if ( CNeighbour* pNeighbour = GetItem( nItem ) )
00470 {
00471 if ( pNeighbour->m_nProtocol != PROTOCOL_ED2K )
00472 {
00473 ChatWindows.OpenPrivate( pNeighbour->m_bGUID ? &pNeighbour->m_pGUID : NULL,
00474 &pNeighbour->m_pHost, FALSE, pNeighbour->m_nProtocol );
00475 }
00476 }
00477 }
00478 }
00479
00480 void CNeighboursWnd::OnUpdateSecurityBan(CCmdUI* pCmdUI)
00481 {
00482 pCmdUI->Enable( m_wndList.GetSelectedCount() > 0 );
00483 }
00484
00485 void CNeighboursWnd::OnSecurityBan()
00486 {
00487 CSingleLock pLock( &Network.m_pSection, TRUE );
00488
00489 for ( int nItem = -1 ; ( nItem = m_wndList.GetNextItem( nItem, LVNI_SELECTED ) ) >= 0 ; )
00490 {
00491 if ( CNeighbour* pNeighbour = GetItem( nItem ) )
00492 {
00493 IN_ADDR pAddress = pNeighbour->m_pHost.sin_addr;
00494 pNeighbour->Close();
00495 pLock.Unlock();
00496 Security.Ban( &pAddress, banSession );
00497 pLock.Lock();
00498 }
00499 }
00500 }
00501
00502 void CNeighboursWnd::OnUpdateBrowseLaunch(CCmdUI* pCmdUI)
00503 {
00504 if ( m_wndList.GetSelectedCount() == 1 )
00505 {
00506 CSingleLock pNetworkLock( &Network.m_pSection );
00507 if ( pNetworkLock.Lock( 500 ) )
00508 {
00509 CNeighbour* pNeighbour = GetItem( m_wndList.GetNextItem( -1, LVNI_SELECTED ) );
00510 if ( pNeighbour && pNeighbour->m_nProtocol != PROTOCOL_ED2K )
00511 {
00512 pCmdUI->Enable( TRUE );
00513 return;
00514 }
00515 }
00516 }
00517 pCmdUI->Enable( FALSE );
00518 }
00519
00520 void CNeighboursWnd::OnBrowseLaunch()
00521 {
00522 CSingleLock pLock( &Network.m_pSection, TRUE );
00523
00524 if ( CNeighbour* pNeighbour = GetItem( m_wndList.GetNextItem( -1, LVNI_SELECTED ) ) )
00525 {
00526 if ( pNeighbour->m_nProtocol != PROTOCOL_ED2K )
00527 {
00528 SOCKADDR_IN pAddress = pNeighbour->m_pHost;
00529 BOOL bGUID = pNeighbour->m_bGUID;
00530 GGUID pGUID = pNeighbour->m_pGUID;
00531
00532 pLock.Unlock();
00533
00534 new CBrowseHostWnd( &pAddress, bGUID ? &pGUID : NULL );
00535 }
00536 }
00537 }
00538
00539 void CNeighboursWnd::OnUpdateNeighboursViewAll(CCmdUI* pCmdUI)
00540 {
00541 pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
00542 }
00543
00544 void CNeighboursWnd::OnNeighboursViewAll()
00545 {
00546 OpenPacketWnd( TRUE, TRUE );
00547 }
00548
00549 void CNeighboursWnd::OnUpdateNeighboursViewIncoming(CCmdUI* pCmdUI)
00550 {
00551 pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
00552 }
00553
00554 void CNeighboursWnd::OnNeighboursViewIncoming()
00555 {
00556 OpenPacketWnd( TRUE, FALSE );
00557 }
00558
00559 void CNeighboursWnd::OnUpdateNeighboursViewOutgoing(CCmdUI* pCmdUI)
00560 {
00561 pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
00562 }
00563
00564 void CNeighboursWnd::OnNeighboursViewOutgoing()
00565 {
00566 OpenPacketWnd( FALSE, TRUE );
00567 }
00568
00569 void CNeighboursWnd::OnNeighboursSettings()
00570 {
00571 CSettingsManagerDlg::Run( _T("CNetworksSettingsPage") );
00572 }
00573
00574 void CNeighboursWnd::OpenPacketWnd(BOOL bIncoming, BOOL bOutgoing)
00575 {
00576 CSingleLock pLock( &Network.m_pSection, TRUE );
00577
00578 CWindowManager* pManager = GetManager();
00579 CPacketWnd* pWnd = NULL;
00580
00581 while ( pWnd = (CPacketWnd*)pManager->Find( RUNTIME_CLASS(CPacketWnd), pWnd ) )
00582 {
00583 if ( pWnd->m_pOwner == this ) break;
00584 }
00585
00586 if ( ! pWnd ) pWnd = new CPacketWnd( this );
00587
00588 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00589 {
00590 if ( CNeighbour* pNeighbour = GetItem( nItem ) )
00591 {
00592 pWnd->m_nInputFilter = bIncoming ? pNeighbour->m_nUnique : 1;
00593 pWnd->m_nOutputFilter = bOutgoing ? pNeighbour->m_nUnique : 1;
00594 }
00595 }
00596
00597 pWnd->m_bPaused = FALSE;
00598 pWnd->BringWindowToTop();
00599 }
00600
00601 void CNeighboursWnd::OnCustomDrawList(NMHDR* pNMHDR, LRESULT* pResult)
00602 {
00603 NMLVCUSTOMDRAW* pDraw = (NMLVCUSTOMDRAW*)pNMHDR;
00604
00605 if ( pDraw->nmcd.dwDrawStage == CDDS_PREPAINT )
00606 {
00607 if ( m_wndList.GetItemCount() == 0 && ! Network.IsConnected() )
00608 {
00609 DrawEmptyMessage( CDC::FromHandle( pDraw->nmcd.hdc ) );
00610 }
00611
00612 *pResult = CDRF_NOTIFYITEMDRAW;
00613 }
00614 else if ( pDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT )
00615 {
00616 LV_ITEM pItem = { LVIF_IMAGE, pDraw->nmcd.dwItemSpec };
00617 m_wndList.GetItem( &pItem );
00618
00619 switch ( pItem.iImage )
00620 {
00621 case PROTOCOL_NULL:
00622 pDraw->clrText = RGB( 192, 192, 192 );
00623 break;
00624 case PROTOCOL_G1:
00625 pDraw->clrText = RGB( 80, 80, 80 );
00626 break;
00627 case PROTOCOL_G2:
00628 pDraw->clrText = RGB( 100, 100, 255 );
00629 break;
00630 case PROTOCOL_ED2K:
00631 pDraw->clrText = RGB( 127, 127, 0 );
00632 break;
00633 }
00634
00635 *pResult = CDRF_DODEFAULT;
00636 }
00637 }
00638
00639 void CNeighboursWnd::DrawEmptyMessage(CDC* pDC)
00640 {
00641 CRect rcClient, rcText;
00642 CString strText;
00643
00644 m_wndList.GetClientRect( &rcClient );
00645
00646 if ( CWnd* pHeader = m_wndList.GetWindow( GW_CHILD ) )
00647 {
00648 pHeader->GetWindowRect( &rcText );
00649 rcClient.top += rcText.Height();
00650 }
00651
00652 rcText.SetRect( rcClient.left, 16, rcClient.right, 0 );
00653 rcText.bottom = ( rcClient.top + rcClient.bottom ) / 2;
00654 rcText.top = rcText.bottom - rcText.top;
00655
00656 pDC->SetBkMode( TRANSPARENT );
00657 pDC->SelectObject( &theApp.m_gdiFont );
00658 pDC->SetTextColor( GetSysColor( COLOR_WINDOWTEXT ) );
00659 LoadString( strText, IDS_NEIGHBOURS_NOT_CONNECTED );
00660 pDC->DrawText( strText, &rcText, DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_NOPREFIX );
00661
00662 rcText.OffsetRect( 0, rcText.Height() );
00663
00664 LoadString( strText, IDS_NEIGHBOURS_CONNECT );
00665 pDC->DrawText( strText, &rcText, DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_NOPREFIX );
00666 }
00667
00668 void CNeighboursWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
00669 {
00670 CPanelWnd::OnActivate(nState, pWndOther, bMinimized);
00671 Update();
00672 }