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

📄 searchresultsview.cpp

📁 使用yahoo图片搜索功能在手机上的以应用
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 * Catch-all for failure. 
 * See TTransactionEvent::EFailed
 */			
void CSearchResultsView::ClientTransactionFailedL( CWebClientEngine& anEngine )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	
	RemoveWaitDialogL();
	HandleWebClientTransactionFailedL( anEngine );
	// ]]] end generated region [Generated Code]
	
	}
/**
 * ClientUnknownEvent
 * Called to notify that an unknown HTTP event has
 * been received.
 * @param aStatus: the iStatus field of the event
 * See THTTPEvent::iStatus
 */			
void CSearchResultsView::ClientUnknownEventL( CWebClientEngine& anEngine, TInt aStatus )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	}
/**
 * ClientRunError()
 * Called when a error occurs in the handling of a transaction event.
 * @param anError: the error code
 */			
void CSearchResultsView::ClientRunErrorL( CWebClientEngine& anEngine, TInt anError )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	
	RemoveWaitDialogL();
	// ]]] end generated region [Generated Code]
	
	}
 /**
 * ClientGetCredentialsL()
 * Called when authentication has been requested by the server.
 * Return EFalse for no authentication or e.g. the user cancels
 * an input dialog. Otherwise return the user name and password 
 * as out parameters along with an ETrue result.
 * @param aUri: the current URI
 * @param aRealm: the realm associated with the request
 * @param aUserName: the returned user name
 * @param aPassword: the returned password
 */		
TBool CSearchResultsView::ClientGetCredentialsL( CWebClientEngine& anEngine, const TUriC8& aUri, const TDesC8& aRealm, TDes& aUsername, TDes& aPassword )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	return EFalse;
	// ]]] end generated region [Generated Code]
	
	}
// [[[ begin generated function: do not modify
			
/**
 * Initiate the HTTP GET transaction. Progress and data will
 * be provided through the MWebClientObserver callback methods.
 * If configured in the UI Designer, the wait dialog is executed
 * before returning.
 * @param aUrl: if non-null this is used as the URL to fetch. Otherwise
 * the URL configured in the UI Designer is used.
 */	
void CSearchResultsView::IssueHTTPGetL( const TDesC8* aUrl )
	{

	ExecuteWaitDialogLD();

	if ( aUrl != NULL )
		{
		iWebClient->IssueHTTPGetL( *aUrl );
		}
	else 
		{
		_LIT8( url, "" );
		iWebClient->IssueHTTPGetL( url );
		}

	}
// ]]] end generated function

// [[[ begin generated function: do not modify
/**
 * Execute the wait dialog for waitDialog. This routine returns
 * while the dialog is showing. It will be closed and destroyed when
 * RemoveWaitDialogL() or the user selects the Cancel soft key.
 * @param aOverrideText optional override text. When null the text configured
 * in the UI Designer is used.
 */
void CSearchResultsView::ExecuteWaitDialogLD( const TDesC* aOverrideText )
	{
	iWaitDialog = new ( ELeave ) CAknWaitDialog( 
			reinterpret_cast< CEikDialog** >( &iWaitDialog ), EFalse );
	if ( aOverrideText != NULL )
		{
		iWaitDialog->SetTextL( *aOverrideText );
		}
	iWaitDialog->ExecuteLD( R_SEARCH_RESULTS_WAIT_DIALOG );
	iWaitDialogCallback = new ( ELeave ) CProgressDialogCallback( 
		this, iWaitDialog, &CSearchResultsView::HandleWaitDialog1CanceledL );
	iWaitDialog->SetCallback( iWaitDialogCallback );
	}
// ]]] end generated function

// [[[ begin generated function: do not modify
/**
 * Close and dispose of the wait dialog for waitDialog
 */
void CSearchResultsView::RemoveWaitDialogL()
	{
	if ( iWaitDialog != NULL )
		{
		iWaitDialog->SetCallback( NULL );
		iWaitDialog->ProcessFinishedL();    // deletes the dialog
		iWaitDialog = NULL;
		}
	delete iWaitDialogCallback;
	iWaitDialogCallback = NULL;
	
	}
// ]]] end generated function

/** 
 * Handle the canceled event.
 */
void CSearchResultsView::HandleWaitDialog1CanceledL( CAknProgressDialog* /* aDialog */ )
	{
	iWebClient->CancelTransactionL(); 
	}
				
/** 
 * Handle the bodyReceived event.
 */
void CSearchResultsView::HandleWebClientBodyReceivedL( CWebClientEngine& /*anEngine*/, const TDesC8& aBodyData )
	{
		TInt err;
		if (requestType == SEARCH_REQUEST)
		{	
			iSearchModel->AppendL(aBodyData);
		}
		else if (requestType == IMAGE_REQUEST)
		{
			AppendImageDataL(aBodyData);
		}
	}
	
void CSearchResultsView::AppendImageDataL(const TDesC8& data)
{
	int newLength = iImageBuffer.Length() + data.Length();
	if (iImageBuffer.MaxLength() < newLength)
	{
		iImageBuffer.ReAllocL(newLength);
	}
	iImageBuffer.Append(data);
}
				
/** 
 * Handle the transactionFailed event.
 */
void CSearchResultsView::HandleWebClientTransactionFailedL( CWebClientEngine& /*anEngine*/ )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	}
				
/** 
 * Handle the transactionSucceeded event.
 */
void CSearchResultsView::HandleWebClientTransactionSucceededL( CWebClientEngine& /*anEngine*/ )
{
	if (requestType == SEARCH_REQUEST)
	{
		iSelectedItem = -1;
		iSearchModel->ParseL();
		PopulateSearchResultsL();
	}
	else if (requestType == IMAGE_REQUEST)
	{
		TYahooImageInfo imageInfo;
		iSearchModel->GetImageInfo(iSelectedItem, imageInfo);
		iImageDisplayer->DisplayImageL(imageInfo.title, iImageBuffer);
		iImageBuffer.SetLength(0);
		iImageBuffer.ReAlloc(0);
	}
}

void CSearchResultsView::PopulateSearchResultsL()
{
	iSearchResults->ResetListL();
	iSearchResults->ListBox()->SetCurrentItemIndex(0);
	for (int i = 0; i < iSearchModel->GetImageCount(); i++)
	{
		TYahooImageInfo info;
		iSearchModel->GetImageInfo(i, info);
		TBuf<256> buf;
		iSearchResults->CreateListBoxItemL(buf, info.title, info.url);
		iSearchResults->AddListBoxItemL(iSearchResults->ListBox(), buf);
	}
	iSearchResults->ListBox()->DrawDeferred();
}
		
	
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CSearchResultsView::HandleNew_searchMenuItemSelectedL( TInt aCommand )
	{
	TBuf<MAX_SEARCH_STRING_LENGTH> searchString;
	if (RunSearchPromptL(searchString, ETrue, NULL) == EAknSoftkeyOk) 
	{
		TBuf8<MAX_SEARCH_STRING_LENGTH> searchString8;
		searchString8.Copy(searchString);
		
		// replace spaces with '+' in search string
		int foundPos;
		_LIT8(plusStr, "+");
		while ((foundPos = searchString8.Locate(' ')) != KErrNotFound)
		{
			searchString8.Replace(foundPos, plusStr().Length(), plusStr);
		}
		
		_LIT8(SEARCH_URL, "http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?appid=carbide.yahoo&query=%S&results=10");
		RBuf8 urlBuf;
		urlBuf.CreateL(512);
		urlBuf.CleanupClosePushL();
		urlBuf.Format(SEARCH_URL, &searchString8);
		requestType = SEARCH_REQUEST;
		IssueHTTPGetL(&urlBuf);
		CleanupStack::PopAndDestroy();
	}
	return ETrue;
	}
				
// [[[ begin generated function: do not modify
/**
 * Show the popup dialog for searchPrompt
 * @param aData in-out TDes data
 * @param aUseDefaults TBool use designer default editor data if ETrue
 * @param aOverridePrompt optional override prompt text
 * @return EAknSoftkeyOk (left soft key id) or 0
 */
TInt CSearchResultsView::RunSearchPromptL( 
		TDes& aData, 
		TBool aUseDefaults, 
		const TDesC* aOverridePrompt )
	{
	if ( aUseDefaults )
		{
		HBufC* text = StringLoader::LoadLC( R_SEARCH_RESULTS_EDIT1 );
		aData.Copy( *text );
		CleanupStack::PopAndDestroy( text );
		}
				
	CAknTextQueryDialog* queryDialog = CAknTextQueryDialog::NewL( aData );	
	
	if ( aOverridePrompt != NULL )
		{
		CleanupStack::PushL( queryDialog );
		queryDialog->SetPromptL( *aOverridePrompt );
		CleanupStack::Pop(); // queryDialog
		}
	
	return queryDialog->ExecuteLD( R_SEARCH_RESULTS_SEARCH_PROMPT );
	}
// ]]] end generated function

void CSearchResultsView::ShowSelectedImageL()
{
	int currItem = iSearchResults->ListBox()->CurrentItemIndex();
	if (currItem >= 0)
	{
		iSelectedItem = currItem;
		TYahooImageInfo imageInfo;
		iSearchModel->GetImageInfo(currItem, imageInfo);
		
		if (imageInfo.thumbnailUrl.Length() > 0)
		{
			RBuf8 urlBuf;
			urlBuf.CreateL(imageInfo.thumbnailUrl.Length());
			urlBuf.Copy(imageInfo.thumbnailUrl);
			urlBuf.CleanupClosePushL();
			
			requestType = IMAGE_REQUEST;
			IssueHTTPGetL(&urlBuf);
			
			CleanupStack::PopAndDestroy();
		}
	}	
}
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CSearchResultsView::HandleInfoMenuItemSelectedL( TInt aCommand )
	{
	RunAttributionL();
	return ETrue;
	}
				
// [[[ begin generated function: do not modify
/**
 * Show the popup note for attribution
 * @param aOverrideText optional override text
 */
void CSearchResultsView::RunAttributionL( const TDesC* aOverrideText )
	{
	CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote();
	if ( aOverrideText == NULL )
		{
		HBufC* noteText = StringLoader::LoadLC( R_SEARCH_RESULTS_ATTRIBUTION );
		note->ExecuteLD( *noteText );
		CleanupStack::PopAndDestroy( noteText );
		}
	else
		{
		note->ExecuteLD( *aOverrideText );
		}
	}
// ]]] end generated function


/**
 *	Creates the top-level container for the view.  You may modify this method's
 *	contents and the CSearchResults::NewL() signature as needed to initialize the
 *	container, but the signature for this method is fixed.
 *	@return new initialized instance of CSearchResults
 */
CSearchResults* CSearchResultsView::CreateContainerL()
	{
	return CSearchResults::NewL( ClientRect(), NULL, this );
	}
			

⌨️ 快捷键说明

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