コード例 #1
0
void CNewSearchDlg::OnOK()
{
	Settings.SaveWindow( _T("NewSearch"), this );

	m_wndSearch.GetWindowText( m_pSearch->m_sSearch );

	CSchemaPtr pSchema = m_wndSchemas.GetSelected();

	if ( m_pSearch->m_pXML != NULL ) delete m_pSearch->m_pXML;

	m_pSearch->m_pSchema	= NULL;
	m_pSearch->m_pXML		= NULL;

	if ( pSchema != NULL )
	{
		m_pSearch->m_pSchema	= pSchema;
		m_pSearch->m_pXML		= pSchema->Instantiate();

		m_wndSchema.UpdateData( m_pSearch->m_pXML->AddElement( pSchema->m_sSingular ), TRUE );

		Settings.Search.LastSchemaURI = pSchema->GetURI();
	}
	else
	{
		Settings.Search.LastSchemaURI.Empty();
	}

	if ( ! m_pSearch->CheckValid() )
	{
		m_wndSearch.SetFocus();
		return;
	}

	CSkinDialog::OnOK();
}
コード例 #2
0
ファイル: CtrlHomeSearch.cpp プロジェクト: ivan386/Shareaza
void CHomeSearchCtrl::Search(bool bAutostart)
{
	CString strText, strURI, strEntry, strClear;

	m_wndText.GetWindowText( strText );
	strText.TrimLeft();
	strText.TrimRight();

	LoadString( strClear, IDS_SEARCH_PAD_CLEAR_HISTORY );
	if ( _tcscmp ( strClear , strText ) == 0 ) return;

	// Check if user mistakenly pasted download link to search input box
	if (theApp.OpenURL( strText, TRUE, TRUE ) )
	{
		m_wndText.SetWindowText( _T("") );
		return;
	}

	CSchemaPtr pSchema = m_wndSchema.GetSelected();
	if ( pSchema != NULL ) strURI = pSchema->GetURI();

	Settings.Search.LastSchemaURI = strURI;

	CQuerySearchPtr pSearch = new CQuerySearch();
	pSearch->m_bAutostart	= bAutostart;
	pSearch->m_sSearch		= strText;
	pSearch->m_pSchema		= pSchema;
	BOOL bValid = pSearch->CheckValid( false );
	if ( ! bValid && bAutostart )
	{
		// Invalid search, open help window
		CQuerySearch::SearchHelp();
	}
	else if ( AdultFilter.IsSearchFiltered( pSearch->m_sSearch ) && bAutostart )
	{
		// Adult search blocked, open help window
		CHelpDlg::Show( _T("SearchHelp.AdultSearch") );
	}
	else
	{
		if ( bValid )
		{
			// Load all
			CStringList oList;
			for ( int i = 0; ; i++ )
			{
				strEntry.Format( _T("Search.%.2i"), i + 1 );
				CString strValue( theApp.GetProfileString( _T("Search"), strEntry ) );
				if ( strValue.IsEmpty() )
					break;
				int lf = strValue.Find( _T('\n') );
				if ( strText.CompareNoCase( ( lf != -1 ) ? strValue.Left( lf ) : strValue ) )
					oList.AddTail( strValue );
			}

			// Cut to 200 items
			while ( oList.GetCount() >= 200 )
				oList.RemoveTail();

			// New one (at top)
			oList.AddHead( strURI.IsEmpty() ? strText : ( strText + _T('\n') + strURI ) );

			// Save list
			POSITION pos = oList.GetHeadPosition();
			for ( int i = 0; pos; ++i )
			{
				strEntry.Format( _T("Search.%.2i"), i + 1 );
				theApp.WriteProfileString( _T("Search"), strEntry, oList.GetNext( pos ) );
			}

			FillHistory();
		}

		new CSearchWnd( pSearch );
	}

	m_wndText.SetWindowText( _T("") );
}
コード例 #3
0
ファイル: Remote.cpp プロジェクト: GetEnvy/Envy
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" );
}
コード例 #4
0
ファイル: CtrlSchemaCombo.cpp プロジェクト: ivan386/Shareaza
void CSchemaCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	if ( lpDrawItemStruct->itemID == (UINT)-1 ) return;
	if ( ( lpDrawItemStruct->itemAction & ODA_SELECT ) == 0 &&
		 ( lpDrawItemStruct->itemAction & ODA_DRAWENTIRE ) == 0 ) return;

	CRect rcItem( &lpDrawItemStruct->rcItem );
	CPoint pt( rcItem.left + 1, rcItem.top + 1 );
	CDC dc;

	dc.Attach( lpDrawItemStruct->hDC );
	if ( Settings.General.LanguageRTL )
		SetLayout( dc.m_hDC, LAYOUT_RTL );

	dc.SetTextColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
		? CoolInterface.m_crHiText : CoolInterface.m_crDropdownText );

	CSchemaPtr pSchema = (CSchemaPtr)lpDrawItemStruct->itemData;

	if ( pSchema != NULL )
	{
		/*dc.FillSolidRect( &rcItem,
			GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );*/
		if ( IsWindowEnabled() )
		{
			if ( lpDrawItemStruct->itemState & ODS_SELECTED )
				dc.FillSolidRect( &rcItem, CoolInterface.m_crHighlight );
			else
				dc.FillSolidRect( &rcItem, CoolInterface.m_crDropdownBox );
		}
		else
			dc.FillSolidRect( &rcItem, GetBkColor(lpDrawItemStruct->hDC) );

		dc.SetBkMode( TRANSPARENT );

		ShellIcons.Draw( &dc, pSchema->m_nIcon16, 16, pt.x, pt.y, CLR_NONE,
			( lpDrawItemStruct->itemState & ODS_SELECTED ) );

		rcItem.left += 20; rcItem.right -= 2;

		CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFont );
		CString strURI = pSchema->GetURI();

		if ( dc.GetTextExtent( pSchema->m_sTitle + strURI ).cx > rcItem.Width() - 20
			 && strURI.GetLength() > 8 )
		{
			LPCTSTR pszLeft = _tcschr( (LPCTSTR)strURI + 7, '/' );
			int nRight		= strURI.ReverseFind( '/' );

			if ( pszLeft && nRight >= 0 )
			{
				int nLeft = static_cast< int >( pszLeft - (LPCTSTR)strURI );  // !!! (TODO)
				strURI = strURI.Left( nLeft ) + _T("/\x2026") + strURI.Mid( nRight );
			}
		}

		if ( dc.GetTextExtent( pSchema->m_sTitle + strURI ).cx <= rcItem.Width() - 20 )
		{
			// COLORREF crBackup = dc.SetTextColor( GetSysColor( COLOR_GRAYTEXT ) );
			dc.DrawText( strURI, &rcItem, DT_SINGLELINE|DT_RIGHT|DT_VCENTER|DT_NOPREFIX );
			// dc.SetTextColor( crBackup );
		}

		dc.SelectObject( &theApp.m_gdiFontBold );
		dc.DrawText( pSchema->m_sTitle, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX );
		dc.SelectObject( pOldFont );
	}
	else if ( lpDrawItemStruct->itemID == 0 )
	{
		/*dc.FillSolidRect( &rcItem,
			GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );*/
		if ( IsWindowEnabled() )
		{
			if ( lpDrawItemStruct->itemState & ODS_SELECTED )
				dc.FillSolidRect( &rcItem, CoolInterface.m_crHighlight );
			else
				dc.FillSolidRect( &rcItem, CoolInterface.m_crDropdownBox );
		}
		else
			dc.FillSolidRect( &rcItem, GetBkColor(lpDrawItemStruct->hDC) );
		dc.SetBkMode( TRANSPARENT );

		CoolInterface.Draw( &dc, IDR_SEARCHFRAME, 16,
			pt.x, pt.y, CLR_NONE, ( lpDrawItemStruct->itemState & ODS_SELECTED ) );

		rcItem.left += 20; rcItem.right -= 2;

		CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFontBold );
		dc.DrawText( m_sNoSchemaText, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX );
		dc.SelectObject( pOldFont );
	}
	else
	{
		dc.Draw3dRect( &rcItem, CoolInterface.m_crDropdownBox , CoolInterface.m_crDropdownBox );
		rcItem.DeflateRect( 1, 1 );

		if ( lpDrawItemStruct->itemState & ODS_SELECTED )
		{
			dc.Draw3dRect( &rcItem, CoolInterface.m_crBorder, CoolInterface.m_crBorder );
			rcItem.DeflateRect( 1, 1 );
			dc.FillSolidRect( &rcItem, CoolInterface.m_crBackSel );
		}
		else
		{
			dc.FillSolidRect( &rcItem, GetSysColor( COLOR_WINDOW /* COLOR_BTNFACE */ ) );
		}

		dc.SetBkMode( TRANSPARENT );

		pt = rcItem.CenterPoint();
		pt.x -= 8;
		pt.y -= 8;

		CoolInterface.Draw( &dc, IDI_CHEVRON, 16, pt.x, pt.y );
	}

	dc.Detach();
}