logonview.cpp

来自「symbian 3nd 实现短信息收发」· C++ 代码 · 共 268 行

CPP
268
字号
/*
* ============================================================================
*  Name     : CLogonView from CAknView
*  Part of  : Logon
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>

#include <FrMes.rsg>
#include "FrMes.hrh"
#include "LogonView.h"
#include "LogonContainer.h"
#include "akntitle.h"
#include "eikenv.h"
#include "MainInterfaceView.h"
#include "aknnotewrappers.h"
#include "s32file.h"
// #include "FrMesAppUi.h"
// #include "ServerManager.h"


// ================= 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()
    {
    }

// EPOC default constructor can leave.
void CLogonView::ConstructL()
    {
    BaseConstructL(R_LOGON_VIEW);
    }

// Destructor
CLogonView::~CLogonView()
    {
    if (iContainer)
        {
        AppUi()->RemoveFromStack(iContainer);
        }

    delete iContainer;
    }

// ---------------------------------------------------------
// TUid CLogonView::Id()
// Returns Id of the view.
// ---------------------------------------------------------
TUid CLogonView::Id() const
    {
    return KLogonViewId;
    }

// ---------------------------------------------------------
// CLogonView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CLogonView::HandleCommandL(TInt aCommand)
    {
		switch(aCommand)
		{
		case EAknSoftkeyLogon:
			{
				TBuf<16> sTmpName;
				TBuf<8> sTmpPSW;
				iContainer->GetInput(sTmpName,1);
				if(sTmpName.Length()==0)
				{
					TBuf<32> sTmp;
					CEikonEnv::Static()->ReadResource(sTmp, R_QTN_FRMES_ERROR_NAME);
					CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
					informationNote->ExecuteLD(sTmp);
					return;
				}
				else
				{
					iContainer->GetInput(sTmpPSW,2);
					if(sTmpPSW.Length()!=6)
					{
						TBuf<64> sTmp;
						CEikonEnv::Static()->ReadResource(sTmp, R_QTN_FRMES_ERROR_PWD);
						CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
						informationNote->ExecuteLD(sTmp);
						return;
					}
					else
					{
						if (iContainer->IsConnectNet())
						{
							m_pMLoginToNotify->LoginInfoNotify(sTmpName,sTmpPSW,ELogin);
							SendUriAndResponse();
						}
						
					}
				}
			
			}
			break;

			default:
				AppUi()->HandleCommandL(aCommand);
				break;
		}
    }

// ---------------------------------------------------------
// CLogonView::HandleClientRectChange()
// Handles client rect change.
// ---------------------------------------------------------
void CLogonView::HandleClientRectChange()
    {
    if (iContainer)
        {
        iContainer->SetRect(ClientRect());
        }
    }

// ---------------------------------------------------------
// CLogonView::DoActivateL(...)
// Creates the Container class object.
// ---------------------------------------------------------
void CLogonView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
                                    TUid /*aCustomMessageId*/,
                                    const TDesC8& /*aCustomMessage*/)
    {
		iContainer = new (ELeave) CLogonContainer;
		iContainer->SetMopParent(this);
// 		iContainer->ConstructL(ClientRect());
// 		AppUi()->AddToStackL(*this, iContainer);

	//===============================modify cba by wzg===============
		TRect rc;
		rc.SetRect(ClientRect().iTl, TSize(176, 144));
		iContainer->ConstructL(rc);
		AppUi()->AddToStackL(*this, iContainer);

	//modify title by wzg
		TBuf<32> sTmpTitle;
		CEikStatusPane* statusPane = StatusPane();
		CEikonEnv::Static()->ReadResource(sTmpTitle,R_FRMES_VIEW_TITLE_LOGON);
		CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
		titlePane->SetTextL(sTmpTitle);
    }

// ---------------------------------------------------------
// CLogonView::DoDeactivate()
// Deletes the Container class object.
// ---------------------------------------------------------
void CLogonView::DoDeactivate()
{
	if (iContainer)
		{
		AppUi()->RemoveFromStack(iContainer);
		}

	delete iContainer;
	iContainer = NULL;
}

// TBool CLogonView::LogonMethod(TDes& aName,TDes& aCode)
// {
// 	#ifdef __WINS__
// 	_LIT(KFrMesUserFile,"c:\\system\\data\\user.ini");
// 	#else
// 	_LIT(KFrMesUserFile,"c:\\system\\apps\\FrMes\\user.ini");
// 	#endif
// 		
// 	RFs iFession;
// 	User::LeaveIfError(iFession.Connect());
// 	RFileReadStream readStream;
// 	User::LeaveIfError( readStream.Open(iFession, KFrMesUserFile, EFileWrite));
// 	readStream.PushL();
// 	
// 	TBuf<16> sName;
// 	TBuf<8> sCode;
//     readStream >> sName; //读取ini文件中的注册信息
// 	readStream >> sCode;
//     
// 	readStream.Pop();
// 	readStream.Release();
// 	iFession.Close();
// 	if(aName == sName && aCode == sCode)
// 		return ETrue;
// 	else
// 		return EFalse;
// }

// void CLogonView::ServerReNotify(const TDesC & aStatusCode,TInt aModel)
// {
// 	m_nStatus.Copy(aStatusCode);
// 	m_nModel = aModel;
// 	
// 	
// }


void CLogonView::SendUriAndResponse()
{
// 	CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();
// 	iContainer->SetRes(pApp->m_pServerManager->m_nStatusCode);
	if (iContainer->IsWaitLogin())
	{
		if (m_sType.Compare(_L("logi"))==0) 
		{
			TBuf<16> sbuf;
			if (m_sResult.Compare(_L("0")) == 0) 
			{
				AppUi()->ActivateLocalViewL(KMainInterfaceViewId);//登录成功
			}
			else if (m_sResult.Compare(_L("1")) == 0) 
			{			
				CEikonEnv::Static()->ReadResource(sbuf, R_QTN_FRMES_ERROR_ERRCODE);		// 密码错误!
				CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
				informationNote->ExecuteLD(sbuf);  //cancer
			}
			else if (m_sResult.Compare(_L("2")) == 0)
			{
				CEikonEnv::Static()->ReadResource(sbuf, R_QTN_FRMES_ERROR_NONAME);		// 用户名不存在!
				CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
				informationNote->ExecuteLD(sbuf);
			}
		}
	}	
	else
	{
		TBuf<32> error;
		CEikonEnv::Static()->ReadResource(error, R_QTN_FRMES_ERROR_CONNECT);
		CAknInformationNote* pInformationNote = new (ELeave) CAknInformationNote;
		pInformationNote->ExecuteLD(error);
	}
}	

void CLogonView::SetRes(TInt aRes)
{
	iContainer->SetRes(aRes);
}

void CLogonView::SetContent(const TDesC & aType,const TDesC & aResult)
{
	m_sType.Copy(aType);
	m_sResult.Copy(aResult);
}

// End of File

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?