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

📄 mmsexample.cpp

📁 Symbian OS MMS Example,希望和大家多多交流
💻 CPP
📖 第 1 页 / 共 2 页
字号:
-----------------------------------------------------------------------------

    CMMSExampleAppUi::HandleCommandL(TInt aCommand)

    Handle the commands from CBA and menu items

-----------------------------------------------------------------------------
*/
void CMMSExampleAppUi::HandleCommandL(TInt aCommand)
    {
    switch (aCommand)
        {
    case EMMSExampleCmdSend:
        CmdSendL();
        break;
    case EAknSoftkeyExit:
    case EClose:
        CmdExitL();
        break;
    default:
        break;
        }
    }


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

    CMMSExampleAppUi::CmdSendL()

    Handle send command  
    
-----------------------------------------------------------------------------
*/
void CMMSExampleAppUi::CmdSendL()
    {
    if (!InitializeCommunicationsL())
        {
        // Note that this message will be shown in emulator only!
        iEikonEnv->InfoMsg(_L("Problems in initializing\ncommunications."));
        return;
        }
    if (!SendMessageL())
        {
        // Note that this message will be shown in emulator only!
        iEikonEnv->InfoMsg(_L("Problems in sending\nmessage."));
        return;
        }
    }


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

    CMMSExampleAppUi::CmdExitL()
    
    Exit application
  
-----------------------------------------------------------------------------
*/

void CMMSExampleAppUi::CmdExitL()
    {
    CBaActiveScheduler::Exit();		// Call the CBaActiveScheduler's Exit function
                                    // that stops the application's thread and destroys it.
    }



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

    CMMSExampleAppUi::InitializeCommunicationsL()
    
    Initialize a new message and ask the user for a recipient address.

    Return values:      ETrue or EFalse

-----------------------------------------------------------------------------
*/
TBool CMMSExampleAppUi::InitializeCommunicationsL()
    { 
    // First the recipients address
    // we get it from a data query dialog.
    TBuf<20> addr = iRecipient->Des();
    CAknTextQueryDialog* telNumDialog = CAknTextQueryDialog::NewL(addr, CAknQueryDialog::ENoTone);

    if (!telNumDialog->ExecuteLD(R_MMSEXAMPLE_TEL_NUMBER_DIALOG))
        return EFalse;

    iRecipient->Des() = addr; // Note that the user can give both numeric and textual data in the query dialog,
                              // so the address can be a GSM number or an e-mail address.

    // set up a new message 
    CreateNewMessageL();

    return ETrue;
    }



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

    CMMSExampleAppUi::CreateNewMessageL()

    Creates a new message server entry and set up default values.

    Return values:      N/A

-----------------------------------------------------------------------------
*/
void CMMSExampleAppUi::CreateNewMessageL()
	{

    // - CMsvEntry accesses and acts upon a particular Message Server entry.
    // - NewL() does not create a new entry, but simply a new object to access an existing entry.
    // - It takes in as parameters the client's message server session,
    //   ID of the entry to access and initial sorting order of the children of the entry. 
	//
    CMsvEntry* entry = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId ,TMsvSelectionOrdering());
    CleanupStack::PushL(entry);

    // Set context to the parent folder (Outbox)
    iMmsMtm->SwitchCurrentEntryL( entry->EntryId() );

    // Create new message in the parent folder (Outbox) and set it as the current context.
    // choose the default service settings for Multimedia message sending (this is set in the Messaging
    // applications Settings menu)
    iMmsMtm->CreateMessageL( iMmsMtm->DefaultSettingsL() );

    CleanupStack::PopAndDestroy(); // entry
	}



/* 
-----------------------------------------------------------------------------
    CMMSExampleAppUi::SendMessageL()

    Prepares the message body and sends the message.

    Return values:      ETrue or EFalse

-----------------------------------------------------------------------------
*/
TBool CMMSExampleAppUi::SendMessageL()
    {
    // Setting recipients
    //
    // This method has no distinction betweed "To" and "Cc" recipients,
    // use this to add the "To" recipients.
    iMmsMtm->AddAddresseeL( iRecipient->Des() );

    // This example sends the message to only one address but here is the code how to
    // define a "Cc" addressee:
/*
    _LIT( KAddress2, "name.surname@company.com" );
    TBufC<20> address2( KAddress2 );
    iMmsMtm->AddTypedAddresseeL( address2, EMmsCc ); // typed addressee "Cc"
*/

    // Setting attachments (message parts)
    //
    // Our message consists of one image
    TMsvId attachmentID = KMsvNullIndexEntryId;
    TFileName attachmentFile( _L("c:\\system\\apps\\MMSExample\\mmsexample.jpg") );
    iMmsMtm->CreateAttachment2L( attachmentID, attachmentFile );

    // It is possible to give more specific data about the content,
    // for example to define attachment type:
/*
    TBufC8<20> content = _L8( "image/jpeg" );
    iMmsMtm->SetAttachmentTypeL( attachmentID, content );
*/

    // You can specify the message part that is the root of the presentation. Normally
    // this is SMIL or WML type of entity. If this is omitted then the message does
    // not have presentation part but contains just a bunch of equal media parts.
/*
    iMmsMtm->SetMessageRoot( attachmentID );
*/

    // Set InPreparation to false
    TMsvEntry ent = iMmsMtm->Entry().Entry();
    ent.SetInPreparation(EFalse);
    ent.SetVisible(ETrue);            // mark as visible, after this the message can be seen in Outbox and, after sending, in Sent folder.
    iMmsMtm->Entry().ChangeL(ent);    // Commit changes

    // Move message to "Sent" folder after sending
    //iMmsMtm->SetMoveToSent(EFalse); // This method has not been implemented. Therefore it is up to the designer to insure that all messages
                                      // created by a 3rd party application (especially invisible entries) will be cleaned from the folders.

    // Save changes (If you do not call this method, all changes made will be lost when the context is changed.)
    iMmsMtm->SaveMessageL();
    
    // 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 );
    wait->Start();
    CleanupStack::PushL( op );
    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

    return ETrue;
    }


//
// CMMSExampleDocument
//

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

    CMMSExampleDocument::NewL(

    2nd phase construction.

-----------------------------------------------------------------------------
*/
CMMSExampleDocument* CMMSExampleDocument::NewL(CEikApplication& aApp)
    {
    CMMSExampleDocument* self = new(ELeave) CMMSExampleDocument(aApp);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(); //self.
    return self;
    }

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

    CMMSExampleDocument::CMMSExampleDocument()

    C++ constructor

-----------------------------------------------------------------------------
*/
CMMSExampleDocument::CMMSExampleDocument(CEikApplication& aApp)
    : CEikDocument(aApp)
    {
    }

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

    CMMSExampleDocument::ConstructL()

    2nd phase constructor.

-----------------------------------------------------------------------------
*/
void CMMSExampleDocument::ConstructL()
    {    
    }

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

    CMMSExampleDocument::CreateAppUiL()

    Create new CMMSExampleAppUi object

    Return values:      CEikAppUi*

-----------------------------------------------------------------------------
*/
CEikAppUi* CMMSExampleDocument::CreateAppUiL()
    {
    return (new(ELeave) CMMSExampleAppUi);
    }


//
// CMMSExampleApplication
//

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

    CMMSExampleApplication::AppDllUid()

    Returns application UID of MMSExample application

-----------------------------------------------------------------------------
*/
TUid CMMSExampleApplication::AppDllUid() const
    {
    return KUidMMSExample;
    }

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

    CMMSExampleApplication::CreateDocumentL()

    Create new application document

    Return values:      CApaDocument*

-----------------------------------------------------------------------------
*/
CApaDocument* CMMSExampleApplication::CreateDocumentL()
    {
    return (CMMSExampleDocument::NewL(*this));
    }



//
// Functions for Application Architecture
//

EXPORT_C CApaApplication* NewApplication()
    {
    return (new CMMSExampleApplication);
    }


//
// DLL entry point
//

GLDEF_C TInt E32Dll(TDllReason)
    {
    return KErrNone;
    }

⌨️ 快捷键说明

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