📄 httpappview.cpp
字号:
/* Copyright (c) 2008, Nokia. All rights reserved */
#include "HttpAppView.h"
#include <eikrted.h>
#include <coemain.h>
#include <EIKENV.H>
#include "http.rsg"
#include <barsread.h>
#include "charconv.h"
#include <EIKCLBD.H>
#include <DocumentHandler.h>
#include <apmstd.h> // TDataType
#include "commdb.h"
_LIT(KFileName,"\\system\\temp.txt");
_LIT(KLogFileName,"\\system\\log.txt");
CHttpAppView* CHttpAppView::NewL(const TRect& aRect)
{
CHttpAppView* self = NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CHttpAppView* CHttpAppView::NewLC(const TRect& aRect)
{
CHttpAppView* self = new (ELeave) CHttpAppView;
CleanupStack::PushL(self);
TRAPD(result,self->ConstructL(aRect));
return self;
}
void CHttpAppView::ConstructL(const TRect& aRect)
{
CreateWindowL();
iExplorer = CExplorer::NewL(*this);
TResourceReader read;
iCoeEnv->CreateResourceReaderLC(read,R_OUTPUT_VIEW_RTEXTED);
iRichEditor = new(ELeave) CEikRichTextEditor;
iRichEditor->SetContainerWindowL(*this);
iRichEditor->ConstructFromResourceL(read);
iRichEditor->SetExtent(TPoint(0,0),aRect.Size());
iRichEditor->SetFocus(ETrue);
CleanupStack::PopAndDestroy();
//获得接入点
iIAPs = new(ELeave) CArrayPtrFlat<IAPs> (1);
GetGPRSIAPsFromIAPTableL(iIAPs);
SetIAPId(iCmwapIad);
SetRect(aRect);
ActivateL();
}
CHttpAppView::CHttpAppView()
{
iConnectType = 2;
iCurTimer = NULL;
iCount = 0;
iIAPs = NULL;
iCmwapIad = 11;
iCmnetIad = 10;
iNeedHost = EFalse;
iStartWrite = ETrue;
iDownLen = 0;
iTotalLen = 0;
// Add any construction code that can not leave here
}
CHttpAppView::~CHttpAppView()
{
// Add any destruction code here
delete iExplorer;
delete iRichEditor;
if (iIAPs)
{
iIAPs->ResetAndDestroy();
delete iIAPs;
iIAPs = NULL;
}
EndCount();
}
void CHttpAppView::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
// Clears the screen
gc.Clear( Rect() );
const CFont* fontUsed = iEikonEnv->TitleFont();
gc.UseFont(fontUsed);
gc.SetPenColor(KRgbBlack);
gc.SetBrushColor(KRgbBlack);
// TPoint pos(10,50);
// TBuf<64> buf;
// buf.Zero();
// buf.AppendFormat(_L("Type: %d"), iConnectType);
// gc.DrawText(buf,pos);
// TPoint pos1(10,100);
// buf.Zero();
// buf.AppendFormat(_L("Process: %d/%d"), iDownLen, iTotalLen);
// gc.DrawText(buf,pos1);
gc.DiscardFont();
}
void CHttpAppView::KeyEventL(TInt aCode)
{
TKeyEvent event;
event.iCode = aCode;
event.iScanCode = aCode;
iRichEditor->SetFocus(ETrue);
iRichEditor->OfferKeyEventL(event,EEventKey);
}
void CHttpAppView::DisplayText(TDesC8& aData)
{
for(TInt i =0;i<aData.Length();i++)
KeyEventL(aData[i]);
}
void CHttpAppView::SizeChanged()
{
}
TInt CHttpAppView::CountComponentControls() const
{
if (iRichEditor)
{
return 1;
}
return 0;
}
CCoeControl* CHttpAppView::ComponentControl(TInt aIndex) const
{
switch(aIndex)
{
case 0:
return iRichEditor;
default:
return 0;
}
}
void CHttpAppView::WriteToFile(TDesC8& aData)
{
RFs fs = iCoeEnv->FsSession();
User::LeaveIfError(fs.Connect());
RFile file;
if(iStartWrite)
{
fs.Delete(KFileName);
iStartWrite = EFalse;
}
if(file.Create(fs,KFileName,EFileWrite) != KErrAlreadyExists)
{
User::LeaveIfError(file.Write(aData));
}
else
{
if(file.Open(fs,KFileName,EFileWrite) == KErrNone)
{
TInt pos = 0;
file.Seek(ESeekEnd,pos);
User::LeaveIfError(file.Write(aData));
}
}
file.Close();
fs.Close();
}
void CHttpAppView::SetStartWrite()
{
iStartWrite = ETrue;
}
void CHttpAppView::SetEditText(TDesC8 aData)
{
TBuf<200> buf;
buf.Copy(aData);
iRichEditor->HandleTextChangedL();
iRichEditor->SetCursorPosL(0,EFalse);
iRichEditor->SetTextL(&buf);
}
void CHttpAppView::EmbedLaunchFileL(const TDesC& aFile)
{
if( !iDocHandler)
{
iDocHandler = CDocumentHandler::NewL((CEikProcess*)iEikonEnv->Process());
}
TDataType empty;
iDocHandler->OpenFileEmbeddedL(aFile, empty);
}
void CHttpAppView::GetGPRSIAPsFromIAPTableL(CArrayPtrFlat<IAPs>* aList)
{
TBuf<52> iapfromtable;
TInt err = KErrNone;
CCommsDatabase* iCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(iCommsDB);
CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerGPRS,
ECommDbConnectionDirectionOutgoing);
IAPs *iaps = new IAPs;
User::LeaveIfError(gprsTable->GotoFirstRecord());
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iaps->name);
gprsTable->ReadUintL(TPtrC(COMMDB_ID), iaps->id);
aList->AppendL(iaps);
while (err = gprsTable->GotoNextRecord(), err == KErrNone)
{
iaps = new IAPs;
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iaps->name);
gprsTable->ReadUintL(TPtrC(COMMDB_ID), iaps->id);
aList->AppendL(iaps);
// iExplorer->WriteLog(iaps->name);
// iExplorer->WriteLogInt(_L("iaps->id=%d"),iaps->id);
if (0 <= iaps->name.FindF(_L("CMNET")))
{
iCmnetIad = iaps->id;
}
else if (0 <= iaps->name.FindF(_L("WAP")) || 0 <= iaps->name.FindF(_L("CMCC")))
{
iCmwapIad = iaps->id;
}
}
CleanupStack::PopAndDestroy(2);
}
void CHttpAppView::SetIAPId(TUint32 aSel)
{
iExplorer->SetIAP(aSel);
}
void CHttpAppView::SetUrl(TDesC8& aData)
{
iUrl.Copy(aData);
iNeedHost = ETrue;
}
void CHttpAppView::NotifyState(TInt aTotalLen, TInt aDownLen)
{
iTotalLen = aTotalLen;
iDownLen = aDownLen;
DrawDeferred();
}
TUint32 CHttpAppView::GetIAPId()
{
return iIAPId;
}
void CHttpAppView::NextConnect()
{
if (NULL != iExplorer)
{
delete iExplorer;
iExplorer = NULL;
}
iExplorer = CExplorer::NewL(*this);
++iConnectType;
// if (2 == iConnectType && iNeedHost)
// {
// iExplorer->iNeedHost = iNeedHost;
// iExplorer->iUrl.Copy(iUrl);
// }
if (3 == iConnectType/* || 2 == iConnectType*/)
{
iConnectType = 4;
}
if (iConnectType > 4)
{
iConnectType = 2;
}
iExplorer->iNeedHost = ETrue;
iExplorer->iConnectType = iConnectType;
iExplorer->SetRequestMethod(REQUEST_METHOD_GET);
if (3 == iConnectType)
{
SetIAPId(iCmnetIad);
}
else
{
SetIAPId(iCmwapIad);
}
iExplorer->StartL();
// EndCount();
// BeginCount();
}
void CHttpAppView::WriteLog(TDesC8& aLog)
{
}
void CHttpAppView::BeginCount()
{
iCount = 0;
if(NULL == iCurTimer)
{
iCurTimer = CPeriodic::NewL(CActive::EPriorityStandard);
iCurTimer->Start(1 * 1000 * 1000, 1 * 1000 * 1000,TCallBack(CHttpAppView::CountCallback, this));
}
}
void CHttpAppView::EndCount()
{
if ( iCurTimer)
{
delete iCurTimer;
iCurTimer = NULL;
}
}
TInt CHttpAppView::CountCallback(TAny* aPtr)
{
((CHttpAppView*)aPtr)->CountCallback();
return 0;
}
void CHttpAppView::CountCallback()
{
++iCount;
if (iCount >= 90)
{
iCount = 0;
NextConnect();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -