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

📄 exampleclientappui.cpp

📁 一个http客户端连接的程序例子
💻 CPP
字号:
/*
 * ============================================================================
 *  Name     : ExampleClientAppUI.cpp
 *  Part of  : HTTP Example
 *  Created  : 11/14/2003 by Forum Nokia
 *  Implementation notes:
 *
 *     
 *  Version  : 1.0
 *  Copyright: Nokia Corporation
 * ============================================================================
 */

#include <avkon.hrh>
#include <aknnotewrappers.h> 
#include <eikmenup.h>

#include <ExampleClient.rsg>
#include "ExampleClient.pan"
#include "ExampleClientAppUi.h"
#include "ExampleClientAppView.h"
#include "ExampleClient.hrh"

// Schemes for given uris
_LIT(KHttpPrefix, "http://");
_LIT8(KHttpPrefix8, "http://");

// HTTPS schemes
_LIT(KHttpsPrefix, "https://");
_LIT8(KHttpsPrefix8, "https://");

// ----------------------------------------------------------------------------
// CExampleClientAppUi::ConstructL()
// 
// Second phase construction.
// ----------------------------------------------------------------------------
void CExampleClientAppUi::ConstructL()
{
    BaseConstructL(EAknEnableSkin);

    iAppView = CExampleClientAppView::NewL(ClientRect());
    AddToStackL(iAppView);

	iClient = CClientEngine::NewL(*iAppView);
}

// ----------------------------------------------------------------------------
// CExampleClientAppUi::CExampleClientAppUi()
//
// First phase construction.
// ----------------------------------------------------------------------------
CExampleClientAppUi::CExampleClientAppUi()
{
}

// ----------------------------------------------------------------------------
// CExampleClientAppUi::~CExampleClientAppUi()
//
// Destructor.
// ----------------------------------------------------------------------------
CExampleClientAppUi::~CExampleClientAppUi()
{
	if (iAppView)
		{
		iEikonEnv->RemoveFromStack(iAppView);
		delete iAppView;
		iAppView = NULL;
		}

	delete iClient;
	iClient = NULL;
}

// ----------------------------------------------------------------------------
// CExampleClientAppUi::HandleCommandL()
//
// Handles user commands.
// ----------------------------------------------------------------------------
void CExampleClientAppUi::HandleCommandL(TInt aCommand)
{
	switch(aCommand) {
	case EEikCmdExit:
	case EAknSoftkeyExit:
		Exit();
		break;

	case EClientGet:
		{
		// Issue HTTP get to engine; first cancel possible existing transaction
		iClient->CancelTransaction();

		// Query uri
		TBuf<256> uri;
		CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(uri, 
			CAknQueryDialog::ENoTone);

		if (! dlg->ExecuteLD(R_DIALOG_URI_QUERY)) 
			break;

		iAppView->Reset();

		// Insert prefix to uri (it must begin with "http://" or "https://")
		TBuf8<256> uri8;
		uri.LowerCase();
		if(uri.Find(KHttpPrefix) == KErrNotFound
			&& uri.Find(KHttpsPrefix) == KErrNotFound)
			{
			// If the uri does not contain http or https, 
			// use the default, "http://"
			uri8.Append(KHttpPrefix8);
			uri8.Append(uri);
			} else {
			uri8.Copy(uri);
			}

		// Start transaction
		iClient->IssueHTTPGetL(uri8);
		}
		break;

	case EClientPost:
		{
		// Issue HTTP post to engine

		iClient->CancelTransaction();

		// Query uri and data to post
		TBuf<256> uri;
		TBuf<256> postData;
		CAknMultiLineDataQueryDialog* dlg = 
			CAknMultiLineDataQueryDialog::NewL(uri, postData);

		if (!dlg->ExecuteLD(R_DIALOG_URI_POST_QUERY))
			break;

		iAppView->Reset();

		// Insert prefix to uri (it must begin with "http://" or "https://")
		TBuf8<256> uri8;
		uri.LowerCase();
		if(uri.Find(KHttpPrefix) == KErrNotFound
			&& uri.Find(KHttpsPrefix) == KErrNotFound)
			{
			// If uri does not contain http or https, 
			// use the default, "http://"
			uri8.Append(KHttpPrefix8);
			uri8.Append(uri);
			} else {
			uri8.Copy(uri);
			}

		TBuf8<256> postData8;
		postData8.Copy(postData);

		// Start transaction
		iClient->IssueHTTPPostL(uri8, _L8("text/plain"), postData8);
		}
		break;

	case EClientCancel:
		// Cancel current transaction
		if(iClient->IsRunning())
			iClient->CancelTransaction();
		break;

	default:
		Panic(EClientUi);
		break;
	}
	}

// ----------------------------------------------------------------------------
// CExampleClientAppUi::DynInitMenuPaneL()
//
// Initializes the menu pane when it's activated.
// ----------------------------------------------------------------------------
void CExampleClientAppUi::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
	{
	// "Cancel" selection is only available when trasaction running in engine
	if (aMenuId == R_EXAMPLECLIENT_MENU)
		aMenuPane->SetItemDimmed(EClientCancel, !iClient->IsRunning());
	}

⌨️ 快捷键说明

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