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

📄 mmsdemo1engine.cpp

📁 这是一个在symbian操作系统下编写的发送彩信的程序。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
* ============================================================================
*  Name     : MMSDemo1Engine from MMSDemo1Engine.cpp
*  Part of  : MMSDemo1
*  Created  : 28.10.2002 by Forum Nokia
*  Implementation notes:
*     MMS engine source file.
*  Version  : 1.0 aaumala
*  Copyright: Nokia Corp. 2003
* ============================================================================
*/

#include <mtclreg.h>                        // for CClientMtmRegistry 
#include <msvstd.h>                         // for TMsvId
#include <mmsclient.h>                      // for CMmsClientMtm
#include <mtmdef.h>                         // for KMsvMessagePartDescription etc.

#include "MMSDemo1Engine.h"                 // own definitions


// Own constants

// define own short names for the standard messaging folders
const TMsvId KInbox = KMsvGlobalInBoxIndexEntryId;
const TMsvId KOutbox = KMsvGlobalOutBoxIndexEntryId;
const TMsvId KDrafts = KMsvDraftEntryId;
const TMsvId KSent = KMsvSentEntryId;

//
// CMMSDemo1Engine class
//

// public methods
/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::NewL()

    Description: Static 2-phase construction.

    Return value: CMMSDemo1Engine pointer

-------------------------------------------------------------------------------
*/
EXPORT_C CMMSDemo1Engine* CMMSDemo1Engine::NewL()
    {
    CMMSDemo1Engine* self = NewLC();
    CleanupStack::Pop(); // self
    return self;
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::NewLC()

    Description: Static 2-phase construction. Reserves memory for a new object,
                 the caller must take care of releasing the memory.

    Return value: CMMSDemo1Engine pointer (is left into CleanupStack)

-------------------------------------------------------------------------------
*/
EXPORT_C CMMSDemo1Engine* CMMSDemo1Engine::NewLC()
    {
    CMMSDemo1Engine* self = new(ELeave) CMMSDemo1Engine();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::~CMMSDemo1Engine()

    Description: Destructor.

    Return value: N/A

-------------------------------------------------------------------------------
*/ 
CMMSDemo1Engine::~CMMSDemo1Engine()
    {
    // the pointers must be released in the correct order
    // (MTM before registry and the session must be the last to delete)
        
    if(iMmsMtm)
        delete iMmsMtm;

    if(iMtmReg)
        delete iMtmReg;
    
    if(iSession)
        delete iSession;

    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::CreateMessageL()

    Description: Create a new multimedia message. This method takes no
                 parameters, default values are used for the parent folder and 
                 service settings.

                 Member data is set to new values by this method.

    Return value: N/A 

-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::CreateMessageL() 
    {
    
    // By default create messages in the Drafts folder
    CMsvEntry* entry = NULL;
    entry = iSession->GetEntryL( KMsvDraftEntryId );
    CleanupStack::PushL(entry);
    iMmsMtm->SwitchCurrentEntryL( entry->EntryId() );
    // Create new, using Default MM Settings
    iMmsMtm->CreateMessageL( iMmsMtm->DefaultSettingsL() );


// message is not ready until a recipient has been set ->   iMessageReady = ETrue;
    CleanupStack::PopAndDestroy(); // entry
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::CreateReplyL()

    Description: Creating a reply message entry from a message that is passed 
                 in as a parameter. The forward message
                 entry is left as the current entry of the MTM.
                 The context is being switched here so all unsaved changes to 
                 an old entry are lost!

                 This implementation creates a reply to the sender only, use
                 KMsvMessagePartRecipient in PartList specification to create 
                 a reply-to-all. The sender of the original message is set as 
                 the recipient of this message.

    Return value: ETrue/EFalse if the operation was successfull or not

-------------------------------------------------------------------------------
*/
TBool CMMSDemo1Engine::CreateReplyL(TMsvId aMessageEntry)
    {
    iMessageReady = EFalse;
    // Set the given message as the current entry
    iMmsMtm->SwitchCurrentEntryL( aMessageEntry );

    // then create a forward message from the current msg.
    TMsvId parentId = KDrafts;                              // create fwd. msg. into Drafts folder

    TMsvPartList PartList(KMsvMessagePartDescription);      // including subject field
    CMsvOperationWait* wait = CMsvOperationWait::NewLC();   // left in CS
    CMsvOperation* oper = iMmsMtm->ReplyL(parentId, PartList, wait->iStatus);
    CleanupStack::PushL(oper);
    wait->Start();
    CActiveScheduler::Start();

    // see if any errors occured
    if(oper->iStatus.Int() != KErrNone)
        {
        // failed
        return EFalse;
        }

    // we can get the entry id from the progress info of the operation
    TPckgBuf<TMsvId> pkg;
    pkg.Copy(oper->ProgressL());
    TMsvId progress = 0;
    progress = pkg();

	// Load created message to iMmsMtm
    LoadMessageL(progress);

    CleanupStack::PopAndDestroy(2);  // wait, oper
    iMessageReady = ETrue;
    return ETrue;
    }


/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::CreateForwardL()

    Description: Creating a forward message entry from a message that is passed 
                 in as a parameter. If the operation is successful, the forward 
                 message entry is left as the current entry of the MTM.

                 The context is being switched here so all unsaved changes to 
                 an old entry are lost!

    Return value: ETrue/EFalse if the operation was successfull or not

-------------------------------------------------------------------------------
*/
TBool CMMSDemo1Engine::CreateForwardL( TMsvId aMessageEntry )
    {
    iMessageReady = EFalse;
    // Set the given message as the current entry
    iMmsMtm->SwitchCurrentEntryL( aMessageEntry );

    // then create a forward message from the current msg.
    TMsvId parentId = KDrafts;                              // create fwd. msg. into Drafts folder
    
    TMsvPartList PartList(KMsvMessagePartDescription);      // including subject field
    CMsvOperationWait* wait = CMsvOperationWait::NewLC();   // left in CS
    CMsvOperation* oper = iMmsMtm->ForwardL(parentId, PartList, wait->iStatus);
    CleanupStack::PushL(oper);
    wait->Start();
    CActiveScheduler::Start();

    // see if any errors occured
    if(oper->iStatus.Int() != KErrNone)
        {
        // failed
        return EFalse;
        }

    // we can get the entry id from the progress info of the operation
    TPckgBuf<TMsvId> pkg;
    pkg.Copy(oper->ProgressL());
    TMsvId progress = 0;
    progress = pkg();

	// Load created message to iMmsMtm
    LoadMessageL(progress);

    CleanupStack::PopAndDestroy(2);  // wait, oper
    iMessageReady = ETrue;
    return ETrue;
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::AddTextObjectL()

    Description: Creating a new text attachment. 
                 This method creates a new text/plain type of an attachment
                 from the given TDesC parameter and filename.

    Return value: ID of the created attachment

-------------------------------------------------------------------------------
*/
TMsvId CMMSDemo1Engine::AddTextObjectL(const TDesC& aText, const TDesC& aFilename)
    {
    // blank id for the new attachment
    TMsvId AttId = KMsvNullIndexEntryId;

    // create the attachment
    iMmsMtm->CreateTextAttachmentL(AttId, aText, aFilename);

    iMmsMtm->SetAttachmentCharsetL(AttId, KMmsUtf8); // send text in Utf8 format

    return AttId;
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::AddTextObjectL()

    Description: Creating a new text attachment. 
                 This method creates a new text/plain type of an attachment
                 from the given TDesC parameter.

    Return value: ID of the created attachment

-------------------------------------------------------------------------------
*/
TMsvId CMMSDemo1Engine::AddTextObjectL(const TDesC& aText)
    {
    // blank id for the new attachment
    TMsvId AttId = KMsvNullIndexEntryId;

    // create without a file name
    iMmsMtm->CreateTextAttachmentL(AttId, aText);

    iMmsMtm->SetAttachmentCharsetL(AttId, KMmsUtf8); // send text in Utf8 format

    return AttId;
    }


/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::AddObjectL()

    Description: Creating a new attachment. 
                 This method calls another overload to create an attachment 
                 and then sets the desired mime type for the attachment.

    Return value: N/A

-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::AddObjectL(const TDesC& aPath, TDesC8& aAttMimeType)
    {
    // New id for the attachment, value is given from the MTM when att entry is
    // created.
    TMsvId AttId = KMsvNullIndexEntryId;
    // First create the attachment (calling to an overload of this method, see below)
    AddObjectL(aPath, AttId);
    // then add the mime type information
    iMmsMtm->SetAttachmentTypeL(AttId, aAttMimeType);
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::AddObjectL()

    Description: Creating a new attachment. 

    Return value: TMsvId of the created attachment entry in aNewAttId

-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::AddObjectL(const TDesC& aPath, TMsvId& aNewAttId)
    {
    // Create a new attachment under our message entry
    // we'll get a new id from the client MTM
    iMmsMtm->CreateAttachment2L(aNewAttId, aPath);
 
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::SendMessageL()

    Description: Send the current message through the MMS server MTM.
                 The message should be validated before calling SendMessageL().

    Return value: N/A

-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::SendMessageL()
    {

    // Start sending the message via the Server MTM to the MMS server
    CMsvOperationWait* wait = CMsvOperationWait::NewLC(); // left in CS
    wait->iStatus = KRequestPending;
    CMsvOperation* op = NULL;
    op = iMmsMtm->SendL( wait->iStatus );
    CleanupStack::PushL( op );
    wait->Start();
    CActiveScheduler::Start();

    // The following is to ignore the completion of other active objects. It is not
    // needed if the app has a command absorbing control.
    while( wait->iStatus.Int() == KRequestPending )
        {
        CActiveScheduler::Start();
        }

    CleanupStack::PopAndDestroy(2); // op, wait

    iMessageReady = EFalse;
    }


//
// This method is to be implemented in a future MMS demo
//
void CMMSDemo1Engine::GetServiceXxxParamL()    
    {
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::AddAddresseeL()

    Description: Add an addressee. If no type is given, addressee is typed
                 as To-addressee by default (see class definition).

    Return value: N/A

-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::AddAddresseeL(TDesC& aAddress, TAddresseeType aType)
    {
    // add a new addressee and define a type
    iMmsMtm->AddTypedAddresseeL(aAddress, (TMmsRecipients)aType);
    iMessageReady = ETrue;
    }


/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::SaveMessageL()

    Description: Save the current message. If you do not call this method, 
                 all changes made will be lost when the context is changed.
                 Also a new message is invisible as default (even after sending)
                 see below how to change the visibility flags.

    Return value: N/A

-------------------------------------------------------------------------------
*/
void CMMSDemo1Engine::SaveMessageL()
    {
    // IMPORTANT: Set visibility flags
    // after this the message will be visible to the user
    TMsvEntry ent = iMmsMtm->Entry().Entry();
    ent.SetInPreparation(EFalse);
    ent.SetVisible(ETrue);            
    iMmsMtm->Entry().ChangeL(ent);

    // Save message
    iMmsMtm->SaveMessageL();
    }

/*
-------------------------------------------------------------------------------

    CMMSDemo1Engine::LoadMessageL()

    Description: Load a message to the MTM. Message is loaded and set as current.

    Return value: TBool

-------------------------------------------------------------------------------
*/
TBool CMMSDemo1Engine::LoadMessageL(TMsvId aMessageEntry)
    {
    iMmsMtm->SwitchCurrentEntryL( aMessageEntry );
    
    iMmsMtm->LoadMessageL();

    // check unread value & change when necessary
    TMsvEntry tEntry = iMmsMtm->Entry().Entry();
    if(tEntry.Unread())
        {
        tEntry.SetUnread(EFalse);
        iMmsMtm->Entry().ChangeL(tEntry);
        // decrease new messages count
        if(iNewMessages > 0)
            iNewMessages--;

⌨️ 快捷键说明

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