📄 registerview.cpp
字号:
/*
* ============================================================================
* Name : CRegisterView from CAknView
* Part of : Hello
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>
#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "RegisterView.h"
#include "RegisterContainer.h"
#include "EveryDayAppUi.h"
#include "LoginView.h"
#include "FungridView.h"
#include <eikmenup.h>
#include <akncontext.h>
#include <akntitle.h>
#include "File.h"
#include <aknnotewrappers.h>
#include <EveryDay.mbg>
#include "HelpView.h"
#include <e32base.h>
#include "XMLparse.h"
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
_LIT(KStatusFormat, "%d: %S");
const TInt KStatusCodeLength = 10;
const TInt KNumberOfSteps = 10;
CRegisterView* CRegisterView::NewL()
{
CRegisterView* self = NewLC();
CleanupStack::Pop(self);
return self;
}
CRegisterView* CRegisterView::NewLC()
{
CRegisterView* self = new (ELeave) CRegisterView;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CRegisterView::CRegisterView()
{
}
// EPOC default constructor can leave.
void CRegisterView::ConstructL()
{
iXML = CXMLparse::NewL();
iTimer.CreateLocal();
BaseConstructL(R_REGISTER_VIEW);
}
// Destructor
CRegisterView::~CRegisterView()
{
if (NULL != iXML)
{
delete iXML;
iXML = NULL;
}
iTimer.Close();
}
// ---------------------------------------------------------
// TUid CRegisterView::Id()
// Returns Id of the view.
// ---------------------------------------------------------
TUid CRegisterView::Id() const
{
return KViewId2;
}
// ---------------------------------------------------------
// CRegisterView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CRegisterView::HandleCommandL(TInt aCommand)
{
switch(aCommand)
{
case ERegisterReg:
{
TBuf<16> strName; //用户名
TBuf<16> strPassword; //密码
TBuf<16> strPswd; //确认密码
TBuf<256> buf;
iContainer->GetName(strName);
iContainer->GetPassWord(strPassword);
iContainer->GetPswd(strPswd);
if (strName.Length()==0) //用户名为空
{
CEikonEnv::Static()->ReadResource(buf, R_QTN_MH_REGISTER_FAIL1);
CAknInformationNote* information = new (ELeave) CAknInformationNote;
information->ExecuteLD(buf);
}
else if (/*strName.Length()!=11 && */strPassword.Compare(strPswd) != 0) //密码不一致
{
CEikonEnv::Static()->ReadResource(buf, R_QTN_MH_REGISTER_FAIL2);
CAknInformationNote* information = new (ELeave) CAknInformationNote;
information->ExecuteLD(buf);
}
else if (strName.Length()!=0 && strName.Length()!=11)//用户名长度不够
{
CEikonEnv::Static()->ReadResource(buf, R_QTN_MH_REGISTER_FAIL5);
CAknInformationNote* information = new (ELeave) CAknInformationNote;
information->ExecuteLD(buf);
}
else if (strName.Length()==11&& strPassword.Length()!=6 && strPassword.Compare(strPswd)==0)//密码不足6位
{
CEikonEnv::Static()->ReadResource(buf, R_QTN_MH_REGISTER_FAIL3);
CAknInformationNote* information = new (ELeave) CAknInformationNote;
information->ExecuteLD(buf);
}
else
{
iXML->Reg(strName, strPassword);
WaitRegResult();
if (iXML->GetResult()==-1)
{
CEikonEnv::Static()->ReadResource(buf,R_QTH_MH_REGISTER_FAIL4);//服务器没有响应
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
}
else if (iXML->GetResult()==0)
{
CEikonEnv::Static()->ReadResource(buf,R_QTH_MH_REGISTER_SUCCESS);//注册成功
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
AppUi()->ActivateLocalViewL(KViewId3); //主界面
}
else if (iXML->GetResult()==1)
{
CEikonEnv::Static()->ReadResource(buf, R_QTH_MH_REGISTER_SUCCESS1);//已经注册
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
AppUi()->ActivateLocalViewL(KViewId1); //已经注册则到登录界面
}
}
break;
}
case EEveryDayCmdHelp:
{
AppUi()->ActivateLocalViewL(KViewId8);//转换到帮助视图
break;
}
default:
{
AppUi()->HandleCommandL(aCommand);
break;
}
}
}
// ---------------------------------------------------------
// CRegisterView::HandleClientRectChange()
// Handles client rect change.
// ---------------------------------------------------------
void CRegisterView::HandleClientRectChange()
{
if (iContainer)
{
iContainer->SetRect(ClientRect());
}
}
// ---------------------------------------------------------
// CRegisterView::DoActivateL(...)
// Creates the Container class object.
// ---------------------------------------------------------
void CRegisterView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
iContainer = new (ELeave) CRegisterContainer;
iContainer->SetMopParent(this);
TRect rc;
rc.SetRect(ClientRect().iTl, TSize(176, 144));
iContainer->ConstructL(rc);
AppUi()->AddToStackL(*this, iContainer);
TBuf<KMaxPath> mbmPath;
#ifdef __WINS__
mbmPath.Copy(_L("Z:\\system\\apps\\EveryDay\\EveryDay.mbm"));
#else
CEveryDayAppUi* pApp = (CEveryDayAppUi*)CEikonEnv::Static()->AppUi();
pApp->GetAppPath(mbmPath);
mbmPath.Append(_L("EveryDay.mbm"));
#endif
CEikStatusPane* statusPane = StatusPane();
CAknContextPane* contextPane = (CAknContextPane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidContext));
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(mbmPath, EMbmEverydayLogin_icon);
CFbsBitmap* bitmapMask = iEikonEnv->CreateBitmapL(mbmPath, EMbmEverydayLogin_mask);
contextPane->SetPicture(bitmap, bitmapMask);
TBuf<32> nTitle;
CEikonEnv::Static()->ReadResource(nTitle, R_QTN_MH_REGISTER_TITLE);
CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
titlePane->SetTextL(nTitle);
}
// ---------------------------------------------------------
// CRegisterView::DoDeactivate()
// Deletes the Container class object.
// ---------------------------------------------------------
void CRegisterView::DoDeactivate()
{
if (iContainer)
{
AppUi()->RemoveFromStack(iContainer);
delete iContainer;
iContainer = NULL;
}
}
void CRegisterView::DialogDismissedL(TInt )
{
}
TBool CRegisterView::IsProcessDone() const // 在服务器得到响应之前或者指定时间之前,False,否则True
{
if((iXML->GetResult()==-1)&&(iStep!=KNumberOfSteps))
{
return EFalse;
}
else
{
return ETrue;
}
}
void CRegisterView::ProcessFinished()
{
CompleteReg();
iStep = 0;
}
void CRegisterView::StepL()
{
WaitPart();
iStep++;
}
void CRegisterView::WaitPart()
{
TRequestStatus status;
TInt delay = 1000000; // 1 second
iTimer.After(status, delay);
User::WaitForRequest(status);
}
void CRegisterView::WaitRegResult()
{
CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL();
CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper));
waitNoteWrapper->ExecuteL(R_WAITNOTE_REGISTER_NOTE, *this);
CleanupStack::PopAndDestroy(waitNoteWrapper);
}
void CRegisterView::CompleteReg()
{
iTimer.Cancel();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -