⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wndneighbours.cpp

📁 著名的下载软件核心Shareaza
💻 CPP
📖 第 1 页 / 共 2 页
字号:

CNeighbour* CNeighboursWnd::GetItem(int nItem)
{
	if ( m_wndList.GetItemState( nItem, LVIS_SELECTED ) )
	{
		return Neighbours.Get( m_wndList.GetItemData( nItem ) );
	}
	
	return NULL;
}

void CNeighboursWnd::OnSkinChange()
{
	CPanelWnd::OnSkinChange();
	Skin.CreateToolBar( _T("CNeighboursWnd"), &m_wndToolBar );
}

/////////////////////////////////////////////////////////////////////////////
// CNeighboursWnd message handlers

BOOL CNeighboursWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	if ( m_wndToolBar.m_hWnd )
	{
		if ( m_wndToolBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
	}
	
	return CPanelWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
}

void CNeighboursWnd::OnSize(UINT nType, int cx, int cy) 
{
	CPanelWnd::OnSize( nType, cx, cy );

	BOOL bSized = m_pSizer.Resize( cx );

	SizeListAndBar( &m_wndList, &m_wndToolBar );

	if ( bSized && m_wndList.GetItemCount() == 0 ) m_wndList.Invalidate();
}

void CNeighboursWnd::OnTimer(UINT nIDEvent) 
{
	Update();
}

void CNeighboursWnd::OnSortList(NMHDR* pNotifyStruct, LRESULT *pResult)
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNotifyStruct;
	CLiveList::Sort( &m_wndList, pNMListView->iSubItem );
	*pResult = 0;
}

void CNeighboursWnd::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	TrackPopupMenu( _T("CNeighboursWnd"), point );
}

void CNeighboursWnd::OnUpdateNeighboursDisconnect(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() > 0 );
}

void CNeighboursWnd::OnNeighboursDisconnect() 
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	for ( int nItem = -1 ; ( nItem = m_wndList.GetNextItem( nItem, LVNI_SELECTED ) ) >= 0 ; )
	{
		if ( CNeighbour* pNeighbour = GetItem( nItem ) )
		{
			HostCache.OnFailure( &pNeighbour->m_pHost.sin_addr,
				htons( pNeighbour->m_pHost.sin_port ) );
			
			pNeighbour->Close();
		}
	}
}

void CNeighboursWnd::OnUpdateNeighboursCopy(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
	
}

void CNeighboursWnd::OnNeighboursCopy() 
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CNeighbour* pNeighbour = GetItem( m_wndList.GetNextItem( -1, LVNI_SELECTED ) );
	if ( ! pNeighbour ) return;
	
	CString strURL;
	
	if ( pNeighbour->m_nProtocol == PROTOCOL_G1 || pNeighbour->m_nProtocol == PROTOCOL_G2 )
	{
		strURL.Format( _T("gnutella:host:%s:%lu"),
			(LPCTSTR)pNeighbour->m_sAddress, htons( pNeighbour->m_pHost.sin_port ) );
	}
	else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
	{
		strURL.Format( _T("ed2k://|server|%s|%lu|/"),
			(LPCTSTR)pNeighbour->m_sAddress, htons( pNeighbour->m_pHost.sin_port ) );
	}
	
	CURLCopyDlg::SetClipboardText( strURL );
}

void CNeighboursWnd::OnUpdateNeighboursChat(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 && Settings.Community.ChatEnable );
}

void CNeighboursWnd::OnNeighboursChat() 
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	for ( int nItem = -1 ; ( nItem = m_wndList.GetNextItem( nItem, LVNI_SELECTED ) ) >= 0 ; )
	{
		if ( CNeighbour* pNeighbour = GetItem( nItem ) )
		{
			if ( pNeighbour->m_nProtocol != PROTOCOL_ED2K )
			{
				ChatWindows.OpenPrivate( pNeighbour->m_bGUID ? &pNeighbour->m_pGUID : NULL,
					&pNeighbour->m_pHost );
			}
		}
	}
}

void CNeighboursWnd::OnUpdateSecurityBan(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() > 0 );
}

void CNeighboursWnd::OnSecurityBan() 
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	for ( int nItem = -1 ; ( nItem = m_wndList.GetNextItem( nItem, LVNI_SELECTED ) ) >= 0 ; )
	{
		if ( CNeighbour* pNeighbour = GetItem( nItem ) )
		{
			IN_ADDR pAddress = pNeighbour->m_pHost.sin_addr;
			pNeighbour->Close();
			pLock.Unlock();
			Security.SessionBan( &pAddress );
			pLock.Lock();
		}
	}
}

void CNeighboursWnd::OnUpdateBrowseLaunch(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
}

void CNeighboursWnd::OnBrowseLaunch() 
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	if ( CNeighbour* pNeighbour = GetItem( m_wndList.GetNextItem( -1, LVNI_SELECTED ) ) )
	{
		if ( pNeighbour->m_nProtocol != PROTOCOL_ED2K )
		{
			SOCKADDR_IN pAddress = pNeighbour->m_pHost;
			BOOL bGUID = pNeighbour->m_bGUID;
			GGUID pGUID = pNeighbour->m_pGUID;
			
			pLock.Unlock();
			
			new CBrowseHostWnd( &pAddress, bGUID ? &pGUID : NULL );
		}
	}
}

void CNeighboursWnd::OnUpdateNeighboursViewAll(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
}

void CNeighboursWnd::OnNeighboursViewAll() 
{
	OpenPacketWnd( TRUE, TRUE );
}

void CNeighboursWnd::OnUpdateNeighboursViewIncoming(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
}

void CNeighboursWnd::OnNeighboursViewIncoming() 
{
	OpenPacketWnd( TRUE, FALSE );
}

void CNeighboursWnd::OnUpdateNeighboursViewOutgoing(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_wndList.GetSelectedCount() == 1 );
}

void CNeighboursWnd::OnNeighboursViewOutgoing() 
{
	OpenPacketWnd( FALSE, TRUE );
}

void CNeighboursWnd::OnNeighboursSettings() 
{
	CSettingsManagerDlg::Run( _T("CNetworksSettingsPage") );	
}

void CNeighboursWnd::OpenPacketWnd(BOOL bIncoming, BOOL bOutgoing)
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CWindowManager* pManager = GetManager();
	CPacketWnd* pWnd = NULL;
	
	while ( pWnd = (CPacketWnd*)pManager->Find( RUNTIME_CLASS(CPacketWnd), pWnd ) )
	{
		if ( pWnd->m_pOwner == this ) break;
	}
	
	if ( ! pWnd ) pWnd = new CPacketWnd( this );
	
	for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
	{
		if ( CNeighbour* pNeighbour = GetItem( nItem ) )
		{
			pWnd->m_nInputFilter	= bIncoming ? pNeighbour->m_nUnique : 1;
			pWnd->m_nOutputFilter	= bOutgoing ? pNeighbour->m_nUnique : 1;
		}
	}
	
	pWnd->m_bPaused = FALSE;
	pWnd->BringWindowToTop();
}

void CNeighboursWnd::OnCustomDrawList(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pDraw = (NMLVCUSTOMDRAW*)pNMHDR;
	
	if ( pDraw->nmcd.dwDrawStage == CDDS_PREPAINT )
	{
		if ( m_wndList.GetItemCount() == 0 && ! Network.IsConnected() )
		{
			DrawEmptyMessage( CDC::FromHandle( pDraw->nmcd.hdc ) );
		}
		
		*pResult = CDRF_NOTIFYITEMDRAW;
	}
	else if ( pDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT )
	{
		LV_ITEM pItem = { LVIF_IMAGE, pDraw->nmcd.dwItemSpec };
		m_wndList.GetItem( &pItem );
				
		switch ( pItem.iImage )
		{
		case PROTOCOL_NULL:
			pDraw->clrText = RGB( 192, 192, 192 );
			break;
		case PROTOCOL_G1:
			pDraw->clrText = RGB( 80, 80, 80 );
			break;
		case PROTOCOL_G2:
			pDraw->clrText = RGB( 100, 100, 255 );
			break;
		case PROTOCOL_ED2K:
			pDraw->clrText = RGB( 127, 127, 0 );
			break;
		}
		
		*pResult = CDRF_DODEFAULT;
	}
}

void CNeighboursWnd::DrawEmptyMessage(CDC* pDC)
{
	CRect rcClient, rcText;
	CString strText;
	
	m_wndList.GetClientRect( &rcClient );
	
	if ( CWnd* pHeader = m_wndList.GetWindow( GW_CHILD ) )
	{
		pHeader->GetWindowRect( &rcText );
		rcClient.top += rcText.Height();
	}
	
	rcText.SetRect( rcClient.left, 16, rcClient.right, 0 );
	rcText.bottom = ( rcClient.top + rcClient.bottom ) / 2;
	rcText.top = rcText.bottom - rcText.top;
	
	pDC->SetBkMode( TRANSPARENT );
	pDC->SelectObject( &theApp.m_gdiFont );
	pDC->SetTextColor( GetSysColor( COLOR_WINDOWTEXT ) );
	LoadString( strText, IDS_NEIGHBOURS_NOT_CONNECTED );
	pDC->DrawText( strText, &rcText, DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_NOPREFIX );
	
	rcText.OffsetRect( 0, rcText.Height() );
	
	LoadString( strText, IDS_NEIGHBOURS_CONNECT );
	pDC->DrawText( strText, &rcText, DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_NOPREFIX );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -