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

📄 smsexamplemtmsengine.cpp

📁 symbian平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    indexEntry.SetInPreparation(EFalse);
	// Sets the sending state
    indexEntry.SetSendingState(KMsvSendStateWaiting);
    iSmsMtm->Entry().ChangeL(indexEntry);

    // Time to send the message
    Cancel(); // prepare iMsvOper for use
	iEntrySelection->Reset();
	iEntrySelection->AppendL(iSmsId);

    TBuf8<1> dummyParam;
	// There is also InvokeSyncFunctionL which is synchronous.
	iMsvOper = iSmsMtm->InvokeAsyncFunctionL(ESmsMtmCommandScheduleCopy, *iEntrySelection, dummyParam, iStatus);
    SetActive();
    }

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::MoveToFolderL( TMsvId aMessageId,  TMsvId aFolder )
//
// Move message to folder. Notice that the iSmsMtm points to the parent, not
// to the message itself. If you move messages from inbox to drafts, those
// messages cannot be edited because their complete flag is true.
// ----------------------------------------------------------------------------
void CSMSExampleMtmsEngine::MoveToFolderL( TMsvId aMessageId,  TMsvId aFolder )
	{
	iSmsMtm->SwitchCurrentEntryL( aMessageId );
	TMsvSelectionOrdering selection;
	selection.SetShowInvisibleEntries(ETrue);
	CMsvEntry* parentEntry = CMsvEntry::NewL( iSmsMtm->Session(), 
		iSmsMtm->Entry().Entry().Parent(), selection );
	CleanupStack::PushL(parentEntry);
	// Move the message
	parentEntry->MoveL( aMessageId, aFolder );
	CleanupStack::PopAndDestroy(); // parentEntry
	}

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::DeleteMessageL( TMsvId aMessageId )
//
// Delete message from a folder. Notice that the iSmsMtm points to the parent, 
// not to the message itself.
// ----------------------------------------------------------------------------
void CSMSExampleMtmsEngine::DeleteMessageL( TMsvId aMessageId )
	{
	iSmsMtm->SwitchCurrentEntryL( aMessageId );
	TMsvId parent = iSmsMtm->Entry().Entry().Parent();

	iSmsMtm->SwitchCurrentEntryL( parent );
	iSmsMtm->Entry().DeleteL( aMessageId );
	}

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::GetMessageAddressL( TMsvId aMessageId, 
//										      TDes& aAddress )
//
// Get originator address from SmsHeader.
// ----------------------------------------------------------------------------
void CSMSExampleMtmsEngine::GetMessageAddressL( TMsvId aMessageId, TDes& aAddress )
	{
	iSmsMtm->SwitchCurrentEntryL( aMessageId );	
	
	// Remember to load before using the SmsHeader
	iSmsMtm->LoadMessageL();

	CSmsHeader&	header = iSmsMtm->SmsHeader();

	aAddress.Append( header.FromAddress() );
	// Other possibility is this: (It's little bit faster than the previous one).
	// aAddress.Append( iSmsMtm->Entry().Entry().iDetails );
	}

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::GetMessageL( TMsvId aMessageId, TDes& aMessage)
//
// Get message body from entry storage (CMsvStore). CMsvStore stores whole
// message, not summary information ( see GetMessageIndexBodyTextL() ).
// ----------------------------------------------------------------------------
TBool CSMSExampleMtmsEngine::GetMessageL( TMsvId aMessageId, TDes& aMessage)
	{
	iSmsMtm->SwitchCurrentEntryL( aMessageId );

	if ( iSmsMtm->Entry().HasStoreL() ) 
		{
		// SMS message is stored inside Messaging store.
		CMsvStore* store = iSmsMtm->Entry().ReadStoreL();
		CleanupStack::PushL(store);
	
		if (store->HasBodyTextL())
			{
			CRichText* richText = CRichText::NewL(
			                  CEikonEnv::Static()->SystemParaFormatLayerL(),
			                  CEikonEnv::Static()->SystemCharFormatLayerL());
			richText->Reset();
			CleanupStack::PushL(richText);

			// Get the SMS body text.
			store->RestoreBodyTextL(*richText);
			const TInt length = richText->DocumentLength();
			TBuf<KMessageBodySize> message;

			// Check length because message is read to limited size TBuf.
			if ( length >= KMessageBodySize ) 
				{
				message.Append( richText->Read(0, KMessageBodySize -1) );
				}
			else 
				{
				message.Append( richText->Read(0, length) );
				}

			aMessage.Append( message );

			CleanupStack::PopAndDestroy(richText);
			}
		CleanupStack::PopAndDestroy(store);
		}
	else
		{
		return EFalse;
		}

	return ETrue;
	}
	
// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::GetMessageIndexBodyTextL( TMsvId aMessageId, TDes& aMessage)
//
// Get beginning of message's body. Index entry is just a summary of the whole
// message.
// ----------------------------------------------------------------------------
TBool CSMSExampleMtmsEngine::GetMessageIndexBodyTextL( TMsvId aMessageId, TDes& aMessage)
	{
	iSmsMtm->SwitchCurrentEntryL( aMessageId );

	aMessage.Append(iSmsMtm->Entry().Entry().iDescription );
	return ETrue;
	}
	

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::CopyMessageL( TMsvId aMessageId, TMsvId aFolder )
//
// Copy message to another folder. 
// ----------------------------------------------------------------------------
void CSMSExampleMtmsEngine::CopyMessageL( TMsvId aMessageId, TMsvId aFolder )
	{
	iSmsMtm->SwitchCurrentEntryL( aMessageId );
	TMsvSelectionOrdering selection;
	selection.SetShowInvisibleEntries(ETrue);
	CMsvEntry* parentEntry = CMsvEntry::NewL( iSmsMtm->Session(), 
		iSmsMtm->Entry().Entry().Parent(), selection );
	CleanupStack::PushL(parentEntry);
	// iSmsMtm points to the parent
	parentEntry->CopyL( aMessageId, aFolder );
	CleanupStack::PopAndDestroy(); // parentEntry
	}

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::GetMessageIds()
//
// ids of messages that has been got using ListMessagesL
// ----------------------------------------------------------------------------
RArray<TMsvId>* CSMSExampleMtmsEngine::GetMessageIds()
	{
	return iIdArray;
	}

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::GetFolderSMSMessageInformation( TMsvId aFolderID, 
//														   CDesCArrayFlat* aAddresses, 
//														   CDesCArrayFlat* aMessages )
//
// Get all folder's children which are SMS messages.
// Note that the folder can contain .sis files which have to be filtered out.
// IdArray is made here because it makes finding the SMS easier later on.
// ----------------------------------------------------------------------------
void CSMSExampleMtmsEngine::GetFolderSMSMessageInformation( TMsvId aFolderID, 
														   CDesCArrayFlat*& aAddresses, 
														   CDesCArrayFlat*& aMessages )
	{

	iSmsMtm->SwitchCurrentEntryL( aFolderID );
	CMsvEntry& entry = iSmsMtm->Entry();

	// Remember to delete this entry after no longer needed!
	// Only intrested in messages. Filter out service etries.
	CMsvEntrySelection* entries = entry.ChildrenWithMtmL(KUidMsgTypeSMS);

	CDesCArrayFlat* arrayAddr = new (ELeave) CDesCArrayFlat(10);
	CDesCArrayFlat* arrayMsgBody = new (ELeave) CDesCArrayFlat(10);

	iIdArray = new (ELeave) RArray<TMsvId>;

	for (TInt i = 0; i < entries->Count(); i++ ) 
		{
		TBuf<KMessageBodySize> body;
		TBuf<KMessageAddressLength> address;
		
		// Append only SMS messages, .sis files etc. are disregarded.
		// Take only beginning of SMS body, because listbox only shows beginning
		// of message.
		if ( GetMessageIndexBodyTextL( (*entries)[i], body ) ) // SMS body
			{
			iIdArray->Append( (*entries)[i] );
			arrayMsgBody->AppendL ( body );	

			// Recipient address
			GetMessageAddressL( (*entries)[i], address );
			arrayAddr->AppendL ( address );
			}
		}
		
	// Delete entries. This is your responsibility.
	entries->Reset();
	delete entries;
	entries = 0;

	aAddresses = arrayAddr; // address array
	aMessages = arrayMsgBody; // msg body array
	}

// ----------------------------------------------------------------------------
// CSMSExampleMtmsEngine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* 
//	/*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
//
// Tells when the session has been opened
// ----------------------------------------------------------------------------
void CSMSExampleMtmsEngine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
    {
    switch (aEvent)
        {
        // This event tells us that the session has been opened
        case EMsvServerReady:
            CreateMtmClientL();
            break;

        default:
            // do nothing
            break;
        }
    }

⌨️ 快捷键说明

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