Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Display wait note between HTTP response delay

From Wiki
Jump to: navigation, search

This Symbian C++ code snippet shows how to display a wait note while waiting for a http response.

Article Metadata
Article
Created: sinhashivam (16 May 2007)
Last edited: hamishwillee (25 Jan 2012)

Contents

Project file (.mmp)

LIBRARY       avkon.lib
LIBRARY eikcdlg.lib
LIBRARY eikctl.lib


RSS file (.rss)

//----------------------------------------------------
//
// r_wait_note_http_request
// Display wait note
//
//----------------------------------------------------
//
RESOURCE DIALOG r_wait_note_http_request
{
flags=EAknWaitNoteFlags;
items =
{
DLG_LINE
{
type = EAknCtNote;
id = EWaitNoteId;
control = AVKON_NOTE
{
layout = EWaitLayout;
singular_label = "Please wait..."
imagefile = "z:\\system\data\avkon.mbm";
imageid = EMbmAvkonQgn_note_progress;
imagemask = EMbmAvkonQgn_note_progress_mask;
animation = R_QGN_GRAF_WAIT_BAR_ANIM;
};
}
};
}

Header file (.h)

#ifndef __TestClass_H__
#define __TestClass_H__
 
#include "HTTPClientEngine.h"
#include <AknWaitNoteWrapper.h>
 
 
class TestClass: public MHTTPObserver,public MAknBackgroundProcess
{
public:
 
static TestClass* NewLC();
static TestClass* NewL();
 
void ConstructL();
TestClass();
virtual ~TestClass();
void IssueHTTPRequest();
 
/*
* HTTP Callback Methods
*
*/

virtual void ClientEvent(const TDesC& aEventDescription);
virtual void ClientBodyReceived(const TDesC8& aBodyData);
 
/*
* From MAKnBackgroundObserver
*
*/

TBuf<32> Status;
RTimer iTimeWaster;
 
private:
TBool iDialogDismissed;
void DialogDismissedL(TInt aButtonId);
TBool IsProcessDone() const;
void ProcessFinished();
void StepL();
 
private:
HBufC8* iHTTPResponse;
CHTTPClientEngine* iHTTPClient;
CAknWaitNoteWrapper* waitNoteWrapper;
};
 
#endif __TestClass_H__

Source file (cpp)

// TestClass.cpp: implementation of the CTestClassclass.
//
//////////////////////////////////////////////////////////////////////
 
#include "TestClass.h"
#include <e32std.h>
#include <eikmenup.h>
#include <e32base.h>
#include <aknnotewrappers.h>
#include <StringLoader.h>
/*
============================================================================
Name  : CTestClass from TestClass.h
Author  : shivam
Version  :
 
============================================================================
*/

 
CTestClass ::CTestClass()
{
}
 
 
CTestClass::~CTestClass()
{
if(iHTTPClient)
{
delete iHTTPClient;
iHTTPClient=NULL;
}
 
if(iHTTPResponse)
{
delete iHTTPResponse;
iHTTPResponse=NULL;
}
 
iTimeWaster.Close();
 
delete this->waitNoteWrapper;
this->waitNoteWrapper=NULL;
}
 
void CTestClass::CTestClass()
{
iHTTPClient=CHTTPClientEngine::NewL(*this);
iHTTPResponse=NULL;
 
waitNoteWrapper = CAknWaitNoteWrapper::NewL();
iTimeWaster.CreateLocal();
}
 
CTestClass* CTestClass::NewL()
{
CTestClass* self = CTestClass::NewLC();
CleanupStack::Pop(self);
return self;
}
 
CTestClass* CTestClass::NewLC()
{
CTestClass* self = new (ELeave) CTestClass();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
 
//=========================================================================
//ClientBodyReceived() -- HTTP Callback Function.This will get the response
// body data.
//returns -- None
//
//==========================================================================
 
void CTestClass::ClientBodyReceived(const TDesC8& aBodyData)
{
if(!iHTTPResponse)
{
iHTTPResponse = HBufC8::NewL(aBodyData.Length());
}
else
{
iHTTPResponse =
iHTTPResponse->ReAllocL(iHTTPResponse->Length()+aBodyData.Length());
}
 
TPtr8 ptr_bufNoteData8=iHTTPResponse->Des();
ptr_bufNoteData8.Append(aBodyData);
}
 
 
//=========================================================================
//ClientEvent() -- HTTP Callback function
//aEventDescription -- The transaction events
//returns -- None
//
//==========================================================================
 
void CTestClass::ClientEvent(const TDesC& aEventDescription)
{
this->Status.Copy(aEventDescription);
 
_LIT(KTransactionSuccessful, "Transaction Successful");
if(aEventDescription==KTransactionSuccessful)
{
//Handle HTTP Response
}
}
 
//=========================================================================
//
//IssueHTTPRequest() -- Issue HTTP request
//
//
//==========================================================================
 
void CConnector::IssueHTTPRequest()
{
iRSSFeed = aCurrentFeed;
Status.Copy(_L("Init"));
TBuf8<256> uri8;
uri8.Append(_L("http://www.developer.nokia.com/"));
 
// Start transaction
iHTTPClient->IssueHTTPGetL(uri8);
 
if (!waitNoteWrapper->ExecuteL(R_WAIT_NOTE_HTTP_REQUEST, *this,ETrue))
{
iHTTPClient->CancelTransaction();
}
 
}
//=========================================================================
//StepL() -- Used by the Wait bar to increment the timer
//Inherited from MAknBackgroundObserver
//
//==========================================================================
 
void CTestClass::StepL()
{
TRequestStatus status;
TInt delay = 100000; // 1 second
iTimeWaster.After(status, delay);
User::WaitForRequest(status);
 
}
 
 
//=========================================================================
//ProcessFinished() -- Diminishes the wait bar when the http process is finished
//
//Inherited from MAknBackgroundObserver
//==========================================================================
 
void CTestClass::ProcessFinished()
{
iTimeWaster.Cancel();
this->Status.Delete(0,this->Status.Length());
}
 
 
//=========================================================================
//IsProcessDone() -- Checks whethet the HTTP request is complete or not
//returns : True/False
//Inherited from MAknBackgroundObserver
//==========================================================================
 
TBool CTestClass::IsProcessDone() const
{
_LIT(KTransactionSuccessful, "Transaction Successful");
TPtrC istatus(this->Status);
return(istatus==KTransactionSuccessful);
}
 
//=========================================================================
//DialogDismissedL() -- Called if the wait bar is stopeed in between
//Inherited from MAknBackgroundObserver
//
//==========================================================================
 
void CTestClass::DialogDismissedL(TInt /*aButtonId*/)
{
}
This page was last modified on 25 January 2012, at 03:39.
80 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×