?? registerview.cpp
字號(hào):
/*
* ============================================================================
* 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; //確認(rèn)密碼
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)//用戶名長(zhǎng)度不夠
{
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);//服務(wù)器沒有響應(yīng)
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
}
else if (iXML->GetResult()==0)
{
CEikonEnv::Static()->ReadResource(buf,R_QTH_MH_REGISTER_SUCCESS);//注冊(cè)成功
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);//已經(jīng)注冊(cè)
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(buf);
AppUi()->ActivateLocalViewL(KViewId1); //已經(jīng)注冊(cè)則到登錄界面
}
}
break;
}
case EEveryDayCmdHelp:
{
AppUi()->ActivateLocalViewL(KViewId8);//轉(zhuǎn)換到幫助視圖
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 // 在服務(wù)器得到響應(yīng)之前或者指定時(shí)間之前,F(xiàn)alse,否則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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -