📄 httpex_appui.cpp
字号:
// HttpEx_CHttpExAppUi.cpp
// ----------------------------
//
// Copyright (c) 2002 Symbian Ltd. All rights reserved.
//
////////////////////////////////////////////////////////////////////////
//
// Source file for the implementation of the
// application UI class - CHttpExAppUi
//
////////////////////////////////////////////////////////////////////////
// To enable the dynamic loading of the menu with a Close command in the UDEB version
#include <eikmenub.h>
#include "HttpEx.h"
#include <HttpStringConstants.h>
#include <http\mhttpdatasupplier.h>
_LIT8(KDemoURL,"http://www.google.com"); // note that URIs are 8-bit!
// The second phase constructor of the application UI class.
// The application UI creates and owns the one and only view.
//
void CHttpExAppUi::ConstructL()
{
// BaseConstructL() completes the UI framework's
// construction of the App UI.
BaseConstructL();
// Create the single application view in which to
// draw the text "Hello World!", passing into it
// the rectangle available to it.
iAppView = CHttpExAppView::NewL(ClientRect());
iSession.OpenL();
}
// The app Ui owns the two views and is.
// therefore, responsible for destroying them
//
CHttpExAppUi::~CHttpExAppUi()
{
iSession.Close();
delete iAppView;
}
// Called by the UI framework when a command has been issued.
// In this example, a command can originate through a
// hot-key press or by selection of a menu item.
// The command Ids are defined in the .hrh file
// and are 'connected' to the hot-key and menu item in the
// resource file.
// Note that the EEikCmdExit is defined by the UI
// framework and is pulled in by including eikon.hrh
//
void CHttpExAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
// begin a transaction?
case EMenuGo:
switch(iAppView->State()) // enforce sequential requests
{
// states that are ok to beginning fetching
case CHttpExAppView::EReady:
case CHttpExAppView::EError:
case CHttpExAppView::EDone:
{
iAppView->SetState(CHttpExAppView::EFetching);
StartRequest(KDemoURL);
}
break;
// else a state where we are inside a transaction already
default:
{
User::InfoPrint(_L("busy"));
}
}
break;
// Exit the application. The call is
// implemented by the UI framework.
case EEikCmdExit:
Exit();
break;
}
}
// This is a way to dynamically initialize the menu.
void CHttpExAppUi::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
{
if(aMenuId == R_MAIN_MENU)
{
// If it is the debug version, the menu should contain a Close command.
// In releaseable versions, there should be no Close command. But this is
// an example app only, so we always want a close button
//#if defined(_DEBUG)
CEikMenuPaneItem::SData itemData;
TBuf<16> closeCommandText;
iEikonEnv->ReadResource(closeCommandText, R_CLOSE_COMMAND);
itemData.iText=closeCommandText;
itemData.iCommandId=EEikCmdExit;
itemData.iFlags=0;
itemData.iCascadeId=0;
aMenuPane->AddMenuItemL(itemData);
//#endif
}
}
//*** methods from MHTTPTransactionCallback ***
void CHttpExAppUi::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
switch (aEvent.iStatus)
{
case THTTPEvent::EGotResponseBodyData:
{
// Some (more) body data has been received. Get the body data supplier
MHTTPDataSupplier* body = aTransaction.Response().Body();
TPtrC8 dataChunk;
body->GetNextDataPart(dataChunk);
for(TInt i=0; (i<dataChunk.Length()) && (iResponse.Length() < iResponse.MaxLength()); ++i)
{
iResponse.Append(dataChunk[i]);
}
// Done with that bit of body data
body->ReleaseData();
}
break;
case THTTPEvent::ESucceeded:
{
iAppView->SetState(CHttpExAppView::EDone);
iAppView->SetTextL(iResponse);
}
break;
case THTTPEvent::EFailed:
{
iAppView->SetState(CHttpExAppView::EError);
}
break;
// not interested in other events
}
}
TInt CHttpExAppUi::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
iAppView->SetState(CHttpExAppView::EError);
User::InfoPrint(_L("MHFRunError"));
return KErrNone; // if you don't handle this error, you'll panic with HTTP-CORE 6
}
//*** doers ***
void CHttpExAppUi::StartRequest(const TDesC8& aUri)
{
TUriParser8 uri;
uri.Parse(aUri);
RHTTPTransaction trans = iSession.OpenTransactionL(uri, *this, iSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable()));
iResponse.Zero();
// submit the transaction
trans.SubmitL();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -