registerview.cpp

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

CPP
243
字号
/*
* ============================================================================
*  Name     : CRegisterView from CAknView
*  Part of  : Register
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

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

#include <FrMes.rsg>
#include "FrMes.hrh"
#include "RegisterView.h"
#include "RegisterContainer.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.
//
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()
{
	BaseConstructL(R_REGISTER_VIEW);
}

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

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

// ---------------------------------------------------------
// CRegisterView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CRegisterView::HandleCommandL(TInt aCommand)
    {
    	switch(aCommand)
		{
		case EFrMesCmdRegisterMenu1:
		{
			TBuf<16> sTmpName;
			TBuf<8> sTmpPSW;
			TBuf<8> STmpConfirm;

			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<32> sTmp;
					CEikonEnv::Static()->ReadResource(sTmp, R_QTN_FRMES_ERROR_PWD);
					CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
					informationNote->ExecuteLD(sTmp);
					//return;
				}
				else
				{
					iContainer->GetInput(STmpConfirm,3);
					if(STmpConfirm.Length()!=6 || STmpConfirm != sTmpPSW )
					{
						TBuf<32> sTmp;
						CEikonEnv::Static()->ReadResource(sTmp, R_QTN_FRMES_ERROR_CPWD);
						CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
						informationNote->ExecuteLD(sTmp);
						//return;
					}
					else
					{
						
						if(iContainer->IsConnectNet())
						{
							//给M类传值
							m_pMLoginToNotify->LoginInfoNotify(sTmpName,sTmpPSW,ERegister);
							//对返回结果进行处理
							SendUriAndResponse();	
						}
						

					}
				}
			}			
		}	
		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);
// 		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_REGISTER);
		CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
		titlePane->SetTextL(sTmpTitle);
    }

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

	delete iContainer;
	iContainer = NULL;
}



void CRegisterView::SendUriAndResponse()
{

	if (iContainer->IsWaitRegister()) //接到返回值
	{
		if (m_sType.Compare(_L("regi"))==0)
		{
			if (m_sResult.Compare(_L("0")) == 0) 
			{
				AppUi()->ActivateLocalViewL(KMainInterfaceViewId); //注册成功
			}
			else if (m_sResult.Compare(_L("1")) == 0) 
			{	
				TBuf<16> sbuf;		
				CEikonEnv::Static()->ReadResource(sbuf, R_QTN_FRMES_ERROR_USEDNAME);   // 用户名已存在!
				CAknInformationNote* pInformationNote = new (ELeave) CAknInformationNote;
				pInformationNote->ExecuteLD(sbuf);
			}
		}
	}	
	else    //未接到返回值
	{
		TBuf<32> error;
		CEikonEnv::Static()->ReadResource(error, R_QTN_FRMES_ERROR_CONNECT);
		CAknInformationNote* pInformationNote = new (ELeave) CAknInformationNote;
		pInformationNote->ExecuteLD(error);
	}
}	

//接收返回值
void CRegisterView::SetRes(TInt aRes)
{
	iContainer->SetRes(aRes);
}

//接收返回的类型值和结果值
void CRegisterView::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 + -
显示快捷键?