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

📄 mmsexamplecontainer.cpp

📁 symbian 彩信发送例子,希望对大家有所帮助
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	EchoL(KCreatingMessage);
	
    // - 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.
    #ifdef __SERIES60_3X__ //3rd edition onwards
        iMmsMtm->CreateMessageL( iMmsMtm->DefaultServiceL()  );
	#else//1st and 2nd edition
	    iMmsMtm->CreateMessageL( iMmsMtm->DefaultSettingsL() );
	#endif
    CleanupStack::PopAndDestroy(); // entry
    
    // Setting recipients
    // use this to add the "To" recipients.
    iMmsMtm->AddAddresseeL( iRecipient->Des() );
    
    //Setting message subject
    _LIT(KMessageSubject, "MMS Example");
    iMmsMtm->SetSubjectL(KMessageSubject);
    
    // Message consists of one image
    #ifndef __HARDCODED_PATHS__ //3rd and 2nd edition
        TFileName attachmentFile(KPhoneRootPath);
        attachmentFile.Append(KDirPictures);
        TFileName fileName(KFileName);
        attachmentFile.Append(KFileName);
    #else//1st edition
        TFileName attachmentFile(KDirPictures);
        attachmentFile.Append(KFileName);
    #endif 
    
    TMsvEntry ent = iMmsMtm->Entry().Entry();
    // Set InPreparation to false
    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

  	#ifdef __SERIES60_3X__ //adding attachment 3rd edition onwards
      	//Save the changes
        iMmsMtm->SaveMessageL();
        
      	//Opening store
      	CMsvStore* store = iMmsMtm->Entry().EditStoreL();
    	CleanupStack::PushL(store);

    	RFile attachment;
    	//open attachment file
    	TInt error = attachment.Open( CCoeEnv::Static()->FsSession(), attachmentFile, EFileShareReadersOnly | EFileRead );
    	CleanupClosePushL( attachment );
    	
    	//Check that the attachment file exist.
    	if(error != KErrNone)
    		{
    		_LIT(KFileNotFound, "Attachment file not found!");
    		EchoL(KFileNotFound);
    		EchoL(attachmentFile);
    		
    		attachment.Close();
    		CleanupStack::PopAndDestroy(); // attachment
    		CleanupStack::PopAndDestroy(); // store
    		return EFalse;
    		}
    	else
    		{
    		//mime header
    		CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
    		CleanupStack::PushL( mimeHeaders );   
    		mimeHeaders->SetSuggestedFilenameL(fileName);

       	 	// Represents a single attachment and information about the attachment
     		CMsvAttachment* attaInfo = 
    			CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
    		CleanupStack::PushL( attaInfo );

    		//Mime Type
    		_LIT8(KMimeType, "image/jpeg");
    		TBufC8<10> mimeType(KMimeType);	

        	TMsvAttachmentId attachId = KMsvNullIndexEntryId;

    		//Attachment file must be an public folder (e.g. c:\Data\images)
        	iMmsMtm->CreateAttachment2L(
                                    *store,
                                    attachment,
                                    mimeType,
                                    *mimeHeaders,
                                    attaInfo,
                                    attachId );

        	CleanupStack::Pop( attaInfo ); // attaInfo
    		CleanupStack::PopAndDestroy(mimeHeaders); // mimeHeaders
    		
    		_LIT(KCreatingComplete, "Message created.");
    		EchoL(KCreatingComplete);
    		
    		store->CommitL();
    		attachment.Close();
    	
    		CleanupStack::PopAndDestroy(); // attachment
    		CleanupStack::PopAndDestroy(); // store
    		}
		
	#else //1st and 2nd edition
	
    	//Check that the attachment file exists.
    	if(!ConeUtils::FileExists(attachmentFile))
    		{
    		_LIT(KFileNotFound, "Attachment file not found!");
    		EchoL(KFileNotFound);
    		#ifdef EKA1//2nd edition
    			EchoL(KPhoneRootPath);
    			EchoL(KDirPictures);
    		#else//1st edition
    			EchoL(KDirPictures);
    		#endif

    		return EFalse;
    		}
    	else
    		{
    		//Create attatchment
    		TMsvId attachmentID = KMsvNullIndexEntryId;
        	iMmsMtm->CreateAttachment2L( attachmentID, attachmentFile );
        	
        	_LIT(KCreatingComplete, "Message created.");
    		EchoL(KCreatingComplete);
    		}
        iMmsMtm->SaveMessageL();
    #endif
    
    return ETrue;
	}
	
/* 
-----------------------------------------------------------------------------
    CMMSExampleContainer::SendMessageL()
    Sends the message.
    Return values: ETrue or EFalse
-----------------------------------------------------------------------------
*/
TBool CMMSExampleContainer::SendMessageL()
    {
	_LIT(KSendingMessage, "Sending message.");
	EchoL(KSendingMessage);

	// Start sending the message via the Server MTM to the MMS server
    CMsvOperationWait* wait = CMsvOperationWait::NewLC();
    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 == KRequestPending )
        {
        CActiveScheduler::Start();
        }

	#ifdef __WINS__
	_LIT(KSendingComplete, "Sending complete.");
	EchoL(KSendingComplete);
	_LIT(KOpenSent, "Open sent folder.");
	EchoL(KOpenSent);
	#endif

    CleanupStack::PopAndDestroy(2); // op, wait
	
    return ETrue;
    }

// ---------------------------------------------------------
// CRTEContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CMMSExampleContainer::CountComponentControls() const
    {
    return 1; // return number of controls inside this container
    }

// ---------------------------------------------------------
// CRTEContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
CCoeControl* CMMSExampleContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
			return iRtEd;
        default:
            return NULL;
        }
    }

// ---------------------------------------------------------
// OfferKeyEventL() 
// Distribute the key event to the Editor
// ---------------------------------------------------------
TKeyResponse CMMSExampleContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	if (iRtEd->IsFocused())
		{
		return iRtEd->OfferKeyEventL(aKeyEvent, aType);	
		}
	else
		{
		return EKeyWasNotConsumed;
		}
	}
	
// ---------------------------------------------------------
// EchoL(const TDesC &aMessage)
// Display information message.
// ---------------------------------------------------------
void CMMSExampleContainer::EchoL(const TDesC &aMessage)
	{
    iRtEd->RichText()->InsertL(0, aMessage);
    iRtEd->RichText()->InsertL(aMessage.Length(), CEditableText::ELineBreak);
    iRtEd->UpdateAllFieldsL();
    iRtEd->UpdateScrollBarsL();
	}


⌨️ 快捷键说明

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