📄 logonview.cpp
字号:
/*
* ============================================================================
* Name : CLogonView from CAknView
* Part of : Logon
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>
#include <FairyLand.rsg>
#include "FairyLand.hrh"
#include "LogonView.h"
#include "LogonContainer.h"
#include "Registerview.h"
#include "MainHelpview.h"
#include "GridView.h"
#include <FairyLand.mbg> //for mbm
#include <akncontext.h> //for CAknContextPane
#include <akntitle.h> //for CAknTitlePane
#include "FairyLandAppUi.h" //for CLDC21AppUi
#include <aknnotewrappers.h>
#include <eikmenup.h> //for CEikMenuPane
#include <eikmenub.h> // for CEikMenuBar
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CLogonView* CLogonView::NewL()
{
CLogonView* self = NewLC();
CleanupStack::Pop(self);
return self;
}
CLogonView* CLogonView::NewLC()
{
CLogonView* self = new (ELeave) CLogonView;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CLogonView::CLogonView()
{
pName = NULL;
pPassWord = NULL;
}
// EPOC default constructor can leave.
void CLogonView::ConstructL()
{
BaseConstructL(R_LOGON_VIEW);
}
// Destructor
CLogonView::~CLogonView()
{
if (pName!=NULL)
{
delete pName;
}
if (pPassWord!=NULL)
{
delete pPassWord;
}
}
// ---------------------------------------------------------
// TUid CWorldView::Id()
// Returns Id of the view.
// ---------------------------------------------------------
TUid CLogonView::Id() const
{
return KViewId2;
}
// ---------------------------------------------------------
// CLogonView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CLogonView::HandleCommandL(TInt aCommand)
{
switch(aCommand)
{
case EFairyLandCmdLogon:
{
HBufC* pStrName = HBufC::NewL(128);
TBuf<16> strName;
iContainer->GetLogonName(strName);
TPtr pTprStr1(pStrName->Des());
pTprStr1.Copy(strName);
HBufC* pStrPassWord = HBufC::NewL(128);
TBuf<16> strPassWord;
iContainer->GetLogonPassWord(strPassWord);
TPtr pTprStr2(pStrPassWord->Des());
pTprStr2.Copy(strPassWord);
if( pStrName->Des() != pName->Des() || pStrPassWord->Des() != pPassWord->Des() )
{
delete pStrName;
delete pStrPassWord;
TBuf<32> LogonUserWarn;
CEikonEnv::Static()->ReadResource(LogonUserWarn, R_QTN_MH_LOGON_WARN);
//显示读取的文件内容
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(LogonUserWarn);
}
else
{
delete pStrName;
delete pStrPassWord;
AppUi()->ActivateLocalViewL(KViewId3);
}
break;
}
case EFairyLandCmdRegister:
{
AppUi()->ActivateLocalViewL(KViewId1);
break;
}
case EFairyLandCmdHelp: //EMyRegisterCmdChageView:
{
AppUi()->ActivateLocalViewL(KViewId9);
break;
}
default:
{
AppUi()->HandleCommandL(aCommand);
break;
}
}
}
// ---------------------------------------------------------
// CWorldView::HandleClientRectChange()
// Handles client rect change.
// ---------------------------------------------------------
void CLogonView::HandleClientRectChange()
{
if (iContainer)
{
iContainer->SetRect(ClientRect());
}
}
// ---------------------------------------------------------
// CWorldView::DoActivateL(...)
// Creates the Container class object.
// ---------------------------------------------------------
void CLogonView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
ReadFileFromStreamL();
iContainer = new (ELeave) CLogonContainer;
iContainer->SetMopParent(this);
TRect rc;
rc.SetRect(ClientRect().iTl, TSize(176, 144));
iContainer->ConstructL(rc,pName);
AppUi()->AddToStackL(*this, iContainer);
TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
pathMbm.Copy(_L("z:\\system\\apps\\FairyLand\\FairyLand.mbm"));
#else
CFairyLandAppUi* pApp = (CFairyLandAppUi*)CEikonEnv::Static()->AppUi();
pApp->GetAppPath(pathMbm);
pathMbm.Append(_L("FairyLand.mbm"));
#endif
CEikStatusPane* statusPane = StatusPane();
//set icon
CAknContextPane* contextPane = (CAknContextPane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidContext));
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(pathMbm, EMbmFairylandLogon);
CFbsBitmap* bitmapMask = iEikonEnv->CreateBitmapL(pathMbm, EMbmFairylandLogon_mask);
//contextPane->SetPicture(bitmap);
contextPane->SetPicture(bitmap, bitmapMask);
//load chinese words
TBuf<32> LogonTitle;
CEikonEnv::Static()->ReadResource(LogonTitle, R_QTN_MH_LOGON);
CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
titlePane->SetTextL(LogonTitle);
// show
// CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
// informationNote->ExecuteLD(LogonTitle);
}
// ---------------------------------------------------------
// CLogonView::DoDeactivate()
// Deletes the Container class object.
// ---------------------------------------------------------
void CLogonView::DoDeactivate()
{
if (iContainer)
{
AppUi()->RemoveFromStack(iContainer);
delete iContainer;
iContainer = NULL;
}
}
//读取流文件内容
void CLogonView::ReadFileFromStreamL()
{
//创建会话
RFs iFession;
User::LeaveIfError(iFession.Connect());
RFileReadStream readStream;
//以读取流文件的方式打开流文件
//对应模拟器中路径:C:\Symbian\7.0s\Series60_v21_C\Epoc32\wins\c\testStream.str
TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
pathMbm.Copy(_L("c:\\testStream.str"));
#else
CFairyLandAppUi* pApp = (CFairyLandAppUi*)CEikonEnv::Static()->AppUi();
pApp->GetAppPath(pathMbm);
pathMbm.Append(_L("testStream.str"));
#endif
if( KErrNone != readStream.Open(iFession,pathMbm, EFileRead))
{
//若文件打开失败,则先关闭会话再返回
iFession.Close();
return;
}
//压栈
readStream.PushL();
//读取流长度
TInt nLen1 = 0;
nLen1 = readStream.ReadInt32L();
pName = HBufC::NewL(nLen1);
readStream >> pName->Des();
TInt nLen2 = 0;
nLen2 = readStream.ReadInt32L();
pPassWord = HBufC::NewL(nLen2);
readStream >> pPassWord->Des();
//弹栈
readStream.Pop();
//释放
readStream.Release();
//关闭会话
iFession.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -