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

📄 mtmsexampleengine.cpp

📁 个人手机助理套件:包含1、记事本(备忘录)、名片夹、名片夹的上传下载(异地备份)、短消息模块
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**
* 
* @brief Definition of CMtmsExampleEngine
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "MtmsExampleEngine.h"

// System includes
#include <aknutils.h>       // CompleteWithAppPath()
#include <f32file.h>        // TParsePtrC
#include <mmsclient.h>      // CMmsClientMtm
#include <mmsconst.h>       // KMmsIso10646Ucs2 etc.
#include <mtclreg.h>        // CClientMtmRegistry 
#include <mtmdef.h>         // KMsvMessagePartBody etc.
#include <smsclnt.h>        // CSmsClientMtm
#include <smscmds.h>        // ESmsMtmCommandScheduleCopy
#include <smuthdr.h>        // CSmsHeader
#include <smutset.h>        // CSmsSettings
#include <txtrich.h>        // CRichText

// String constants
_LIT(KSMSBody, "Example SMS body text");
_LIT(KMMSSubject, "Penguins");
_LIT(KMMSText, "Look! Some penguins!");
_LIT(KMMSTextFilename, "hello.txt");


// Filenames
_LIT(KMMSImageFilename, "image.jpg");
_LIT(KMMSSmilFilename,  "simple.smil");


// ================= MEMBER FUNCTIONS =======================


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

CMtmsExampleEngine::CMtmsExampleEngine(MMtmsExampleEngineObserver& aObserver)
: CActive(0),
  iObserver(aObserver),
  iReady(EFalse),
  iSmsId(KMsvNullIndexEntryId),
  iMmsId(KMsvNullIndexEntryId)
{
}

/**
* Symbian OS 2nd phase constructor.
*/  
void CMtmsExampleEngine::ConstructL()
{
    CActiveScheduler::Add(this);

    // Create iEntrySelection
    iEntrySelection = new (ELeave) CMsvEntrySelection;

    // Create CMsvSession
    iSession = CMsvSession::OpenAsyncL(*this);
    // New session is opened asynchronously
    // CompleteConstructL() is called when async call is finished.
}


void CMtmsExampleEngine::CompleteConstructL()
{
    // Construct the client MTM registry
    iMtmReg = CClientMtmRegistry::NewL(*iSession);

    // Obtain MTMs from the MTM registry
    iSmsMtm = static_cast<CSmsClientMtm*>(iMtmReg->NewMtmL(KUidMsgTypeSMS));
    iMmsMtm = static_cast<CMmsClientMtm*>(iMtmReg->NewMtmL(KUidMsgTypeMultimedia));

    iReady = ETrue;
}

/**
* Destructor.
*/  
CMtmsExampleEngine::~CMtmsExampleEngine()
{
    Cancel();
    delete iOp;
    delete iEntrySelection;
    delete iSmsMtm;
    delete iMmsMtm;
    delete iMtmReg;
    delete iSession;
}


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


void CMtmsExampleEngine::RunL()
{
    iObserver.HandleMessageSentL(iStatus.Int());
}


//
// SMS Functions
//

void CMtmsExampleEngine::CreateSentSMSL( const TDesC& aAddress, const TDesC& aContent )
{
    // 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(KMsvSentEntryId);
    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, aContent);
    indexEntry.iDescription.Set(aContent);
	
    // Add addressee
    iSmsMtm->AddAddresseeL(aAddress);
    indexEntry.iDetails.Set(aAddress);
	
    // Update index entry
    iSmsMtm->Entry().ChangeL(indexEntry);
	
    // Update store entry
    iSmsMtm->SaveMessageL();

	// Update the index entry
//    TMsvEntry indexEntry = iSmsMtm->Entry().Entry();
    indexEntry.SetInPreparation(EFalse);
    indexEntry.SetSendingState(KMsvSendStateWaiting);
    iSmsMtm->Entry().ChangeL(indexEntry);
}

void CMtmsExampleEngine::CreateInBoxSMSL( const TDesC& aAddress, const TDesC& aContent )
{
    // 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(KMsvGlobalInBoxIndexEntryId);
    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, aContent);
    indexEntry.iDescription.Set(aContent);
	
    // Add addressee
    iSmsMtm->AddAddresseeL(aAddress);
    indexEntry.iDetails.Set(aAddress);
	
    // Update index entry
    iSmsMtm->Entry().ChangeL(indexEntry);
	
    // Update store entry
    iSmsMtm->SaveMessageL();

	// Update the index entry
   // TMsvEntry indexEntry = iSmsMtm->Entry().Entry();
    indexEntry.SetInPreparation(EFalse);
    indexEntry.SetSendingState(KMsvSendStateWaiting);
    iSmsMtm->Entry().ChangeL(indexEntry);
}

void CMtmsExampleEngine::CreateDraftSMSL( const TDesC& aAddress, const TDesC& aContent )
{
    // 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, aContent);
    indexEntry.iDescription.Set(aContent);

    // Add addressee
    iSmsMtm->AddAddresseeL(aAddress);
    indexEntry.iDetails.Set(aAddress);

    // Update index entry
    iSmsMtm->Entry().ChangeL(indexEntry);

    // Update store entry
    iSmsMtm->SaveMessageL();

	// Update the index entry
//    TMsvEntry indexEntry = iSmsMtm->Entry().Entry();
    indexEntry.SetInPreparation(EFalse);
    indexEntry.SetSendingState(KMsvSendStateWaiting);
    iSmsMtm->Entry().ChangeL(indexEntry);
}


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


void CMtmsExampleEngine::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;

⌨️ 快捷键说明

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