⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmessageengine.cpp

📁 symbian uiq 例子代码,功能包括文件断点续传、编辑通讯录、后台短信回复等
💻 CPP
字号:
/*
 * Copyright (c) 2007,苏州丰达
 * All rights reserved.
 * 版权所有(C)2007-2008 苏州丰达 
 * 公司地址:中国,江苏省苏州市 
 * 网址:http://www.
 *
 * 文件名称:CHTTPClientEngine.cpp
 * 摘 要:用于信息发送
 *
 * 产品版本:彩视 1.0
 *
 * 作 者:xxxx
 * 创建日期:xxxxx
 * 负责人:xxxxx
 *
 * 修改者:司治国
 * 修改日期:2008.1.17
 *
 * 编译器或环境等描述:uiqsdk2.1
 * 适用于VC2003+symbian 7.x的环境开发。
 *
 **/
 
#include <MmsUtils.h>

#include "CMessageEngine.h"

CMessageEngine::CMessageEngine(MImageHandlerCallback *aObserver) : CActive(EPriorityStandard),
                                     iObserver(aObserver),
                                     iReady(EFalse),
                                     iSmsId(KMsvNullIndexEntryId)
{
}

void CMessageEngine::ConstructL()
{
    User::LeaveIfError(iTimer.CreateLocal());   // Initialize timer
    CActiveScheduler::Add(this);                // Add to scheduler

	// Create iEntrySelection
	iEntrySelection = new (ELeave) CMsvEntrySelection;
	// Create CMsvSession
	iSession = CMsvSession::OpenAsyncL(*this);	
}

CMessageEngine::~CMessageEngine()
{
    Cancel();
	delete iOp;
	iTimer.Close();
	if (iEntrySelection)
	{
		delete iEntrySelection;
		iEntrySelection = NULL;
	}
	if (iSmsMtm)
	{
		delete iSmsMtm;
		iSmsMtm = NULL;
	}
	if (iMtmReg)
	{
		delete iMtmReg;
		iMtmReg = NULL;
	}
	if (iSession)
	{
		delete iSession;
		iSession = NULL;
	}
	if (iAddress)
	{
		delete iAddress;
		iAddress = NULL;
	}
	if (iBodyContent)
	{
		delete iBodyContent;
		iBodyContent = NULL;
	}
}

void CMessageEngine::DoCancel()
{
    iTimer.Cancel();
	if (iOp)
	{
		iOp->Cancel();
		delete iOp;
		iOp = NULL;
	}
}

void CMessageEngine::StartL(TTimeIntervalMicroSeconds32 aDelay)
{
    Cancel();                       // Cancel any request, just to be sure
    iState = EUninitialized;
    iTimer.After(iStatus, aDelay);  // Set for later
    SetActive();                    // Tell scheduler a request is active
}

void CMessageEngine::RunL()
{
    if (iState == EUninitialized)
    {
        // Do something the first time RunL() is called
        iState = EInitialized;
    }
    else if (iState != EError)
    {
        // Do something
    }    
	iObserver->OperationComplete(1);
}

void CMessageEngine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny *aArg1, TAny *aArg2, TAny *aArg3)
{
    switch (aEvent)
    {
            // This event tells us that the session has been opened
        case EMsvServerReady:
            CompleteConstructL();
            break;
        default:            
            break;
    }
}

void CMessageEngine::CompleteConstructL()
{
	// Construct the client MTM registry
	iMtmReg = CClientMtmRegistry::NewL(*iSession);
	// Obtain MTMs from the MTM registry	
	iSmsMtm = static_cast<CSmsClientMtm*>(iMtmReg->NewMtmL(KUidMsgTypeSMS));		
}

CMessageEngine * CMessageEngine::NewL( MImageHandlerCallback *aObserver )
{
	CMessageEngine *self = new (ELeave) CMessageEngine(aObserver);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
}

void CMessageEngine::CreateDraftSMSL()
{
	// Set attributes on index entry
	TMsvEntry indexEntry;
	indexEntry.SetInPreparation(ETrue);
	indexEntry.iMtm = KUidMsgTypeSMS;
	indexEntry.iType = KUidMsvMessageEntry;
	indexEntry.iServiceId = iSmsMtm->ServiceId();
	indexEntry.iDate.HomeTime();

	// Create entry from this index entry
	iSmsMtm->SwitchCurrentEntryL(KMsvDraftEntryId);
	iSmsMtm->Entry().CreateL(indexEntry);

	// Set the MTM's active context to the new message
	iSmsId = indexEntry.Id();
	iSmsMtm->SwitchCurrentEntryL(iSmsId);

	// Add body
	CRichText &body = iSmsMtm->Body();
	body.Reset();	
	body.InsertL(0, *iBodyContent);
	indexEntry.iDescription.Set(*iBodyContent);

	// Add addressee
	iSmsMtm->AddAddresseeL(*iAddress);
	indexEntry.iDetails.Set(*iAddress);
	// Update index entry
	iSmsMtm->Entry().ChangeL(indexEntry);
	// Update store entry
	iSmsMtm->SaveMessageL();
}

TBool CMessageEngine::ValidateSMS()
{
	TMsvPartList msgCheckParts = KMsvMessagePartBody |
		KMsvMessagePartRecipient |
		KMsvMessagePartOriginator |
		KMsvMessagePartDate;
	TMsvPartList msgFailParts = iSmsMtm->ValidateMessage(msgCheckParts);
	return msgFailParts == KMsvMessagePartNone;
}

void CMessageEngine::SendSMSL()
{
	// Set context to the SMS message
	iSmsMtm->SwitchCurrentEntryL(iSmsId);
	// Load the message
	iSmsMtm->LoadMessageL();
 	//Set the SMS service centre address
 	CSmsSettings &settings = iSmsMtm->ServiceSettings();
 	const TInt numSCAddresses = settings.NumSCAddresses();
	if (numSCAddresses > 0)
	{
		CSmsNumber *serviceCentreNumber = NULL;
		// Get the default SC address, if valid, Otherwise just get the first from the list.
		if ((settings.DefaultSC() >= 0) && (settings.DefaultSC() < numSCAddresses))
		{
			serviceCentreNumber = &(settings.SCAddress(settings.DefaultSC()));
		}
		else
		{
			serviceCentreNumber = &(settings.SCAddress(0));
		}

		iSmsMtm->SmsHeader().SetServiceCenterAddressL(serviceCentreNumber->Address());
	}
	else
	{
		// report panic, programming error - there should never be a missing service number,
	}
	// Save the message
	iSmsMtm->SaveMessageL();
	// Update the index entry
	TMsvEntry indexEntry = iSmsMtm->Entry().Entry();
	indexEntry.SetInPreparation(EFalse);
	indexEntry.SetSendingState(KMsvSendStateWaiting);
	iSmsMtm->Entry().ChangeL(indexEntry);

	// Now send
	Cancel(); // prepare iOp for use
	iEntrySelection->Reset();
	iEntrySelection->AppendL(iSmsId);
	TBuf8<1> dummyParams;
	iOp = iSmsMtm->InvokeAsyncFunctionL(ESmsMtmCommandScheduleCopy, *iEntrySelection, dummyParams, iStatus);
	SetActive();
}

/**
 *	发送包月消息
 **/
void CMessageEngine::SendMemberMsg(const TDesC* aServer, const TDesC* aBody)
{
	iAddress = HBufC::NewL(256);
	iAddress->Des().Append(*aServer);
	iBodyContent = HBufC::NewL(512);
	iBodyContent->Des().Append(*aBody);
	//发送信息
	CreateDraftSMSL();
	if (!ValidateSMS())
	{
		//iEikonEnv->AlertWin(_L("wrong"), _L("Message is invalid"));
	}
	else
	{
		SendSMSL();
	}
}
//end file

⌨️ 快捷键说明

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