📄 nettestappui.cpp
字号:
/*
============================================================================
Name : NetTestAppUi.cpp
Author :
Version :
Copyright : Your copyright notice
Description : Main application UI class (controller)
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <NetTest.rsg>
#include <f32file.h>
#include <s32file.h>
#include <sys/reent.h> // for CloseSTDLib()
#include <m5httpdown.h>
#include <bautils.h> // for file exist check
#include "NetTest.pan"
#include "NetTestAppUi.h"
//#include "NetTestAppView.h"
#include "NetTest.hrh"
#include "NetTestContainer.h"
#include "NetTestApplication.h"
// ============================ MEMBER FUNCTIONS ===============================
//_LIT8(KTargetUri, "http://www.5mbox.com/bbs/test1.mp3") ;
_LIT8(KTargetUri, "http://blog.ytcnc.net/UploadFiles/2008-4/422210244.mp3 ") ;
#ifndef __WINSCW__
_LIT(KTargetFilename, "e:\\love.mp3 ") ;
_LIT(KTargetFilename2, "e:\\love.mp3.tmp ") ;
#else
_LIT(KTargetFilename, "c:\\love.mp3 ") ;
_LIT(KTargetFilename2, "c:\\love.mp3.tmp ") ;
#endif
// -----------------------------------------------------------------------------
// CNetTestAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CNetTestAppUi::ConstructL()
{
BaseConstructL();
iAppContainer = new (ELeave) CNetTestContainer;
iAppContainer->SetMopParent( this );
iAppContainer->ConstructL( ClientRect() );
AddToStackL( iAppContainer );
iPrintBuf.SetLength(0) ;
iHttpDown = NULL ;
iRecvSize = 0 ;
iFirstIn = ETrue ;
}
// -----------------------------------------------------------------------------
// CNetTestAppUi::CNetTestAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CNetTestAppUi::CNetTestAppUi()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CNetTestAppUi::~CNetTestAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CNetTestAppUi::~CNetTestAppUi()
{
if (iAppContainer)
{
RemoveFromStack( iAppContainer );
delete iAppContainer;
}
}
// -----------------------------------------------------------------------------
// CNetTestAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CNetTestAppUi::HandleCommandL( TInt aCommand )
{
TBuf8<100> s8(KTargetUri) ;
switch ( aCommand )
{
case EAknSoftkeyBack:
case EEikCmdExit:
{
if(iHttpDown) delete iHttpDown ;
Exit();
}
break;
case ENetTestCMWapConn:
{
iPrintBuf.SetLength(0) ;
iFirstIn = ETrue ;
if(iHttpDown) delete iHttpDown ;
iHttpDown = CM5HttpDown::NewL(*this, HTTP_DOWN_CMWAP) ;
iHttpDown->HttpConnPorxy(s8) ;
iRecvSize = 0 ;
// check whether the file exists
User::LeaveIfError(iFs.Connect()) ;
iRecvSize = 0 ;
if(BaflUtils::FileExists(iFs, KTargetFilename)) {
TInt seek_pos = 0 ;
iFile.Open(iFs, KTargetFilename, EFileStream | EFileWrite) ;
if(iFile.Size(iRecvSize) != KErrNone)
iRecvSize = 0 ;
iFile.Seek(ESeekEnd, seek_pos) ;
} else {
iFile.Replace(iFs, KTargetFilename, EFileStream | EFileWrite) ;
}
}
break ;
case ENetTestCMNetConn:
{
iPrintBuf.SetLength(0) ;
iFirstIn = ETrue ;
if(iHttpDown) delete iHttpDown ;
iHttpDown = CM5HttpDown::NewL(*this, HTTP_DOWN_CMNET) ;
iHttpDown->HttpConnPorxy(s8) ;
iRecvSize = 0 ;
// check whether the file exists
User::LeaveIfError(iFs.Connect()) ;
iRecvSize = 0 ;
TBuf<32> aFilename;
aFilename.Append(KTargetFilename);
TBuf<32> aFilenameTmp;
aFilenameTmp.Append(KTargetFilename2);
for (TInt i = 1;;i++)
{
if(BaflUtils::FileExists(iFs, aFilename)) {
TInt aIndex2;
aIndex2 = aFilenameTmp.Find(_L("."));
if (1==i)
{
aFilenameTmp.Insert(aIndex2,_L("("));
TBuf<4> aIntegerBuf2 ;
aIntegerBuf2.AppendNum(i);
aFilenameTmp.Insert(aIndex2+1,aIntegerBuf2);
aFilenameTmp.Insert(aIndex2+2,_L(")"));
}
else
{
aFilenameTmp.Delete(aIndex2-3,3);
aFilenameTmp.Insert(aIndex2-3,_L("("));
TBuf<4> aIntegerBuf2 ;
aIntegerBuf2.AppendNum(i);
aFilenameTmp.Insert(aIndex2-2,aIntegerBuf2);
aFilenameTmp.Insert(aIndex2-1,_L(")"));
}
if (BaflUtils::FileExists(iFs, aFilenameTmp))
{
TInt seek_pos = 0 ;
iFile.Open(iFs, aFilenameTmp, EFileStream | EFileWrite) ;
if(iFile.Size(iRecvSize) != KErrNone)
iRecvSize = 0 ;
iFile.Seek(ESeekEnd, seek_pos) ;
break;
}
else
{
TInt aIndex1;
aIndex1 = aFilename.Find(_L("."));
if (1==i)
{
aFilename.Insert(aIndex1,_L("("));
TBuf<4> aIntegerBuf1;
aIntegerBuf1.AppendNum(i);
aFilename.Insert(aIndex1+1,aIntegerBuf1);
aFilename.Insert(aIndex1+2,_L(")"));
}
else
{
aFilename.Delete(aIndex1-3,3);
aFilename.Insert(aIndex1-3,_L("("));
TBuf<4> aIntegerBuf1;
aIntegerBuf1.AppendNum(i);
aFilename.Insert(aIndex1-2,aIntegerBuf1);
aFilename.Insert(aIndex1-1,_L(")"));
}
continue;
}
} else {
if (BaflUtils::FileExists(iFs, aFilenameTmp))
{
TInt seek_pos = 0 ;
iFile.Open(iFs, aFilenameTmp, EFileStream | EFileWrite) ;
if(iFile.Size(iRecvSize) != KErrNone)
iRecvSize = 0 ;
iFile.Seek(ESeekEnd, seek_pos) ;
break;
}
else
{
iFile.Replace(iFs, aFilenameTmp, EFileStream | EFileWrite) ;
iFileName.Append(aFilenameTmp);
break;
}
}
}
}
break ;
case ENetTestResume:
{
TBuf<20> s16 ;
if(iHttpDown->HttpDown(s8, iRecvSize)) {
s16.Format(_L("req sent!")) ;
M5PrintNotify(s16) ;
} else {
s16.Format(_L("req send failed!")) ;
M5PrintNotify(s16) ;
}
}
break;
case ENetTestStop:
{
if(iHttpDown->IsRunning()) {
iHttpDown->HttpStopDown() ;
delete iHttpDown ;
iHttpDown = NULL ;
iFile.Close() ;
iFs.Close() ;
iFirstIn = ETrue ;
}
}
break ;
default:
Panic( ENetTestUi );
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CNetTestAppUi::HandleStatusPaneSizeChange()
{
iAppContainer->SetRect( ClientRect() );
}
void CNetTestAppUi::M5PrintNotify(const TDesC & aMessage)
{
if(iPrintBuf.Length() + aMessage.Length() >= PRINT_BUF_LEN) {
iPrintBuf.SetLength(0) ;
return ;
}
iPrintBuf.Append(aMessage) ;
iPrintBuf.Append(_L("\n")) ;
iAppContainer->SetMsgBody(iPrintBuf) ;
}
void CNetTestAppUi::M5RecvNotify(const TDesC8 & recv_buf)
{
if(iFirstIn) {
TBuf<30> s ;
s.Format(_L("total size : %d"), iHttpDown->HttpTotalSize()) ;
M5PrintNotify(s) ;
s.Format(_L("recv size : %d"), iHttpDown->HttpRecvSize()) ;
M5PrintNotify(s) ;
iFirstIn = EFalse ;
} else {
iPrintBuf.Format(_L("total %d bytes\nrecv %d bytes"),
iHttpDown->HttpTotalSize(),
iHttpDown->HttpRecvSize()) ;
iAppContainer->SetMsgBody(iPrintBuf) ;
}
// record the music data into file
iFile.Write(recv_buf) ;
if(iHttpDown->HttpTotalSize() > 0 &&
iHttpDown->HttpTotalSize() <= iHttpDown->HttpRecvSize()) {
TBuf<20> s ;
s.Format(_L("\nend recv!\n")) ;
M5PrintNotify(s) ;
TInt aIndexofTmp;
aIndexofTmp = iFileName.Find(_L(".tmp"));
iFileName.Delete(aIndexofTmp,4);
iFile.Rename(iFileName);
}
}
void CNetTestAppUi::M5TimerExpireNotify()
{
}
void CNetTestAppUi::M5ErrorNotify(const TDesC& /*aErrMessage*/, TInt /*aErrCode*/)
{
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -