Exemplo n.º 1
0
void CSearchInputBox::OnSkinChange()
{
	CString strCaption;
	CSearchWnd* pwndSearch = static_cast< CSearchWnd* >( GetParent()->GetParent() );
	BOOL bStarted = ! pwndSearch->IsPaused();
	BOOL bSearching = ! pwndSearch->IsWaitMore();

	LoadString( strCaption, bStarted ?
		( bSearching? IDS_SEARCH_PANEL_SEARCHING : IDS_SEARCH_PANEL_MORE ) :
		IDS_SEARCH_PANEL_START );
	m_wndStart.SetWindowText( strCaption );
	m_wndStart.SetCoolIcon( ID_SEARCH_SEARCH, FALSE );

	LoadString( strCaption, bStarted ? IDS_SEARCH_PANEL_STOP : IDS_SEARCH_PANEL_CLEAR );
	m_wndStop.SetWindowText( strCaption );
	m_wndStop.SetCoolIcon( ID_SEARCH_STOP, FALSE );

	m_wndPrefix.SetIcon( IDI_HASH );
}
Exemplo n.º 2
0
void CRemote::PageSearch()
{
	if ( CheckCookie() ) return;
	m_nTab = tabSearch;

	CMainWnd* pMainWnd = static_cast< CMainWnd* >( theApp.m_pMainWnd );
	if ( pMainWnd == NULL || ! pMainWnd->IsKindOf( RUNTIME_CLASS(CMainWnd) ) ) return;

	CSingleLock pLock( &theApp.m_pSection );
	if ( ! SafeLock( pLock ) ) return;

	INT_PTR nSearchID = NULL;
	INT_PTR nCloseID = NULL;
	CSearchWnd* pSearchWnd = NULL;
	CString str;

	_stscanf( GetKey( L"id" ), L"%Ii", &nSearchID );
	_stscanf( GetKey( L"close" ), L"%Ii", &nCloseID );

	Prepare();		// Header
	Output( L"searchHeader" );

	for ( CSearchWnd* pFindWnd = NULL; ( pFindWnd = static_cast< CSearchWnd* >( pMainWnd->m_pWindows.Find( RUNTIME_CLASS(CSearchWnd), pFindWnd ) ) ) != NULL; )
	{
		Prepare();
		INT_PTR nFindWnd = reinterpret_cast< INT_PTR >( pFindWnd );
		if ( nCloseID == nFindWnd )
		{
			pFindWnd->PostMessage( WM_CLOSE );
			continue;
		}
		else if ( nSearchID == nFindWnd )
		{
			pSearchWnd = pFindWnd;
			Add( L"search_selected", L"true" );
		}

		str.Format( L"%Ii", nFindWnd );
		Add( L"search_id", str );
		str = pFindWnd->GetCaption();
		if ( str.Find( L"Search : " ) == 0 ) str = str.Mid( 9 ).SpanExcluding( L"[" );
		Add( L"search_caption", str );
		Output( L"searchTab" );
	}

	if ( pSearchWnd == NULL )
	{
		str.Empty();

		for ( POSITION pos = SchemaCache.GetIterator(); pos != NULL; )
		{
			CSchemaPtr pSchema = SchemaCache.GetNext( pos );
			if ( ! pSchema->m_bPrivate && pSchema->m_nType == CSchema::stFile )
			{
				str += L"<option value=\"" + pSchema->GetURI();
				str += L"\">" + pSchema->m_sTitle;
				str += L"</option>\r\n";
			}
		}

		Prepare();		// Header
		Add( L"schema_option_list", str );
		Output( L"searchNew" );
		Output( L"searchFooter" );
		return;
	}

	if ( ! GetKey( L"stop" ).IsEmpty() )
	{
		pSearchWnd->PostMessage( WM_COMMAND, ID_SEARCH_STOP );
		Sleep( 500 );
	}

	CLockedMatchList pMatches( pSearchWnd->GetMatches() );

	str = GetKey( L"sort" );
	if ( ! str.IsEmpty() )
	{
		int nColumn = 0;
		_stscanf( str, L"%i", &nColumn );

		if ( pMatches->m_bSortDir != 1 && pMatches->m_nSortColumn == nColumn )
			pMatches->SetSortColumn( nColumn, FALSE );
		else
			pMatches->SetSortColumn( nColumn, TRUE );

		pSearchWnd->PostMessage( WM_TIMER, 7 );
	}

	str = GetKey( L"expcol" );
	if ( ! str.IsEmpty() )
	{
		CMatchFile** pLoop = pMatches->m_pFiles;
		for ( DWORD nCount = 0; nCount < pMatches->m_nFiles; nCount++, pLoop++ )
		{
			if ( (*pLoop)->GetURN() == str )
			{
				(*pLoop)->Expand( GetKey( L"collapse" ).IsEmpty() );
				pSearchWnd->PostMessage( WM_TIMER, 7 );
				break;
			}
		}
	}

	str = GetKey( L"download" );
	if ( ! str.IsEmpty() )
	{
		CMatchFile** pLoop = pMatches->m_pFiles;
		for ( DWORD nCount = 0; nCount < pMatches->m_nFiles; nCount++, pLoop++ )
		{
			if ( (*pLoop)->GetURN() == str )
			{
				Downloads.Add( *pLoop );
				pSearchWnd->PostMessage( WM_TIMER, 7 );
				m_sResponse.Empty();
				m_sRedirect = L"downloads?group_reveal=all";
				return;
			}
		}
	}

	if ( ! GetKey( L"setfilter" ).IsEmpty() )
	{
		pMatches->m_sFilter = GetKey( L"filter" );
		pMatches->Filter();
		pSearchWnd->PostMessage( WM_TIMER, 7 );
	}

	Prepare();		// Header
	str.Format( L"%Ii", nSearchID );
	Add( L"search_id", str );
	str.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );
	Add( L"random", str );
	if ( ! pSearchWnd->IsPaused() )
		Add( L"searching", L"true" );
	Add( L"search_filter", pMatches->m_sFilter );
	Output( L"searchTop" );

	PageSearchHeaderColumn( MATCH_COL_NAME, Skin.GetHeaderTranslation( L"CMatchCtrl", L"File" ), L"left" );
	PageSearchHeaderColumn( MATCH_COL_SIZE, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Size" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_RATING, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Rating" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_STATUS, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Status" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_COUNT, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Host/Count" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_SPEED, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Speed" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_CLIENT, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Client" ), L"center" );

	Output( L"searchMiddle" );

	CMatchFile** pLoop = pMatches->m_pFiles;

	for ( DWORD nCount = 0; nCount < pMatches->m_nFiles; nCount++, pLoop++ )
	{
		CMatchFile* pFile = *pLoop;
		if ( pFile->GetFilteredCount() == 0 ) continue;

		Add( L"row_urn", pFile->GetURN() );
		Add( L"row_filename", pFile->m_sName );
		if ( pFile->GetFilteredCount() <= 1 )
			Add( L"row_single", L"true" );
		else if ( pFile->m_bExpanded )
			Add( L"row_expanded", L"true" );
		else
			Add( L"row_collapsed", L"true" );

		Output( L"searchRowStart" );

		PageSearchRowColumn( MATCH_COL_SIZE, pFile, Settings.SmartVolume( pFile->m_nSize ) );

		str.Empty();
		for ( INT_PTR nStar = pFile->m_nRating / max( 1, pFile->m_nRated ); nStar > 1; nStar -- ) str += L'*';
		PageSearchRowColumn( MATCH_COL_RATING, pFile, str );

		str.Empty();
		str += pFile->m_bBusy == TRI_TRUE ? L'B' : L'-';
		str += pFile->m_bPush == TRI_TRUE ? L'F' : L'-';
		str += pFile->m_bStable == TRI_FALSE ? L'U' : L'-';
		PageSearchRowColumn( MATCH_COL_STATUS, pFile, str );

		str.Empty();
		if ( pFile->GetFilteredCount() > 1 )
			str.Format(L"(%u sources)", pFile->GetFilteredCount());
		else
			str = (CString)inet_ntoa( pFile->GetBestAddress() );
		PageSearchRowColumn( MATCH_COL_COUNT, pFile, str );


		PageSearchRowColumn( MATCH_COL_SPEED, pFile, pFile->m_sSpeed );
		PageSearchRowColumn( MATCH_COL_CLIENT, pFile, pFile->GetFilteredCount() == 1 ? pFile->GetBestVendorName() : L"" );

		Output( L"searchRowEnd" );
		Prepare( L"column_" );
		Prepare( L"row_" );

		if ( pFile->m_bExpanded )
		{
			for ( CQueryHit* pHit = pFile->GetHits(); pHit != NULL; pHit = pHit->m_pNext )
			{
				if ( ! pHit->m_bFiltered ) continue;

				Add( L"row_urn", pFile->GetURN() );
				Add( L"row_filename", pHit->m_sName );
				Add( L"row_source", L"true" );
				Output( L"searchRowStart" );

				PageSearchRowColumn( MATCH_COL_SIZE, pFile, Settings.SmartVolume( pHit->m_nSize ) );
				str.Empty();
				for ( int nStar = pHit->m_nRating; nStar > 1; nStar -- ) str += L"*";
				PageSearchRowColumn( MATCH_COL_RATING, pFile, str );

				str.Empty();
				str += pFile->m_bBusy == TRI_TRUE ? L'B' : L'-';
				str += pFile->m_bPush == TRI_TRUE ? L'F' : L'-';
				str += pFile->m_bStable == TRI_FALSE ? L'U' : L'-';
				PageSearchRowColumn( MATCH_COL_STATUS, pFile, str );

				PageSearchRowColumn( MATCH_COL_COUNT, pFile, (CString)inet_ntoa( pHit->m_pAddress ) );
				PageSearchRowColumn( MATCH_COL_SPEED, pFile, pHit->m_sSpeed );
				PageSearchRowColumn( MATCH_COL_CLIENT, pFile, pHit->m_pVendor->m_sName );

				Output( L"searchRowEnd" );
				Prepare( L"column_" );
				Prepare( L"row_" );
			}
		}
	}

	Output( L"searchBottom" );
	Prepare();
	Output( L"searchFooter" );
}