📄 orcoperbook.cpp
字号:
/* Copyright (c) 2007, Nokia. All rights reserved */
#include <aknnotewrappers.h>
#include <f32file.h> //RFs头文件
#include <charconv.h> // 文字转换
#include "OrcerAppUi.h"
#include "ORCOperBook.h"
#include "Orcer.hrh"
#include "Orcer.rsg"
#include <e32des8.h> //HBufC8头文件
#include <e32std.h>
#include "BookEngine.h"
const TInt KNumberOfStepsToSelupdate(25);
CORCOperBook* CORCOperBook::NewL(CBookEngine* aBookEngine)
{
CORCOperBook* self = NewLC(aBookEngine);
CleanupStack::Pop(self);
return self;
}
CORCOperBook* CORCOperBook::NewLC(CBookEngine* aBookEngine)
{
CORCOperBook* self = new (ELeave) CORCOperBook(aBookEngine);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CORCOperBook::ConstructL()
{
// mNameData = NULL;
// mMobelData = NULL;
iTimeWaster.CreateLocal();
}
CORCOperBook::CORCOperBook(CBookEngine* aBookEngine)
{
m_pBookEngine = aBookEngine;
m_pRecordData = NULL;
m_pfName = NULL;
m_phName = NULL;
m_pMobel = NULL;
m_nType = 0;
}
CORCOperBook::~CORCOperBook()
{
m_sDataList.ResetAndDestroy();
iTimeWaster.Close();
m_sFirstName.Reset();
m_sLastName.Reset();
m_sMobelData.Reset();
m_nContent_ID.Reset();
m_nContent_ID.Close();
MEMORY_FREE(m_pBodyData);
}
void CORCOperBook::AppendBodyL(const TDesC& aBody)
{
if (!m_pBodyData)
{
m_pBodyData = HBufC::NewL(aBody.Length());
m_pBodyData->Des().Copy(aBody);
}
else
{
m_pBodyData = m_pBodyData->ReAllocL(m_pBodyData->Length()+aBody.Length());
m_pBodyData->Des().Append(aBody);
}
}
void CORCOperBook::SetBookID(RArray<TInt> aBookID)
{
for (TInt i = 0; i < aBookID.Count(); i++)
{
m_nContent_ID.Append(aBookID[i]);
}
}
//数据包信息解析函数
void CORCOperBook::DoParse(const TDesC& aBody)
{
TInt nResPonsesSize;
nResPonsesSize = aBody.Length();
HBufC* pStrFileBuf = HBufC::NewL(nResPonsesSize);
pStrFileBuf->Des().Copy(aBody);
TBuf<10> label0;
label0.Append(_L("</RSS>"));
TBuf<10> label1;
label1.Append(_L("</record>"));
TBuf<10> label2;
label2.Append(_L("<fname>"));
TBuf<10> label3;
label3.Append(_L("</fname>"));
TBuf<10> label4;
label4.Append(_L("<hname>"));
TBuf<10> label5;
label5.Append(_L("</hname>"));
TBuf<10> label6;
label6.Append(_L("<mob>"));
TBuf<10> label7;
label7.Append(_L("</mob>"));
TPtr p = pStrFileBuf->Des();
TInt nPos = 0;
for (TInt i = 0; i < pStrFileBuf->Length(); i++)
{
if (label0.Compare(pStrFileBuf->Mid(i, label0.Length())) == 0)
{
break;
}
if (label1.Compare(pStrFileBuf->Mid(i, label1.Length())) == 0)
{
if (nPos == 0)
{
m_pRecordData = HBufC::NewL(i);
m_pRecordData->Des().Copy(pStrFileBuf->Mid(0, i));
m_pfName = HBufC::NewL(m_pRecordData->Find(label3) - m_pRecordData->Find(label2)-label2.Length());
m_phName = HBufC::NewL(m_pRecordData->Find(label5) - m_pRecordData->Find(label4)-label4.Length());
m_pMobel = HBufC::NewL(m_pRecordData->Find(label7) - m_pRecordData->Find(label6)-label6.Length());
//get family name
m_pfName->Des().Copy(m_pRecordData->Mid(m_pRecordData->Find(label2)+label2.Length(),
m_pRecordData->Find(label3) - m_pRecordData->Find(label2)-label2.Length()));
//get home name
m_phName->Des().Copy(m_pRecordData->Mid(m_pRecordData->Find(label4)+label4.Length(),
m_pRecordData->Find(label5) - m_pRecordData->Find(label4)-label4.Length()));
//get mobelnumber
m_pMobel->Des().Copy(m_pRecordData->Mid(m_pRecordData->Find(label6)+label6.Length(),
m_pRecordData->Find(label7) - m_pRecordData->Find(label6)-label6.Length()));
m_sFNameBuf.Append(m_pfName);
m_sLNameBuf.Append(m_phName);
m_sMobelBuf.Append(m_pMobel);
}
else
{
m_pRecordData = HBufC::NewL(i-nPos-1);
m_pRecordData->Des().Copy(pStrFileBuf->Mid(nPos+1, i-nPos-1));
m_pfName = HBufC::NewL(m_pRecordData->Find(label3) - m_pRecordData->Find(label2)-label2.Length());
m_phName = HBufC::NewL(m_pRecordData->Find(label5) - m_pRecordData->Find(label4)-label4.Length());
m_pMobel = HBufC::NewL(m_pRecordData->Find(label7) - m_pRecordData->Find(label6)-label6.Length());
//get family name
m_pfName->Des().Copy(m_pRecordData->Mid(m_pRecordData->Find(label2)+label2.Length(),
m_pRecordData->Find(label3) - m_pRecordData->Find(label2)-label2.Length()));
//get home name
m_phName->Des().Copy(m_pRecordData->Mid(m_pRecordData->Find(label4)+label4.Length(),
m_pRecordData->Find(label5) - m_pRecordData->Find(label4)-label4.Length()));
//get mobelnumber
m_pMobel->Des().Copy(m_pRecordData->Mid(m_pRecordData->Find(label6)+label6.Length(),
m_pRecordData->Find(label7) - m_pRecordData->Find(label6)-label6.Length()));
m_sFNameBuf.Append(m_pfName);
m_sLNameBuf.Append(m_phName);
m_sMobelBuf.Append(m_pMobel);
}
nPos = i;
if(m_pRecordData)
{
delete m_pRecordData;
m_pRecordData = NULL;
}
}
}
delete pStrFileBuf;
pStrFileBuf=NULL;
// CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
// informationNote->ExecuteLD(*(m_sMobelData)[2]);
}
//用户信息数据组包函数
void CORCOperBook::DoAssem()
{
MEMORY_FREE(m_pBodyData);
TBuf<16> label0;
label0.Append(_L("<record>"));
TBuf<16> label1;
label1.Append(_L("</record>"));
TBuf<16> label2;
label2.Append(_L("<fname>"));
TBuf<16> label3;
label3.Append(_L("</fname>"));
TBuf<16> label4;
label4.Append(_L("<hname>"));
TBuf<16> label5;
label5.Append(_L("</hname>"));
TBuf<16> label6;
label6.Append(_L("<mob>"));
TBuf<16> label7;
label7.Append(_L("</mob>"));
TBuf<16> label8;
label8.Append(_L("</RSS>--\n"));
TBuf<32> label9;
label9.Append(_L("<RSS><type>update</type>"));
TBuf<16> label10;
label10.Append(_L("<mobile>"));
TBuf<16> label11;
label11.Append(_L("</mobile>"));
// TBuf<32> label9;
// label9.Append(_L("<RSS>"));
TBuf8<32> sTempBuf;
TBuf8<32> sTempBuf1;
TBuf<32> sFirstName;
TBuf<32> sLastName;
CCnvCharacterSetConverter* converter1 = NULL;
converter1 = CCnvCharacterSetConverter::NewLC();
converter1->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, CEikonEnv::Static()->FsSession());
AppendBodyL(label9);
AppendBodyL(label10);
AppendBodyL(m_sPoneNum);
AppendBodyL(label11);
if (m_nContent_ID.Count() != 0)
{
for (TInt i = 0; i < m_nContent_ID.Count(); i++)
{
TInt nID = m_nContent_ID[i];
AppendBodyL(label0);
AppendBodyL(label2);
// AppendBodyL(*(m_sFirstName)[nID]);
// TBuf8<32> sTempBuf;
// TBuf<32> sFirstName;
// CCnvCharacterSetConverter* converter1 = NULL;
// converter1 = CCnvCharacterSetConverter::NewLC();
// converter1->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, CEikonEnv::Static()->FsSession());
converter1->ConvertFromUnicode(sTempBuf, *(m_sFirstName)[nID]);
sFirstName.Copy(sTempBuf);
AppendBodyL(sFirstName);
// sTmpBuf.Append(sTempBuf);
AppendBodyL(label3);
AppendBodyL(label4);
// AppendBodyL(*(m_sLastName)[nID]);
converter1->ConvertFromUnicode(sTempBuf1, *(m_sLastName)[nID]);
sLastName.Copy(sTempBuf1);
AppendBodyL(sLastName);
AppendBodyL(label5);
AppendBodyL(label6);
AppendBodyL(*(m_sMobelData)[nID]);
AppendBodyL(label7);
AppendBodyL(label1);
}
}
else
{
for (TInt i = 0; i < m_sMobelData.Count(); i++)
{
AppendBodyL(label0);
AppendBodyL(label2);
// AppendBodyL(*(m_sFirstName)[i]);
converter1->ConvertFromUnicode(sTempBuf, *(m_sFirstName)[i]);
sFirstName.Copy(sTempBuf);
AppendBodyL(sFirstName);
AppendBodyL(label3);
AppendBodyL(label4);
// AppendBodyL(*(m_sLastName)[i]);
converter1->ConvertFromUnicode(sTempBuf1, *(m_sLastName)[i]);
sLastName.Copy(sTempBuf1);
AppendBodyL(sLastName);
AppendBodyL(label5);
AppendBodyL(label6);
AppendBodyL(*(m_sMobelData)[i]);
AppendBodyL(label7);
AppendBodyL(label1);
}
}
AppendBodyL(label8);
CleanupStack::PopAndDestroy(converter1);
}
void CORCOperBook::GetDataFromBook()
{
if (m_nType != 2)
{
m_pBookEngine->UpdatePhoneBook(0, m_sDataList);
}
// m_pBookEngine->UpdatePhoneBook(0, m_sDataList);
for (TInt i = 0; i < m_sDataList.Count(); i++)
{
if (m_sDataList[i]->GetFirstName() != NULL)
{
m_sFirstName.Append(m_sDataList[i]->GetFirstName());
}
if (m_sDataList[i]->GetLastName() != NULL)
{
m_sLastName.Append(m_sDataList[i]->GetLastName());
}
if (m_sDataList[i]->GetHomeMobileNumber() != NULL)
{
m_sMobelData.Append(m_sDataList[i]->GetHomeMobileNumber());
}
}
// DoAssem();
m_nType = 2;
}
void CORCOperBook::SetDataToBook()
{
// DoParse();
for (TInt i = 0; i < m_sMobelBuf.Count(); i++)
{
m_pBookInfo = CBookInfo::NewL();
m_pBookInfo->SetItemID(-1);
TBuf<16> m_sFirstNameBuf;
m_sFirstNameBuf.Copy(m_sFNameBuf[i]->Des());
m_pBookInfo->SetFirstName(m_sFirstNameBuf);
TBuf<16> m_sLastNameBuf;
m_sLastNameBuf.Copy(m_sLNameBuf[i]->Des());
m_pBookInfo->SetLastName(m_sLastNameBuf);
TBuf<16> m_sMobelDataBuf;
m_sMobelDataBuf.Copy(m_sMobelBuf[i]->Des());
m_pBookInfo->SetHomeMobileNumber(m_sMobelDataBuf);
m_sDataListBuf.Append(m_pBookInfo);
}
m_pBookEngine->UpdatePhoneBook(1, m_sDataListBuf);
m_nType = 1;
m_sDataListBuf.ResetAndDestroy();
m_sFNameBuf.ResetAndDestroy();
m_sLNameBuf.ResetAndDestroy();
m_sMobelBuf.ResetAndDestroy();
}
void CORCOperBook::ResPonseContent(const TDesC& aResponse)
{
DoParse(aResponse);
}
void CORCOperBook::Notarize()
{
CAknQueryDialog* m_pAlmond = CAknQueryDialog::NewL();
if (m_pAlmond->ExecuteLD(R_ORC_SEL_DIALOG))
{
WaitnoteL();
}
else
{
}
}
//wait
void CORCOperBook::WaitnoteL()
{
CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL();
CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper));
if (! waitNoteWrapper->ExecuteL(R_OCE_SEL_WAITNOTE, *this))
CancelSelUp();
CleanupStack::PopAndDestroy(waitNoteWrapper);
}
void CORCOperBook::DialogDismissedL(TInt /*aButtonId*/)//处理结束
{
}
TBool CORCOperBook::IsProcessDone() const //检查处理是否已经完成
{
// return EFalse;
return (iStepsCompleted == KNumberOfStepsToSelupdate);
}
void CORCOperBook::ProcessFinished()//时间到,没有完成
{
SelUpFail();
iStepsCompleted = 0;
}
void CORCOperBook::StepL()//
{
SelupPartToFile();
// Note that we have completed a step
iStepsCompleted++;
}
void CORCOperBook::CancelSelUp()//取消上传
{
}
void CORCOperBook::SelupPartToFile ()//保存数据是否完成
{
// Use an arbitrary delay to simulate saving part of the game
TRequestStatus status;
TInt delay = 1000000; // 1 second
iTimeWaster.After(status, delay);
User::WaitForRequest(status);
// this->DoAssem();
m_pOperHttp->DoSentBodyPost(m_pBodyData->Des());
}
void CORCOperBook::CompleteSelUp()//全部保存
{
TBuf<16> sCompleteUp;
CEikonEnv::Static()->ReadResource(sCompleteUp,R_ORCER_SEL_COMPLETE);
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(sCompleteUp);
iTimeWaster.Cancel();
}
void CORCOperBook::SelUpFail()
{
TBuf<16> sFailUp;
CEikonEnv::Static()->ReadResource(sFailUp,R_ORCER_SEL_FAIL);
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(sFailUp);
iTimeWaster.Cancel();
}
void CORCOperBook::SetSelUpResult(const TDesC& aResult)
{
TBuf<10> sResult;
sResult.Copy(aResult);
if (0 == sResult.Compare(_L("0")) )
{
this->CompleteSelUp();
}
if (0 == sResult.Compare(_L("1")))
{
this->SelUpFail();
}
}
void CORCOperBook::SetPoneNum(const TDes& aPoneNum)
{
m_sPoneNum.Copy(aPoneNum);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -